blob: 48432bb3228f910d7882c7cad59c2f5c29e329ff [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)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100117#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100140#ifdef FEAT_MBYTE
141# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
142#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#define PV_MA OPT_BUF(BV_MA)
144#define PV_ML OPT_BUF(BV_ML)
145#define PV_MOD OPT_BUF(BV_MOD)
146#define PV_MPS OPT_BUF(BV_MPS)
147#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000148#ifdef FEAT_COMPL_FUNC
149# define PV_OFU OPT_BUF(BV_OFU)
150#endif
151#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
152#define PV_PI OPT_BUF(BV_PI)
153#ifdef FEAT_TEXTOBJ
154# define PV_QE OPT_BUF(BV_QE)
155#endif
156#define PV_RO OPT_BUF(BV_RO)
157#ifdef FEAT_SMARTINDENT
158# define PV_SI OPT_BUF(BV_SI)
159#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100160#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200223#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100230#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200253# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200254# define PV_TMS OPT_WIN(WV_TMS)
255#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200256#ifdef FEAT_SIGNS
257# define PV_SCL OPT_WIN(WV_SCL)
258#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000259
260/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261typedef enum
262{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000263 PV_NONE = 0,
264 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265} idopt_T;
266
267/*
268 * Options local to a window have a value local to a buffer and global to all
269 * buffers. Indicate this by setting "var" to VAR_WIN.
270 */
271#define VAR_WIN ((char_u *)-1)
272
273/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000274 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * Only to be used in option.c!
276 */
277static int p_ai;
278static int p_bin;
279#ifdef FEAT_MBYTE
280static int p_bomb;
281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282static char_u *p_bh;
283static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200308static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_et;
310#ifdef FEAT_MBYTE
311static char_u *p_fenc;
312#endif
313static char_u *p_ff;
314static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000315static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static long p_iminsert;
318static long p_imsearch;
319#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
320static char_u *p_inex;
321#endif
322#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
323static char_u *p_inde;
324static char_u *p_indk;
325#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000326#if defined(FEAT_EVAL)
327static char_u *p_fex;
328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000329static int p_inf;
330static char_u *p_isk;
331#ifdef FEAT_CRYPT
332static char_u *p_key;
333#endif
334#ifdef FEAT_LISP
335static int p_lisp;
336#endif
337static int p_ml;
338static int p_ma;
339static int p_mod;
340static char_u *p_mps;
341static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000343#ifdef FEAT_TEXTOBJ
344static char_u *p_qe;
345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_ro;
347#ifdef FEAT_SMARTINDENT
348static int p_si;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static long p_sts;
352#if defined(FEAT_SEARCHPATH)
353static char_u *p_sua;
354#endif
355static long p_sw;
356static int p_swf;
357#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000358static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000360#endif
361#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000362static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000363static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000364static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365#endif
366static long p_ts;
367static long p_tw;
368static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200369#ifdef FEAT_PERSISTENT_UNDO
370static int p_udf;
371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372static long p_wm;
373#ifdef FEAT_KEYMAP
374static char_u *p_keymap;
375#endif
376
377/* Saved values for when 'bin' is set. */
378static int p_et_nobin;
379static int p_ml_nobin;
380static long p_tw_nobin;
381static long p_wm_nobin;
382
383/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200384static int p_ai_nopaste;
385static int p_et_nopaste;
386static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387static long p_tw_nopaste;
388static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389
390struct vimoption
391{
392 char *fullname; /* full option name */
393 char *shortname; /* permissible abbreviation */
394 long_u flags; /* see below */
395 char_u *var; /* global option: pointer to variable;
396 * window-local option: VAR_WIN;
397 * buffer-local option: global value */
398 idopt_T indir; /* global option: PV_NONE;
399 * local option: indirect option index */
400 char_u *def_val[2]; /* default values for variable (vi and vim) */
401#ifdef FEAT_EVAL
402 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000403# define SCRIPTID_INIT , 0
404#else
405# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000406#endif
407};
408
409#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
410#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
411
412/*
413 * Flags
414 */
415#define P_BOOL 0x01 /* the option is boolean */
416#define P_NUM 0x02 /* the option is numeric */
417#define P_STRING 0x04 /* the option is a string */
418#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000419 must use free_string_option() when
420 assigning new value. Not set if default is
421 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
423 never be used for local or hidden options! */
424#define P_NODEFAULT 0x40 /* don't set to default value */
425#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
426 use vim_free() when assigning new value */
427#define P_WAS_SET 0x100 /* option has been set/reset */
428#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
429#define P_VI_DEF 0x400 /* Use Vi default for Vim */
430#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
431
432 /* when option changed, what to display: */
433#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100434#define P_RWIN 0x2000 /* redraw current window and recompute text */
435#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436#define P_RALL 0x6000 /* redraw all windows */
437#define P_RCLR 0x7000 /* clear and redraw all */
438
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200439#define P_COMMA 0x8000 /* comma separated list */
440#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
441 * commas */
442#define P_NODUP 0x20000L /* don't allow duplicate strings */
443#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200445#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x100000L /* expand default value with _() */
447#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
448#define P_NFNAME 0x400000L /* only normal file name chars allowed */
449#define P_INSECURE 0x800000L /* option was set from a modeline */
450#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100451 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_NO_ML 0x2000000L /* not allowed in modeline */
453#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200454 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100455#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100456#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000458#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
459
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000460/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
461 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100462#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000463# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000464#else
465# define ISP_LATIN1 (char_u *)"@,161-255"
466#endif
467
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200468# 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 +0000469
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100470/* Default python version for pyx* commands */
471#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
472# define DEFAULT_PYTHON_VER 0
473#elif defined(FEAT_PYTHON3)
474# define DEFAULT_PYTHON_VER 3
475#elif defined(FEAT_PYTHON)
476# define DEFAULT_PYTHON_VER 2
477#else
478# define DEFAULT_PYTHON_VER 0
479#endif
480
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481/*
482 * options[] is initialized here.
483 * The order of the options MUST be alphabetic for ":set all" and findoption().
484 * All option names MUST start with a lowercase letter (for findoption()).
485 * Exception: "t_" options are at the end.
486 * The options with a NULL variable are 'hidden': a set command for them is
487 * ignored and they are not printed.
488 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100489static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200491 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492#ifdef FEAT_RIGHTLEFT
493 (char_u *)&p_aleph, PV_NONE,
494#else
495 (char_u *)NULL, PV_NONE,
496#endif
497 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100498#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 (char_u *)128L,
500#else
501 (char_u *)224L,
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200505#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 (char_u *)&p_antialias, PV_NONE,
507 {(char_u *)FALSE, (char_u *)FALSE}
508#else
509 (char_u *)NULL, PV_NONE,
510 {(char_u *)FALSE, (char_u *)FALSE}
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200513 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514#ifdef FEAT_ARABIC
515 (char_u *)VAR_WIN, PV_ARAB,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521#ifdef FEAT_ARABIC
522 (char_u *)&p_arshape, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
528#ifdef FEAT_RIGHTLEFT
529 (char_u *)&p_ari, PV_NONE,
530#else
531 (char_u *)NULL, PV_NONE,
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
535#ifdef FEAT_FKMAP
536 (char_u *)&p_altkeymap, PV_NONE,
537#else
538 (char_u *)NULL, PV_NONE,
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
542#if defined(FEAT_MBYTE)
543 (char_u *)&p_ambw, PV_NONE,
544 {(char_u *)"single", (char_u *)0L}
545#else
546 (char_u *)NULL, PV_NONE,
547 {(char_u *)0L, (char_u *)0L}
548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100551#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100553 {(char_u *)FALSE, (char_u *)0L}
554#else
555 (char_u *)NULL, PV_NONE,
556 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000566 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
576 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100577#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 (char_u *)"dark",
579#else
580 (char_u *)"light",
581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200590 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591#ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593#else
594 {(char_u *)"auto", (char_u *)"auto"}
595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
598 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000601 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bex, PV_NONE,
603 {
604#ifdef VMS
605 (char_u *)"_",
606#else
607 (char_u *)"~",
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200610 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_WILDIGN
612 (char_u *)&p_bsk, PV_NONE,
613 {(char_u *)"", (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100620#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100622 {(char_u *)600L, (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100627 SCRIPTID_INIT},
628 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100629#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 (char_u *)&p_beval, PV_NONE,
631 {(char_u *)FALSE, (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
635#endif
636 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100637 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100638#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100639 (char_u *)&p_bevalterm, PV_NONE,
640 {(char_u *)FALSE, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
644#endif
645 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
647#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
648 (char_u *)&p_bexpr, PV_BEXPR,
649 {(char_u *)"", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 {"beautify", "bf", P_BOOL|P_VI_DEF,
656 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200658 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
659 (char_u *)&p_bo, PV_NONE,
660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
662 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000666 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
668#ifdef FEAT_MBYTE
669 (char_u *)&p_bomb, PV_BOMB,
670#else
671 (char_u *)NULL, PV_NONE,
672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
675#ifdef FEAT_LINEBREAK
676 (char_u *)&p_breakat, PV_NONE,
677 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)0L, (char_u *)0L}
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200683 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
684#ifdef FEAT_LINEBREAK
685 (char_u *)VAR_WIN, PV_BRI,
686 {(char_u *)FALSE, (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
691 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200692 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
693 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRIOPT,
696 {(char_u *)"", (char_u *)NULL}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)"", (char_u *)NULL}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
703#ifdef FEAT_BROWSE
704 (char_u *)&p_bsdir, PV_NONE,
705 {(char_u *)"last", (char_u *)0L}
706#else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)0L, (char_u *)0L}
709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000710 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 (char_u *)&p_bh, PV_BH,
713 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
716 (char_u *)&p_bl, PV_BL,
717 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bt, PV_BT,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200723 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000724#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 (char_u *)&p_cmp, PV_NONE,
726 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
733#ifdef FEAT_SEARCHPATH
734 (char_u *)&p_cdpath, PV_NONE,
735 {(char_u *)",,", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cedit", NULL, P_STRING,
742#ifdef FEAT_CMDWIN
743 (char_u *)&p_cedit, PV_NONE,
744 {(char_u *)"", (char_u *)CTRL_F_STR}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
751#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
752 (char_u *)&p_ccv, PV_NONE,
753 {(char_u *)"", (char_u *)0L}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
760#ifdef FEAT_CINDENT
761 (char_u *)&p_cin, PV_CIN,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cink, PV_CINK,
769 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cino, PV_CINO,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000781 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
784 (char_u *)&p_cinw, PV_CINW,
785 {(char_u *)"if,else,while,do,for,switch",
786 (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#ifdef FEAT_CLIPBOARD
794 (char_u *)&p_cb, PV_NONE,
795# ifdef FEAT_XCLIPBOARD
796 {(char_u *)"autoselect,exclude:cons\\|linux",
797 (char_u *)0L}
798# else
799 {(char_u *)"", (char_u *)0L}
800# endif
801#else
802 (char_u *)NULL, PV_NONE,
803 {(char_u *)"", (char_u *)0L}
804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000805 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
807 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
810#ifdef FEAT_CMDWIN
811 (char_u *)&p_cwh, PV_NONE,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200816 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200817#ifdef FEAT_SYN_HL
818 (char_u *)VAR_WIN, PV_CC,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
822 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
824 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
827 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828#ifdef FEAT_COMMENTS
829 (char_u *)&p_com, PV_COM,
830 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
831 (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200837 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_FOLDING
839 (char_u *)&p_cms, PV_CMS,
840 {(char_u *)"/*%s*/", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000846 /* P_PRI_MKRC isn't needed here, optval_default()
847 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"compatible", "cp", P_BOOL|P_RALL,
849 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000850 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200851 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852#ifdef FEAT_INS_EXPAND
853 (char_u *)&p_cpt, PV_CPT,
854 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)0L, (char_u *)0L}
858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200862 (char_u *)VAR_WIN, PV_COCU,
863 {(char_u *)"", (char_u *)NULL}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)NULL, (char_u *)0L}
867#endif
868 SCRIPTID_INIT},
869 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
870#ifdef FEAT_CONCEAL
871 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)0L, (char_u *)0L}
876 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000877 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
878#ifdef FEAT_COMPL_FUNC
879 (char_u *)&p_cfu, PV_CFU,
880 {(char_u *)"", (char_u *)0L}
881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200886 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000887#ifdef FEAT_INS_EXPAND
888 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000889 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"confirm", "cf", P_BOOL|P_VI_DEF,
896#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
897 (char_u *)&p_confirm, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
906 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
909 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
911 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200914 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#else
917 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200918 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200919#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_cspc, PV_NONE,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000927 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
929#ifdef FEAT_CSCOPE
930 (char_u *)&p_csprg, PV_NONE,
931 {(char_u *)"cscope", (char_u *)0L}
932#else
933 (char_u *)NULL, PV_NONE,
934 {(char_u *)0L, (char_u *)0L}
935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000936 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200937 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
939 (char_u *)&p_csqf, PV_NONE,
940 {(char_u *)"", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200946 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_csre, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
952 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_cst, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csto, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_CSCOPE
969 (char_u *)&p_csverbose, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200974 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200975 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200976 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000977 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
978#ifdef FEAT_SYN_HL
979 (char_u *)VAR_WIN, PV_CUC,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100984 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985#ifdef FEAT_SYN_HL
986 (char_u *)VAR_WIN, PV_CUL,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"debug", NULL, P_STRING|P_VI_DEF,
992 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200994 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000996 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000997 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1004#ifdef FEAT_MBYTE
1005 (char_u *)&p_deco, PV_NONE,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001010 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001012 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#else
1014 (char_u *)NULL, PV_NONE,
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1018#ifdef FEAT_DIFF
1019 (char_u *)VAR_WIN, PV_DIFF,
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 Moolenaar913077c2012-03-28 19:59:04 +02001024 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1026 (char_u *)&p_dex, PV_NONE,
1027 {(char_u *)"", (char_u *)0L}
1028#else
1029 (char_u *)NULL, PV_NONE,
1030 {(char_u *)0L, (char_u *)0L}
1031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001033 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1034 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035#ifdef FEAT_DIFF
1036 (char_u *)&p_dip, PV_NONE,
1037 {(char_u *)"filler", (char_u *)NULL}
1038#else
1039 (char_u *)NULL, PV_NONE,
1040 {(char_u *)"", (char_u *)NULL}
1041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1044#ifdef FEAT_DIGRAPHS
1045 (char_u *)&p_dg, PV_NONE,
1046#else
1047 (char_u *)NULL, PV_NONE,
1048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1051 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_ead, PV_NONE,
1059 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1062 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001064 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1065#if defined(FEAT_MBYTE)
1066 (char_u *)&p_emoji, PV_NONE,
1067 {(char_u *)TRUE, (char_u *)0L}
1068#else
1069 (char_u *)NULL, PV_NONE,
1070 {(char_u *)0L, (char_u *)0L}
1071#endif
1072 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001073 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074#ifdef FEAT_MBYTE
1075 (char_u *)&p_enc, PV_NONE,
1076 {(char_u *)ENC_DFLT, (char_u *)0L}
1077#else
1078 (char_u *)NULL, PV_NONE,
1079 {(char_u *)0L, (char_u *)0L}
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1083 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1086 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001089 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1092 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1095#ifdef FEAT_QUICKFIX
1096 (char_u *)&p_ef, PV_NONE,
1097 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1098#else
1099 (char_u *)NULL, PV_NONE,
1100 {(char_u *)NULL, (char_u *)0L}
1101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001103 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001105 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#else
1108 (char_u *)NULL, PV_NONE,
1109 {(char_u *)NULL, (char_u *)0L}
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"esckeys", "ek", P_BOOL|P_VIM,
1113 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 (char_u *)&p_ei, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1119 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1122 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001124 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1125 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fenc, PV_FENC,
1128 {(char_u *)"", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_MBYTE
1136 (char_u *)&p_fencs, PV_NONE,
1137 {(char_u *)"ucs-bom", (char_u *)0L}
1138#else
1139 (char_u *)NULL, PV_NONE,
1140 {(char_u *)0L, (char_u *)0L}
1141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001143 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1144 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1150 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001151 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1152 (char_u *)&p_fic, PV_NONE,
1153 {
1154#ifdef CASE_INSENSITIVE_FILENAME
1155 (char_u *)TRUE,
1156#else
1157 (char_u *)FALSE,
1158#endif
1159 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001160 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ft, PV_FT,
1162 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001164 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 (char_u *)&p_fcs, PV_NONE,
1166 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001168 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1169 (char_u *)&p_fixeol, PV_FIXEOL,
1170 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1172#ifdef FEAT_FKMAP
1173 (char_u *)&p_fkmap, PV_NONE,
1174#else
1175 (char_u *)NULL, PV_NONE,
1176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"flash", "fl", P_BOOL|P_VI_DEF,
1179 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001181 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001182#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001184 {(char_u *)"", (char_u *)0L}
1185#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188#endif
1189 SCRIPTID_INIT},
1190 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1191#ifdef FEAT_FOLDING
1192 (char_u *)VAR_WIN, PV_FDC,
1193 {(char_u *)FALSE, (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
1198 SCRIPTID_INIT},
1199 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1200#ifdef FEAT_FOLDING
1201 (char_u *)VAR_WIN, PV_FEN,
1202 {(char_u *)TRUE, (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
1207 SCRIPTID_INIT},
1208 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1209#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1210 (char_u *)VAR_WIN, PV_FDE,
1211 {(char_u *)"0", (char_u *)NULL}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)"#", (char_u *)NULL}
1221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
1225 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001229 {(char_u *)0L, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
1234 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001235 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001238 {(char_u *)-1L, (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
1243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001244 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001245 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001246#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001249#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 SCRIPTID_INIT},
1254 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1255#ifdef FEAT_FOLDING
1256 (char_u *)VAR_WIN, PV_FDM,
1257 {(char_u *)"manual", (char_u *)NULL}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
1262 SCRIPTID_INIT},
1263 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1264#ifdef FEAT_FOLDING
1265 (char_u *)VAR_WIN, PV_FML,
1266 {(char_u *)1L, (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
1271 SCRIPTID_INIT},
1272 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1273#ifdef FEAT_FOLDING
1274 (char_u *)VAR_WIN, PV_FDN,
1275 {(char_u *)20L, (char_u *)0L}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)NULL, (char_u *)0L}
1279#endif
1280 SCRIPTID_INIT},
1281 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1282#ifdef FEAT_FOLDING
1283 (char_u *)&p_fdo, PV_NONE,
1284 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1285 (char_u *)0L}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
1290 SCRIPTID_INIT},
1291 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1292#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1293 (char_u *)VAR_WIN, PV_FDT,
1294 {(char_u *)"foldtext()", (char_u *)NULL}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)NULL, (char_u *)0L}
1298#endif
1299 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001300 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001301#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001302 (char_u *)&p_fex, PV_FEX,
1303 {(char_u *)"", (char_u *)0L}
1304#else
1305 (char_u *)NULL, PV_NONE,
1306 {(char_u *)0L, (char_u *)0L}
1307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1310 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1312 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001313 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1314 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1316 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001318 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001320 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1321#ifdef HAVE_FSYNC
1322 (char_u *)&p_fs, PV_NONE,
1323 {(char_u *)TRUE, (char_u *)0L}
1324#else
1325 (char_u *)NULL, PV_NONE,
1326 {(char_u *)FALSE, (char_u *)0L}
1327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1330 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"graphic", "gr", P_BOOL|P_VI_DEF,
1333 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001335 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#ifdef FEAT_QUICKFIX
1337 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)NULL, (char_u *)0L}
1342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1345#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001346 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {
1348# ifdef WIN3264
1349 /* may be changed to "grep -n" in os_win32.c */
1350 (char_u *)"findstr /n",
1351# else
1352# ifdef UNIX
1353 /* Add an extra file name so that grep will always
1354 * insert a file name in the match line. */
1355 (char_u *)"grep -n $* /dev/null",
1356# else
1357# ifdef VMS
1358 (char_u *)"SEARCH/NUMBERS ",
1359# else
1360 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361# endif
1362# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001370 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371#ifdef CURSOR_SHAPE
1372 (char_u *)&p_guicursor, PV_NONE,
1373 {
1374# ifdef FEAT_GUI
1375 (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 +01001376# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1378# endif
1379 (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001385 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#ifdef FEAT_GUI
1387 (char_u *)&p_guifont, PV_NONE,
1388 {(char_u *)"", (char_u *)0L}
1389#else
1390 (char_u *)NULL, PV_NONE,
1391 {(char_u *)NULL, (char_u *)0L}
1392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001394 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1396 (char_u *)&p_guifontset, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001403 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1405 (char_u *)&p_guifontwide, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)NULL, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001413#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 (char_u *)&p_ghr, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001418 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001420#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001422# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001423 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001425 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426# endif
1427#else
1428 (char_u *)NULL, PV_NONE,
1429 {(char_u *)NULL, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"guipty", NULL, P_BOOL|P_VI_DEF,
1433#if defined(FEAT_GUI)
1434 (char_u *)&p_guipty, PV_NONE,
1435#else
1436 (char_u *)NULL, PV_NONE,
1437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001438 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001439 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001440#if defined(FEAT_GUI_TABLINE)
1441 (char_u *)&p_gtl, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)NULL, (char_u *)0L}
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001448 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001449#if defined(FEAT_GUI_TABLINE)
1450 (char_u *)&p_gtt, PV_NONE,
1451 {(char_u *)"", (char_u *)0L}
1452#else
1453 (char_u *)NULL, PV_NONE,
1454 {(char_u *)NULL, (char_u *)0L}
1455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001456 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1458 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1461 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001462 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1463 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001467 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468#ifdef FEAT_MULTI_LANG
1469 (char_u *)&p_hlg, PV_NONE,
1470 {(char_u *)"", (char_u *)0L}
1471#else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)0L, (char_u *)0L}
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"hidden", "hid", P_BOOL|P_VI_DEF,
1477 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001481 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1482 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 {"history", "hi", P_NUM|P_VIM,
1484 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001485 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1487#ifdef FEAT_RIGHTLEFT
1488 (char_u *)&p_hkmap, PV_NONE,
1489#else
1490 (char_u *)NULL, PV_NONE,
1491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1494#ifdef FEAT_RIGHTLEFT
1495 (char_u *)&p_hkmapp, PV_NONE,
1496#else
1497 (char_u *)NULL, PV_NONE,
1498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1501 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"icon", NULL, P_BOOL|P_VI_DEF,
1504#ifdef FEAT_TITLE
1505 (char_u *)&p_icon, PV_NONE,
1506#else
1507 (char_u *)NULL, PV_NONE,
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 {"iconstring", NULL, P_STRING|P_VI_DEF,
1511#ifdef FEAT_TITLE
1512 (char_u *)&p_iconstring, PV_NONE,
1513#else
1514 (char_u *)NULL, PV_NONE,
1515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001516 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1518 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001520 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001521#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001522 (char_u *)&p_imaf, PV_NONE,
1523 {(char_u *)"", (char_u *)NULL}
1524# else
1525 (char_u *)NULL, PV_NONE,
1526 {(char_u *)NULL, (char_u *)0L}
1527# endif
1528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001530#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 (char_u *)&p_imak, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001537#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 (char_u *)&p_imcmdline, PV_NONE,
1539#else
1540 (char_u *)NULL, PV_NONE,
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001544#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 (char_u *)&p_imdisable, PV_NONE,
1546#else
1547 (char_u *)NULL, PV_NONE,
1548#endif
1549#ifdef __sgi
1550 {(char_u *)TRUE, (char_u *)0L}
1551#else
1552 {(char_u *)FALSE, (char_u *)0L}
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"iminsert", "imi", P_NUM|P_VI_DEF,
1556 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 {"imsearch", "ims", P_NUM|P_VI_DEF,
1560 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001561 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001563 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001564#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001565 (char_u *)&p_imsf, PV_NONE,
1566 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001567#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001570#endif
1571 SCRIPTID_INIT},
1572 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1573#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1574 (char_u *)&p_imst, PV_NONE,
1575 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1576#else
1577 (char_u *)NULL, PV_NONE,
1578 {(char_u *)0L, (char_u *)0L}
1579#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1582#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001583 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1585#else
1586 (char_u *)NULL, PV_NONE,
1587 {(char_u *)0L, (char_u *)0L}
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1591#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1592 (char_u *)&p_inex, PV_INEX,
1593 {(char_u *)"", (char_u *)0L}
1594#else
1595 (char_u *)NULL, PV_NONE,
1596 {(char_u *)0L, (char_u *)0L}
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1600 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1603#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1604 (char_u *)&p_inde, PV_INDE,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001611 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1613 (char_u *)&p_indk, PV_INDK,
1614 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"infercase", "inf", P_BOOL|P_VI_DEF,
1621 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1624 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1627 (char_u *)&p_isf, PV_NONE,
1628 {
1629#ifdef BACKSLASH_IN_FILENAME
1630 /* Excluded are: & and ^ are special in cmd.exe
1631 * ( and ) are used in text separating fnames */
1632 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1633#else
1634# ifdef AMIGA
1635 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1636# else
1637# ifdef VMS
1638 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1639# else /* UNIX et al. */
1640# ifdef EBCDIC
1641 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1642# else
1643 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1644# endif
1645# endif
1646# endif
1647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001648 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1650 (char_u *)&p_isi, PV_NONE,
1651 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001652#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,48-57,_,128-167,224-235",
1654#else
1655# ifdef EBCDIC
1656 /* TODO: EBCDIC Check this! @ == isalpha()*/
1657 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1658 "112-120,128,140-142,156,158,172,"
1659 "174,186,191,203-207,219-225,235-239,"
1660 "251-254",
1661# else
1662 (char_u *)"@,48-57,_,192-255",
1663# endif
1664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001665 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1667 (char_u *)&p_isk, PV_ISK,
1668 {
1669#ifdef EBCDIC
1670 (char_u *)"@,240-249,_",
1671 /* TODO: EBCDIC Check this! @ == isalpha()*/
1672 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1673 "112-120,128,140-142,156,158,172,"
1674 "174,186,191,203-207,219-225,235-239,"
1675 "251-254",
1676#else
1677 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001678# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 (char_u *)"@,48-57,_,128-167,224-235"
1680# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001681 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682# endif
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1686 (char_u *)&p_isp, PV_NONE,
1687 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001688#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)"@,~-255",
1690#else
1691# ifdef EBCDIC
1692 /* all chars above 63 are printable */
1693 (char_u *)"63-255",
1694# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001695 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696# endif
1697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001698 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1700 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1703#ifdef FEAT_CRYPT
1704 (char_u *)&p_key, PV_KEY,
1705 {(char_u *)"", (char_u *)0L}
1706#else
1707 (char_u *)NULL, PV_NONE,
1708 {(char_u *)0L, (char_u *)0L}
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001711 {"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 +00001712#ifdef FEAT_KEYMAP
1713 (char_u *)&p_keymap, PV_KMAP,
1714 {(char_u *)"", (char_u *)0L}
1715#else
1716 (char_u *)NULL, PV_NONE,
1717 {(char_u *)"", (char_u *)0L}
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001720 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001724 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001726#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 (char_u *)":help",
1728#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001729# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001731# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001732# ifdef USEMAN_S
1733 (char_u *)"man -s",
1734# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001736# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737# endif
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001740 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741#ifdef FEAT_LANGMAP
1742 (char_u *)&p_langmap, PV_NONE,
1743 {(char_u *)"", /* unmatched } */
1744#else
1745 (char_u *)NULL, PV_NONE,
1746 {(char_u *)NULL,
1747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001749 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1751 (char_u *)&p_lm, PV_NONE,
1752#else
1753 (char_u *)NULL, PV_NONE,
1754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001756 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1757#ifdef FEAT_LANGMAP
1758 (char_u *)&p_lnr, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
1762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001763 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1764#ifdef FEAT_LANGMAP
1765 (char_u *)&p_lrm, PV_NONE,
1766#else
1767 (char_u *)NULL, PV_NONE,
1768#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001769 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1774 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1777#ifdef FEAT_LINEBREAK
1778 (char_u *)VAR_WIN, PV_LBR,
1779#else
1780 (char_u *)NULL, PV_NONE,
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1784 (char_u *)&Rows, PV_NONE,
1785 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001786#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 (char_u *)25L,
1788#else
1789 (char_u *)24L,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1793#ifdef FEAT_GUI
1794 (char_u *)&p_linespace, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
1798#ifdef FEAT_GUI_W32
1799 {(char_u *)1L, (char_u *)0L}
1800#else
1801 {(char_u *)0L, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lisp", NULL, P_BOOL|P_VI_DEF,
1805#ifdef FEAT_LISP
1806 (char_u *)&p_lisp, PV_LISP,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001811 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001813 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1815#else
1816 (char_u *)NULL, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1821 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001823 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1827 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001829 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001830#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001831 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001832 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001833#else
1834 (char_u *)NULL, PV_NONE,
1835 {(char_u *)"", (char_u *)0L}
1836#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001837 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001838 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001839#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001840 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001841 {(char_u *)TRUE, (char_u *)0L}
1842#else
1843 (char_u *)NULL, PV_NONE,
1844 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001845#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001846 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"magic", NULL, P_BOOL|P_VI_DEF,
1848 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001850 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851#ifdef FEAT_QUICKFIX
1852 (char_u *)&p_mef, PV_NONE,
1853 {(char_u *)"", (char_u *)0L}
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)NULL, (char_u *)0L}
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001859 {"makeencoding","menc", P_STRING|P_VI_DEF,
1860#ifdef FEAT_MBYTE
1861 (char_u *)&p_menc, PV_MENC,
1862 {(char_u *)"", (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
1867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1869#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001870 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871# ifdef VMS
1872 {(char_u *)"MMS", (char_u *)0L}
1873# else
1874 {(char_u *)"make", (char_u *)0L}
1875# endif
1876#else
1877 (char_u *)NULL, PV_NONE,
1878 {(char_u *)NULL, (char_u *)0L}
1879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001881 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1884 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"matchtime", "mat", P_NUM|P_VI_DEF,
1886 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001888 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001889#ifdef FEAT_MBYTE
1890 (char_u *)&p_mco, PV_NONE,
1891#else
1892 (char_u *)NULL, PV_NONE,
1893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1896#ifdef FEAT_EVAL
1897 (char_u *)&p_mfd, PV_NONE,
1898#else
1899 (char_u *)NULL, PV_NONE,
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1903 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"maxmem", "mm", P_NUM|P_VI_DEF,
1906 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1908 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001909 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1910 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1913 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"menuitems", "mis", P_NUM|P_VI_DEF,
1917#ifdef FEAT_MENU
1918 (char_u *)&p_mis, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"mesg", NULL, P_BOOL|P_VI_DEF,
1924 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001926 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001927#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001928 (char_u *)&p_msm, PV_NONE,
1929 {(char_u *)"460000,2000,500", (char_u *)0L}
1930#else
1931 (char_u *)NULL, PV_NONE,
1932 {(char_u *)0L, (char_u *)0L}
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"modeline", "ml", P_BOOL|P_VIM,
1936 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"modelines", "mls", P_NUM|P_VI_DEF,
1939 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1942 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1945 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"more", NULL, P_BOOL|P_VIM,
1948 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1951 (char_u *)&p_mouse, PV_NONE,
1952 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001953#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)"a",
1955#else
1956 (char_u *)"",
1957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1960#ifdef FEAT_GUI
1961 (char_u *)&p_mousef, PV_NONE,
1962#else
1963 (char_u *)NULL, PV_NONE,
1964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1967#ifdef FEAT_GUI
1968 (char_u *)&p_mh, PV_NONE,
1969#else
1970 (char_u *)NULL, PV_NONE,
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1974 (char_u *)&p_mousem, PV_NONE,
1975 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001976#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 (char_u *)"popup",
1978#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001979# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 (char_u *)"popup_setpos",
1981# else
1982 (char_u *)"extend",
1983# endif
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001986 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987#ifdef FEAT_MOUSESHAPE
1988 (char_u *)&p_mouseshape, PV_NONE,
1989 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1990#else
1991 (char_u *)NULL, PV_NONE,
1992 {(char_u *)NULL, (char_u *)0L}
1993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1996 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001998 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1999#if defined(DYNAMIC_MZSCHEME)
2000 (char_u *)&p_mzschemedll, PV_NONE,
2001 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)"", (char_u *)0L}
2005#endif
2006 SCRIPTID_INIT},
2007 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2008#if defined(DYNAMIC_MZSCHEME)
2009 (char_u *)&p_mzschemegcdll, PV_NONE,
2010 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)"", (char_u *)0L}
2014#endif
2015 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002016 {"mzquantum", "mzq", P_NUM,
2017#ifdef FEAT_MZSCHEME
2018 (char_u *)&p_mzq, PV_NONE,
2019#else
2020 (char_u *)NULL, PV_NONE,
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"novice", NULL, P_BOOL|P_VI_DEF,
2024 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002026 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002028 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2031 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002033 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2034#ifdef FEAT_LINEBREAK
2035 (char_u *)VAR_WIN, PV_NUW,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002040 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002041#ifdef FEAT_COMPL_FUNC
2042 (char_u *)&p_ofu, PV_OFU,
2043 {(char_u *)"", (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)0L, (char_u *)0L}
2047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"open", NULL, P_BOOL|P_VI_DEF,
2050 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002052 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002053#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002054 (char_u *)&p_odev, PV_NONE,
2055#else
2056 (char_u *)NULL, PV_NONE,
2057#endif
2058 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002060 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2061 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"optimize", "opt", P_BOOL|P_VI_DEF,
2064 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002068 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002069 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2070 |P_SECURE,
2071 (char_u *)&p_pp, PV_NONE,
2072 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 {"paragraphs", "para", P_STRING|P_VI_DEF,
2075 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002076 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002078 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2082 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2085#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2086 (char_u *)&p_pex, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)0L, (char_u *)0L}
2091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002093 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002097 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002099#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)".,,",
2101#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002105 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002106#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002107 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002108 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002112#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002113 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2115 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002117 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002118#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 (char_u *)&p_pvh, PV_NONE,
2120#else
2121 (char_u *)NULL, PV_NONE,
2122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002125#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 (char_u *)VAR_WIN, PV_PVW,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002131 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#ifdef FEAT_PRINTER
2133 (char_u *)&p_pdev, PV_NONE,
2134 {(char_u *)"", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"printencoding", "penc", P_STRING|P_VI_DEF,
2141#ifdef FEAT_POSTSCRIPT
2142 (char_u *)&p_penc, PV_NONE,
2143 {(char_u *)"", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002149 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150#ifdef FEAT_POSTSCRIPT
2151 (char_u *)&p_pexpr, PV_NONE,
2152 {(char_u *)"", (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)NULL, (char_u *)0L}
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"printfont", "pfn", P_STRING|P_VI_DEF,
2159#ifdef FEAT_PRINTER
2160 (char_u *)&p_pfn, PV_NONE,
2161 {
2162# ifdef MSWIN
2163 (char_u *)"Courier_New:h10",
2164# else
2165 (char_u *)"courier",
2166# endif
2167 (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2174#ifdef FEAT_PRINTER
2175 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002176 /* untranslated to avoid problems when 'encoding'
2177 * is changed */
2178 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#else
2180 (char_u *)NULL, PV_NONE,
2181 {(char_u *)NULL, (char_u *)0L}
2182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002184 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2185#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2186 (char_u *)&p_pmcs, PV_NONE,
2187 {(char_u *)"", (char_u *)0L}
2188#else
2189 (char_u *)NULL, PV_NONE,
2190 {(char_u *)NULL, (char_u *)0L}
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002193 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2194#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2195 (char_u *)&p_pmfn, PV_NONE,
2196 {(char_u *)"", (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002202 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203#ifdef FEAT_PRINTER
2204 (char_u *)&p_popt, PV_NONE,
2205 {(char_u *)"", (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002212 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002214 {"pumheight", "ph", P_NUM|P_VI_DEF,
2215#ifdef FEAT_INS_EXPAND
2216 (char_u *)&p_ph, PV_NONE,
2217#else
2218 (char_u *)NULL, PV_NONE,
2219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002221 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2222#ifdef FEAT_INS_EXPAND
2223 (char_u *)&p_pw, PV_NONE,
2224#else
2225 (char_u *)NULL, PV_NONE,
2226#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002227 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002228 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002229#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002230 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002231 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002232#else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002235#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002237 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2238#if defined(FEAT_PYTHON3)
2239 (char_u *)&p_py3home, PV_NONE,
2240 {(char_u *)"", (char_u *)0L}
2241#else
2242 (char_u *)NULL, PV_NONE,
2243 {(char_u *)NULL, (char_u *)0L}
2244#endif
2245 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002246 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002247#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002248 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002249 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250#else
2251 (char_u *)NULL, PV_NONE,
2252 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002253#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002255 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2256#if defined(FEAT_PYTHON)
2257 (char_u *)&p_pyhome, PV_NONE,
2258 {(char_u *)"", (char_u *)0L}
2259#else
2260 (char_u *)NULL, PV_NONE,
2261 {(char_u *)NULL, (char_u *)0L}
2262#endif
2263 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002264 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2265#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2266 (char_u *)&p_pyx, PV_NONE,
2267#else
2268 (char_u *)NULL, PV_NONE,
2269#endif
2270 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2271 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002272 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2273#ifdef FEAT_TEXTOBJ
2274 (char_u *)&p_qe, PV_QE,
2275 {(char_u *)"\\", (char_u *)0L}
2276#else
2277 (char_u *)NULL, PV_NONE,
2278 {(char_u *)NULL, (char_u *)0L}
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2282 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"redraw", NULL, P_BOOL|P_VI_DEF,
2285 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002287 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2288#ifdef FEAT_RELTIME
2289 (char_u *)&p_rdt, PV_NONE,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002294 {"regexpengine", "re", P_NUM|P_VI_DEF,
2295 (char_u *)&p_re, PV_NONE,
2296 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002297 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2298 (char_u *)VAR_WIN, PV_RNU,
2299 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"remap", NULL, P_BOOL|P_VI_DEF,
2301 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002303 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002304#ifdef FEAT_RENDER_OPTIONS
2305 (char_u *)&p_rop, PV_NONE,
2306 {(char_u *)"", (char_u *)0L}
2307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)NULL, (char_u *)0L}
2310#endif
2311 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"report", NULL, P_NUM|P_VI_DEF,
2313 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2316#ifdef WIN3264
2317 (char_u *)&p_rs, PV_NONE,
2318#else
2319 (char_u *)NULL, PV_NONE,
2320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2323#ifdef FEAT_RIGHTLEFT
2324 (char_u *)&p_ri, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2330#ifdef FEAT_RIGHTLEFT
2331 (char_u *)VAR_WIN, PV_RL,
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 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2337#ifdef FEAT_RIGHTLEFT
2338 (char_u *)VAR_WIN, PV_RLC,
2339 {(char_u *)"search", (char_u *)NULL}
2340#else
2341 (char_u *)NULL, PV_NONE,
2342 {(char_u *)NULL, (char_u *)0L}
2343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002345 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002346#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002347 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002348 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349#else
2350 (char_u *)NULL, PV_NONE,
2351 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002352#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2355#ifdef FEAT_CMDL_INFO
2356 (char_u *)&p_ru, PV_NONE,
2357#else
2358 (char_u *)NULL, PV_NONE,
2359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2362#ifdef FEAT_STL_OPT
2363 (char_u *)&p_ruf, PV_NONE,
2364#else
2365 (char_u *)NULL, PV_NONE,
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002368 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2369 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2374 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002375 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002385 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 (char_u *)&p_sbo, PV_NONE,
2387 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"sections", "sect", P_STRING|P_VI_DEF,
2390 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2394 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"inclusive", (char_u *)0L}
2399 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002400 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002403 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404#ifdef FEAT_SESSION
2405 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002406 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 (char_u *)0L}
2408#else
2409 (char_u *)NULL, PV_NONE,
2410 {(char_u *)0L, (char_u *)0L}
2411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2414 (char_u *)&p_sh, PV_NONE,
2415 {
2416#ifdef VMS
2417 (char_u *)"-",
2418#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002419# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002421# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423# endif
2424#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2427 (char_u *)&p_shcf, PV_NONE,
2428 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002429#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)"/c",
2431#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2436#ifdef FEAT_QUICKFIX
2437 (char_u *)&p_sp, PV_NONE,
2438 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002439#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441#else
2442 (char_u *)">",
2443#endif
2444 (char_u *)0L}
2445#else
2446 (char_u *)NULL, PV_NONE,
2447 {(char_u *)0L, (char_u *)0L}
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2451 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2454 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2457#ifdef BACKSLASH_IN_FILENAME
2458 (char_u *)&p_ssl, PV_NONE,
2459#else
2460 (char_u *)NULL, PV_NONE,
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002463 {"shelltemp", "stmp", P_BOOL,
2464 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"shelltype", "st", P_NUM|P_VI_DEF,
2467#ifdef AMIGA
2468 (char_u *)&p_st, PV_NONE,
2469#else
2470 (char_u *)NULL, PV_NONE,
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2474 (char_u *)&p_sxq, PV_NONE,
2475 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002476#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 (char_u *)"\"",
2478#else
2479 (char_u *)"",
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002482 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2483 (char_u *)&p_sxe, PV_NONE,
2484 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002485#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002486 (char_u *)"\"&|<>()@^",
2487#else
2488 (char_u *)"",
2489#endif
2490 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2492 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2495 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2498 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)"", (char_u *)"filnxtToO"}
2500 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2505#ifdef FEAT_LINEBREAK
2506 (char_u *)&p_sbr, PV_NONE,
2507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"showcmd", "sc", P_BOOL|P_VIM,
2512#ifdef FEAT_CMDL_INFO
2513 (char_u *)&p_sc, PV_NONE,
2514#else
2515 (char_u *)NULL, PV_NONE,
2516#endif
2517 {(char_u *)FALSE,
2518#ifdef UNIX
2519 (char_u *)FALSE
2520#else
2521 (char_u *)TRUE
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2525 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2528 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"showmode", "smd", P_BOOL|P_VIM,
2531 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002533 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002534 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2537 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2540 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002542 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2543#ifdef FEAT_SIGNS
2544 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002545 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002546#else
2547 (char_u *)NULL, PV_NONE,
2548 {(char_u *)NULL, (char_u *)0L}
2549#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2552 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2555 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2558#ifdef FEAT_SMARTINDENT
2559 (char_u *)&p_si, PV_SI,
2560#else
2561 (char_u *)NULL, PV_NONE,
2562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2565 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2568 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002573 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002574#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002575 (char_u *)VAR_WIN, PV_SPELL,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002580 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002581#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002582 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002583 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002584#else
2585 (char_u *)NULL, PV_NONE,
2586 {(char_u *)0L, (char_u *)0L}
2587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002589 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2590 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002591#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002592 (char_u *)&p_spf, PV_SPF,
2593 {(char_u *)"", (char_u *)0L}
2594#else
2595 (char_u *)NULL, PV_NONE,
2596 {(char_u *)0L, (char_u *)0L}
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002599 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2600 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002601#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002602 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002603 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +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 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002610#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002611 (char_u *)&p_sps, PV_NONE,
2612 {(char_u *)"best", (char_u *)0L}
2613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2625 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2628#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002629 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002634 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 (char_u *)&p_su, PV_NONE,
2636 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002639#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_sua, PV_SUA,
2641 {(char_u *)"", (char_u *)0L}
2642#else
2643 (char_u *)NULL, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2648 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"swapsync", "sws", P_STRING|P_VI_DEF,
2651 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002653 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002656 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2657#ifdef FEAT_SYN_HL
2658 (char_u *)&p_smc, PV_SMC,
2659 {(char_u *)3000L, (char_u *)0L}
2660#else
2661 (char_u *)NULL, PV_NONE,
2662 {(char_u *)0L, (char_u *)0L}
2663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002665 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666#ifdef FEAT_SYN_HL
2667 (char_u *)&p_syn, PV_SYN,
2668 {(char_u *)"", (char_u *)0L}
2669#else
2670 (char_u *)NULL, PV_NONE,
2671 {(char_u *)0L, (char_u *)0L}
2672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002674 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2675#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002676 (char_u *)&p_tal, PV_NONE,
2677#else
2678 (char_u *)NULL, PV_NONE,
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002681 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002682 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2685 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2688 (char_u *)&p_tbs, PV_NONE,
2689#ifdef VMS /* binary searching doesn't appear to work on VMS */
2690 {(char_u *)0L, (char_u *)0L}
2691#else
2692 {(char_u *)TRUE, (char_u *)0L}
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002695 {"tagcase", "tc", P_STRING|P_VIM,
2696 (char_u *)&p_tc, PV_TC,
2697 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {"taglength", "tl", P_NUM|P_VI_DEF,
2699 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"tagrelative", "tr", P_BOOL|P_VIM,
2702 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002704 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002705 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {
2707#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2708 (char_u *)"./tags,./TAGS,tags,TAGS",
2709#else
2710 (char_u *)"./tags,tags",
2711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2714 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002716 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002717#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002718 (char_u *)&p_tcldll, PV_NONE,
2719 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002720#else
2721 (char_u *)NULL, PV_NONE,
2722 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002723#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2726 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2729#ifdef FEAT_ARABIC
2730 (char_u *)&p_tbidi, PV_NONE,
2731#else
2732 (char_u *)NULL, PV_NONE,
2733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2736#ifdef FEAT_MBYTE
2737 (char_u *)&p_tenc, PV_NONE,
2738 {(char_u *)"", (char_u *)0L}
2739#else
2740 (char_u *)NULL, PV_NONE,
2741 {(char_u *)0L, (char_u *)0L}
2742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002744 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2745#ifdef FEAT_TERMGUICOLORS
2746 (char_u *)&p_tgc, PV_NONE,
2747 {(char_u *)FALSE, (char_u *)FALSE}
2748#else
2749 (char_u*)NULL, PV_NONE,
2750 {(char_u *)FALSE, (char_u *)FALSE}
2751#endif
2752 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002753 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2754#ifdef FEAT_TERMINAL
2755 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002756 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002757#else
2758 (char_u *)NULL, PV_NONE,
2759 {(char_u *)NULL, (char_u *)0L}
2760#endif
2761 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002762 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2763#ifdef FEAT_TERMINAL
2764 (char_u *)VAR_WIN, PV_TMS,
2765 {(char_u *)"", (char_u *)NULL}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)NULL, (char_u *)0L}
2769#endif
2770 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"terse", NULL, P_BOOL|P_VI_DEF,
2772 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"textauto", "ta", P_BOOL|P_VIM,
2775 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2777 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2779 (char_u *)&p_tx, PV_TX,
2780 {
2781#ifdef USE_CRNL
2782 (char_u *)TRUE,
2783#else
2784 (char_u *)FALSE,
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002787 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002790 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002792 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793#else
2794 (char_u *)NULL, PV_NONE,
2795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2798 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"timeout", "to", P_BOOL|P_VI_DEF,
2801 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2804 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"title", NULL, P_BOOL|P_VI_DEF,
2807#ifdef FEAT_TITLE
2808 (char_u *)&p_title, PV_NONE,
2809#else
2810 (char_u *)NULL, PV_NONE,
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"titlelen", NULL, P_NUM|P_VI_DEF,
2814#ifdef FEAT_TITLE
2815 (char_u *)&p_titlelen, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002820 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821#ifdef FEAT_TITLE
2822 (char_u *)&p_titleold, PV_NONE,
2823 {(char_u *)N_("Thanks for flying Vim"),
2824 (char_u *)0L}
2825#else
2826 (char_u *)NULL, PV_NONE,
2827 {(char_u *)0L, (char_u *)0L}
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"titlestring", NULL, P_STRING|P_VI_DEF,
2831#ifdef FEAT_TITLE
2832 (char_u *)&p_titlestring, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002837 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002838#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002841#else
2842 (char_u *)NULL, PV_NONE,
2843 {(char_u *)0L, (char_u *)0L}
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002849 {(char_u *)"small", (char_u *)0L}
2850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2856 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2859 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2862 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2865 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2868#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2869 (char_u *)&p_ttym, PV_NONE,
2870#else
2871 (char_u *)NULL, PV_NONE,
2872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2875 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2878 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2881 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002882#ifdef FEAT_PERSISTENT_UNDO
2883 (char_u *)&p_udir, PV_NONE,
2884 {(char_u *)".", (char_u *)0L}
2885#else
2886 (char_u *)NULL, PV_NONE,
2887 {(char_u *)0L, (char_u *)0L}
2888#endif
2889 SCRIPTID_INIT},
2890 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udf, PV_UDF,
2893#else
2894 (char_u *)NULL, PV_NONE,
2895#endif
2896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002898 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002900#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 (char_u *)1000L,
2902#else
2903 (char_u *)100L,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002906 {"undoreload", "ur", P_NUM|P_VI_DEF,
2907 (char_u *)&p_ur, PV_NONE,
2908 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"updatecount", "uc", P_NUM|P_VI_DEF,
2910 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"updatetime", "ut", P_NUM|P_VI_DEF,
2913 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 {"verbose", "vbs", P_NUM|P_VI_DEF,
2916 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002918 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2919 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2922#ifdef FEAT_SESSION
2923 (char_u *)&p_vdir, PV_NONE,
2924 {(char_u *)DFLT_VDIR, (char_u *)0L}
2925#else
2926 (char_u *)NULL, PV_NONE,
2927 {(char_u *)0L, (char_u *)0L}
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002930 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931#ifdef FEAT_SESSION
2932 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002933 {(char_u *)"folds,options,cursor,curdir",
2934 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935#else
2936 (char_u *)NULL, PV_NONE,
2937 {(char_u *)0L, (char_u *)0L}
2938#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002940 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#ifdef FEAT_VIMINFO
2942 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002943#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002944 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945#else
2946# ifdef AMIGA
2947 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002948 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002950 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951# endif
2952#endif
2953#else
2954 (char_u *)NULL, PV_NONE,
2955 {(char_u *)0L, (char_u *)0L}
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002958 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2959#ifdef FEAT_VIMINFO
2960 (char_u *)&p_viminfofile, PV_NONE,
2961 {(char_u *)"", (char_u *)0L}
2962#else
2963 (char_u *)NULL, PV_NONE,
2964 {(char_u *)0L, (char_u *)0L}
2965#endif
2966 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002967 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2968 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969#ifdef FEAT_VIRTUALEDIT
2970 (char_u *)&p_ve, PV_NONE,
2971 {(char_u *)"", (char_u *)""}
2972#else
2973 (char_u *)NULL, PV_NONE,
2974 {(char_u *)0L, (char_u *)0L}
2975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w300", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"w1200", NULL, P_NUM|P_VI_DEF,
2984 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002985 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"w9600", NULL, P_NUM|P_VI_DEF,
2987 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"warn", NULL, P_BOOL|P_VI_DEF,
2990 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2993 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002997 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"wildchar", "wc", P_NUM|P_VIM,
2999 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3001 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003002 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003005 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006#ifdef FEAT_WILDIGN
3007 (char_u *)&p_wig, PV_NONE,
3008#else
3009 (char_u *)NULL, PV_NONE,
3010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003012 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3013 (char_u *)&p_wic, PV_NONE,
3014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3016#ifdef FEAT_WILDMENU
3017 (char_u *)&p_wmnu, PV_NONE,
3018#else
3019 (char_u *)NULL, PV_NONE,
3020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003022 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003025 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3026#ifdef FEAT_CMDL_COMPL
3027 (char_u *)&p_wop, PV_NONE,
3028 {(char_u *)"", (char_u *)0L}
3029#else
3030 (char_u *)NULL, PV_NONE,
3031 {(char_u *)NULL, (char_u *)0L}
3032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3035#ifdef FEAT_WAK
3036 (char_u *)&p_wak, PV_NONE,
3037 {(char_u *)"menu", (char_u *)0L}
3038#else
3039 (char_u *)NULL, PV_NONE,
3040 {(char_u *)NULL, (char_u *)0L}
3041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003044 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003045 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003048 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003052 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003053 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003057 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003060 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003061 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003062#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003063 (char_u *)&p_winptydll, PV_NONE, {
3064# ifdef _WIN64
3065 (char_u *)"winpty64.dll",
3066# else
3067 (char_u *)"winpty32.dll",
3068# endif
3069 (char_u *)0L}
3070#else
3071 (char_u *)NULL, PV_NONE,
3072 {(char_u *)0L, (char_u *)0L}
3073#endif
3074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003077 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3079 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3082 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3085 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"write", NULL, P_BOOL|P_VI_DEF,
3088 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"writeany", "wa", P_BOOL|P_VI_DEF,
3091 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3094 (char_u *)&p_wb, PV_NONE,
3095 {
3096#ifdef FEAT_WRITEBACKUP
3097 (char_u *)TRUE,
3098#else
3099 (char_u *)FALSE,
3100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writedelay", "wd", P_NUM|P_VI_DEF,
3103 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105
3106/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003107#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
3111 p_term("t_AB", T_CAB)
3112 p_term("t_AF", T_CAF)
3113 p_term("t_AL", T_CAL)
3114 p_term("t_al", T_AL)
3115 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003116 p_term("t_BE", T_BE)
3117 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_cd", T_CD)
3119 p_term("t_ce", T_CE)
3120 p_term("t_cl", T_CL)
3121 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003122 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_Co", T_CCO)
3124 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003125 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_da", T_DA)
3129 p_term("t_db", T_DB)
3130 p_term("t_DL", T_CDL)
3131 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003132 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003133 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003135 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_IE", T_CIE)
3137 p_term("t_IS", T_CIS)
3138 p_term("t_ke", T_KE)
3139 p_term("t_ks", T_KS)
3140 p_term("t_le", T_LE)
3141 p_term("t_mb", T_MB)
3142 p_term("t_md", T_MD)
3143 p_term("t_me", T_ME)
3144 p_term("t_mr", T_MR)
3145 p_term("t_ms", T_MS)
3146 p_term("t_nd", T_ND)
3147 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003148 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003149 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003150 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_RV", T_CRV)
3154 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003155 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003159 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003161 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003163 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_te", T_TE)
3165 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003166 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ts", T_TS)
3168 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_ue", T_UE)
3170 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vb", T_VB)
3173 p_term("t_ve", T_VE)
3174 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_vs", T_VS)
3177 p_term("t_WP", T_CWP)
3178 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003179 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 p_term("t_xs", T_XS)
3181 p_term("t_ZH", T_CZH)
3182 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003183 p_term("t_8f", T_8F)
3184 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185
3186/* terminal key codes are not in here */
3187
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003188 /* end marker */
3189 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190};
3191
3192#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3193
3194#ifdef FEAT_MBYTE
3195static char *(p_ambw_values[]) = {"single", "double", NULL};
3196#endif
3197static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003198static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003200#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003201static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003202#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003203#ifdef FEAT_CMDL_COMPL
3204static char *(p_wop_values[]) = {"tagfile", NULL};
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206#ifdef FEAT_WAK
3207static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3208#endif
3209static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3211static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213#ifdef FEAT_BROWSE
3214static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003217static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003220static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3222#ifdef FEAT_FOLDING
3223static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003224# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 NULL};
3228static char *(p_fcl_values[]) = {"all", NULL};
3229#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003230#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003231static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003233#ifdef FEAT_SIGNS
3234static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3235#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003237static void set_option_default(int, int opt_flags, int compatible);
3238static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003239static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static char_u *term_bg_default(void);
3241static void did_set_option(int opt_idx, int opt_flags, int new_value);
3242static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245#endif
3246#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static char_u *option_expand(int opt_idx, char_u *val);
3250static void didset_options(void);
3251static void didset_options2(void);
3252static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003253#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003255#else
3256# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3257#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void set_string_option_global(int opt_idx, char_u **varp);
3259static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3260static 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);
3261static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003262#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static char_u *did_set_spell_option(int is_spellfile);
3270static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003272#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003274#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3277static void check_redraw(long_u flags);
3278static int findoption(char_u *);
3279static int find_key_option(char_u *);
3280static void showoptions(int all, int opt_flags);
3281static int optval_default(struct vimoption *, char_u *varp);
3282static void showoneopt(struct vimoption *, int opt_flags);
3283static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3284static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286static int istermoption(struct vimoption *);
3287static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288static char_u *get_varp(struct vimoption *);
3289static void option_value2string(struct vimoption *, int opt_flags);
3290static void check_winopt(winopt_T *wop);
3291static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void langmap_init(void);
3294static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static void paste_option_changed(void);
3297static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302static int check_opt_strings(char_u *val, char **values, int);
3303static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003304#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308/*
3309 * Initialize the options, first part.
3310 *
3311 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003312 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 */
3314 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003315set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316{
3317 char_u *p;
3318 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003319 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321#ifdef FEAT_LANGMAP
3322 langmap_init();
3323#endif
3324
3325 /* Be Vi compatible by default */
3326 p_cp = TRUE;
3327
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003328 /* Use POSIX compatibility when $VIM_POSIX is set. */
3329 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003330 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003331 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003332 set_string_default("shm", (char_u *)"A");
3333 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003334
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 /*
3336 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003337 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003339 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003340#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003341 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003343 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344# endif
3345#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003347 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349#ifdef FEAT_WILDIGN
3350 /*
3351 * Set the default for 'backupskip' to include environment variables for
3352 * temp files.
3353 */
3354 {
3355# ifdef UNIX
3356 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3357# else
3358 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3359# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003360 int len;
3361 garray_T ga;
3362 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364 ga_init2(&ga, 1, 100);
3365 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3366 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003367 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368# ifdef UNIX
3369 if (*names[n] == NUL)
3370 p = (char_u *)"/tmp";
3371 else
3372# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003373 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 if (p != NULL && *p != NUL)
3375 {
3376 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003377 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 if (ga_grow(&ga, len) == OK)
3379 {
3380 if (ga.ga_len > 0)
3381 STRCAT(ga.ga_data, ",");
3382 STRCAT(ga.ga_data, p);
3383 add_pathsep(ga.ga_data);
3384 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 ga.ga_len += len;
3386 }
3387 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003388 if (mustfree)
3389 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 }
3391 if (ga.ga_data != NULL)
3392 {
3393 set_string_default("bsk", ga.ga_data);
3394 vim_free(ga.ga_data);
3395 }
3396 }
3397#endif
3398
3399 /*
3400 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3401 */
3402 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3406 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3407#endif
3408 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003410 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003411 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412#else
3413# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003415 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003417 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418# endif
3419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003421 opt_idx = findoption((char_u *)"maxmem");
3422 if (opt_idx >= 0)
3423 {
3424#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003425 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3426 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427#endif
3428 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3429 }
3430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 }
3432
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433#ifdef FEAT_SEARCHPATH
3434 {
3435 char_u *cdpath;
3436 char_u *buf;
3437 int i;
3438 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003439 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
3441 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003442 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 if (cdpath != NULL)
3444 {
3445 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3446 if (buf != NULL)
3447 {
3448 buf[0] = ','; /* start with ",", current dir first */
3449 j = 1;
3450 for (i = 0; cdpath[i] != NUL; ++i)
3451 {
3452 if (vim_ispathlistsep(cdpath[i]))
3453 buf[j++] = ',';
3454 else
3455 {
3456 if (cdpath[i] == ' ' || cdpath[i] == ',')
3457 buf[j++] = '\\';
3458 buf[j++] = cdpath[i];
3459 }
3460 }
3461 buf[j] = NUL;
3462 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463 if (opt_idx >= 0)
3464 {
3465 options[opt_idx].def_val[VI_DEFAULT] = buf;
3466 options[opt_idx].flags |= P_DEF_ALLOCED;
3467 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003468 else
3469 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003471 if (mustfree)
3472 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473 }
3474 }
3475#endif
3476
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003477#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 /* Set print encoding on platforms that don't default to latin1 */
3479 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003480# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 (char_u *)"cp1252"
3482# else
3483# ifdef VMS
3484 (char_u *)"dec-mcs"
3485# else
3486# ifdef EBCDIC
3487 (char_u *)"ebcdic-uk"
3488# else
3489# ifdef MAC
3490 (char_u *)"mac-roman"
3491# else /* HPUX */
3492 (char_u *)"hp-roman8"
3493# endif
3494# endif
3495# endif
3496# endif
3497 );
3498#endif
3499
3500#ifdef FEAT_POSTSCRIPT
3501 /* 'printexpr' must be allocated to be able to evaluate it. */
3502 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003503# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003504 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505# else
3506# ifdef VMS
3507 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3508
3509# else
3510 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3511# endif
3512# endif
3513 );
3514#endif
3515
3516 /*
3517 * Set all the options (except the terminal options) to their default
3518 * value. Also set the global value for local options.
3519 */
3520 set_options_default(0);
3521
Bram Moolenaar07268702018-03-01 21:57:32 +01003522#ifdef CLEAN_RUNTIMEPATH
3523 if (clean_arg)
3524 {
3525 opt_idx = findoption((char_u *)"runtimepath");
3526 if (opt_idx >= 0)
3527 {
3528 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3529 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3530 }
3531 opt_idx = findoption((char_u *)"packpath");
3532 if (opt_idx >= 0)
3533 {
3534 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3535 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3536 }
3537 }
3538#endif
3539
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540#ifdef FEAT_GUI
3541 if (found_reverse_arg)
3542 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3543#endif
3544
3545 curbuf->b_p_initialized = TRUE;
3546 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003547 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548 check_buf_options(curbuf);
3549 check_win_options(curwin);
3550 check_options();
3551
3552 /* Must be before option_expand(), because that one needs vim_isIDc() */
3553 didset_options();
3554
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003555#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003556 /* Use the current chartab for the generic chartab. This is not in
3557 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003558 init_spell_chartab();
3559#endif
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 /*
3562 * Expand environment variables and things like "~" for the defaults.
3563 * If option_expand() returns non-NULL the variable is expanded. This can
3564 * only happen for non-indirect options.
3565 * Also set the default to the expanded value, so ":set" does not list
3566 * them.
3567 * Don't set the P_ALLOCED flag, because we don't want to free the
3568 * default.
3569 */
3570 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3571 {
3572 if ((options[opt_idx].flags & P_GETTEXT)
3573 && options[opt_idx].var != NULL)
3574 p = (char_u *)_(*(char **)options[opt_idx].var);
3575 else
3576 p = option_expand(opt_idx, NULL);
3577 if (p != NULL && (p = vim_strsave(p)) != NULL)
3578 {
3579 *(char_u **)options[opt_idx].var = p;
3580 /* VIMEXP
3581 * Defaults for all expanded options are currently the same for Vi
3582 * and Vim. When this changes, add some code here! Also need to
3583 * split P_DEF_ALLOCED in two.
3584 */
3585 if (options[opt_idx].flags & P_DEF_ALLOCED)
3586 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3587 options[opt_idx].def_val[VI_DEFAULT] = p;
3588 options[opt_idx].flags |= P_DEF_ALLOCED;
3589 }
3590 }
3591
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 save_file_ff(curbuf); /* Buffer is unchanged */
3593
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594#if defined(FEAT_ARABIC)
3595 /* Detect use of mlterm.
3596 * Mlterm is a terminal emulator akin to xterm that has some special
3597 * abilities (bidi namely).
3598 * NOTE: mlterm's author is being asked to 'set' a variable
3599 * instead of an environment variable due to inheritance.
3600 */
3601 if (mch_getenv((char_u *)"MLTERM") != NULL)
3602 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3603#endif
3604
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003605 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606
3607#ifdef FEAT_MBYTE
3608# if defined(WIN3264) && defined(FEAT_GETTEXT)
3609 /*
3610 * If $LANG isn't set, try to get a good value for it. This makes the
3611 * right language be used automatically. Don't do this for English.
3612 */
3613 if (mch_getenv((char_u *)"LANG") == NULL)
3614 {
3615 char buf[20];
3616
3617 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3618 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3619 * only the first two. */
3620 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3621 (LPTSTR)buf, 20);
3622 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3623 {
3624 /* There are a few exceptions (probably more) */
3625 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3626 STRCPY(buf, "zh_TW");
3627 else if (STRNICMP(buf, "chs", 3) == 0
3628 || STRNICMP(buf, "zhc", 3) == 0)
3629 STRCPY(buf, "zh_CN");
3630 else if (STRNICMP(buf, "jp", 2) == 0)
3631 STRCPY(buf, "ja");
3632 else
3633 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003634 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635 }
3636 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003637# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003638# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003639 /* Moved to os_mac_conv.c to avoid dependency problems. */
3640 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003641# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642# endif
3643
3644 /* enc_locale() will try to find the encoding of the current locale. */
3645 p = enc_locale();
3646 if (p != NULL)
3647 {
3648 char_u *save_enc;
3649
3650 /* Try setting 'encoding' and check if the value is valid.
3651 * If not, go back to the default "latin1". */
3652 save_enc = p_enc;
3653 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003654 if (STRCMP(p_enc, "gb18030") == 0)
3655 {
3656 /* We don't support "gb18030", but "cp936" is a good substitute
3657 * for practical purposes, thus use that. It's not an alias to
3658 * still support conversion between gb18030 and utf-8. */
3659 p_enc = vim_strsave((char_u *)"cp936");
3660 vim_free(p);
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 if (mb_init() == NULL)
3663 {
3664 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003665 if (opt_idx >= 0)
3666 {
3667 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3668 options[opt_idx].flags |= P_DEF_ALLOCED;
3669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670
Bram Moolenaard0573012017-10-28 21:11:06 +02003671#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 if (STRCMP(p_enc, "latin1") == 0
3673# ifdef FEAT_MBYTE
3674 || enc_utf8
3675# endif
3676 )
3677 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003678 /* Adjust the default for 'isprint' and 'iskeyword' to match
3679 * latin1. Also set the defaults for when 'nocompatible' is
3680 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003681 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003682 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003683 set_string_option_direct((char_u *)"isk", -1,
3684 ISK_LATIN1, OPT_FREE, SID_NONE);
3685 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003686 if (opt_idx >= 0)
3687 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003688 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003689 if (opt_idx >= 0)
3690 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003691 (void)init_chartab();
3692 }
3693#endif
3694
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695# if defined(WIN3264) && !defined(FEAT_GUI)
3696 /* Win32 console: When GetACP() returns a different value from
3697 * GetConsoleCP() set 'termencoding'. */
3698 if (GetACP() != GetConsoleCP())
3699 {
3700 char buf[50];
3701
3702 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3703 p_tenc = vim_strsave((char_u *)buf);
3704 if (p_tenc != NULL)
3705 {
3706 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003707 if (opt_idx >= 0)
3708 {
3709 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3710 options[opt_idx].flags |= P_DEF_ALLOCED;
3711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712 convert_setup(&input_conv, p_tenc, p_enc);
3713 convert_setup(&output_conv, p_enc, p_tenc);
3714 }
3715 else
3716 p_tenc = empty_option;
3717 }
3718# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003719# if defined(WIN3264) && defined(FEAT_MBYTE)
3720 /* $HOME may have characters in active code page. */
3721 init_homedir();
3722# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 }
3724 else
3725 {
3726 vim_free(p_enc);
3727 p_enc = save_enc;
3728 }
3729 }
3730#endif
3731
3732#ifdef FEAT_MULTI_LANG
3733 /* Set the default for 'helplang'. */
3734 set_helplang_default(get_mess_lang());
3735#endif
3736}
3737
3738/*
3739 * Set an option to its default value.
3740 * This does not take care of side effects!
3741 */
3742 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003743set_option_default(
3744 int opt_idx,
3745 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3746 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747{
3748 char_u *varp; /* pointer to variable for current option */
3749 int dvi; /* index in def_val[] */
3750 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003751 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3753
3754 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3755 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003756 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 {
3758 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3759 if (flags & P_STRING)
3760 {
3761 /* Use set_string_option_direct() for local options to handle
3762 * freeing and allocating the value. */
3763 if (options[opt_idx].indir != PV_NONE)
3764 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003765 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 else
3767 {
3768 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3769 free_string_option(*(char_u **)(varp));
3770 *(char_u **)varp = options[opt_idx].def_val[dvi];
3771 options[opt_idx].flags &= ~P_ALLOCED;
3772 }
3773 }
3774 else if (flags & P_NUM)
3775 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003776 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 win_comp_scroll(curwin);
3778 else
3779 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003780 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 /* May also set global value for local option. */
3782 if (both)
3783 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3784 *(long *)varp;
3785 }
3786 }
3787 else /* P_BOOL */
3788 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003789 /* the cast to long is required for Manx C, long_i is needed for
3790 * MSVC */
3791 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003792#ifdef UNIX
3793 /* 'modeline' defaults to off for root */
3794 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3795 *(int *)varp = FALSE;
3796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 /* May also set global value for local option. */
3798 if (both)
3799 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3800 *(int *)varp;
3801 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003802
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003803 /* The default value is not insecure. */
3804 flagsp = insecure_flag(opt_idx, opt_flags);
3805 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 }
3807
3808#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003809 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810#endif
3811}
3812
3813/*
3814 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003815 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 */
3817 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003818set_options_default(
3819 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820{
3821 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824
3825 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003826 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003827#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003828 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003829 || (TRUE
3830# if defined(FEAT_MBYTE)
3831 && options[i].var != (char_u *)&p_enc
3832# endif
3833# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003834 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003835 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003836# endif
3837 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003838#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003839 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 set_option_default(i, opt_flags, p_cp);
3841
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003843 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003845#ifdef FEAT_CINDENT
3846 parse_cino(curbuf);
3847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848}
3849
3850/*
3851 * Set the Vi-default value of a string option.
3852 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003853 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003855 static void
3856set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857{
3858 char_u *p;
3859 int opt_idx;
3860
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003861 if (escape && vim_strchr(val, ' ') != NULL)
3862 p = vim_strsave_escaped(val, (char_u *)" ");
3863 else
3864 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865 if (p != NULL) /* we don't want a NULL */
3866 {
3867 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003868 if (opt_idx >= 0)
3869 {
3870 if (options[opt_idx].flags & P_DEF_ALLOCED)
3871 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3872 options[opt_idx].def_val[VI_DEFAULT] = p;
3873 options[opt_idx].flags |= P_DEF_ALLOCED;
3874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 }
3876}
3877
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003878 void
3879set_string_default(char *name, char_u *val)
3880{
3881 set_string_default_esc(name, val, FALSE);
3882}
3883
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884/*
3885 * Set the Vi-default value of a number option.
3886 * Used for 'lines' and 'columns'.
3887 */
3888 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003889set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003891 int opt_idx;
3892
3893 opt_idx = findoption((char_u *)name);
3894 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003895 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896}
3897
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003898#if defined(EXITFREE) || defined(PROTO)
3899/*
3900 * Free all options.
3901 */
3902 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003903free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003904{
3905 int i;
3906
3907 for (i = 0; !istermoption(&options[i]); i++)
3908 {
3909 if (options[i].indir == PV_NONE)
3910 {
3911 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003912 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003913 free_string_option(*(char_u **)options[i].var);
3914 if (options[i].flags & P_DEF_ALLOCED)
3915 free_string_option(options[i].def_val[VI_DEFAULT]);
3916 }
3917 else if (options[i].var != VAR_WIN
3918 && (options[i].flags & P_STRING))
3919 /* buffer-local option: free global value */
3920 free_string_option(*(char_u **)options[i].var);
3921 }
3922}
3923#endif
3924
3925
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926/*
3927 * Initialize the options, part two: After getting Rows and Columns and
3928 * setting 'term'.
3929 */
3930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003931set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003933 int idx;
3934
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003936 * 'scroll' defaults to half the window height. The stored default is zero,
3937 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003939 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003940 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003941 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 comp_col();
3943
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003944 /*
3945 * 'window' is only for backwards compatibility with Vi.
3946 * Default is Rows - 1.
3947 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003948 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003949 p_window = Rows - 1;
3950 set_number_default("window", Rows - 1);
3951
Bram Moolenaarf740b292006-02-16 22:11:02 +00003952 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003953#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003954 /*
3955 * If 'background' wasn't set by the user, try guessing the value,
3956 * depending on the terminal name. Only need to check for terminals
3957 * with a dark background, that can handle color.
3958 */
3959 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003960 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3961 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003963 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003964 /* don't mark it as set, when starting the GUI it may be
3965 * changed again */
3966 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 }
3968#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003969
3970#ifdef CURSOR_SHAPE
3971 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3972#endif
3973#ifdef FEAT_MOUSESHAPE
3974 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3975#endif
3976#ifdef FEAT_PRINTER
3977 (void)parse_printoptions(); /* parse 'printoptions' default value */
3978#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979}
3980
3981/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003982 * Return "dark" or "light" depending on the kind of terminal.
3983 * This is just guessing! Recognized are:
3984 * "linux" Linux console
3985 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003986 * "cygwin.*" Cygwin shell
3987 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003988 * We also check the COLORFGBG environment variable, which is set by
3989 * rxvt and derivatives. This variable contains either two or three
3990 * values separated by semicolons; we want the last value in either
3991 * case. If this value is 0-6 or 8, our background is dark.
3992 */
3993 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003994term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003996#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003997 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003998 return (char_u *)"dark";
3999#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004000 char_u *p;
4001
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002 if (STRCMP(T_NAME, "linux") == 0
4003 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004004 || STRNCMP(T_NAME, "cygwin", 6) == 0
4005 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004006 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4007 && (p = vim_strrchr(p, ';')) != NULL
4008 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4009 && p[2] == NUL))
4010 return (char_u *)"dark";
4011 return (char_u *)"light";
4012#endif
4013}
4014
4015/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 * Initialize the options, part three: After reading the .vimrc
4017 */
4018 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004019set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022/*
4023 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4024 * This is done after other initializations, where 'shell' might have been
4025 * set, but only if they have not been set before.
4026 */
4027 char_u *p;
4028 int idx_srr;
4029 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004030# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 int idx_sp;
4032 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034
4035 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004036 if (idx_srr < 0)
4037 do_srr = FALSE;
4038 else
4039 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004042 if (idx_sp < 0)
4043 do_sp = FALSE;
4044 else
4045 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004047 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 if (p != NULL)
4049 {
4050 /*
4051 * Default for p_sp is "| tee", for p_srr is ">".
4052 * For known shells it is changed here to include stderr.
4053 */
4054 if ( fnamecmp(p, "csh") == 0
4055 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 || fnamecmp(p, "csh.exe") == 0
4058 || fnamecmp(p, "tcsh.exe") == 0
4059# endif
4060 )
4061 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 if (do_sp)
4064 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004067# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4071 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 if (do_srr)
4074 {
4075 p_srr = (char_u *)">&";
4076 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4077 }
4078 }
4079 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 if ( fnamecmp(p, "sh") == 0
4082 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004083 || fnamecmp(p, "mksh") == 0
4084 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004086 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004088 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 || fnamecmp(p, "cmd") == 0
4091 || fnamecmp(p, "sh.exe") == 0
4092 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004093 || fnamecmp(p, "mksh.exe") == 0
4094 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004096 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 || fnamecmp(p, "bash.exe") == 0
4098 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 if (do_sp)
4104 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004107# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4111 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 if (do_srr)
4114 {
4115 p_srr = (char_u *)">%s 2>&1";
4116 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4117 }
4118 }
4119 vim_free(p);
4120 }
4121#endif
4122
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004123#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004125 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4126 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 * This is done after other initializations, where 'shell' might have been
4128 * set, but only if they have not been set before. Default for p_shcf is
4129 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004130 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004132 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 {
4134 int idx3;
4135
4136 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004137 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 {
4139 p_shcf = (char_u *)"-c";
4140 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4141 }
4142
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 /* Somehow Win32 requires the quotes around the redirection too */
4144 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004145 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 {
4147 p_sxq = (char_u *)"\"";
4148 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004151 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4152 {
4153 int idx3;
4154
4155 /*
4156 * cmd.exe on Windows will strip the first and last double quote given
4157 * on the command line, e.g. most of the time things like:
4158 * cmd /c "my path/to/echo" "my args to echo"
4159 * become:
4160 * my path/to/echo" "my args to echo
4161 * when executed.
4162 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004163 * To avoid this, set shellxquote to surround the command in
4164 * parenthesis. This appears to make most commands work, without
4165 * breaking commands that worked previously, such as
4166 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004167 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 idx3 = findoption((char_u *)"sxq");
4169 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4170 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004171 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004172 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4173 }
4174
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 idx3 = findoption((char_u *)"shcf");
4176 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4177 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004178 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004179 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4180 }
4181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182#endif
4183
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004184 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004185 {
4186 int idx_ffs = findoption((char_u *)"ffs");
4187
4188 /* Apply the first entry of 'fileformats' to the initial buffer. */
4189 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4190 set_fileformat(default_fileformat(), OPT_LOCAL);
4191 }
4192
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193#ifdef FEAT_TITLE
4194 set_title_defaults();
4195#endif
4196}
4197
4198#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4199/*
4200 * When 'helplang' is still at its default value, set it to "lang".
4201 * Only the first two characters of "lang" are used.
4202 */
4203 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004204set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205{
4206 int idx;
4207
4208 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4209 return;
4210 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004211 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 {
4213 if (options[idx].flags & P_ALLOCED)
4214 free_string_option(p_hlg);
4215 p_hlg = vim_strsave(lang);
4216 if (p_hlg == NULL)
4217 p_hlg = empty_option;
4218 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004219 {
4220 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4221 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4222 {
4223 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4224 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004227 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 options[idx].flags |= P_ALLOCED;
4229 }
4230}
4231#endif
4232
4233#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004234static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235
4236 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004237gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238{
4239 if (gui_get_lightness(gui.back_pixel) < 127)
4240 return (char_u *)"dark";
4241 return (char_u *)"light";
4242}
4243
4244/*
4245 * Option initializations that can only be done after opening the GUI window.
4246 */
4247 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004248init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249{
4250 /* Set the 'background' option according to the lightness of the
4251 * background color, unless the user has set it already. */
4252 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4253 {
4254 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4255 highlight_changed();
4256 }
4257}
4258#endif
4259
4260#ifdef FEAT_TITLE
4261/*
4262 * 'title' and 'icon' only default to true if they have not been set or reset
4263 * in .vimrc and we can read the old value.
4264 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4265 * they can be reset. This reduces startup time when using X on a remote
4266 * machine.
4267 */
4268 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004269set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270{
4271 int idx1;
4272 long val;
4273
4274 /*
4275 * If GUI is (going to be) used, we can always set the window title and
4276 * icon name. Saves a bit of time, because the X11 display server does
4277 * not need to be contacted.
4278 */
4279 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004280 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281 {
4282#ifdef FEAT_GUI
4283 if (gui.starting || gui.in_use)
4284 val = TRUE;
4285 else
4286#endif
4287 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004288 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004289 p_title = val;
4290 }
4291 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004292 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293 {
4294#ifdef FEAT_GUI
4295 if (gui.starting || gui.in_use)
4296 val = TRUE;
4297 else
4298#endif
4299 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004300 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 p_icon = val;
4302 }
4303}
4304#endif
4305
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004306#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004307 static void
4308trigger_optionsset_string(
4309 int opt_idx,
4310 int opt_flags,
4311 char_u *oldval,
4312 char_u *newval)
4313{
4314 if (oldval != NULL && newval != NULL)
4315 {
4316 char_u buf_type[7];
4317
4318 sprintf((char *)buf_type, "%s",
4319 (opt_flags & OPT_LOCAL) ? "local" : "global");
4320 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4321 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4322 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4323 apply_autocmds(EVENT_OPTIONSET,
4324 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4325 reset_v_option_vars();
4326 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004327}
4328#endif
4329
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330/*
4331 * Parse 'arg' for option settings.
4332 *
4333 * 'arg' may be IObuff, but only when no errors can be present and option
4334 * does not need to be expanded with option_expand().
4335 * "opt_flags":
4336 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004337 * OPT_GLOBAL for ":setglobal"
4338 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004339 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004340 * OPT_WINONLY to only set window-local options
4341 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342 *
4343 * returns FAIL if an error is detected, OK otherwise
4344 */
4345 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004346do_set(
4347 char_u *arg, /* option string (may be written to!) */
4348 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349{
4350 int opt_idx;
4351 char_u *errmsg;
4352 char_u errbuf[80];
4353 char_u *startarg;
4354 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4355 int nextchar; /* next non-white char after option name */
4356 int afterchar; /* character just after option name */
4357 int len;
4358 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004359 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 int key;
4361 long_u flags; /* flags for current option */
4362 char_u *varp = NULL; /* pointer to variable for current option */
4363 int did_show = FALSE; /* already showed one value */
4364 int adding; /* "opt+=arg" */
4365 int prepending; /* "opt^=arg" */
4366 int removing; /* "opt-=arg" */
4367 int cp_val = 0;
4368 char_u key_name[2];
4369
4370 if (*arg == NUL)
4371 {
4372 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004373 did_show = TRUE;
4374 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 }
4376
4377 while (*arg != NUL) /* loop to process all options */
4378 {
4379 errmsg = NULL;
4380 startarg = arg; /* remember for error message */
4381
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004382 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4383 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 {
4385 /*
4386 * ":set all" show all options.
4387 * ":set all&" set all options to their default value.
4388 */
4389 arg += 3;
4390 if (*arg == '&')
4391 {
4392 ++arg;
4393 /* Only for :set command set global value of local options. */
4394 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004395 didset_options();
4396 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004397 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398 }
4399 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004400 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004402 did_show = TRUE;
4403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004405 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406 {
4407 showoptions(2, opt_flags);
4408 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004409 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 arg += 7;
4411 }
4412 else
4413 {
4414 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004415 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 {
4417 prefix = 0;
4418 arg += 2;
4419 }
4420 else if (STRNCMP(arg, "inv", 3) == 0)
4421 {
4422 prefix = 2;
4423 arg += 3;
4424 }
4425
4426 /* find end of name */
4427 key = 0;
4428 if (*arg == '<')
4429 {
4430 nextchar = 0;
4431 opt_idx = -1;
4432 /* look out for <t_>;> */
4433 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4434 len = 5;
4435 else
4436 {
4437 len = 1;
4438 while (arg[len] != NUL && arg[len] != '>')
4439 ++len;
4440 }
4441 if (arg[len] != '>')
4442 {
4443 errmsg = e_invarg;
4444 goto skip;
4445 }
4446 arg[len] = NUL; /* put NUL after name */
4447 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4448 opt_idx = findoption(arg + 1);
4449 arg[len++] = '>'; /* restore '>' */
4450 if (opt_idx == -1)
4451 key = find_key_option(arg + 1);
4452 }
4453 else
4454 {
4455 len = 0;
4456 /*
4457 * The two characters after "t_" may not be alphanumeric.
4458 */
4459 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4460 len = 4;
4461 else
4462 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4463 ++len;
4464 nextchar = arg[len];
4465 arg[len] = NUL; /* put NUL after name */
4466 opt_idx = findoption(arg);
4467 arg[len] = nextchar; /* restore nextchar */
4468 if (opt_idx == -1)
4469 key = find_key_option(arg);
4470 }
4471
4472 /* remember character after option name */
4473 afterchar = arg[len];
4474
4475 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004476 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004477 ++len;
4478
4479 adding = FALSE;
4480 prepending = FALSE;
4481 removing = FALSE;
4482 if (arg[len] != NUL && arg[len + 1] == '=')
4483 {
4484 if (arg[len] == '+')
4485 {
4486 adding = TRUE; /* "+=" */
4487 ++len;
4488 }
4489 else if (arg[len] == '^')
4490 {
4491 prepending = TRUE; /* "^=" */
4492 ++len;
4493 }
4494 else if (arg[len] == '-')
4495 {
4496 removing = TRUE; /* "-=" */
4497 ++len;
4498 }
4499 }
4500 nextchar = arg[len];
4501
4502 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4503 {
4504 errmsg = (char_u *)N_("E518: Unknown option");
4505 goto skip;
4506 }
4507
4508 if (opt_idx >= 0)
4509 {
4510 if (options[opt_idx].var == NULL) /* hidden option: skip */
4511 {
4512 /* Only give an error message when requesting the value of
4513 * a hidden option, ignore setting it. */
4514 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4515 && (!(options[opt_idx].flags & P_BOOL)
4516 || nextchar == '?'))
4517 errmsg = (char_u *)N_("E519: Option not supported");
4518 goto skip;
4519 }
4520
4521 flags = options[opt_idx].flags;
4522 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4523 }
4524 else
4525 {
4526 flags = P_STRING;
4527 if (key < 0)
4528 {
4529 key_name[0] = KEY2TERMCAP0(key);
4530 key_name[1] = KEY2TERMCAP1(key);
4531 }
4532 else
4533 {
4534 key_name[0] = KS_KEY;
4535 key_name[1] = (key & 0xff);
4536 }
4537 }
4538
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004539 /* Skip all options that are not window-local (used when showing
4540 * an already loaded buffer in a window). */
4541 if ((opt_flags & OPT_WINONLY)
4542 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4543 goto skip;
4544
Bram Moolenaara3227e22006-03-08 21:32:40 +00004545 /* Skip all options that are window-local (used for :vimgrep). */
4546 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4547 && options[opt_idx].var == VAR_WIN)
4548 goto skip;
4549
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004550 /* Disallow changing some options from modelines. */
4551 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004552 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004553 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004554 {
4555 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4556 goto skip;
4557 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004558#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004559 /* In diff mode some options are overruled. This avoids that
4560 * 'foldmethod' becomes "marker" instead of "diff" and that
4561 * "wrap" gets set. */
4562 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004563 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004564 && (
4565#ifdef FEAT_FOLDING
4566 options[opt_idx].indir == PV_FDM ||
4567#endif
4568 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004569 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 }
4572
4573#ifdef HAVE_SANDBOX
4574 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004575 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 {
4577 errmsg = (char_u *)_(e_sandbox);
4578 goto skip;
4579 }
4580#endif
4581
4582 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4583 {
4584 arg += len;
4585 cp_val = p_cp;
4586 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4587 {
4588 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4589 {
4590 cp_val = FALSE;
4591 arg += 3;
4592 }
4593 else /* "opt&vi": set to Vi default */
4594 {
4595 cp_val = TRUE;
4596 arg += 2;
4597 }
4598 }
4599 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004600 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601 {
4602 errmsg = e_trailing;
4603 goto skip;
4604 }
4605 }
4606
4607 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004608 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4609 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 */
4611 if (nextchar == '?'
4612 || (prefix == 1
4613 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4614 && !(flags & P_BOOL)))
4615 {
4616 /*
4617 * print value
4618 */
4619 if (did_show)
4620 msg_putchar('\n'); /* cursor below last one */
4621 else
4622 {
4623 gotocmdline(TRUE); /* cursor at status line */
4624 did_show = TRUE; /* remember that we did a line */
4625 }
4626 if (opt_idx >= 0)
4627 {
4628 showoneopt(&options[opt_idx], opt_flags);
4629#ifdef FEAT_EVAL
4630 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004631 {
4632 /* Mention where the option was last set. */
4633 if (varp == options[opt_idx].var)
4634 last_set_msg(options[opt_idx].scriptID);
4635 else if ((int)options[opt_idx].indir & PV_WIN)
4636 last_set_msg(curwin->w_p_scriptID[
4637 (int)options[opt_idx].indir & PV_MASK]);
4638 else if ((int)options[opt_idx].indir & PV_BUF)
4639 last_set_msg(curbuf->b_p_scriptID[
4640 (int)options[opt_idx].indir & PV_MASK]);
4641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642#endif
4643 }
4644 else
4645 {
4646 char_u *p;
4647
4648 p = find_termcode(key_name);
4649 if (p == NULL)
4650 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004651 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 goto skip;
4653 }
4654 else
4655 (void)show_one_termcode(key_name, p, TRUE);
4656 }
4657 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004658 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 errmsg = e_trailing;
4660 }
4661 else
4662 {
4663 if (flags & P_BOOL) /* boolean */
4664 {
4665 if (nextchar == '=' || nextchar == ':')
4666 {
4667 errmsg = e_invarg;
4668 goto skip;
4669 }
4670
4671 /*
4672 * ":set opt!": invert
4673 * ":set opt&": reset to default value
4674 * ":set opt<": reset to global value
4675 */
4676 if (nextchar == '!')
4677 value = *(int *)(varp) ^ 1;
4678 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004679 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680 ((flags & P_VI_DEF) || cp_val)
4681 ? VI_DEFAULT : VIM_DEFAULT];
4682 else if (nextchar == '<')
4683 {
4684 /* For 'autoread' -1 means to use global value. */
4685 if ((int *)varp == &curbuf->b_p_ar
4686 && opt_flags == OPT_LOCAL)
4687 value = -1;
4688 else
4689 value = *(int *)get_varp_scope(&(options[opt_idx]),
4690 OPT_GLOBAL);
4691 }
4692 else
4693 {
4694 /*
4695 * ":set invopt": invert
4696 * ":set opt" or ":set noopt": set or reset
4697 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004698 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 {
4700 errmsg = e_trailing;
4701 goto skip;
4702 }
4703 if (prefix == 2) /* inv */
4704 value = *(int *)(varp) ^ 1;
4705 else
4706 value = prefix;
4707 }
4708
4709 errmsg = set_bool_option(opt_idx, varp, (int)value,
4710 opt_flags);
4711 }
4712 else /* numeric or string */
4713 {
4714 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4715 || prefix != 1)
4716 {
4717 errmsg = e_invarg;
4718 goto skip;
4719 }
4720
4721 if (flags & P_NUM) /* numeric */
4722 {
4723 /*
4724 * Different ways to set a number option:
4725 * & set to default value
4726 * < set to global value
4727 * <xx> accept special key codes for 'wildchar'
4728 * c accept any non-digit for 'wildchar'
4729 * [-]0-9 set number
4730 * other error
4731 */
4732 ++arg;
4733 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004734 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 ((flags & P_VI_DEF) || cp_val)
4736 ? VI_DEFAULT : VIM_DEFAULT];
4737 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004738 {
4739 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4740 * use the global value. */
4741 if ((long *)varp == &curbuf->b_p_ul
4742 && opt_flags == OPT_LOCAL)
4743 value = NO_LOCAL_UNDOLEVEL;
4744 else
4745 value = *(long *)get_varp_scope(
4746 &(options[opt_idx]), OPT_GLOBAL);
4747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 else if (((long *)varp == &p_wc
4749 || (long *)varp == &p_wcm)
4750 && (*arg == '<'
4751 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004752 || (*arg != NUL
4753 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 && !VIM_ISDIGIT(*arg))))
4755 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004756 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004757 if (value == 0 && (long *)varp != &p_wcm)
4758 {
4759 errmsg = e_invarg;
4760 goto skip;
4761 }
4762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004763 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4764 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004765 /* Allow negative (for 'undolevels'), octal and
4766 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004767 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4768 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004769 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 {
4771 errmsg = e_invarg;
4772 goto skip;
4773 }
4774 }
4775 else
4776 {
4777 errmsg = (char_u *)N_("E521: Number required after =");
4778 goto skip;
4779 }
4780
4781 if (adding)
4782 value = *(long *)varp + value;
4783 if (prepending)
4784 value = *(long *)varp * value;
4785 if (removing)
4786 value = *(long *)varp - value;
4787 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004788 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 }
4790 else if (opt_idx >= 0) /* string */
4791 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004792 char_u *save_arg = NULL;
4793 char_u *s = NULL;
4794 char_u *oldval = NULL; /* previous value if *varp */
4795 char_u *newval;
4796 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004797#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004798 char_u *saved_origval = NULL;
4799 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004800#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004801 unsigned newlen;
4802 int comma;
4803 int bs;
4804 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 was allocated */
4806
4807 /* When using ":set opt=val" for a global option
4808 * with a local value the local value will be
4809 * reset, use the global value here. */
4810 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004811 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004812 varp = options[opt_idx].var;
4813
4814 /* The old value is kept until we are sure that the
4815 * new value is valid. */
4816 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004817
4818 /* When setting the local value of a global
4819 * option, the old value may be the global value. */
4820 if (((int)options[opt_idx].indir & PV_BOTH)
4821 && (opt_flags & OPT_LOCAL))
4822 origval = *(char_u **)get_varp(
4823 &options[opt_idx]);
4824 else
4825 origval = oldval;
4826
Bram Moolenaar071d4272004-06-13 20:20:40 +00004827 if (nextchar == '&') /* set to default val */
4828 {
4829 newval = options[opt_idx].def_val[
4830 ((flags & P_VI_DEF) || cp_val)
4831 ? VI_DEFAULT : VIM_DEFAULT];
4832 if ((char_u **)varp == &p_bg)
4833 {
4834 /* guess the value of 'background' */
4835#ifdef FEAT_GUI
4836 if (gui.in_use)
4837 newval = gui_bg_default();
4838 else
4839#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004840 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 }
4842
4843 /* expand environment variables and ~ (since the
4844 * default value was already expanded, only
4845 * required when an environment variable was set
4846 * later */
4847 if (newval == NULL)
4848 newval = empty_option;
4849 else
4850 {
4851 s = option_expand(opt_idx, newval);
4852 if (s == NULL)
4853 s = newval;
4854 newval = vim_strsave(s);
4855 }
4856 new_value_alloced = TRUE;
4857 }
4858 else if (nextchar == '<') /* set to global val */
4859 {
4860 newval = vim_strsave(*(char_u **)get_varp_scope(
4861 &(options[opt_idx]), OPT_GLOBAL));
4862 new_value_alloced = TRUE;
4863 }
4864 else
4865 {
4866 ++arg; /* jump to after the '=' or ':' */
4867
4868 /*
4869 * Set 'keywordprg' to ":help" if an empty
4870 * value was passed to :set by the user.
4871 * Misuse errbuf[] for the resulting string.
4872 */
4873 if (varp == (char_u *)&p_kp
4874 && (*arg == NUL || *arg == ' '))
4875 {
4876 STRCPY(errbuf, ":help");
4877 save_arg = arg;
4878 arg = errbuf;
4879 }
4880 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004881 * Convert 'backspace' number to string, for
4882 * adding, prepending and removing string.
4883 */
4884 else if (varp == (char_u *)&p_bs
4885 && VIM_ISDIGIT(**(char_u **)varp))
4886 {
4887 i = getdigits((char_u **)varp);
4888 switch (i)
4889 {
4890 case 0:
4891 *(char_u **)varp = empty_option;
4892 break;
4893 case 1:
4894 *(char_u **)varp = vim_strsave(
4895 (char_u *)"indent,eol");
4896 break;
4897 case 2:
4898 *(char_u **)varp = vim_strsave(
4899 (char_u *)"indent,eol,start");
4900 break;
4901 }
4902 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004903 if (origval == oldval)
4904 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004905 oldval = *(char_u **)varp;
4906 }
4907 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 * Convert 'whichwrap' number to string, for
4909 * backwards compatibility with Vim 3.0.
4910 * Misuse errbuf[] for the resulting string.
4911 */
4912 else if (varp == (char_u *)&p_ww
4913 && VIM_ISDIGIT(*arg))
4914 {
4915 *errbuf = NUL;
4916 i = getdigits(&arg);
4917 if (i & 1)
4918 STRCAT(errbuf, "b,");
4919 if (i & 2)
4920 STRCAT(errbuf, "s,");
4921 if (i & 4)
4922 STRCAT(errbuf, "h,l,");
4923 if (i & 8)
4924 STRCAT(errbuf, "<,>,");
4925 if (i & 16)
4926 STRCAT(errbuf, "[,],");
4927 if (*errbuf != NUL) /* remove trailing , */
4928 errbuf[STRLEN(errbuf) - 1] = NUL;
4929 save_arg = arg;
4930 arg = errbuf;
4931 }
4932 /*
4933 * Remove '>' before 'dir' and 'bdir', for
4934 * backwards compatibility with version 3.0
4935 */
4936 else if ( *arg == '>'
4937 && (varp == (char_u *)&p_dir
4938 || varp == (char_u *)&p_bdir))
4939 {
4940 ++arg;
4941 }
4942
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 /*
4944 * Copy the new string into allocated memory.
4945 * Can't use set_string_option_direct(), because
4946 * we need to remove the backslashes.
4947 */
4948 /* get a bit too much */
4949 newlen = (unsigned)STRLEN(arg) + 1;
4950 if (adding || prepending || removing)
4951 newlen += (unsigned)STRLEN(origval) + 1;
4952 newval = alloc(newlen);
4953 if (newval == NULL) /* out of mem, don't change */
4954 break;
4955 s = newval;
4956
4957 /*
4958 * Copy the string, skip over escaped chars.
4959 * For MS-DOS and WIN32 backslashes before normal
4960 * file name characters are not removed, and keep
4961 * backslash at start, for "\\machine\path", but
4962 * do remove it for "\\\\machine\\path".
4963 * The reverse is found in ExpandOldSetting().
4964 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004965 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004966 {
4967 if (*arg == '\\' && arg[1] != NUL
4968#ifdef BACKSLASH_IN_FILENAME
4969 && !((flags & P_EXPAND)
4970 && vim_isfilec(arg[1])
4971 && (arg[1] != '\\'
4972 || (s == newval
4973 && arg[2] != '\\')))
4974#endif
4975 )
4976 ++arg; /* remove backslash */
4977#ifdef FEAT_MBYTE
4978 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004979 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004980 {
4981 /* copy multibyte char */
4982 mch_memmove(s, arg, (size_t)i);
4983 arg += i;
4984 s += i;
4985 }
4986 else
4987#endif
4988 *s++ = *arg++;
4989 }
4990 *s = NUL;
4991
4992 /*
4993 * Expand environment variables and ~.
4994 * Don't do it when adding without inserting a
4995 * comma.
4996 */
4997 if (!(adding || prepending || removing)
4998 || (flags & P_COMMA))
4999 {
5000 s = option_expand(opt_idx, newval);
5001 if (s != NULL)
5002 {
5003 vim_free(newval);
5004 newlen = (unsigned)STRLEN(s) + 1;
5005 if (adding || prepending || removing)
5006 newlen += (unsigned)STRLEN(origval) + 1;
5007 newval = alloc(newlen);
5008 if (newval == NULL)
5009 break;
5010 STRCPY(newval, s);
5011 }
5012 }
5013
5014 /* locate newval[] in origval[] when removing it
5015 * and when adding to avoid duplicates */
5016 i = 0; /* init for GCC */
5017 if (removing || (flags & P_NODUP))
5018 {
5019 i = (int)STRLEN(newval);
5020 bs = 0;
5021 for (s = origval; *s; ++s)
5022 {
5023 if ((!(flags & P_COMMA)
5024 || s == origval
5025 || (s[-1] == ',' && !(bs & 1)))
5026 && STRNCMP(s, newval, i) == 0
5027 && (!(flags & P_COMMA)
5028 || s[i] == ','
5029 || s[i] == NUL))
5030 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005031 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005032 * even number of backslashes or a single
5033 * backslash preceded by a comma before it
5034 * is recognized as a separator */
5035 if ((s > origval + 1
5036 && s[-1] == '\\'
5037 && s[-2] != ',')
5038 || (s == origval + 1
5039 && s[-1] == '\\'))
5040
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 ++bs;
5042 else
5043 bs = 0;
5044 }
5045
5046 /* do not add if already there */
5047 if ((adding || prepending) && *s)
5048 {
5049 prepending = FALSE;
5050 adding = FALSE;
5051 STRCPY(newval, origval);
5052 }
5053 }
5054
5055 /* concatenate the two strings; add a ',' if
5056 * needed */
5057 if (adding || prepending)
5058 {
5059 comma = ((flags & P_COMMA) && *origval != NUL
5060 && *newval != NUL);
5061 if (adding)
5062 {
5063 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005064 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005065 if (comma && i > 1
5066 && (flags & P_ONECOMMA) == P_ONECOMMA
5067 && origval[i - 1] == ','
5068 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005069 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005070 mch_memmove(newval + i + comma, newval,
5071 STRLEN(newval) + 1);
5072 mch_memmove(newval, origval, (size_t)i);
5073 }
5074 else
5075 {
5076 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005077 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 }
5079 if (comma)
5080 newval[i] = ',';
5081 }
5082
5083 /* Remove newval[] from origval[]. (Note: "i" has
5084 * been set above and is used here). */
5085 if (removing)
5086 {
5087 STRCPY(newval, origval);
5088 if (*s)
5089 {
5090 /* may need to remove a comma */
5091 if (flags & P_COMMA)
5092 {
5093 if (s == origval)
5094 {
5095 /* include comma after string */
5096 if (s[i] == ',')
5097 ++i;
5098 }
5099 else
5100 {
5101 /* include comma before string */
5102 --s;
5103 ++i;
5104 }
5105 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005106 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005107 }
5108 }
5109
5110 if (flags & P_FLAGLIST)
5111 {
5112 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005113 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005114 {
5115 /* if options have P_FLAGLIST and
5116 * P_ONECOMMA such as 'whichwrap' */
5117 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005118 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005119 if (*s != ',' && *(s + 1) == ','
5120 && vim_strchr(s + 2, *s) != NULL)
5121 {
5122 /* Remove the duplicated value and
5123 * the next comma. */
5124 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005125 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005128 else
5129 {
5130 if ((!(flags & P_COMMA) || *s != ',')
5131 && vim_strchr(s + 1, *s) != NULL)
5132 {
5133 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005134 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005135 }
5136 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005137 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 }
5140
5141 if (save_arg != NULL) /* number for 'whichwrap' */
5142 arg = save_arg;
5143 new_value_alloced = TRUE;
5144 }
5145
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005146 /*
5147 * Set the new value.
5148 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005149 *(char_u **)(varp) = newval;
5150
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005151#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005152 if (!starting
5153# ifdef FEAT_CRYPT
5154 && options[opt_idx].indir != PV_KEY
5155# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005156 && origval != NULL && newval != NULL)
5157 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005158 /* origval may be freed by
5159 * did_set_string_option(), make a copy. */
5160 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005161 /* newval (and varp) may become invalid if the
5162 * buffer is closed by autocommands. */
5163 saved_newval = vim_strsave(newval);
5164 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005165#endif
5166
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005168 * ":set" on local options. Note: when setting 'syntax'
5169 * or 'filetype' autocommands may be triggered that can
5170 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5172 new_value_alloced, oldval, errbuf, opt_flags);
5173
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005174#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005175 if (errmsg == NULL)
5176 trigger_optionsset_string(opt_idx, opt_flags,
5177 saved_origval, saved_newval);
5178 vim_free(saved_origval);
5179 vim_free(saved_newval);
5180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005181 /* If error detected, print the error message. */
5182 if (errmsg != NULL)
5183 goto skip;
5184 }
5185 else /* key code option */
5186 {
5187 char_u *p;
5188
5189 if (nextchar == '&')
5190 {
5191 if (add_termcap_entry(key_name, TRUE) == FAIL)
5192 errmsg = (char_u *)N_("E522: Not found in termcap");
5193 }
5194 else
5195 {
5196 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005197 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005198 if (*p == '\\' && p[1] != NUL)
5199 ++p;
5200 nextchar = *p;
5201 *p = NUL;
5202 add_termcode(key_name, arg, FALSE);
5203 *p = nextchar;
5204 }
5205 if (full_screen)
5206 ttest(FALSE);
5207 redraw_all_later(CLEAR);
5208 }
5209 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005210
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005212 did_set_option(opt_idx, opt_flags,
5213 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 }
5215
5216skip:
5217 /*
5218 * Advance to next argument.
5219 * - skip until a blank found, taking care of backslashes
5220 * - skip blanks
5221 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5222 */
5223 for (i = 0; i < 2 ; ++i)
5224 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005225 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226 if (*arg++ == '\\' && *arg != NUL)
5227 ++arg;
5228 arg = skipwhite(arg);
5229 if (*arg != '=')
5230 break;
5231 }
5232 }
5233
5234 if (errmsg != NULL)
5235 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005236 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005237 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005238 if (i + (arg - startarg) < IOSIZE)
5239 {
5240 /* append the argument with the error */
5241 STRCAT(IObuff, ": ");
5242 mch_memmove(IObuff + i, startarg, (arg - startarg));
5243 IObuff[i + (arg - startarg)] = NUL;
5244 }
5245 /* make sure all characters are printable */
5246 trans_characters(IObuff, IOSIZE);
5247
5248 ++no_wait_return; /* wait_return done later */
5249 emsg(IObuff); /* show error highlighted */
5250 --no_wait_return;
5251
5252 return FAIL;
5253 }
5254
5255 arg = skipwhite(arg);
5256 }
5257
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005258theend:
5259 if (silent_mode && did_show)
5260 {
5261 /* After displaying option values in silent mode. */
5262 silent_mode = FALSE;
5263 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5264 msg_putchar('\n');
5265 cursor_on(); /* msg_start() switches it off */
5266 out_flush();
5267 silent_mode = TRUE;
5268 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5269 }
5270
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 return OK;
5272}
5273
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005274/*
5275 * Call this when an option has been given a new value through a user command.
5276 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5277 */
5278 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005279did_set_option(
5280 int opt_idx,
5281 int opt_flags, /* possibly with OPT_MODELINE */
5282 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005283{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005284 long_u *p;
5285
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005286 options[opt_idx].flags |= P_WAS_SET;
5287
5288 /* When an option is set in the sandbox, from a modeline or in secure mode
5289 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005290 * flag. */
5291 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005292 if (secure
5293#ifdef HAVE_SANDBOX
5294 || sandbox != 0
5295#endif
5296 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005297 *p = *p | P_INSECURE;
5298 else if (new_value)
5299 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005300}
5301
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005303illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304{
5305 if (errbuf == NULL)
5306 return (char_u *)"";
5307 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005308 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 return errbuf;
5310}
5311
5312/*
5313 * Convert a key name or string into a key value.
5314 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005315 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005317 int
5318string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319{
5320 if (*arg == '<')
5321 return find_key_option(arg + 1);
5322 if (*arg == '^')
5323 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005324 if (multi_byte)
5325 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 return *arg;
5327}
5328
5329#ifdef FEAT_CMDWIN
5330/*
5331 * Check value of 'cedit' and set cedit_key.
5332 * Returns NULL if value is OK, error message otherwise.
5333 */
5334 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005335check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336{
5337 int n;
5338
5339 if (*p_cedit == NUL)
5340 cedit_key = -1;
5341 else
5342 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005343 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344 if (vim_isprintc(n))
5345 return e_invarg;
5346 cedit_key = n;
5347 }
5348 return NULL;
5349}
5350#endif
5351
5352#ifdef FEAT_TITLE
5353/*
5354 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5355 * maketitle() to create and display it.
5356 * When switching the title or icon off, call mch_restore_title() to get
5357 * the old value back.
5358 */
5359 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005360did_set_title(
5361 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362{
5363 if (starting != NO_SCREEN
5364#ifdef FEAT_GUI
5365 && !gui.starting
5366#endif
5367 )
5368 {
5369 maketitle();
5370 if (icon)
5371 {
5372 if (!p_icon)
5373 mch_restore_title(2);
5374 }
5375 else
5376 {
5377 if (!p_title)
5378 mch_restore_title(1);
5379 }
5380 }
5381}
5382#endif
5383
5384/*
5385 * set_options_bin - called when 'bin' changes value.
5386 */
5387 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005388set_options_bin(
5389 int oldval,
5390 int newval,
5391 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392{
5393 /*
5394 * The option values that are changed when 'bin' changes are
5395 * copied when 'bin is set and restored when 'bin' is reset.
5396 */
5397 if (newval)
5398 {
5399 if (!oldval) /* switched on */
5400 {
5401 if (!(opt_flags & OPT_GLOBAL))
5402 {
5403 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5404 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5405 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5406 curbuf->b_p_et_nobin = curbuf->b_p_et;
5407 }
5408 if (!(opt_flags & OPT_LOCAL))
5409 {
5410 p_tw_nobin = p_tw;
5411 p_wm_nobin = p_wm;
5412 p_ml_nobin = p_ml;
5413 p_et_nobin = p_et;
5414 }
5415 }
5416
5417 if (!(opt_flags & OPT_GLOBAL))
5418 {
5419 curbuf->b_p_tw = 0; /* no automatic line wrap */
5420 curbuf->b_p_wm = 0; /* no automatic line wrap */
5421 curbuf->b_p_ml = 0; /* no modelines */
5422 curbuf->b_p_et = 0; /* no expandtab */
5423 }
5424 if (!(opt_flags & OPT_LOCAL))
5425 {
5426 p_tw = 0;
5427 p_wm = 0;
5428 p_ml = FALSE;
5429 p_et = FALSE;
5430 p_bin = TRUE; /* needed when called for the "-b" argument */
5431 }
5432 }
5433 else if (oldval) /* switched off */
5434 {
5435 if (!(opt_flags & OPT_GLOBAL))
5436 {
5437 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5438 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5439 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5440 curbuf->b_p_et = curbuf->b_p_et_nobin;
5441 }
5442 if (!(opt_flags & OPT_LOCAL))
5443 {
5444 p_tw = p_tw_nobin;
5445 p_wm = p_wm_nobin;
5446 p_ml = p_ml_nobin;
5447 p_et = p_et_nobin;
5448 }
5449 }
5450}
5451
5452#ifdef FEAT_VIMINFO
5453/*
5454 * Find the parameter represented by the given character (eg ', :, ", or /),
5455 * and return its associated value in the 'viminfo' string.
5456 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005457 * If the parameter is not specified in the string or there is no following
5458 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459 */
5460 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005461get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462{
5463 char_u *p;
5464
5465 p = find_viminfo_parameter(type);
5466 if (p != NULL && VIM_ISDIGIT(*p))
5467 return atoi((char *)p);
5468 return -1;
5469}
5470
5471/*
5472 * Find the parameter represented by the given character (eg ''', ':', '"', or
5473 * '/') in the 'viminfo' option and return a pointer to the string after it.
5474 * Return NULL if the parameter is not specified in the string.
5475 */
5476 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005477find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478{
5479 char_u *p;
5480
5481 for (p = p_viminfo; *p; ++p)
5482 {
5483 if (*p == type)
5484 return p + 1;
5485 if (*p == 'n') /* 'n' is always the last one */
5486 break;
5487 p = vim_strchr(p, ','); /* skip until next ',' */
5488 if (p == NULL) /* hit the end without finding parameter */
5489 break;
5490 }
5491 return NULL;
5492}
5493#endif
5494
5495/*
5496 * Expand environment variables for some string options.
5497 * These string options cannot be indirect!
5498 * If "val" is NULL expand the current value of the option.
5499 * Return pointer to NameBuff, or NULL when not expanded.
5500 */
5501 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005502option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503{
5504 /* if option doesn't need expansion nothing to do */
5505 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5506 return NULL;
5507
5508 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5509 * expand_env() would truncate the string. */
5510 if (val != NULL && STRLEN(val) > MAXPATHL)
5511 return NULL;
5512
5513 if (val == NULL)
5514 val = *(char_u **)options[opt_idx].var;
5515
5516 /*
5517 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5518 * Escape spaces when expanding 'tags', they are used to separate file
5519 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005520 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521 */
5522 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005523 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005524#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005525 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5526#endif
5527 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5529 return NULL;
5530
5531 return NameBuff;
5532}
5533
5534/*
5535 * After setting various option values: recompute variables that depend on
5536 * option values.
5537 */
5538 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005539didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540{
5541 /* initialize the table for 'iskeyword' et.al. */
5542 (void)init_chartab();
5543
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005544#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005548 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549#ifdef FEAT_SESSION
5550 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5551 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5552#endif
5553#ifdef FEAT_FOLDING
5554 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5555#endif
5556 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005557 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558#ifdef FEAT_VIRTUALEDIT
5559 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5560#endif
5561#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5562 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005564#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005565 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005566 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005567 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005568 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005569#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5571 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5572#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005573#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5575#endif
5576#ifdef FEAT_CMDWIN
5577 /* set cedit_key */
5578 (void)check_cedit();
5579#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005580#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005581 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005582#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005583#ifdef FEAT_LINEBREAK
5584 /* initialize the table for 'breakat'. */
5585 fill_breakat_flags();
5586#endif
5587
5588}
5589
5590/*
5591 * More side effects of setting options.
5592 */
5593 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005594didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005595{
5596 /* Initialize the highlight_attr[] table. */
5597 (void)highlight_changed();
5598
5599 /* Parse default for 'wildmode' */
5600 check_opt_wim();
5601
5602 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005603 /* Parse default for 'fillchars'. */
5604 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005605
5606#ifdef FEAT_CLIPBOARD
5607 /* Parse default for 'clipboard' */
5608 (void)check_clipboard_option();
5609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005610}
5611
5612/*
5613 * Check for string options that are NULL (normally only termcap options).
5614 */
5615 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005616check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617{
5618 int opt_idx;
5619
5620 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5621 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5622 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5623}
5624
5625/*
5626 * Check string options in a buffer for NULL value.
5627 */
5628 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005629check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631 check_string_option(&buf->b_p_bh);
5632 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633#ifdef FEAT_MBYTE
5634 check_string_option(&buf->b_p_fenc);
5635#endif
5636 check_string_option(&buf->b_p_ff);
5637#ifdef FEAT_FIND_ID
5638 check_string_option(&buf->b_p_def);
5639 check_string_option(&buf->b_p_inc);
5640# ifdef FEAT_EVAL
5641 check_string_option(&buf->b_p_inex);
5642# endif
5643#endif
5644#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5645 check_string_option(&buf->b_p_inde);
5646 check_string_option(&buf->b_p_indk);
5647#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005648#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5649 check_string_option(&buf->b_p_bexpr);
5650#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005651#if defined(FEAT_CRYPT)
5652 check_string_option(&buf->b_p_cm);
5653#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005654 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005655#if defined(FEAT_EVAL)
5656 check_string_option(&buf->b_p_fex);
5657#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658#ifdef FEAT_CRYPT
5659 check_string_option(&buf->b_p_key);
5660#endif
5661 check_string_option(&buf->b_p_kp);
5662 check_string_option(&buf->b_p_mps);
5663 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005664 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 check_string_option(&buf->b_p_isk);
5666#ifdef FEAT_COMMENTS
5667 check_string_option(&buf->b_p_com);
5668#endif
5669#ifdef FEAT_FOLDING
5670 check_string_option(&buf->b_p_cms);
5671#endif
5672 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005673#ifdef FEAT_TEXTOBJ
5674 check_string_option(&buf->b_p_qe);
5675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676#ifdef FEAT_SYN_HL
5677 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005678 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005679#endif
5680#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005681 check_string_option(&buf->b_s.b_p_spc);
5682 check_string_option(&buf->b_s.b_p_spf);
5683 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684#endif
5685#ifdef FEAT_SEARCHPATH
5686 check_string_option(&buf->b_p_sua);
5687#endif
5688#ifdef FEAT_CINDENT
5689 check_string_option(&buf->b_p_cink);
5690 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005691 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5695 check_string_option(&buf->b_p_cinw);
5696#endif
5697#ifdef FEAT_INS_EXPAND
5698 check_string_option(&buf->b_p_cpt);
5699#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005700#ifdef FEAT_COMPL_FUNC
5701 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005702 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704#ifdef FEAT_KEYMAP
5705 check_string_option(&buf->b_p_keymap);
5706#endif
5707#ifdef FEAT_QUICKFIX
5708 check_string_option(&buf->b_p_gp);
5709 check_string_option(&buf->b_p_mp);
5710 check_string_option(&buf->b_p_efm);
5711#endif
5712 check_string_option(&buf->b_p_ep);
5713 check_string_option(&buf->b_p_path);
5714 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005715 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716#ifdef FEAT_INS_EXPAND
5717 check_string_option(&buf->b_p_dict);
5718 check_string_option(&buf->b_p_tsr);
5719#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005720#ifdef FEAT_LISP
5721 check_string_option(&buf->b_p_lw);
5722#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005723 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005724#ifdef FEAT_MBYTE
5725 check_string_option(&buf->b_p_menc);
5726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727}
5728
5729/*
5730 * Free the string allocated for an option.
5731 * Checks for the string being empty_option. This may happen if we're out of
5732 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5733 * check_options().
5734 * Does NOT check for P_ALLOCED flag!
5735 */
5736 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005737free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738{
5739 if (p != empty_option)
5740 vim_free(p);
5741}
5742
5743 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005744clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745{
5746 if (*pp != empty_option)
5747 vim_free(*pp);
5748 *pp = empty_option;
5749}
5750
5751 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005752check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753{
5754 if (*pp == NULL)
5755 *pp = empty_option;
5756}
5757
5758/*
5759 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5760 */
5761 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005762set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763{
5764 int opt_idx;
5765
5766 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5767 if (options[opt_idx].var == (char_u *)p)
5768 {
5769 options[opt_idx].flags |= P_ALLOCED;
5770 return;
5771 }
5772 return; /* cannot happen: didn't find it! */
5773}
5774
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005775#if defined(FEAT_EVAL) || defined(PROTO)
5776/*
5777 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5778 * Return FALSE when it wasn't.
5779 * Return -1 for an unknown option.
5780 */
5781 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005782was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005783{
5784 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005786
5787 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005788 {
5789 flagp = insecure_flag(idx, opt_flags);
5790 return (*flagp & P_INSECURE) != 0;
5791 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005792 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005793 return -1;
5794}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795
5796/*
5797 * Get a pointer to the flags used for the P_INSECURE flag of option
5798 * "opt_idx". For some local options a local flags field is used.
5799 */
5800 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005801insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005802{
5803 if (opt_flags & OPT_LOCAL)
5804 switch ((int)options[opt_idx].indir)
5805 {
5806#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005807 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005808#endif
5809#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005810# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005811 case PV_FDE: return &curwin->w_p_fde_flags;
5812 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005813# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005814# ifdef FEAT_BEVAL
5815 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5816# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005817# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005818 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005819# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005820 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005823# endif
5824#endif
5825 }
5826
5827 /* Nothing special, return global flags field. */
5828 return &options[opt_idx].flags;
5829}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005830#endif
5831
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005832#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005833static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005834
5835/*
5836 * Redraw the window title and/or tab page text later.
5837 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005838static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005839{
5840 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005841 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005842}
5843#endif
5844
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845/*
5846 * Set a string option to a new value (without checking the effect).
5847 * The string is copied into allocated memory.
5848 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005849 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005850 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 */
5852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005853set_string_option_direct(
5854 char_u *name,
5855 int opt_idx,
5856 char_u *val,
5857 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5858 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859{
5860 char_u *s;
5861 char_u **varp;
5862 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005863 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 idx = findoption(name);
5868 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005869 {
5870 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005871 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874 }
5875
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877 return;
5878
5879 s = vim_strsave(val);
5880 if (s != NULL)
5881 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 free_string_option(*varp);
5886 *varp = s;
5887
5888 /* For buffer/window local option may also set the global value. */
5889 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005890 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891
Bram Moolenaar89d40322006-08-29 15:30:07 +00005892 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893
5894 /* When setting both values of a global option with a local value,
5895 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005896 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 {
5898 free_string_option(*varp);
5899 *varp = empty_option;
5900 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005901# ifdef FEAT_EVAL
5902 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005904 set_sid == 0 ? current_SID : set_sid);
5905# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 }
5907}
5908
5909/*
5910 * Set global value for string option when it's a local option.
5911 */
5912 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005913set_string_option_global(
5914 int opt_idx, /* option index */
5915 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916{
5917 char_u **p, *s;
5918
5919 /* the global value is always allocated */
5920 if (options[opt_idx].var == VAR_WIN)
5921 p = (char_u **)GLOBAL_WO(varp);
5922 else
5923 p = (char_u **)options[opt_idx].var;
5924 if (options[opt_idx].indir != PV_NONE
5925 && p != varp
5926 && (s = vim_strsave(*varp)) != NULL)
5927 {
5928 free_string_option(*p);
5929 *p = s;
5930 }
5931}
5932
5933/*
5934 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005935 *
5936 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005938 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005939set_string_option(
5940 int opt_idx,
5941 char_u *value,
5942 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943{
5944 char_u *s;
5945 char_u **varp;
5946 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005947#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005948 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005949 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005950#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005951 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005952
5953 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005954 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955
5956 s = vim_strsave(value);
5957 if (s != NULL)
5958 {
5959 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5960 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005961 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962 ? OPT_GLOBAL : OPT_LOCAL)
5963 : opt_flags);
5964 oldval = *varp;
5965 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005966
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005967#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005968 if (!starting
5969# ifdef FEAT_CRYPT
5970 && options[opt_idx].indir != PV_KEY
5971# endif
5972 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005973 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005974 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005975 saved_newval = vim_strsave(s);
5976 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005977#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005978 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5979 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005980 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005981
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005982#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005983 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005984 if (r == NULL)
5985 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005986 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005987 vim_free(saved_oldval);
5988 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005991 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992}
5993
5994/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005995 * Return TRUE if "val" is a valid 'filetype' name.
5996 * Also used for 'syntax' and 'keymap'.
5997 */
5998 static int
5999valid_filetype(char_u *val)
6000{
6001 char_u *s;
6002
6003 for (s = val; *s != NUL; ++s)
6004 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6005 return FALSE;
6006 return TRUE;
6007}
6008
6009/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006010 * Handle string options that need some action to perform when changed.
6011 * Returns NULL for success, or an error message for an error.
6012 */
6013 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006014did_set_string_option(
6015 int opt_idx, /* index in options[] table */
6016 char_u **varp, /* pointer to the option variable */
6017 int new_value_alloced, /* new value was allocated */
6018 char_u *oldval, /* previous value of the option */
6019 char_u *errbuf, /* buffer for errors, or NULL */
6020 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006021{
6022 char_u *errmsg = NULL;
6023 char_u *s, *p;
6024 int did_chartab = FALSE;
6025 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006026 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006027#ifdef FEAT_GUI
6028 /* set when changing an option that only requires a redraw in the GUI */
6029 int redraw_gui_only = FALSE;
6030#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006031 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032
6033 /* Get the global option to compare with, otherwise we would have to check
6034 * two values for all local options. */
6035 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6036
6037 /* Disallow changing some options from secure mode */
6038 if ((secure
6039#ifdef HAVE_SANDBOX
6040 || sandbox != 0
6041#endif
6042 ) && (options[opt_idx].flags & P_SECURE))
6043 {
6044 errmsg = e_secure;
6045 }
6046
Bram Moolenaar7554da42016-11-25 22:04:13 +01006047 /* Check for a "normal" directory or file name in some options. Disallow a
6048 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006049 * are often illegal in a file name. Be more permissive if "secure" is off.
6050 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006051 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006052 && vim_strpbrk(*varp, (char_u *)(secure
6053 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006054 || ((options[opt_idx].flags & P_NDNAME)
6055 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006056 {
6057 errmsg = e_invarg;
6058 }
6059
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060 /* 'term' */
6061 else if (varp == &T_NAME)
6062 {
6063 if (T_NAME[0] == NUL)
6064 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6065#ifdef FEAT_GUI
6066 if (gui.in_use)
6067 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6068 else if (term_is_gui(T_NAME))
6069 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6070#endif
6071 else if (set_termname(T_NAME) == FAIL)
6072 errmsg = (char_u *)N_("E522: Not found in termcap");
6073 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006074 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075 /* Screen colors may have changed. */
6076 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006077
6078 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6079 * P_ALLOCED flag on 'term'. */
6080 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006081 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083 }
6084
6085 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006086 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006088 char_u *bkc = p_bkc;
6089 unsigned int *flags = &bkc_flags;
6090
6091 if (opt_flags & OPT_LOCAL)
6092 {
6093 bkc = curbuf->b_p_bkc;
6094 flags = &curbuf->b_bkc_flags;
6095 }
6096
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006097 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6098 /* make the local value empty: use the global value */
6099 *flags = 0;
6100 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006102 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6103 errmsg = e_invarg;
6104 if ((((int)*flags & BKC_AUTO) != 0)
6105 + (((int)*flags & BKC_YES) != 0)
6106 + (((int)*flags & BKC_NO) != 0) != 1)
6107 {
6108 /* Must have exactly one of "auto", "yes" and "no". */
6109 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6110 errmsg = e_invarg;
6111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 }
6113 }
6114
6115 /* 'backupext' and 'patchmode' */
6116 else if (varp == &p_bex || varp == &p_pm)
6117 {
6118 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6119 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6120 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6121 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006122#ifdef FEAT_LINEBREAK
6123 /* 'breakindentopt' */
6124 else if (varp == &curwin->w_p_briopt)
6125 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006126 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006127 errmsg = e_invarg;
6128 }
6129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130
6131 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006132 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006134 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 */
6136 else if ( varp == &p_isi
6137 || varp == &(curbuf->b_p_isk)
6138 || varp == &p_isp
6139 || varp == &p_isf)
6140 {
6141 if (init_chartab() == FAIL)
6142 {
6143 did_chartab = TRUE; /* need to restore it below */
6144 errmsg = e_invarg; /* error in value */
6145 }
6146 }
6147
6148 /* 'helpfile' */
6149 else if (varp == &p_hf)
6150 {
6151 /* May compute new values for $VIM and $VIMRUNTIME */
6152 if (didset_vim)
6153 {
6154 vim_setenv((char_u *)"VIM", (char_u *)"");
6155 didset_vim = FALSE;
6156 }
6157 if (didset_vimruntime)
6158 {
6159 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6160 didset_vimruntime = FALSE;
6161 }
6162 }
6163
Bram Moolenaar1a384422010-07-14 19:53:30 +02006164#ifdef FEAT_SYN_HL
6165 /* 'colorcolumn' */
6166 else if (varp == &curwin->w_p_cc)
6167 errmsg = check_colorcolumn(curwin);
6168#endif
6169
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170#ifdef FEAT_MULTI_LANG
6171 /* 'helplang' */
6172 else if (varp == &p_hlg)
6173 {
6174 /* Check for "", "ab", "ab,cd", etc. */
6175 for (s = p_hlg; *s != NUL; s += 3)
6176 {
6177 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6178 {
6179 errmsg = e_invarg;
6180 break;
6181 }
6182 if (s[2] == NUL)
6183 break;
6184 }
6185 }
6186#endif
6187
6188 /* 'highlight' */
6189 else if (varp == &p_hl)
6190 {
6191 if (highlight_changed() == FAIL)
6192 errmsg = e_invarg; /* invalid flags */
6193 }
6194
6195 /* 'nrformats' */
6196 else if (gvarp == &p_nf)
6197 {
6198 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6199 errmsg = e_invarg;
6200 }
6201
6202#ifdef FEAT_SESSION
6203 /* 'sessionoptions' */
6204 else if (varp == &p_ssop)
6205 {
6206 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6207 errmsg = e_invarg;
6208 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6209 {
6210 /* Don't allow both "sesdir" and "curdir". */
6211 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6212 errmsg = e_invarg;
6213 }
6214 }
6215 /* 'viewoptions' */
6216 else if (varp == &p_vop)
6217 {
6218 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6219 errmsg = e_invarg;
6220 }
6221#endif
6222
6223 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 else if (varp == &p_sbo)
6225 {
6226 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6227 errmsg = e_invarg;
6228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229
6230 /* 'ambiwidth' */
6231#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006232 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233 {
6234 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6235 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006236 else if (set_chars_option(&p_lcs) != NULL)
6237 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006238 else if (set_chars_option(&p_fcs) != NULL)
6239 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 }
6241#endif
6242
6243 /* 'background' */
6244 else if (varp == &p_bg)
6245 {
6246 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6247 {
6248#ifdef FEAT_EVAL
6249 int dark = (*p_bg == 'd');
6250#endif
6251
6252 init_highlight(FALSE, FALSE);
6253
6254#ifdef FEAT_EVAL
6255 if (dark != (*p_bg == 'd')
6256 && get_var_value((char_u *)"g:colors_name") != NULL)
6257 {
6258 /* The color scheme must have set 'background' back to another
6259 * value, that's not what we want here. Disable the color
6260 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006261 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262 free_string_option(p_bg);
6263 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6264 check_string_option(&p_bg);
6265 init_highlight(FALSE, FALSE);
6266 }
6267#endif
6268 }
6269 else
6270 errmsg = e_invarg;
6271 }
6272
6273 /* 'wildmode' */
6274 else if (varp == &p_wim)
6275 {
6276 if (check_opt_wim() == FAIL)
6277 errmsg = e_invarg;
6278 }
6279
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006280#ifdef FEAT_CMDL_COMPL
6281 /* 'wildoptions' */
6282 else if (varp == &p_wop)
6283 {
6284 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6285 errmsg = e_invarg;
6286 }
6287#endif
6288
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289#ifdef FEAT_WAK
6290 /* 'winaltkeys' */
6291 else if (varp == &p_wak)
6292 {
6293 if (*p_wak == NUL
6294 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6295 errmsg = e_invarg;
6296# ifdef FEAT_MENU
6297# ifdef FEAT_GUI_MOTIF
6298 else if (gui.in_use)
6299 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6300# else
6301# ifdef FEAT_GUI_GTK
6302 else if (gui.in_use)
6303 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6304# endif
6305# endif
6306# endif
6307 }
6308#endif
6309
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 /* 'eventignore' */
6311 else if (varp == &p_ei)
6312 {
6313 if (check_ei() == FAIL)
6314 errmsg = e_invarg;
6315 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316
6317#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006318 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6319 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6320 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 {
6322 if (gvarp == &p_fenc)
6323 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006324 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 errmsg = e_modifiable;
6326 else if (vim_strchr(*varp, ',') != NULL)
6327 /* No comma allowed in 'fileencoding'; catches confusing it
6328 * with 'fileencodings'. */
6329 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006331 {
6332# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006333 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006334 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006335# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006336 /* Add 'fileencoding' to the swap file. */
6337 ml_setflags(curbuf);
6338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 }
6340 if (errmsg == NULL)
6341 {
6342 /* canonize the value, so that STRCMP() can be used on it */
6343 p = enc_canonize(*varp);
6344 if (p != NULL)
6345 {
6346 vim_free(*varp);
6347 *varp = p;
6348 }
6349 if (varp == &p_enc)
6350 {
6351 errmsg = mb_init();
6352# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006353 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354# endif
6355 }
6356 }
6357
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006358# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6360 {
6361 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6362 if (STRCMP(p_tenc, "utf-8") != 0)
6363 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6364 }
6365# endif
6366
6367 if (errmsg == NULL)
6368 {
6369# ifdef FEAT_KEYMAP
6370 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6371 * (with another encoding). */
6372 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6373 (void)keymap_init();
6374# endif
6375
6376 /* When 'termencoding' is not empty and 'encoding' changes or when
6377 * 'termencoding' changes, need to setup for keyboard input and
6378 * display output conversion. */
6379 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6380 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006381 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6382 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6383 {
6384 EMSG3(_("E950: Cannot convert between %s and %s"),
6385 p_tenc, p_enc);
6386 errmsg = e_invarg;
6387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006389
6390# if defined(WIN3264) && defined(FEAT_MBYTE)
6391 /* $HOME may have characters in active code page. */
6392 if (varp == &p_enc)
6393 init_homedir();
6394# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006395 }
6396 }
6397#endif
6398
6399#if defined(FEAT_POSTSCRIPT)
6400 else if (varp == &p_penc)
6401 {
6402 /* Canonize printencoding if VIM standard one */
6403 p = enc_canonize(p_penc);
6404 if (p != NULL)
6405 {
6406 vim_free(p_penc);
6407 p_penc = p;
6408 }
6409 else
6410 {
6411 /* Ensure lower case and '-' for '_' */
6412 for (s = p_penc; *s != NUL; s++)
6413 {
6414 if (*s == '_')
6415 *s = '-';
6416 else
6417 *s = TOLOWER_ASC(*s);
6418 }
6419 }
6420 }
6421#endif
6422
Bram Moolenaar9372a112005-12-06 19:59:18 +00006423#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424 else if (varp == &p_imak)
6425 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006426 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006427 errmsg = e_invarg;
6428 }
6429#endif
6430
6431#ifdef FEAT_KEYMAP
6432 else if (varp == &curbuf->b_p_keymap)
6433 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006434 if (!valid_filetype(*varp))
6435 errmsg = e_invarg;
6436 else
6437 /* load or unload key mapping tables */
6438 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439
Bram Moolenaarfab06232009-03-04 03:13:35 +00006440 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006442 if (*curbuf->b_p_keymap != NUL)
6443 {
6444 /* Installed a new keymap, switch on using it. */
6445 curbuf->b_p_iminsert = B_IMODE_LMAP;
6446 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6447 curbuf->b_p_imsearch = B_IMODE_LMAP;
6448 }
6449 else
6450 {
6451 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6452 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6453 curbuf->b_p_iminsert = B_IMODE_NONE;
6454 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6455 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6456 }
6457 if ((opt_flags & OPT_LOCAL) == 0)
6458 {
6459 set_iminsert_global();
6460 set_imsearch_global();
6461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006462 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463 }
6464 }
6465#endif
6466
6467 /* 'fileformat' */
6468 else if (gvarp == &p_ff)
6469 {
6470 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6471 errmsg = e_modifiable;
6472 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6473 errmsg = e_invarg;
6474 else
6475 {
6476 /* may also change 'textmode' */
6477 if (get_fileformat(curbuf) == EOL_DOS)
6478 curbuf->b_p_tx = TRUE;
6479 else
6480 curbuf->b_p_tx = FALSE;
6481#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006482 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006484 /* update flag in swap file */
6485 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006486 /* Redraw needed when switching to/from "mac": a CR in the text
6487 * will be displayed differently. */
6488 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6489 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 }
6491 }
6492
6493 /* 'fileformats' */
6494 else if (varp == &p_ffs)
6495 {
6496 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6497 errmsg = e_invarg;
6498 else
6499 {
6500 /* also change 'textauto' */
6501 if (*p_ffs == NUL)
6502 p_ta = FALSE;
6503 else
6504 p_ta = TRUE;
6505 }
6506 }
6507
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006508#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 /* 'cryptkey' */
6510 else if (gvarp == &p_key)
6511 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006512# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 /* Make sure the ":set" command doesn't show the new value in the
6514 * history. */
6515 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006516# endif
6517 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6518 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006519 ml_set_crypt_key(curbuf, oldval,
6520 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006521 }
6522
6523 else if (gvarp == &p_cm)
6524 {
6525 if (opt_flags & OPT_LOCAL)
6526 p = curbuf->b_p_cm;
6527 else
6528 p = p_cm;
6529 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6530 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006531 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006532 errmsg = e_invarg;
6533 else
6534 {
6535 /* When setting the global value to empty, make it "zip". */
6536 if (*p_cm == NUL)
6537 {
6538 if (new_value_alloced)
6539 free_string_option(p_cm);
6540 p_cm = vim_strsave((char_u *)"zip");
6541 new_value_alloced = TRUE;
6542 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006543 /* When using ":set cm=name" the local value is going to be empty.
6544 * Do that here, otherwise the crypt functions will still use the
6545 * local value. */
6546 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6547 {
6548 free_string_option(curbuf->b_p_cm);
6549 curbuf->b_p_cm = empty_option;
6550 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006551
6552 /* Need to update the swapfile when the effective method changed.
6553 * Set "s" to the effective old value, "p" to the effective new
6554 * method and compare. */
6555 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6556 s = p_cm; /* was previously using the global value */
6557 else
6558 s = oldval;
6559 if (*curbuf->b_p_cm == NUL)
6560 p = p_cm; /* is now using the global value */
6561 else
6562 p = curbuf->b_p_cm;
6563 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006564 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006565
6566 /* If the global value changes need to update the swapfile for all
6567 * buffers using that value. */
6568 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6569 {
6570 buf_T *buf;
6571
Bram Moolenaar29323592016-07-24 22:04:11 +02006572 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006573 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006574 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006575 }
6576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577 }
6578#endif
6579
6580 /* 'matchpairs' */
6581 else if (gvarp == &p_mps)
6582 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006583#ifdef FEAT_MBYTE
6584 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006586 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006588 int x2 = -1;
6589 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006590
6591 if (*p != NUL)
6592 p += mb_ptr2len(p);
6593 if (*p != NUL)
6594 x2 = *p++;
6595 if (*p != NUL)
6596 {
6597 x3 = mb_ptr2char(p);
6598 p += mb_ptr2len(p);
6599 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006600 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006601 {
6602 errmsg = e_invarg;
6603 break;
6604 }
6605 if (*p == NUL)
6606 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006608 }
6609 else
6610#endif
6611 {
6612 /* Check for "x:y,x:y" */
6613 for (p = *varp; *p != NUL; p += 4)
6614 {
6615 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6616 {
6617 errmsg = e_invarg;
6618 break;
6619 }
6620 if (p[3] == NUL)
6621 break;
6622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 }
6624 }
6625
6626#ifdef FEAT_COMMENTS
6627 /* 'comments' */
6628 else if (gvarp == &p_com)
6629 {
6630 for (s = *varp; *s; )
6631 {
6632 while (*s && *s != ':')
6633 {
6634 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6635 && !VIM_ISDIGIT(*s) && *s != '-')
6636 {
6637 errmsg = illegal_char(errbuf, *s);
6638 break;
6639 }
6640 ++s;
6641 }
6642 if (*s++ == NUL)
6643 errmsg = (char_u *)N_("E524: Missing colon");
6644 else if (*s == ',' || *s == NUL)
6645 errmsg = (char_u *)N_("E525: Zero length string");
6646 if (errmsg != NULL)
6647 break;
6648 while (*s && *s != ',')
6649 {
6650 if (*s == '\\' && s[1] != NUL)
6651 ++s;
6652 ++s;
6653 }
6654 s = skip_to_option_part(s);
6655 }
6656 }
6657#endif
6658
6659 /* 'listchars' */
6660 else if (varp == &p_lcs)
6661 {
6662 errmsg = set_chars_option(varp);
6663 }
6664
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 /* 'fillchars' */
6666 else if (varp == &p_fcs)
6667 {
6668 errmsg = set_chars_option(varp);
6669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670
6671#ifdef FEAT_CMDWIN
6672 /* 'cedit' */
6673 else if (varp == &p_cedit)
6674 {
6675 errmsg = check_cedit();
6676 }
6677#endif
6678
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006679 /* 'verbosefile' */
6680 else if (varp == &p_vfile)
6681 {
6682 verbose_stop();
6683 if (*p_vfile != NUL && verbose_open() == FAIL)
6684 errmsg = e_invarg;
6685 }
6686
Bram Moolenaar071d4272004-06-13 20:20:40 +00006687#ifdef FEAT_VIMINFO
6688 /* 'viminfo' */
6689 else if (varp == &p_viminfo)
6690 {
6691 for (s = p_viminfo; *s;)
6692 {
6693 /* Check it's a valid character */
6694 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6695 {
6696 errmsg = illegal_char(errbuf, *s);
6697 break;
6698 }
6699 if (*s == 'n') /* name is always last one */
6700 {
6701 break;
6702 }
6703 else if (*s == 'r') /* skip until next ',' */
6704 {
6705 while (*++s && *s != ',')
6706 ;
6707 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006708 else if (*s == '%')
6709 {
6710 /* optional number */
6711 while (vim_isdigit(*++s))
6712 ;
6713 }
6714 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715 ++s; /* no extra chars */
6716 else /* must have a number */
6717 {
6718 while (vim_isdigit(*++s))
6719 ;
6720
6721 if (!VIM_ISDIGIT(*(s - 1)))
6722 {
6723 if (errbuf != NULL)
6724 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006725 sprintf((char *)errbuf,
6726 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727 transchar_byte(*(s - 1)));
6728 errmsg = errbuf;
6729 }
6730 else
6731 errmsg = (char_u *)"";
6732 break;
6733 }
6734 }
6735 if (*s == ',')
6736 ++s;
6737 else if (*s)
6738 {
6739 if (errbuf != NULL)
6740 errmsg = (char_u *)N_("E527: Missing comma");
6741 else
6742 errmsg = (char_u *)"";
6743 break;
6744 }
6745 }
6746 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6747 errmsg = (char_u *)N_("E528: Must specify a ' value");
6748 }
6749#endif /* FEAT_VIMINFO */
6750
6751 /* terminal options */
6752 else if (istermoption(&options[opt_idx]) && full_screen)
6753 {
6754 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6755 if (varp == &T_CCO)
6756 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006757 int colors = atoi((char *)T_CCO);
6758
6759 /* Only reinitialize colors if t_Co value has really changed to
6760 * avoid expensive reload of colorscheme if t_Co is set to the
6761 * same value multiple times. */
6762 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006764 t_colors = colors;
6765 if (t_colors <= 1)
6766 {
6767 if (new_value_alloced)
6768 vim_free(T_CCO);
6769 T_CCO = empty_option;
6770 }
6771 /* We now have a different color setup, initialize it again. */
6772 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774 }
6775 ttest(FALSE);
6776 if (varp == &T_ME)
6777 {
6778 out_str(T_ME);
6779 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006780#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 /* Since t_me has been set, this probably means that the user
6782 * wants to use this as default colors. Need to reset default
6783 * background/foreground colors. */
6784 mch_set_normal_colors();
6785#endif
6786 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006787 if (varp == &T_BE && termcap_active)
6788 {
6789 if (*T_BE == NUL)
6790 /* When clearing t_BE we assume the user no longer wants
6791 * bracketed paste, thus disable it by writing t_BD. */
6792 out_str(T_BD);
6793 else
6794 out_str(T_BE);
6795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 }
6797
6798#ifdef FEAT_LINEBREAK
6799 /* 'showbreak' */
6800 else if (varp == &p_sbr)
6801 {
6802 for (s = p_sbr; *s; )
6803 {
6804 if (ptr2cells(s) != 1)
6805 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006806 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 }
6808 }
6809#endif
6810
6811#ifdef FEAT_GUI
6812 /* 'guifont' */
6813 else if (varp == &p_guifont)
6814 {
6815 if (gui.in_use)
6816 {
6817 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006818# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 /*
6820 * Put up a font dialog and let the user select a new value.
6821 * If this is cancelled go back to the old value but don't
6822 * give an error message.
6823 */
6824 if (STRCMP(p, "*") == 0)
6825 {
6826 p = gui_mch_font_dialog(oldval);
6827
6828 if (new_value_alloced)
6829 free_string_option(p_guifont);
6830
6831 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6832 new_value_alloced = TRUE;
6833 }
6834# endif
6835 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6836 {
6837# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6838 if (STRCMP(p_guifont, "*") == 0)
6839 {
6840 /* Dialog was cancelled: Keep the old value without giving
6841 * an error message. */
6842 if (new_value_alloced)
6843 free_string_option(p_guifont);
6844 p_guifont = vim_strsave(oldval);
6845 new_value_alloced = TRUE;
6846 }
6847 else
6848# endif
6849 errmsg = (char_u *)N_("E596: Invalid font(s)");
6850 }
6851 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006852 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 }
6854# ifdef FEAT_XFONTSET
6855 else if (varp == &p_guifontset)
6856 {
6857 if (STRCMP(p_guifontset, "*") == 0)
6858 errmsg = (char_u *)N_("E597: can't select fontset");
6859 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6860 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006861 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 }
6863# endif
6864# ifdef FEAT_MBYTE
6865 else if (varp == &p_guifontwide)
6866 {
6867 if (STRCMP(p_guifontwide, "*") == 0)
6868 errmsg = (char_u *)N_("E533: can't select wide font");
6869 else if (gui_get_wide_font() == FAIL)
6870 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006871 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 }
6873# endif
6874#endif
6875
6876#ifdef CURSOR_SHAPE
6877 /* 'guicursor' */
6878 else if (varp == &p_guicursor)
6879 errmsg = parse_shape_opt(SHAPE_CURSOR);
6880#endif
6881
6882#ifdef FEAT_MOUSESHAPE
6883 /* 'mouseshape' */
6884 else if (varp == &p_mouseshape)
6885 {
6886 errmsg = parse_shape_opt(SHAPE_MOUSE);
6887 update_mouseshape(-1);
6888 }
6889#endif
6890
6891#ifdef FEAT_PRINTER
6892 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006893 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006894# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006895 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006896 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006897# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898#endif
6899
6900#ifdef FEAT_LANGMAP
6901 /* 'langmap' */
6902 else if (varp == &p_langmap)
6903 langmap_set();
6904#endif
6905
6906#ifdef FEAT_LINEBREAK
6907 /* 'breakat' */
6908 else if (varp == &p_breakat)
6909 fill_breakat_flags();
6910#endif
6911
6912#ifdef FEAT_TITLE
6913 /* 'titlestring' and 'iconstring' */
6914 else if (varp == &p_titlestring || varp == &p_iconstring)
6915 {
6916# ifdef FEAT_STL_OPT
6917 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6918
6919 /* NULL => statusline syntax */
6920 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6921 stl_syntax |= flagval;
6922 else
6923 stl_syntax &= ~flagval;
6924# endif
6925 did_set_title(varp == &p_iconstring);
6926
6927 }
6928#endif
6929
6930#ifdef FEAT_GUI
6931 /* 'guioptions' */
6932 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006933 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006935 redraw_gui_only = TRUE;
6936 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937#endif
6938
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006939#if defined(FEAT_GUI_TABLINE)
6940 /* 'guitablabel' */
6941 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006942 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006943 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006944 redraw_gui_only = TRUE;
6945 }
6946 /* 'guitabtooltip' */
6947 else if (varp == &p_gtt)
6948 {
6949 redraw_gui_only = TRUE;
6950 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006951#endif
6952
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6954 /* 'ttymouse' */
6955 else if (varp == &p_ttym)
6956 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006957 /* Switch the mouse off before changing the escape sequences used for
6958 * that. */
6959 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006960 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6961 errmsg = e_invarg;
6962 else
6963 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006964 if (termcap_active)
6965 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 }
6967#endif
6968
Bram Moolenaar071d4272004-06-13 20:20:40 +00006969 /* 'selection' */
6970 else if (varp == &p_sel)
6971 {
6972 if (*p_sel == NUL
6973 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6974 errmsg = e_invarg;
6975 }
6976
6977 /* 'selectmode' */
6978 else if (varp == &p_slm)
6979 {
6980 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6981 errmsg = e_invarg;
6982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983
6984#ifdef FEAT_BROWSE
6985 /* 'browsedir' */
6986 else if (varp == &p_bsdir)
6987 {
6988 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6989 && !mch_isdir(p_bsdir))
6990 errmsg = e_invarg;
6991 }
6992#endif
6993
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994 /* 'keymodel' */
6995 else if (varp == &p_km)
6996 {
6997 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6998 errmsg = e_invarg;
6999 else
7000 {
7001 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7002 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7003 }
7004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005
7006 /* 'mousemodel' */
7007 else if (varp == &p_mousem)
7008 {
7009 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7010 errmsg = e_invarg;
7011#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7012 else if (*p_mousem != *oldval)
7013 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7014 * to create or delete the popup menus. */
7015 gui_motif_update_mousemodel(root_menu);
7016#endif
7017 }
7018
7019 /* 'switchbuf' */
7020 else if (varp == &p_swb)
7021 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007022 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 errmsg = e_invarg;
7024 }
7025
7026 /* 'debug' */
7027 else if (varp == &p_debug)
7028 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007029 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030 errmsg = e_invarg;
7031 }
7032
7033 /* 'display' */
7034 else if (varp == &p_dy)
7035 {
7036 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7037 errmsg = e_invarg;
7038 else
7039 (void)init_chartab();
7040
7041 }
7042
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 /* 'eadirection' */
7044 else if (varp == &p_ead)
7045 {
7046 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7047 errmsg = e_invarg;
7048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049
7050#ifdef FEAT_CLIPBOARD
7051 /* 'clipboard' */
7052 else if (varp == &p_cb)
7053 errmsg = check_clipboard_option();
7054#endif
7055
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007056#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007057 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7058 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007059 else if (varp == &(curwin->w_s->b_p_spl)
7060 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007061 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007062 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007063 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007064 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007065 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007066 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007067 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007068 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007069 /* 'spellsuggest' */
7070 else if (varp == &p_sps)
7071 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007072 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007073 errmsg = e_invarg;
7074 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007075 /* 'mkspellmem' */
7076 else if (varp == &p_msm)
7077 {
7078 if (spell_check_msm() != OK)
7079 errmsg = e_invarg;
7080 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007081#endif
7082
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 /* When 'bufhidden' is set, check for valid value. */
7084 else if (gvarp == &p_bh)
7085 {
7086 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7087 errmsg = e_invarg;
7088 }
7089
7090 /* When 'buftype' is set, check for valid value. */
7091 else if (gvarp == &p_bt)
7092 {
7093 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7094 errmsg = e_invarg;
7095 else
7096 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 if (curwin->w_status_height)
7098 {
7099 curwin->w_redr_status = TRUE;
7100 redraw_later(VALID);
7101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007103#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007104 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 }
7107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108
7109#ifdef FEAT_STL_OPT
7110 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007111 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 {
7113 int wid;
7114
7115 if (varp == &p_ruf) /* reset ru_wid first */
7116 ru_wid = 0;
7117 s = *varp;
7118 if (varp == &p_ruf && *s == '%')
7119 {
7120 /* set ru_wid if 'ruf' starts with "%99(" */
7121 if (*++s == '-') /* ignore a '-' */
7122 s++;
7123 wid = getdigits(&s);
7124 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7125 ru_wid = wid;
7126 else
7127 errmsg = check_stl_option(p_ruf);
7128 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007129 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007130 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007132 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 comp_col();
7134 }
7135#endif
7136
7137#ifdef FEAT_INS_EXPAND
7138 /* check if it is a valid value for 'complete' -- Acevedo */
7139 else if (gvarp == &p_cpt)
7140 {
7141 for (s = *varp; *s;)
7142 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007143 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 s++;
7145 if (!*s)
7146 break;
7147 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7148 {
7149 errmsg = illegal_char(errbuf, *s);
7150 break;
7151 }
7152 if (*++s != NUL && *s != ',' && *s != ' ')
7153 {
7154 if (s[-1] == 'k' || s[-1] == 's')
7155 {
7156 /* skip optional filename after 'k' and 's' */
7157 while (*s && *s != ',' && *s != ' ')
7158 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007159 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160 ++s;
7161 ++s;
7162 }
7163 }
7164 else
7165 {
7166 if (errbuf != NULL)
7167 {
7168 sprintf((char *)errbuf,
7169 _("E535: Illegal character after <%c>"),
7170 *--s);
7171 errmsg = errbuf;
7172 }
7173 else
7174 errmsg = (char_u *)"";
7175 break;
7176 }
7177 }
7178 }
7179 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007180
7181 /* 'completeopt' */
7182 else if (varp == &p_cot)
7183 {
7184 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7185 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007186 else
7187 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189#endif /* FEAT_INS_EXPAND */
7190
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007191#ifdef FEAT_SIGNS
7192 /* 'signcolumn' */
7193 else if (varp == &curwin->w_p_scl)
7194 {
7195 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7196 errmsg = e_invarg;
7197 }
7198#endif
7199
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200
7201#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007202 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 else if (varp == &p_toolbar)
7204 {
7205 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7206 &toolbar_flags, TRUE) != OK)
7207 errmsg = e_invarg;
7208 else
7209 {
7210 out_flush();
7211 gui_mch_show_toolbar((toolbar_flags &
7212 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7213 }
7214 }
7215#endif
7216
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007217#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007218 /* 'toolbariconsize': GTK+ 2 only */
7219 else if (varp == &p_tbis)
7220 {
7221 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7222 errmsg = e_invarg;
7223 else
7224 {
7225 out_flush();
7226 gui_mch_show_toolbar((toolbar_flags &
7227 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7228 }
7229 }
7230#endif
7231
7232 /* 'pastetoggle': translate key codes like in a mapping */
7233 else if (varp == &p_pt)
7234 {
7235 if (*p_pt)
7236 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007237 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007238 if (p != NULL)
7239 {
7240 if (new_value_alloced)
7241 free_string_option(p_pt);
7242 p_pt = p;
7243 new_value_alloced = TRUE;
7244 }
7245 }
7246 }
7247
7248 /* 'backspace' */
7249 else if (varp == &p_bs)
7250 {
7251 if (VIM_ISDIGIT(*p_bs))
7252 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007253 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254 errmsg = e_invarg;
7255 }
7256 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7257 errmsg = e_invarg;
7258 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007259 else if (varp == &p_bo)
7260 {
7261 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7262 errmsg = e_invarg;
7263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007265 /* 'tagcase' */
7266 else if (gvarp == &p_tc)
7267 {
7268 unsigned int *flags;
7269
7270 if (opt_flags & OPT_LOCAL)
7271 {
7272 p = curbuf->b_p_tc;
7273 flags = &curbuf->b_tc_flags;
7274 }
7275 else
7276 {
7277 p = p_tc;
7278 flags = &tc_flags;
7279 }
7280
7281 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7282 /* make the local value empty: use the global value */
7283 *flags = 0;
7284 else if (*p == NUL
7285 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7286 errmsg = e_invarg;
7287 }
7288
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007289#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 /* 'casemap' */
7291 else if (varp == &p_cmp)
7292 {
7293 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7294 errmsg = e_invarg;
7295 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007297
7298#ifdef FEAT_DIFF
7299 /* 'diffopt' */
7300 else if (varp == &p_dip)
7301 {
7302 if (diffopt_changed() == FAIL)
7303 errmsg = e_invarg;
7304 }
7305#endif
7306
7307#ifdef FEAT_FOLDING
7308 /* 'foldmethod' */
7309 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7310 {
7311 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7312 || *curwin->w_p_fdm == NUL)
7313 errmsg = e_invarg;
7314 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007315 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007316 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007317 if (foldmethodIsDiff(curwin))
7318 newFoldLevel();
7319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 }
7321# ifdef FEAT_EVAL
7322 /* 'foldexpr' */
7323 else if (varp == &curwin->w_p_fde)
7324 {
7325 if (foldmethodIsExpr(curwin))
7326 foldUpdateAll(curwin);
7327 }
7328# endif
7329 /* 'foldmarker' */
7330 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7331 {
7332 p = vim_strchr(*varp, ',');
7333 if (p == NULL)
7334 errmsg = (char_u *)N_("E536: comma required");
7335 else if (p == *varp || p[1] == NUL)
7336 errmsg = e_invarg;
7337 else if (foldmethodIsMarker(curwin))
7338 foldUpdateAll(curwin);
7339 }
7340 /* 'commentstring' */
7341 else if (gvarp == &p_cms)
7342 {
7343 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7344 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7345 }
7346 /* 'foldopen' */
7347 else if (varp == &p_fdo)
7348 {
7349 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7350 errmsg = e_invarg;
7351 }
7352 /* 'foldclose' */
7353 else if (varp == &p_fcl)
7354 {
7355 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7356 errmsg = e_invarg;
7357 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007358 /* 'foldignore' */
7359 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7360 {
7361 if (foldmethodIsIndent(curwin))
7362 foldUpdateAll(curwin);
7363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007364#endif
7365
7366#ifdef FEAT_VIRTUALEDIT
7367 /* 'virtualedit' */
7368 else if (varp == &p_ve)
7369 {
7370 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7371 errmsg = e_invarg;
7372 else if (STRCMP(p_ve, oldval) != 0)
7373 {
7374 /* Recompute cursor position in case the new 've' setting
7375 * changes something. */
7376 validate_virtcol();
7377 coladvance(curwin->w_virtcol);
7378 }
7379 }
7380#endif
7381
7382#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7383 else if (varp == &p_csqf)
7384 {
7385 if (p_csqf != NULL)
7386 {
7387 p = p_csqf;
7388 while (*p != NUL)
7389 {
7390 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7391 || p[1] == NUL
7392 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7393 || (p[2] != NUL && p[2] != ','))
7394 {
7395 errmsg = e_invarg;
7396 break;
7397 }
7398 else if (p[2] == NUL)
7399 break;
7400 else
7401 p += 3;
7402 }
7403 }
7404 }
7405#endif
7406
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007407#ifdef FEAT_CINDENT
7408 /* 'cinoptions' */
7409 else if (gvarp == &p_cino)
7410 {
7411 /* TODO: recognize errors */
7412 parse_cino(curbuf);
7413 }
7414#endif
7415
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007416#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007417 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007418 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007419 {
7420 if (!gui_mch_set_rendering_options(p_rop))
7421 errmsg = e_invarg;
7422 }
7423#endif
7424
Bram Moolenaard0b51382016-11-04 15:23:45 +01007425 else if (gvarp == &p_ft)
7426 {
7427 if (!valid_filetype(*varp))
7428 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007429 else
7430 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007431 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007432
7433#ifdef FEAT_SYN_HL
7434 else if (gvarp == &p_syn)
7435 {
7436 if (!valid_filetype(*varp))
7437 errmsg = e_invarg;
7438 }
7439#endif
7440
Bram Moolenaar825680f2017-07-22 17:04:02 +02007441#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007442 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007443 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007444 {
7445 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7446 errmsg = e_invarg;
7447 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007448 /* 'termsize' */
7449 else if (varp == &curwin->w_p_tms)
7450 {
7451 if (*curwin->w_p_tms != NUL)
7452 {
7453 p = skipdigits(curwin->w_p_tms);
7454 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7455 errmsg = e_invarg;
7456 }
7457 }
7458#endif
7459
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 /* Options that are a list of flags. */
7461 else
7462 {
7463 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007466 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007468 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007469 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007470 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007472#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007473 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007474 p = (char_u *)COCU_ALL;
7475#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007476 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 {
7478#ifdef FEAT_MOUSE
7479 p = (char_u *)MOUSE_ALL;
7480#else
7481 if (*p_mouse != NUL)
7482 errmsg = (char_u *)N_("E538: No mouse support");
7483#endif
7484 }
7485#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007486 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 p = (char_u *)GO_ALL;
7488#endif
7489 if (p != NULL)
7490 {
7491 for (s = *varp; *s; ++s)
7492 if (vim_strchr(p, *s) == NULL)
7493 {
7494 errmsg = illegal_char(errbuf, *s);
7495 break;
7496 }
7497 }
7498 }
7499
7500 /*
7501 * If error detected, restore the previous value.
7502 */
7503 if (errmsg != NULL)
7504 {
7505 if (new_value_alloced)
7506 free_string_option(*varp);
7507 *varp = oldval;
7508 /*
7509 * When resetting some values, need to act on it.
7510 */
7511 if (did_chartab)
7512 (void)init_chartab();
7513 if (varp == &p_hl)
7514 (void)highlight_changed();
7515 }
7516 else
7517 {
7518#ifdef FEAT_EVAL
7519 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007520 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521#endif
7522 /*
7523 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007524 * Use "free_oldval", because recursiveness may change the flags under
7525 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007527 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528 free_string_option(oldval);
7529 if (new_value_alloced)
7530 options[opt_idx].flags |= P_ALLOCED;
7531 else
7532 options[opt_idx].flags &= ~P_ALLOCED;
7533
7534 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007535 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536 {
7537 /* global option with local value set to use global value; free
7538 * the local value and make it empty */
7539 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7540 free_string_option(*(char_u **)p);
7541 *(char_u **)p = empty_option;
7542 }
7543
7544 /* May set global value for local option. */
7545 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7546 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007547
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007548 /*
7549 * Trigger the autocommand only after setting the flags.
7550 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007551#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007552 /* When 'syntax' is set, load the syntax of that name */
7553 if (varp == &(curbuf->b_p_syn))
7554 {
7555 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7556 curbuf->b_fname, TRUE, curbuf);
7557 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007558#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007559 else if (varp == &(curbuf->b_p_ft))
7560 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007561 /* 'filetype' is set, trigger the FileType autocommand.
7562 * Skip this when called from a modeline and the filetype was
7563 * already set to this value. */
7564 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7565 {
7566 did_filetype = TRUE;
7567 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007568 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007569 /* Just in case the old "curbuf" is now invalid. */
7570 if (varp != &(curbuf->b_p_ft))
7571 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007572 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007573 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007574#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007575 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007576 {
7577 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007578 char_u *q = curwin->w_s->b_p_spl;
7579
7580 /* Skip the first name if it is "cjk". */
7581 if (STRNCMP(q, "cjk,", 4) == 0)
7582 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007583
7584 /*
7585 * Source the spell/LANG.vim in 'runtimepath'.
7586 * They could set 'spellcapcheck' depending on the language.
7587 * Use the first name in 'spelllang' up to '_region' or
7588 * '.encoding'.
7589 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007590 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007591 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7592 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007593 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007594 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595 }
7596#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 }
7598
7599#ifdef FEAT_MOUSE
7600 if (varp == &p_mouse)
7601 {
7602# ifdef FEAT_MOUSE_TTY
7603 if (*p_mouse == NUL)
7604 mch_setmouse(FALSE); /* switch mouse off */
7605 else
7606# endif
7607 setmouse(); /* in case 'mouse' changed */
7608 }
7609#endif
7610
Bram Moolenaar913077c2012-03-28 19:59:04 +02007611 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007612 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007613 curwin->w_set_curswant = TRUE;
7614
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007615#ifdef FEAT_GUI
7616 /* check redraw when it's not a GUI option or the GUI is active. */
7617 if (!redraw_gui_only || gui.in_use)
7618#endif
7619 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007620
7621 return errmsg;
7622}
7623
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007624#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007625/*
7626 * Simple int comparison function for use with qsort()
7627 */
7628 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007629int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007630{
7631 return *(const int *)a - *(const int *)b;
7632}
7633
7634/*
7635 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7636 * Returns error message, NULL if it's OK.
7637 */
7638 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007639check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007640{
7641 char_u *s;
7642 int col;
7643 int count = 0;
7644 int color_cols[256];
7645 int i;
7646 int j = 0;
7647
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007648 if (wp->w_buffer == NULL)
7649 return NULL; /* buffer was closed */
7650
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007651 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007652 {
7653 if (*s == '-' || *s == '+')
7654 {
7655 /* -N and +N: add to 'textwidth' */
7656 col = (*s == '-') ? -1 : 1;
7657 ++s;
7658 if (!VIM_ISDIGIT(*s))
7659 return e_invarg;
7660 col = col * getdigits(&s);
7661 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007662 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007663 col += wp->w_buffer->b_p_tw;
7664 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007665 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007666 }
7667 else if (VIM_ISDIGIT(*s))
7668 col = getdigits(&s);
7669 else
7670 return e_invarg;
7671 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007672skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007673 if (*s == NUL)
7674 break;
7675 if (*s != ',')
7676 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007677 if (*++s == NUL)
7678 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007679 }
7680
7681 vim_free(wp->w_p_cc_cols);
7682 if (count == 0)
7683 wp->w_p_cc_cols = NULL;
7684 else
7685 {
7686 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7687 if (wp->w_p_cc_cols != NULL)
7688 {
7689 /* sort the columns for faster usage on screen redraw inside
7690 * win_line() */
7691 qsort(color_cols, count, sizeof(int), int_cmp);
7692
7693 for (i = 0; i < count; ++i)
7694 /* skip duplicates */
7695 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7696 wp->w_p_cc_cols[j++] = color_cols[i];
7697 wp->w_p_cc_cols[j] = -1; /* end marker */
7698 }
7699 }
7700
7701 return NULL; /* no error */
7702}
7703#endif
7704
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705/*
7706 * Handle setting 'listchars' or 'fillchars'.
7707 * Returns error message, NULL if it's OK.
7708 */
7709 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007710set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007711{
7712 int round, i, len, entries;
7713 char_u *p, *s;
7714 int c1, c2 = 0;
7715 struct charstab
7716 {
7717 int *cp;
7718 char *name;
7719 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 static struct charstab filltab[] =
7721 {
7722 {&fill_stl, "stl"},
7723 {&fill_stlnc, "stlnc"},
7724 {&fill_vert, "vert"},
7725 {&fill_fold, "fold"},
7726 {&fill_diff, "diff"},
7727 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007728 static struct charstab lcstab[] =
7729 {
7730 {&lcs_eol, "eol"},
7731 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007732 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007734 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 {&lcs_tab2, "tab"},
7736 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007737#ifdef FEAT_CONCEAL
7738 {&lcs_conceal, "conceal"},
7739#else
7740 {NULL, "conceal"},
7741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742 };
7743 struct charstab *tab;
7744
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 {
7747 tab = lcstab;
7748 entries = sizeof(lcstab) / sizeof(struct charstab);
7749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 else
7751 {
7752 tab = filltab;
7753 entries = sizeof(filltab) / sizeof(struct charstab);
7754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755
7756 /* first round: check for valid value, second round: assign values */
7757 for (round = 0; round <= 1; ++round)
7758 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760 {
7761 /* After checking that the value is valid: set defaults: space for
7762 * 'fillchars', NUL for 'listchars' */
7763 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007764 if (tab[i].cp != NULL)
7765 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 if (varp == &p_lcs)
7767 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768 else
7769 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 }
7771 p = *varp;
7772 while (*p)
7773 {
7774 for (i = 0; i < entries; ++i)
7775 {
7776 len = (int)STRLEN(tab[i].name);
7777 if (STRNCMP(p, tab[i].name, len) == 0
7778 && p[len] == ':'
7779 && p[len + 1] != NUL)
7780 {
7781 s = p + len + 1;
7782#ifdef FEAT_MBYTE
7783 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007784 if (mb_char2cells(c1) > 1)
7785 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786#else
7787 c1 = *s++;
7788#endif
7789 if (tab[i].cp == &lcs_tab2)
7790 {
7791 if (*s == NUL)
7792 continue;
7793#ifdef FEAT_MBYTE
7794 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007795 if (mb_char2cells(c2) > 1)
7796 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797#else
7798 c2 = *s++;
7799#endif
7800 }
7801 if (*s == ',' || *s == NUL)
7802 {
7803 if (round)
7804 {
7805 if (tab[i].cp == &lcs_tab2)
7806 {
7807 lcs_tab1 = c1;
7808 lcs_tab2 = c2;
7809 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007810 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007811 *(tab[i].cp) = c1;
7812
7813 }
7814 p = s;
7815 break;
7816 }
7817 }
7818 }
7819
7820 if (i == entries)
7821 return e_invarg;
7822 if (*p == ',')
7823 ++p;
7824 }
7825 }
7826
7827 return NULL; /* no error */
7828}
7829
7830#ifdef FEAT_STL_OPT
7831/*
7832 * Check validity of options with the 'statusline' format.
7833 * Return error message or NULL.
7834 */
7835 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007836check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837{
7838 int itemcnt = 0;
7839 int groupdepth = 0;
7840 static char_u errbuf[80];
7841
7842 while (*s && itemcnt < STL_MAX_ITEM)
7843 {
7844 /* Check for valid keys after % sequences */
7845 while (*s && *s != '%')
7846 s++;
7847 if (!*s)
7848 break;
7849 s++;
7850 if (*s != '%' && *s != ')')
7851 ++itemcnt;
7852 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7853 {
7854 s++;
7855 continue;
7856 }
7857 if (*s == ')')
7858 {
7859 s++;
7860 if (--groupdepth < 0)
7861 break;
7862 continue;
7863 }
7864 if (*s == '-')
7865 s++;
7866 while (VIM_ISDIGIT(*s))
7867 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007868 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 continue;
7870 if (*s == '.')
7871 {
7872 s++;
7873 while (*s && VIM_ISDIGIT(*s))
7874 s++;
7875 }
7876 if (*s == '(')
7877 {
7878 groupdepth++;
7879 continue;
7880 }
7881 if (vim_strchr(STL_ALL, *s) == NULL)
7882 {
7883 return illegal_char(errbuf, *s);
7884 }
7885 if (*s == '{')
7886 {
7887 s++;
7888 while (*s != '}' && *s)
7889 s++;
7890 if (*s != '}')
7891 return (char_u *)N_("E540: Unclosed expression sequence");
7892 }
7893 }
7894 if (itemcnt >= STL_MAX_ITEM)
7895 return (char_u *)N_("E541: too many items");
7896 if (groupdepth != 0)
7897 return (char_u *)N_("E542: unbalanced groups");
7898 return NULL;
7899}
7900#endif
7901
7902#ifdef FEAT_CLIPBOARD
7903/*
7904 * Extract the items in the 'clipboard' option and set global values.
7905 */
7906 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007907check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007909 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007910 int new_autoselect_star = FALSE;
7911 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007913 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 regprog_T *new_exclude_prog = NULL;
7915 char_u *errmsg = NULL;
7916 char_u *p;
7917
7918 for (p = p_cb; *p != NUL; )
7919 {
7920 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7921 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007922 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 p += 7;
7924 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007925 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007926 && (p[11] == ',' || p[11] == NUL))
7927 {
7928 new_unnamed |= CLIP_UNNAMED_PLUS;
7929 p += 11;
7930 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007932 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007934 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 p += 10;
7936 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007937 else if (STRNCMP(p, "autoselectplus", 14) == 0
7938 && (p[14] == ',' || p[14] == NUL))
7939 {
7940 new_autoselect_plus = TRUE;
7941 p += 14;
7942 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007944 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 {
7946 new_autoselectml = TRUE;
7947 p += 12;
7948 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007949 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7950 {
7951 new_html = TRUE;
7952 p += 4;
7953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7955 {
7956 p += 8;
7957 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7958 if (new_exclude_prog == NULL)
7959 errmsg = e_invarg;
7960 break;
7961 }
7962 else
7963 {
7964 errmsg = e_invarg;
7965 break;
7966 }
7967 if (*p == ',')
7968 ++p;
7969 }
7970 if (errmsg == NULL)
7971 {
7972 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007973 clip_autoselect_star = new_autoselect_star;
7974 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007976 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007977 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007979#ifdef FEAT_GUI_GTK
7980 if (gui.in_use)
7981 {
7982 gui_gtk_set_selection_targets();
7983 gui_gtk_set_dnd_targets();
7984 }
7985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 }
7987 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007988 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989
7990 return errmsg;
7991}
7992#endif
7993
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007994#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007995 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007996did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007997{
7998 char_u *errmsg = NULL;
7999 win_T *wp;
8000 int l;
8001
8002 if (is_spellfile)
8003 {
8004 l = (int)STRLEN(curwin->w_s->b_p_spf);
8005 if (l > 0 && (l < 4
8006 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8007 errmsg = e_invarg;
8008 }
8009
8010 if (errmsg == NULL)
8011 {
8012 FOR_ALL_WINDOWS(wp)
8013 if (wp->w_buffer == curbuf && wp->w_p_spell)
8014 {
8015 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008016 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008017 }
8018 }
8019 return errmsg;
8020}
8021
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008022/*
8023 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8024 * Return error message when failed, NULL when OK.
8025 */
8026 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008027compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008028{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008029 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008030 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008031
Bram Moolenaar860cae12010-06-05 23:22:07 +02008032 if (*synblock->b_p_spc == NUL)
8033 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008034 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008035 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008036 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008037 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008038 if (re != NULL)
8039 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008040 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008041 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008042 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008043 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008044 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008045 return e_invarg;
8046 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008047 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008048 }
8049
Bram Moolenaar473de612013-06-08 18:19:48 +02008050 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008051 return NULL;
8052}
8053#endif
8054
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008055#if defined(FEAT_EVAL) || defined(PROTO)
8056/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008057 * Set the scriptID for an option, taking care of setting the buffer- or
8058 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008059 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008060 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008061set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008062{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008063 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8064 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008065
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008066 /* Remember where the option was set. For local options need to do that
8067 * in the buffer or window structure. */
8068 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008069 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008070 if (both || (opt_flags & OPT_LOCAL))
8071 {
8072 if (indir & PV_BUF)
8073 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8074 else if (indir & PV_WIN)
8075 curwin->w_p_scriptID[indir & PV_MASK] = id;
8076 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008077}
8078#endif
8079
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080/*
8081 * Set the value of a boolean option, and take care of side effects.
8082 * Returns NULL for success, or an error message for an error.
8083 */
8084 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008085set_bool_option(
8086 int opt_idx, /* index in options[] table */
8087 char_u *varp, /* pointer to the option variable */
8088 int value, /* new value */
8089 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090{
8091 int old_value = *(int *)varp;
8092
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 /* Disallow changing some options from secure mode */
8094 if ((secure
8095#ifdef HAVE_SANDBOX
8096 || sandbox != 0
8097#endif
8098 ) && (options[opt_idx].flags & P_SECURE))
8099 return e_secure;
8100
8101 *(int *)varp = value; /* set the new value */
8102#ifdef FEAT_EVAL
8103 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008104 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105#endif
8106
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008107#ifdef FEAT_GUI
8108 need_mouse_correct = TRUE;
8109#endif
8110
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 /* May set global value for local option. */
8112 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8113 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8114
8115 /*
8116 * Handle side effects of changing a bool option.
8117 */
8118
8119 /* 'compatible' */
8120 if ((int *)varp == &p_cp)
8121 {
8122 compatible_set();
8123 }
8124
Bram Moolenaar920694c2016-08-21 17:45:02 +02008125#ifdef FEAT_LANGMAP
8126 if ((int *)varp == &p_lrm)
8127 /* 'langremap' -> !'langnoremap' */
8128 p_lnr = !p_lrm;
8129 else if ((int *)varp == &p_lnr)
8130 /* 'langnoremap' -> !'langremap' */
8131 p_lrm = !p_lnr;
8132#endif
8133
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008134#ifdef FEAT_PERSISTENT_UNDO
8135 /* 'undofile' */
8136 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8137 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008138 /* Only take action when the option was set. When reset we do not
8139 * delete the undo file, the option may be set again without making
8140 * any changes in between. */
8141 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008142 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008143 char_u hash[UNDO_HASH_SIZE];
8144 buf_T *save_curbuf = curbuf;
8145
Bram Moolenaar29323592016-07-24 22:04:11 +02008146 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008147 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008148 /* When 'undofile' is set globally: for every buffer, otherwise
8149 * only for the current buffer: Try to read in the undofile,
8150 * if one exists, the buffer wasn't changed and the buffer was
8151 * loaded */
8152 if ((curbuf == save_curbuf
8153 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8154 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8155 {
8156 u_compute_hash(hash);
8157 u_read_undo(NULL, hash, curbuf->b_fname);
8158 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008159 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008160 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008161 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008162 }
8163#endif
8164
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 else if ((int *)varp == &curbuf->b_p_ro)
8166 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008167 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8169 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008170
8171 /* when 'readonly' is set may give W10 again */
8172 if (curbuf->b_p_ro)
8173 curbuf->b_did_warn = FALSE;
8174
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008176 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177#endif
8178 }
8179
Bram Moolenaar9c449722010-07-20 18:44:27 +02008180#ifdef FEAT_GUI
8181 else if ((int *)varp == &p_mh)
8182 {
8183 if (!p_mh)
8184 gui_mch_mousehide(FALSE);
8185 }
8186#endif
8187
Bram Moolenaara539df02010-08-01 14:35:05 +02008188 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008190 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008191# ifdef FEAT_TERMINAL
8192 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008193 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8194 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008195 {
8196 curbuf->b_p_ma = FALSE;
8197 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8198 }
8199# endif
8200# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008201 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008202# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008203 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008204#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 /* when 'endofline' is changed, redraw the window title */
8206 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008207 {
8208 redraw_titles();
8209 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008210 /* when 'fixeol' is changed, redraw the window title */
8211 else if ((int *)varp == &curbuf->b_p_fixeol)
8212 {
8213 redraw_titles();
8214 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008215# ifdef FEAT_MBYTE
8216 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008217 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008218 {
8219 redraw_titles();
8220 }
8221# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222#endif
8223
8224 /* when 'bin' is set also set some other options */
8225 else if ((int *)varp == &curbuf->b_p_bin)
8226 {
8227 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8228#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008229 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008230#endif
8231 }
8232
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 /* when 'buflisted' changes, trigger autocommands */
8234 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8235 {
8236 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8237 NULL, NULL, TRUE, curbuf);
8238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239
8240 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8241 else if ((int *)varp == &curbuf->b_p_swf)
8242 {
8243 if (curbuf->b_p_swf && p_uc)
8244 ml_open_file(curbuf); /* create the swap file */
8245 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008246 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8247 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008248 mf_close_file(curbuf, TRUE); /* remove the swap file */
8249 }
8250
8251 /* when 'terse' is set change 'shortmess' */
8252 else if ((int *)varp == &p_terse)
8253 {
8254 char_u *p;
8255
8256 p = vim_strchr(p_shm, SHM_SEARCH);
8257
8258 /* insert 's' in p_shm */
8259 if (p_terse && p == NULL)
8260 {
8261 STRCPY(IObuff, p_shm);
8262 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008263 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 }
8265 /* remove 's' from p_shm */
8266 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008267 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 }
8269
8270 /* when 'paste' is set or reset also change other options */
8271 else if ((int *)varp == &p_paste)
8272 {
8273 paste_option_changed();
8274 }
8275
8276 /* when 'insertmode' is set from an autocommand need to do work here */
8277 else if ((int *)varp == &p_im)
8278 {
8279 if (p_im)
8280 {
8281 if ((State & INSERT) == 0)
8282 need_start_insertmode = TRUE;
8283 stop_insert_mode = FALSE;
8284 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008285 /* only reset if it was set previously */
8286 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 {
8288 need_start_insertmode = FALSE;
8289 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008290 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 clear_cmdline = TRUE; /* remove "(insert)" */
8292 restart_edit = 0;
8293 }
8294 }
8295
8296 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8297 else if ((int *)varp == &p_ic && p_hls)
8298 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008299 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 }
8301
8302#ifdef FEAT_SEARCH_EXTRA
8303 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8304 else if ((int *)varp == &p_hls)
8305 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008306 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 }
8308#endif
8309
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8311 * at the end of normal_cmd() */
8312 else if ((int *)varp == &curwin->w_p_scb)
8313 {
8314 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008315 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008317 curwin->w_scbind_pos = curwin->w_topline;
8318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320
Bram Moolenaar4033c552017-09-16 20:54:51 +02008321#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 /* There can be only one window with 'previewwindow' set. */
8323 else if ((int *)varp == &curwin->w_p_pvw)
8324 {
8325 if (curwin->w_p_pvw)
8326 {
8327 win_T *win;
8328
Bram Moolenaar29323592016-07-24 22:04:11 +02008329 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 if (win->w_p_pvw && win != curwin)
8331 {
8332 curwin->w_p_pvw = FALSE;
8333 return (char_u *)N_("E590: A preview window already exists");
8334 }
8335 }
8336 }
8337#endif
8338
8339 /* when 'textmode' is set or reset also change 'fileformat' */
8340 else if ((int *)varp == &curbuf->b_p_tx)
8341 {
8342 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8343 }
8344
8345 /* when 'textauto' is set or reset also change 'fileformats' */
8346 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347 set_string_option_direct((char_u *)"ffs", -1,
8348 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008349 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350
8351 /*
8352 * When 'lisp' option changes include/exclude '-' in
8353 * keyword characters.
8354 */
8355#ifdef FEAT_LISP
8356 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8357 {
8358 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8359 }
8360#endif
8361
8362#ifdef FEAT_TITLE
8363 /* when 'title' changed, may need to change the title; same for 'icon' */
8364 else if ((int *)varp == &p_title)
8365 {
8366 did_set_title(FALSE);
8367 }
8368
8369 else if ((int *)varp == &p_icon)
8370 {
8371 did_set_title(TRUE);
8372 }
8373#endif
8374
8375 else if ((int *)varp == &curbuf->b_changed)
8376 {
8377 if (!value)
8378 save_file_ff(curbuf); /* Buffer is unchanged */
8379#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008380 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 }
8384
8385#ifdef BACKSLASH_IN_FILENAME
8386 else if ((int *)varp == &p_ssl)
8387 {
8388 if (p_ssl)
8389 {
8390 psepc = '/';
8391 psepcN = '\\';
8392 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 }
8394 else
8395 {
8396 psepc = '\\';
8397 psepcN = '/';
8398 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399 }
8400
8401 /* need to adjust the file name arguments and buffer names. */
8402 buflist_slash_adjust();
8403 alist_slash_adjust();
8404# ifdef FEAT_EVAL
8405 scriptnames_slash_adjust();
8406# endif
8407 }
8408#endif
8409
8410 /* If 'wrap' is set, set w_leftcol to zero. */
8411 else if ((int *)varp == &curwin->w_p_wrap)
8412 {
8413 if (curwin->w_p_wrap)
8414 curwin->w_leftcol = 0;
8415 }
8416
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 else if ((int *)varp == &p_ea)
8418 {
8419 if (p_ea && !old_value)
8420 win_equal(curwin, FALSE, 0);
8421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422
8423 else if ((int *)varp == &p_wiv)
8424 {
8425 /*
8426 * When 'weirdinvert' changed, set/reset 't_xs'.
8427 * Then set 'weirdinvert' according to value of 't_xs'.
8428 */
8429 if (p_wiv && !old_value)
8430 T_XS = (char_u *)"y";
8431 else if (!p_wiv && old_value)
8432 T_XS = empty_option;
8433 p_wiv = (*T_XS != NUL);
8434 }
8435
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008436#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 else if ((int *)varp == &p_beval)
8438 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008439 if (!balloonEvalForTerm)
8440 {
8441 if (p_beval && !old_value)
8442 gui_mch_enable_beval_area(balloonEval);
8443 else if (!p_beval && old_value)
8444 gui_mch_disable_beval_area(balloonEval);
8445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008447#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008448#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008449 else if ((int *)varp == &p_bevalterm)
8450 {
8451 mch_bevalterm_changed();
8452 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008455#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008456 else if ((int *)varp == &p_acd)
8457 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008458 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008459 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 }
8461#endif
8462
8463#ifdef FEAT_DIFF
8464 /* 'diff' */
8465 else if ((int *)varp == &curwin->w_p_diff)
8466 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008467 /* May add or remove the buffer from the list of diff buffers. */
8468 diff_buf_adjust(curwin);
8469# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470 if (foldmethodIsDiff(curwin))
8471 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008472# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 }
8474#endif
8475
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008476#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 /* 'imdisable' */
8478 else if ((int *)varp == &p_imdisable)
8479 {
8480 /* Only de-activate it here, it will be enabled when changing mode. */
8481 if (p_imdisable)
8482 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008483 else if (State & INSERT)
8484 /* When the option is set from an autocommand, it may need to take
8485 * effect right away. */
8486 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008487 }
8488#endif
8489
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008490#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008491 /* 'spell' */
8492 else if ((int *)varp == &curwin->w_p_spell)
8493 {
8494 if (curwin->w_p_spell)
8495 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008496 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008497 if (errmsg != NULL)
8498 EMSG(_(errmsg));
8499 }
8500 }
8501#endif
8502
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503#ifdef FEAT_FKMAP
8504 else if ((int *)varp == &p_altkeymap)
8505 {
8506 if (old_value != p_altkeymap)
8507 {
8508 if (!p_altkeymap)
8509 {
8510 p_hkmap = p_fkmap;
8511 p_fkmap = 0;
8512 }
8513 else
8514 {
8515 p_fkmap = p_hkmap;
8516 p_hkmap = 0;
8517 }
8518 (void)init_chartab();
8519 }
8520 }
8521
8522 /*
8523 * In case some second language keymapping options have changed, check
8524 * and correct the setting in a consistent way.
8525 */
8526
8527 /*
8528 * If hkmap or fkmap are set, reset Arabic keymapping.
8529 */
8530 if ((p_hkmap || p_fkmap) && p_altkeymap)
8531 {
8532 p_altkeymap = p_fkmap;
8533# ifdef FEAT_ARABIC
8534 curwin->w_p_arab = FALSE;
8535# endif
8536 (void)init_chartab();
8537 }
8538
8539 /*
8540 * If hkmap set, reset Farsi keymapping.
8541 */
8542 if (p_hkmap && p_altkeymap)
8543 {
8544 p_altkeymap = 0;
8545 p_fkmap = 0;
8546# ifdef FEAT_ARABIC
8547 curwin->w_p_arab = FALSE;
8548# endif
8549 (void)init_chartab();
8550 }
8551
8552 /*
8553 * If fkmap set, reset Hebrew keymapping.
8554 */
8555 if (p_fkmap && !p_altkeymap)
8556 {
8557 p_altkeymap = 1;
8558 p_hkmap = 0;
8559# ifdef FEAT_ARABIC
8560 curwin->w_p_arab = FALSE;
8561# endif
8562 (void)init_chartab();
8563 }
8564#endif
8565
8566#ifdef FEAT_ARABIC
8567 if ((int *)varp == &curwin->w_p_arab)
8568 {
8569 if (curwin->w_p_arab)
8570 {
8571 /*
8572 * 'arabic' is set, handle various sub-settings.
8573 */
8574 if (!p_tbidi)
8575 {
8576 /* set rightleft mode */
8577 if (!curwin->w_p_rl)
8578 {
8579 curwin->w_p_rl = TRUE;
8580 changed_window_setting();
8581 }
8582
8583 /* Enable Arabic shaping (major part of what Arabic requires) */
8584 if (!p_arshape)
8585 {
8586 p_arshape = TRUE;
8587 redraw_later_clear();
8588 }
8589 }
8590
8591 /* Arabic requires a utf-8 encoding, inform the user if its not
8592 * set. */
8593 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008594 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008595 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8596
Bram Moolenaar8820b482017-03-16 17:23:31 +01008597 msg_source(HL_ATTR(HLF_W));
8598 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008599#ifdef FEAT_EVAL
8600 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8601#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603
8604# ifdef FEAT_MBYTE
8605 /* set 'delcombine' */
8606 p_deco = TRUE;
8607# endif
8608
8609# ifdef FEAT_KEYMAP
8610 /* Force-set the necessary keymap for arabic */
8611 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8612 OPT_LOCAL);
8613# endif
8614# ifdef FEAT_FKMAP
8615 p_altkeymap = 0;
8616 p_hkmap = 0;
8617 p_fkmap = 0;
8618 (void)init_chartab();
8619# endif
8620 }
8621 else
8622 {
8623 /*
8624 * 'arabic' is reset, handle various sub-settings.
8625 */
8626 if (!p_tbidi)
8627 {
8628 /* reset rightleft mode */
8629 if (curwin->w_p_rl)
8630 {
8631 curwin->w_p_rl = FALSE;
8632 changed_window_setting();
8633 }
8634
8635 /* 'arabicshape' isn't reset, it is a global option and
8636 * another window may still need it "on". */
8637 }
8638
8639 /* 'delcombine' isn't reset, it is a global option and another
8640 * window may still want it "on". */
8641
8642# ifdef FEAT_KEYMAP
8643 /* Revert to the default keymap */
8644 curbuf->b_p_iminsert = B_IMODE_NONE;
8645 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8646# endif
8647 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008648 }
8649
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008650#endif
8651
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008652#ifdef FEAT_TERMGUICOLORS
8653 /* 'termguicolors' */
8654 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008655 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008656# ifdef FEAT_VTP
8657 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8658 if (!has_vtp_working())
8659 {
8660 p_tgc = 0;
8661 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8662 }
8663 swap_tcap();
8664# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008665# ifdef FEAT_GUI
8666 if (!gui.in_use && !gui.starting)
8667# endif
8668 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008669# ifdef FEAT_VTP
8670 control_console_color_rgb();
8671 /* reset t_Co */
8672 if (STRCMP(T_NAME, "win32") == 0)
8673 set_termname(T_NAME);
8674# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008675 }
8676#endif
8677
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 /*
8679 * End of handling side effects for bool options.
8680 */
8681
Bram Moolenaar53744302015-07-17 17:38:22 +02008682 /* after handling side effects, call autocommand */
8683
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 options[opt_idx].flags |= P_WAS_SET;
8685
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008686#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008687 if (!starting)
8688 {
8689 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008690 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8691 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8692 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008693 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8694 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8695 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8696 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8697 reset_v_option_vars();
8698 }
8699#endif
8700
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008702 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008703 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008704 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 check_redraw(options[opt_idx].flags);
8706
8707 return NULL;
8708}
8709
8710/*
8711 * Set the value of a number option, and take care of side effects.
8712 * Returns NULL for success, or an error message for an error.
8713 */
8714 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008715set_num_option(
8716 int opt_idx, /* index in options[] table */
8717 char_u *varp, /* pointer to the option variable */
8718 long value, /* new value */
8719 char_u *errbuf, /* buffer for error messages */
8720 size_t errbuflen, /* length of "errbuf" */
8721 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 OPT_MODELINE */
8723{
8724 char_u *errmsg = NULL;
8725 long old_value = *(long *)varp;
8726 long old_Rows = Rows; /* remember old Rows */
8727 long old_Columns = Columns; /* remember old Columns */
8728 long *pp = (long *)varp;
8729
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008730 /* Disallow changing some options from secure mode. */
8731 if ((secure
8732#ifdef HAVE_SANDBOX
8733 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008735 ) && (options[opt_idx].flags & P_SECURE))
8736 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737
8738 *pp = value;
8739#ifdef FEAT_EVAL
8740 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008741 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008743#ifdef FEAT_GUI
8744 need_mouse_correct = TRUE;
8745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746
Bram Moolenaar14f24742012-08-08 18:01:05 +02008747 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 {
8749 errmsg = e_positive;
8750 curbuf->b_p_sw = curbuf->b_p_ts;
8751 }
8752
8753 /*
8754 * Number options that need some action when changed
8755 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 if (pp == &p_wh || pp == &p_hh)
8757 {
8758 if (p_wh < 1)
8759 {
8760 errmsg = e_positive;
8761 p_wh = 1;
8762 }
8763 if (p_wmh > p_wh)
8764 {
8765 errmsg = e_winheight;
8766 p_wh = p_wmh;
8767 }
8768 if (p_hh < 0)
8769 {
8770 errmsg = e_positive;
8771 p_hh = 0;
8772 }
8773
8774 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008775 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 {
8777 if (pp == &p_wh && curwin->w_height < p_wh)
8778 win_setheight((int)p_wh);
8779 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8780 win_setheight((int)p_hh);
8781 }
8782 }
8783
8784 /* 'winminheight' */
8785 else if (pp == &p_wmh)
8786 {
8787 if (p_wmh < 0)
8788 {
8789 errmsg = e_positive;
8790 p_wmh = 0;
8791 }
8792 if (p_wmh > p_wh)
8793 {
8794 errmsg = e_winheight;
8795 p_wmh = p_wh;
8796 }
8797 win_setminheight();
8798 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008799 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 {
8801 if (p_wiw < 1)
8802 {
8803 errmsg = e_positive;
8804 p_wiw = 1;
8805 }
8806 if (p_wmw > p_wiw)
8807 {
8808 errmsg = e_winwidth;
8809 p_wiw = p_wmw;
8810 }
8811
8812 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008813 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 win_setwidth((int)p_wiw);
8815 }
8816
8817 /* 'winminwidth' */
8818 else if (pp == &p_wmw)
8819 {
8820 if (p_wmw < 0)
8821 {
8822 errmsg = e_positive;
8823 p_wmw = 0;
8824 }
8825 if (p_wmw > p_wiw)
8826 {
8827 errmsg = e_winwidth;
8828 p_wmw = p_wiw;
8829 }
8830 win_setminheight();
8831 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 /* (re)set last window status line */
8834 else if (pp == &p_ls)
8835 {
8836 last_status(FALSE);
8837 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008838
8839 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008840 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008841 {
8842 shell_new_rows(); /* recompute window positions and heights */
8843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844
8845#ifdef FEAT_GUI
8846 else if (pp == &p_linespace)
8847 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008848 /* Recompute gui.char_height and resize the Vim window to keep the
8849 * same number of lines. */
8850 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008851 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 }
8853#endif
8854
8855#ifdef FEAT_FOLDING
8856 /* 'foldlevel' */
8857 else if (pp == &curwin->w_p_fdl)
8858 {
8859 if (curwin->w_p_fdl < 0)
8860 curwin->w_p_fdl = 0;
8861 newFoldLevel();
8862 }
8863
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008864 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 else if (pp == &curwin->w_p_fml)
8866 {
8867 foldUpdateAll(curwin);
8868 }
8869
8870 /* 'foldnestmax' */
8871 else if (pp == &curwin->w_p_fdn)
8872 {
8873 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8874 foldUpdateAll(curwin);
8875 }
8876
8877 /* 'foldcolumn' */
8878 else if (pp == &curwin->w_p_fdc)
8879 {
8880 if (curwin->w_p_fdc < 0)
8881 {
8882 errmsg = e_positive;
8883 curwin->w_p_fdc = 0;
8884 }
8885 else if (curwin->w_p_fdc > 12)
8886 {
8887 errmsg = e_invarg;
8888 curwin->w_p_fdc = 12;
8889 }
8890 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008891#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008892
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008893#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894 /* 'shiftwidth' or 'tabstop' */
8895 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8896 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008897# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 if (foldmethodIsIndent(curwin))
8899 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008900# endif
8901# ifdef FEAT_CINDENT
8902 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8903 * parse 'cinoptions'. */
8904 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8905 parse_cino(curbuf);
8906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008910#ifdef FEAT_MBYTE
8911 /* 'maxcombine' */
8912 else if (pp == &p_mco)
8913 {
8914 if (p_mco > MAX_MCO)
8915 p_mco = MAX_MCO;
8916 else if (p_mco < 0)
8917 p_mco = 0;
8918 screenclear(); /* will re-allocate the screen */
8919 }
8920#endif
8921
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 else if (pp == &curbuf->b_p_iminsert)
8923 {
8924 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8925 {
8926 errmsg = e_invarg;
8927 curbuf->b_p_iminsert = B_IMODE_NONE;
8928 }
8929 p_iminsert = curbuf->b_p_iminsert;
8930 if (termcap_active) /* don't do this in the alternate screen */
8931 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008932#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 /* Show/unshow value of 'keymap' in status lines. */
8934 status_redraw_curbuf();
8935#endif
8936 }
8937
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008938#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8939 /* 'imstyle' */
8940 else if (pp == &p_imst)
8941 {
8942 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8943 errmsg = e_invarg;
8944 }
8945#endif
8946
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008947 else if (pp == &p_window)
8948 {
8949 if (p_window < 1)
8950 p_window = 1;
8951 else if (p_window >= Rows)
8952 p_window = Rows - 1;
8953 }
8954
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955 else if (pp == &curbuf->b_p_imsearch)
8956 {
8957 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8958 {
8959 errmsg = e_invarg;
8960 curbuf->b_p_imsearch = B_IMODE_NONE;
8961 }
8962 p_imsearch = curbuf->b_p_imsearch;
8963 }
8964
8965#ifdef FEAT_TITLE
8966 /* if 'titlelen' has changed, redraw the title */
8967 else if (pp == &p_titlelen)
8968 {
8969 if (p_titlelen < 0)
8970 {
8971 errmsg = e_positive;
8972 p_titlelen = 85;
8973 }
8974 if (starting != NO_SCREEN && old_value != p_titlelen)
8975 need_maketitle = TRUE;
8976 }
8977#endif
8978
8979 /* if p_ch changed value, change the command line height */
8980 else if (pp == &p_ch)
8981 {
8982 if (p_ch < 1)
8983 {
8984 errmsg = e_positive;
8985 p_ch = 1;
8986 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008987 if (p_ch > Rows - min_rows() + 1)
8988 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989
8990 /* Only compute the new window layout when startup has been
8991 * completed. Otherwise the frame sizes may be wrong. */
8992 if (p_ch != old_value && full_screen
8993#ifdef FEAT_GUI
8994 && !gui.starting
8995#endif
8996 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008997 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 }
8999
9000 /* when 'updatecount' changes from zero to non-zero, open swap files */
9001 else if (pp == &p_uc)
9002 {
9003 if (p_uc < 0)
9004 {
9005 errmsg = e_positive;
9006 p_uc = 100;
9007 }
9008 if (p_uc && !old_value)
9009 ml_open_files();
9010 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009011#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009012 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009013 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009014 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009015 {
9016 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009017 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009018 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009019 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009020 {
9021 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009022 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009023 }
9024 }
9025#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009026#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009027 else if (pp == &p_mzq)
9028 mzvim_reset_timer();
9029#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009030
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009031#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9032 /* 'pyxversion' */
9033 else if (pp == &p_pyx)
9034 {
9035 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9036 errmsg = e_invarg;
9037 }
9038#endif
9039
Bram Moolenaar071d4272004-06-13 20:20:40 +00009040 /* sync undo before 'undolevels' changes */
9041 else if (pp == &p_ul)
9042 {
9043 /* use the old value, otherwise u_sync() may not work properly */
9044 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009045 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 p_ul = value;
9047 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009048 else if (pp == &curbuf->b_p_ul)
9049 {
9050 /* use the old value, otherwise u_sync() may not work properly */
9051 curbuf->b_p_ul = old_value;
9052 u_sync(TRUE);
9053 curbuf->b_p_ul = value;
9054 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009056#ifdef FEAT_LINEBREAK
9057 /* 'numberwidth' must be positive */
9058 else if (pp == &curwin->w_p_nuw)
9059 {
9060 if (curwin->w_p_nuw < 1)
9061 {
9062 errmsg = e_positive;
9063 curwin->w_p_nuw = 1;
9064 }
9065 if (curwin->w_p_nuw > 10)
9066 {
9067 errmsg = e_invarg;
9068 curwin->w_p_nuw = 10;
9069 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009070 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009071 }
9072#endif
9073
Bram Moolenaar1a384422010-07-14 19:53:30 +02009074 else if (pp == &curbuf->b_p_tw)
9075 {
9076 if (curbuf->b_p_tw < 0)
9077 {
9078 errmsg = e_positive;
9079 curbuf->b_p_tw = 0;
9080 }
9081#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009082 {
9083 win_T *wp;
9084 tabpage_T *tp;
9085
9086 FOR_ALL_TAB_WINDOWS(tp, wp)
9087 check_colorcolumn(wp);
9088 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009089#endif
9090 }
9091
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 /*
9093 * Check the bounds for numeric options here
9094 */
9095 if (Rows < min_rows() && full_screen)
9096 {
9097 if (errbuf != NULL)
9098 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009099 vim_snprintf((char *)errbuf, errbuflen,
9100 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101 errmsg = errbuf;
9102 }
9103 Rows = min_rows();
9104 }
9105 if (Columns < MIN_COLUMNS && full_screen)
9106 {
9107 if (errbuf != NULL)
9108 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009109 vim_snprintf((char *)errbuf, errbuflen,
9110 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 errmsg = errbuf;
9112 }
9113 Columns = MIN_COLUMNS;
9114 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009115 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 /*
9118 * If the screen (shell) height has been changed, assume it is the
9119 * physical screenheight.
9120 */
9121 if (old_Rows != Rows || old_Columns != Columns)
9122 {
9123 /* Changing the screen size is not allowed while updating the screen. */
9124 if (updating_screen)
9125 *pp = old_value;
9126 else if (full_screen
9127#ifdef FEAT_GUI
9128 && !gui.starting
9129#endif
9130 )
9131 set_shellsize((int)Columns, (int)Rows, TRUE);
9132 else
9133 {
9134 /* Postpone the resizing; check the size and cmdline position for
9135 * messages. */
9136 check_shellsize();
9137 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9138 cmdline_row = Rows - p_ch;
9139 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009140 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009141 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 }
9143
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144 if (curbuf->b_p_ts <= 0)
9145 {
9146 errmsg = e_positive;
9147 curbuf->b_p_ts = 8;
9148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 if (p_tm < 0)
9150 {
9151 errmsg = e_positive;
9152 p_tm = 0;
9153 }
9154 if ((curwin->w_p_scr <= 0
9155 || (curwin->w_p_scr > curwin->w_height
9156 && curwin->w_height > 0))
9157 && full_screen)
9158 {
9159 if (pp == &(curwin->w_p_scr))
9160 {
9161 if (curwin->w_p_scr != 0)
9162 errmsg = e_scroll;
9163 win_comp_scroll(curwin);
9164 }
9165 /* If 'scroll' became invalid because of a side effect silently adjust
9166 * it. */
9167 else if (curwin->w_p_scr <= 0)
9168 curwin->w_p_scr = 1;
9169 else /* curwin->w_p_scr > curwin->w_height */
9170 curwin->w_p_scr = curwin->w_height;
9171 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009172 if (p_hi < 0)
9173 {
9174 errmsg = e_positive;
9175 p_hi = 0;
9176 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009177 else if (p_hi > 10000)
9178 {
9179 errmsg = e_invarg;
9180 p_hi = 10000;
9181 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009182 if (p_re < 0 || p_re > 2)
9183 {
9184 errmsg = e_invarg;
9185 p_re = 0;
9186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 if (p_report < 0)
9188 {
9189 errmsg = e_positive;
9190 p_report = 1;
9191 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009192 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193 {
9194 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9195 p_sj = Rows / 2;
9196 else
9197 {
9198 errmsg = e_scroll;
9199 p_sj = 1;
9200 }
9201 }
9202 if (p_so < 0 && full_screen)
9203 {
9204 errmsg = e_scroll;
9205 p_so = 0;
9206 }
9207 if (p_siso < 0 && full_screen)
9208 {
9209 errmsg = e_positive;
9210 p_siso = 0;
9211 }
9212#ifdef FEAT_CMDWIN
9213 if (p_cwh < 1)
9214 {
9215 errmsg = e_positive;
9216 p_cwh = 1;
9217 }
9218#endif
9219 if (p_ut < 0)
9220 {
9221 errmsg = e_positive;
9222 p_ut = 2000;
9223 }
9224 if (p_ss < 0)
9225 {
9226 errmsg = e_positive;
9227 p_ss = 0;
9228 }
9229
9230 /* May set global value for local option. */
9231 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9232 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9233
9234 options[opt_idx].flags |= P_WAS_SET;
9235
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009236#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009237 if (!starting && errmsg == NULL)
9238 {
9239 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009240 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9241 vim_snprintf((char *)buf_new, 10, "%ld", value);
9242 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009243 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9244 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9245 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9246 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9247 reset_v_option_vars();
9248 }
9249#endif
9250
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009252 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009253 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009254 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 check_redraw(options[opt_idx].flags);
9256
9257 return errmsg;
9258}
9259
9260/*
9261 * Called after an option changed: check if something needs to be redrawn.
9262 */
9263 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009264check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009265{
9266 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009267 int doclear = (flags & P_RCLR) == P_RCLR;
9268 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9271 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009272
9273 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9274 changed_window_setting();
9275 if (flags & P_RBUF)
9276 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009277 if (flags & P_RWINONLY)
9278 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009279 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 redraw_all_later(CLEAR);
9281 else if (all)
9282 redraw_all_later(NOT_VALID);
9283}
9284
9285/*
9286 * Find index for option 'arg'.
9287 * Return -1 if not found.
9288 */
9289 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009290findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009291{
9292 int opt_idx;
9293 char *s, *p;
9294 static short quick_tab[27] = {0, 0}; /* quick access table */
9295 int is_term_opt;
9296
9297 /*
9298 * For first call: Initialize the quick-access table.
9299 * It contains the index for the first option that starts with a certain
9300 * letter. There are 26 letters, plus the first "t_" option.
9301 */
9302 if (quick_tab[1] == 0)
9303 {
9304 p = options[0].fullname;
9305 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9306 {
9307 if (s[0] != p[0])
9308 {
9309 if (s[0] == 't' && s[1] == '_')
9310 quick_tab[26] = opt_idx;
9311 else
9312 quick_tab[CharOrdLow(s[0])] = opt_idx;
9313 }
9314 p = s;
9315 }
9316 }
9317
9318 /*
9319 * Check for name starting with an illegal character.
9320 */
9321#ifdef EBCDIC
9322 if (!islower(arg[0]))
9323#else
9324 if (arg[0] < 'a' || arg[0] > 'z')
9325#endif
9326 return -1;
9327
9328 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9329 if (is_term_opt)
9330 opt_idx = quick_tab[26];
9331 else
9332 opt_idx = quick_tab[CharOrdLow(arg[0])];
9333 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9334 {
9335 if (STRCMP(arg, s) == 0) /* match full name */
9336 break;
9337 }
9338 if (s == NULL && !is_term_opt)
9339 {
9340 opt_idx = quick_tab[CharOrdLow(arg[0])];
9341 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9342 {
9343 s = options[opt_idx].shortname;
9344 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9345 break;
9346 s = NULL;
9347 }
9348 }
9349 if (s == NULL)
9350 opt_idx = -1;
9351 return opt_idx;
9352}
9353
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009354#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355/*
9356 * Get the value for an option.
9357 *
9358 * Returns:
9359 * Number or Toggle option: 1, *numval gets value.
9360 * String option: 0, *stringval gets allocated string.
9361 * Hidden Number or Toggle option: -1.
9362 * hidden String option: -2.
9363 * unknown option: -3.
9364 */
9365 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009366get_option_value(
9367 char_u *name,
9368 long *numval,
9369 char_u **stringval, /* NULL when only checking existence */
9370 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371{
9372 int opt_idx;
9373 char_u *varp;
9374
9375 opt_idx = findoption(name);
9376 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009377 {
9378 int key;
9379
9380 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9381 && (key = find_key_option(name)) != 0)
9382 {
9383 char_u key_name[2];
9384 char_u *p;
9385
9386 if (key < 0)
9387 {
9388 key_name[0] = KEY2TERMCAP0(key);
9389 key_name[1] = KEY2TERMCAP1(key);
9390 }
9391 else
9392 {
9393 key_name[0] = KS_KEY;
9394 key_name[1] = (key & 0xff);
9395 }
9396 p = find_termcode(key_name);
9397 if (p != NULL)
9398 {
9399 if (stringval != NULL)
9400 *stringval = vim_strsave(p);
9401 return 0;
9402 }
9403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009404 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009405 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406
9407 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9408
9409 if (options[opt_idx].flags & P_STRING)
9410 {
9411 if (varp == NULL) /* hidden option */
9412 return -2;
9413 if (stringval != NULL)
9414 {
9415#ifdef FEAT_CRYPT
9416 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009417 if ((char_u **)varp == &curbuf->b_p_key
9418 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419 *stringval = vim_strsave((char_u *)"*****");
9420 else
9421#endif
9422 *stringval = vim_strsave(*(char_u **)(varp));
9423 }
9424 return 0;
9425 }
9426
9427 if (varp == NULL) /* hidden option */
9428 return -1;
9429 if (options[opt_idx].flags & P_NUM)
9430 *numval = *(long *)varp;
9431 else
9432 {
9433 /* Special case: 'modified' is b_changed, but we also want to consider
9434 * it set when 'ff' or 'fenc' changed. */
9435 if ((int *)varp == &curbuf->b_changed)
9436 *numval = curbufIsChanged();
9437 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009438 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439 }
9440 return 1;
9441}
9442#endif
9443
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009444#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009445/*
9446 * Returns the option attributes and its value. Unlike the above function it
9447 * will return either global value or local value of the option depending on
9448 * what was requested, but it will never return global value if it was
9449 * requested to return local one and vice versa. Neither it will return
9450 * buffer-local value if it was requested to return window-local one.
9451 *
9452 * Pretends that option is absent if it is not present in the requested scope
9453 * (i.e. has no global, window-local or buffer-local value depending on
9454 * opt_type). Uses
9455 *
9456 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009457 * 0 hidden or unknown option, also option that does not have requested
9458 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009459 * see SOPT_* in vim.h for other flags
9460 *
9461 * Possible opt_type values: see SREQ_* in vim.h
9462 */
9463 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009464get_option_value_strict(
9465 char_u *name,
9466 long *numval,
9467 char_u **stringval, /* NULL when only obtaining attributes */
9468 int opt_type,
9469 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009470{
9471 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009472 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009473 struct vimoption *p;
9474 int r = 0;
9475
9476 opt_idx = findoption(name);
9477 if (opt_idx < 0)
9478 return 0;
9479
9480 p = &(options[opt_idx]);
9481
9482 /* Hidden option */
9483 if (p->var == NULL)
9484 return 0;
9485
9486 if (p->flags & P_BOOL)
9487 r |= SOPT_BOOL;
9488 else if (p->flags & P_NUM)
9489 r |= SOPT_NUM;
9490 else if (p->flags & P_STRING)
9491 r |= SOPT_STRING;
9492
9493 if (p->indir == PV_NONE)
9494 {
9495 if (opt_type == SREQ_GLOBAL)
9496 r |= SOPT_GLOBAL;
9497 else
9498 return 0; /* Did not request global-only option */
9499 }
9500 else
9501 {
9502 if (p->indir & PV_BOTH)
9503 r |= SOPT_GLOBAL;
9504 else if (opt_type == SREQ_GLOBAL)
9505 return 0; /* Requested global option */
9506
9507 if (p->indir & PV_WIN)
9508 {
9509 if (opt_type == SREQ_BUF)
9510 return 0; /* Did not request window-local option */
9511 else
9512 r |= SOPT_WIN;
9513 }
9514 else if (p->indir & PV_BUF)
9515 {
9516 if (opt_type == SREQ_WIN)
9517 return 0; /* Did not request buffer-local option */
9518 else
9519 r |= SOPT_BUF;
9520 }
9521 }
9522
9523 if (stringval == NULL)
9524 return r;
9525
9526 if (opt_type == SREQ_GLOBAL)
9527 varp = p->var;
9528 else
9529 {
9530 if (opt_type == SREQ_BUF)
9531 {
9532 /* Special case: 'modified' is b_changed, but we also want to
9533 * consider it set when 'ff' or 'fenc' changed. */
9534 if (p->indir == PV_MOD)
9535 {
9536 *numval = bufIsChanged((buf_T *) from);
9537 varp = NULL;
9538 }
9539#ifdef FEAT_CRYPT
9540 else if (p->indir == PV_KEY)
9541 {
9542 /* never return the value of the crypt key */
9543 *stringval = NULL;
9544 varp = NULL;
9545 }
9546#endif
9547 else
9548 {
9549 aco_save_T aco;
9550 aucmd_prepbuf(&aco, (buf_T *) from);
9551 varp = get_varp(p);
9552 aucmd_restbuf(&aco);
9553 }
9554 }
9555 else if (opt_type == SREQ_WIN)
9556 {
9557 win_T *save_curwin;
9558 save_curwin = curwin;
9559 curwin = (win_T *) from;
9560 curbuf = curwin->w_buffer;
9561 varp = get_varp(p);
9562 curwin = save_curwin;
9563 curbuf = curwin->w_buffer;
9564 }
9565 if (varp == p->var)
9566 return (r | SOPT_UNSET);
9567 }
9568
9569 if (varp != NULL)
9570 {
9571 if (p->flags & P_STRING)
9572 *stringval = vim_strsave(*(char_u **)(varp));
9573 else if (p->flags & P_NUM)
9574 *numval = *(long *) varp;
9575 else
9576 *numval = *(int *)varp;
9577 }
9578
9579 return r;
9580}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009581
9582/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009583 * Iterate over options. First argument is a pointer to a pointer to a
9584 * structure inside options[] array, second is option type like in the above
9585 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009586 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009587 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009588 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009589 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009590 * first argument to NULL.
9591 *
9592 * Returns full option name for current option on each call.
9593 */
9594 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009595option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009596{
9597 struct vimoption *ret = NULL;
9598 do
9599 {
9600 if (*option == NULL)
9601 *option = (void *) options;
9602 else if (((struct vimoption *) (*option))->fullname == NULL)
9603 {
9604 *option = NULL;
9605 return NULL;
9606 }
9607 else
9608 *option = (void *) (((struct vimoption *) (*option)) + 1);
9609
9610 ret = ((struct vimoption *) (*option));
9611
9612 /* Hidden option */
9613 if (ret->var == NULL)
9614 {
9615 ret = NULL;
9616 continue;
9617 }
9618
9619 switch (opt_type)
9620 {
9621 case SREQ_GLOBAL:
9622 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9623 ret = NULL;
9624 break;
9625 case SREQ_BUF:
9626 if (!(ret->indir & PV_BUF))
9627 ret = NULL;
9628 break;
9629 case SREQ_WIN:
9630 if (!(ret->indir & PV_WIN))
9631 ret = NULL;
9632 break;
9633 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009634 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009635 return NULL;
9636 }
9637 }
9638 while (ret == NULL);
9639
9640 return (char_u *)ret->fullname;
9641}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009642#endif
9643
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644/*
9645 * Set the value of option "name".
9646 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009647 *
9648 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009649 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009650 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009651set_option_value(
9652 char_u *name,
9653 long number,
9654 char_u *string,
9655 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656{
9657 int opt_idx;
9658 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009659 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660
9661 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009662 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009663 {
9664 int key;
9665
9666 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9667 && (key = find_key_option(name)) != 0)
9668 {
9669 char_u key_name[2];
9670
9671 if (key < 0)
9672 {
9673 key_name[0] = KEY2TERMCAP0(key);
9674 key_name[1] = KEY2TERMCAP1(key);
9675 }
9676 else
9677 {
9678 key_name[0] = KS_KEY;
9679 key_name[1] = (key & 0xff);
9680 }
9681 add_termcode(key_name, string, FALSE);
9682 if (full_screen)
9683 ttest(FALSE);
9684 redraw_all_later(CLEAR);
9685 return NULL;
9686 }
9687
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 else
9691 {
9692 flags = options[opt_idx].flags;
9693#ifdef HAVE_SANDBOX
9694 /* Disallow changing some options in the sandbox */
9695 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009696 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009698 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009701 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009702 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 else
9704 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009705 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706 if (varp != NULL) /* hidden option is not changed */
9707 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009708 if (number == 0 && string != NULL)
9709 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009710 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009711
9712 /* Either we are given a string or we are setting option
9713 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009714 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009715 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009716 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009717 {
9718 /* There's another character after zeros or the string
9719 * is empty. In both cases, we are trying to set a
9720 * num option using a string. */
9721 EMSG3(_("E521: Number required: &%s = '%s'"),
9722 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009723 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009724
9725 }
9726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009728 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009729 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009731 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009732 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733 }
9734 }
9735 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009736 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737}
9738
9739/*
9740 * Get the terminal code for a terminal option.
9741 * Returns NULL when not found.
9742 */
9743 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009744get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745{
9746 int opt_idx;
9747 char_u *varp;
9748
9749 if (tname[0] != 't' || tname[1] != '_' ||
9750 tname[2] == NUL || tname[3] == NUL)
9751 return NULL;
9752 if ((opt_idx = findoption(tname)) >= 0)
9753 {
9754 varp = get_varp(&(options[opt_idx]));
9755 if (varp != NULL)
9756 varp = *(char_u **)(varp);
9757 return varp;
9758 }
9759 return find_termcode(tname + 2);
9760}
9761
9762 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009763get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764{
9765 int i;
9766
9767 i = findoption((char_u *)"hl");
9768 if (i >= 0)
9769 return options[i].def_val[VI_DEFAULT];
9770 return (char_u *)NULL;
9771}
9772
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009773#if defined(FEAT_MBYTE) || defined(PROTO)
9774 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009775get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009776{
9777 int i;
9778
9779 i = findoption((char_u *)"enc");
9780 if (i >= 0)
9781 return options[i].def_val[VI_DEFAULT];
9782 return (char_u *)NULL;
9783}
9784#endif
9785
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786/*
9787 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9788 */
9789 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009790find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791{
9792 int key;
9793 int modifiers;
9794
9795 /*
9796 * Don't use get_special_key_code() for t_xx, we don't want it to call
9797 * add_termcap_entry().
9798 */
9799 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9800 key = TERMCAP2KEY(arg[2], arg[3]);
9801 else
9802 {
9803 --arg; /* put arg at the '<' */
9804 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009805 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009806 if (modifiers) /* can't handle modifiers here */
9807 key = 0;
9808 }
9809 return key;
9810}
9811
9812/*
9813 * if 'all' == 0: show changed options
9814 * if 'all' == 1: show all normal options
9815 * if 'all' == 2: show all terminal options
9816 */
9817 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009818showoptions(
9819 int all,
9820 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821{
9822 struct vimoption *p;
9823 int col;
9824 int isterm;
9825 char_u *varp;
9826 struct vimoption **items;
9827 int item_count;
9828 int run;
9829 int row, rows;
9830 int cols;
9831 int i;
9832 int len;
9833
9834#define INC 20
9835#define GAP 3
9836
9837 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9838 PARAM_COUNT));
9839 if (items == NULL)
9840 return;
9841
9842 /* Highlight title */
9843 if (all == 2)
9844 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9845 else if (opt_flags & OPT_GLOBAL)
9846 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9847 else if (opt_flags & OPT_LOCAL)
9848 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9849 else
9850 MSG_PUTS_TITLE(_("\n--- Options ---"));
9851
9852 /*
9853 * do the loop two times:
9854 * 1. display the short items
9855 * 2. display the long items (only strings and numbers)
9856 */
9857 for (run = 1; run <= 2 && !got_int; ++run)
9858 {
9859 /*
9860 * collect the items in items[]
9861 */
9862 item_count = 0;
9863 for (p = &options[0]; p->fullname != NULL; p++)
9864 {
9865 varp = NULL;
9866 isterm = istermoption(p);
9867 if (opt_flags != 0)
9868 {
9869 if (p->indir != PV_NONE && !isterm)
9870 varp = get_varp_scope(p, opt_flags);
9871 }
9872 else
9873 varp = get_varp(p);
9874 if (varp != NULL
9875 && ((all == 2 && isterm)
9876 || (all == 1 && !isterm)
9877 || (all == 0 && !optval_default(p, varp))))
9878 {
9879 if (p->flags & P_BOOL)
9880 len = 1; /* a toggle option fits always */
9881 else
9882 {
9883 option_value2string(p, opt_flags);
9884 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9885 }
9886 if ((len <= INC - GAP && run == 1) ||
9887 (len > INC - GAP && run == 2))
9888 items[item_count++] = p;
9889 }
9890 }
9891
9892 /*
9893 * display the items
9894 */
9895 if (run == 1)
9896 {
9897 cols = (Columns + GAP - 3) / INC;
9898 if (cols == 0)
9899 cols = 1;
9900 rows = (item_count + cols - 1) / cols;
9901 }
9902 else /* run == 2 */
9903 rows = item_count;
9904 for (row = 0; row < rows && !got_int; ++row)
9905 {
9906 msg_putchar('\n'); /* go to next line */
9907 if (got_int) /* 'q' typed in more */
9908 break;
9909 col = 0;
9910 for (i = row; i < item_count; i += rows)
9911 {
9912 msg_col = col; /* make columns */
9913 showoneopt(items[i], opt_flags);
9914 col += INC;
9915 }
9916 out_flush();
9917 ui_breakcheck();
9918 }
9919 }
9920 vim_free(items);
9921}
9922
9923/*
9924 * Return TRUE if option "p" has its default value.
9925 */
9926 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009927optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009928{
9929 int dvi;
9930
9931 if (varp == NULL)
9932 return TRUE; /* hidden option is always at default */
9933 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9934 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009935 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009937 /* the cast to long is required for Manx C, long_i is
9938 * needed for MSVC */
9939 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 /* P_STRING */
9941 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9942}
9943
9944/*
9945 * showoneopt: show the value of one option
9946 * must not be called with a hidden option!
9947 */
9948 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009949showoneopt(
9950 struct vimoption *p,
9951 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009953 char_u *varp;
9954 int save_silent = silent_mode;
9955
9956 silent_mode = FALSE;
9957 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958
9959 varp = get_varp_scope(p, opt_flags);
9960
9961 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9962 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9963 ? !curbufIsChanged() : !*(int *)varp))
9964 MSG_PUTS("no");
9965 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9966 MSG_PUTS("--");
9967 else
9968 MSG_PUTS(" ");
9969 MSG_PUTS(p->fullname);
9970 if (!(p->flags & P_BOOL))
9971 {
9972 msg_putchar('=');
9973 /* put value string in NameBuff */
9974 option_value2string(p, opt_flags);
9975 msg_outtrans(NameBuff);
9976 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009977
9978 silent_mode = save_silent;
9979 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980}
9981
9982/*
9983 * Write modified options as ":set" commands to a file.
9984 *
9985 * There are three values for "opt_flags":
9986 * OPT_GLOBAL: Write global option values and fresh values of
9987 * buffer-local options (used for start of a session
9988 * file).
9989 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9990 * curwin (used for a vimrc file).
9991 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9992 * and local values for window-local options of
9993 * curwin. Local values are also written when at the
9994 * default value, because a modeline or autocommand
9995 * may have set them when doing ":edit file" and the
9996 * user has set them back at the default or fresh
9997 * value.
9998 * When "local_only" is TRUE, don't write fresh
9999 * values, only local values (for ":mkview").
10000 * (fresh value = value used for a new buffer or window for a local option).
10001 *
10002 * Return FAIL on error, OK otherwise.
10003 */
10004 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010005makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006{
10007 struct vimoption *p;
10008 char_u *varp; /* currently used value */
10009 char_u *varp_fresh; /* local value */
10010 char_u *varp_local = NULL; /* fresh value */
10011 char *cmd;
10012 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010013 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014
10015 /*
10016 * The options that don't have a default (terminal name, columns, lines)
10017 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010018 * Do the loop over "options[]" twice: once for options with the
10019 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010020 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010021 for (pri = 1; pri >= 0; --pri)
10022 {
10023 for (p = &options[0]; !istermoption(p); p++)
10024 if (!(p->flags & P_NO_MKRC)
10025 && !istermoption(p)
10026 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010027 {
10028 /* skip global option when only doing locals */
10029 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10030 continue;
10031
10032 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10033 * file, they are always buffer-specific. */
10034 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10035 continue;
10036
10037 /* Global values are only written when not at the default value. */
10038 varp = get_varp_scope(p, opt_flags);
10039 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10040 continue;
10041
10042 round = 2;
10043 if (p->indir != PV_NONE)
10044 {
10045 if (p->var == VAR_WIN)
10046 {
10047 /* skip window-local option when only doing globals */
10048 if (!(opt_flags & OPT_LOCAL))
10049 continue;
10050 /* When fresh value of window-local option is not at the
10051 * default, need to write it too. */
10052 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10053 {
10054 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10055 if (!optval_default(p, varp_fresh))
10056 {
10057 round = 1;
10058 varp_local = varp;
10059 varp = varp_fresh;
10060 }
10061 }
10062 }
10063 }
10064
10065 /* Round 1: fresh value for window-local options.
10066 * Round 2: other values */
10067 for ( ; round <= 2; varp = varp_local, ++round)
10068 {
10069 if (round == 1 || (opt_flags & OPT_GLOBAL))
10070 cmd = "set";
10071 else
10072 cmd = "setlocal";
10073
10074 if (p->flags & P_BOOL)
10075 {
10076 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10077 return FAIL;
10078 }
10079 else if (p->flags & P_NUM)
10080 {
10081 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10082 return FAIL;
10083 }
10084 else /* P_STRING */
10085 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010086 int do_endif = FALSE;
10087
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088 /* Don't set 'syntax' and 'filetype' again if the value is
10089 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010090 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010091#if defined(FEAT_SYN_HL)
10092 p->indir == PV_SYN ||
10093#endif
10094 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010095 {
10096 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10097 *(char_u **)(varp)) < 0
10098 || put_eol(fd) < 0)
10099 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010100 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 }
10102 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10103 (p->flags & P_EXPAND) != 0) == FAIL)
10104 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010105 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 {
10107 if (put_line(fd, "endif") == FAIL)
10108 return FAIL;
10109 }
10110 }
10111 }
10112 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114 return OK;
10115}
10116
10117#if defined(FEAT_FOLDING) || defined(PROTO)
10118/*
10119 * Generate set commands for the local fold options only. Used when
10120 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10121 */
10122 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010123makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124{
10125 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10126# ifdef FEAT_EVAL
10127 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10128 == FAIL
10129# endif
10130 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10131 == FAIL
10132 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10133 == FAIL
10134 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10135 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10136 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10137 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10138 )
10139 return FAIL;
10140
10141 return OK;
10142}
10143#endif
10144
10145 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010146put_setstring(
10147 FILE *fd,
10148 char *cmd,
10149 char *name,
10150 char_u **valuep,
10151 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152{
10153 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010154 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155
10156 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10157 return FAIL;
10158 if (*valuep != NULL)
10159 {
10160 /* Output 'pastetoggle' as key names. For other
10161 * options some characters have to be escaped with
10162 * CTRL-V or backslash */
10163 if (valuep == &p_pt)
10164 {
10165 s = *valuep;
10166 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010167 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 return FAIL;
10169 }
10170 else if (expand)
10171 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010172 buf = alloc(MAXPATHL);
10173 if (buf == NULL)
10174 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10176 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010177 {
10178 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010180 }
10181 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 }
10183 else if (put_escstr(fd, *valuep, 2) == FAIL)
10184 return FAIL;
10185 }
10186 if (put_eol(fd) < 0)
10187 return FAIL;
10188 return OK;
10189}
10190
10191 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010192put_setnum(
10193 FILE *fd,
10194 char *cmd,
10195 char *name,
10196 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197{
10198 long wc;
10199
10200 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10201 return FAIL;
10202 if (wc_use_keyname((char_u *)valuep, &wc))
10203 {
10204 /* print 'wildchar' and 'wildcharm' as a key name */
10205 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10206 return FAIL;
10207 }
10208 else if (fprintf(fd, "%ld", *valuep) < 0)
10209 return FAIL;
10210 if (put_eol(fd) < 0)
10211 return FAIL;
10212 return OK;
10213}
10214
10215 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010216put_setbool(
10217 FILE *fd,
10218 char *cmd,
10219 char *name,
10220 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221{
Bram Moolenaar893de922007-10-02 18:40:57 +000010222 if (value < 0) /* global/local option using global value */
10223 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10225 || put_eol(fd) < 0)
10226 return FAIL;
10227 return OK;
10228}
10229
10230/*
10231 * Clear all the terminal options.
10232 * If the option has been allocated, free the memory.
10233 * Terminal options are never hidden or indirect.
10234 */
10235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010236clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238 /*
10239 * Reset a few things before clearing the old options. This may cause
10240 * outputting a few things that the terminal doesn't understand, but the
10241 * screen will be cleared later, so this is OK.
10242 */
10243#ifdef FEAT_MOUSE_TTY
10244 mch_setmouse(FALSE); /* switch mouse off */
10245#endif
10246#ifdef FEAT_TITLE
10247 mch_restore_title(3); /* restore window titles */
10248#endif
10249#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10250 /* When starting the GUI close the display opened for the clipboard.
10251 * After restoring the title, because that will need the display. */
10252 if (gui.starting)
10253 clear_xterm_clip();
10254#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010255 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010257 free_termoptions();
10258}
10259
10260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010261free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010262{
10263 struct vimoption *p;
10264
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 for (p = &options[0]; p->fullname != NULL; p++)
10266 if (istermoption(p))
10267 {
10268 if (p->flags & P_ALLOCED)
10269 free_string_option(*(char_u **)(p->var));
10270 if (p->flags & P_DEF_ALLOCED)
10271 free_string_option(p->def_val[VI_DEFAULT]);
10272 *(char_u **)(p->var) = empty_option;
10273 p->def_val[VI_DEFAULT] = empty_option;
10274 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10275 }
10276 clear_termcodes();
10277}
10278
10279/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010280 * Free the string for one term option, if it was allocated.
10281 * Set the string to empty_option and clear allocated flag.
10282 * "var" points to the option value.
10283 */
10284 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010285free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010286{
10287 struct vimoption *p;
10288
10289 for (p = &options[0]; p->fullname != NULL; p++)
10290 if (p->var == var)
10291 {
10292 if (p->flags & P_ALLOCED)
10293 free_string_option(*(char_u **)(p->var));
10294 *(char_u **)(p->var) = empty_option;
10295 p->flags &= ~P_ALLOCED;
10296 break;
10297 }
10298}
10299
10300/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301 * Set the terminal option defaults to the current value.
10302 * Used after setting the terminal name.
10303 */
10304 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010305set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306{
10307 struct vimoption *p;
10308
10309 for (p = &options[0]; p->fullname != NULL; p++)
10310 {
10311 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10312 {
10313 if (p->flags & P_DEF_ALLOCED)
10314 {
10315 free_string_option(p->def_val[VI_DEFAULT]);
10316 p->flags &= ~P_DEF_ALLOCED;
10317 }
10318 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10319 if (p->flags & P_ALLOCED)
10320 {
10321 p->flags |= P_DEF_ALLOCED;
10322 p->flags &= ~P_ALLOCED; /* don't free the value now */
10323 }
10324 }
10325 }
10326}
10327
10328/*
10329 * return TRUE if 'p' starts with 't_'
10330 */
10331 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010332istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333{
10334 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10335}
10336
10337/*
10338 * Compute columns for ruler and shown command. 'sc_col' is also used to
10339 * decide what the maximum length of a message on the status line can be.
10340 * If there is a status line for the last window, 'sc_col' is independent
10341 * of 'ru_col'.
10342 */
10343
10344#define COL_RULER 17 /* columns needed by standard ruler */
10345
10346 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010347comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010349#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010350 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351
10352 sc_col = 0;
10353 ru_col = 0;
10354 if (p_ru)
10355 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010356# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010358# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010360# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 /* no last status line, adjust sc_col */
10362 if (!last_has_status)
10363 sc_col = ru_col;
10364 }
10365 if (p_sc)
10366 {
10367 sc_col += SHOWCMD_COLS;
10368 if (!p_ru || last_has_status) /* no need for separating space */
10369 ++sc_col;
10370 }
10371 sc_col = Columns - sc_col;
10372 ru_col = Columns - ru_col;
10373 if (sc_col <= 0) /* screen too narrow, will become a mess */
10374 sc_col = 1;
10375 if (ru_col <= 0)
10376 ru_col = 1;
10377#else
10378 sc_col = Columns;
10379 ru_col = Columns;
10380#endif
10381}
10382
10383/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010384 * Unset local option value, similar to ":set opt<".
10385 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010386 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010387unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010388{
10389 struct vimoption *p;
10390 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010391 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010392
10393 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010394 if (opt_idx < 0)
10395 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010396 p = &(options[opt_idx]);
10397
10398 switch ((int)p->indir)
10399 {
10400 /* global option with local value: use local value if it's been set */
10401 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010402 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010403 break;
10404 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010405 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010406 break;
10407 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010408 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 break;
10410 case PV_AR:
10411 buf->b_p_ar = -1;
10412 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010413 case PV_BKC:
10414 clear_string_option(&buf->b_p_bkc);
10415 buf->b_bkc_flags = 0;
10416 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010420 case PV_TC:
10421 clear_string_option(&buf->b_p_tc);
10422 buf->b_tc_flags = 0;
10423 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010424#ifdef FEAT_FIND_ID
10425 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010426 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010427 break;
10428 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010429 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010430 break;
10431#endif
10432#ifdef FEAT_INS_EXPAND
10433 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010434 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010435 break;
10436 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010437 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010438 break;
10439#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010440 case PV_FP:
10441 clear_string_option(&buf->b_p_fp);
10442 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010443#ifdef FEAT_QUICKFIX
10444 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010445 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010446 break;
10447 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010448 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449 break;
10450 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453#endif
10454#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10455 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010456 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010457 break;
10458#endif
10459#if defined(FEAT_CRYPT)
10460 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010461 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462 break;
10463#endif
10464#ifdef FEAT_STL_OPT
10465 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010466 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010467 break;
10468#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010469 case PV_UL:
10470 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10471 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010472#ifdef FEAT_LISP
10473 case PV_LW:
10474 clear_string_option(&buf->b_p_lw);
10475 break;
10476#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010477#ifdef FEAT_MBYTE
10478 case PV_MENC:
10479 clear_string_option(&buf->b_p_menc);
10480 break;
10481#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010482 }
10483}
10484
10485/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 * Get pointer to option variable, depending on local or global scope.
10487 */
10488 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010489get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490{
10491 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10492 {
10493 if (p->var == VAR_WIN)
10494 return (char_u *)GLOBAL_WO(get_varp(p));
10495 return p->var;
10496 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010497 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498 {
10499 switch ((int)p->indir)
10500 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010501 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010503 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10504 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10505 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010507 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10508 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10509 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010510 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010511 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010512 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010514 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10515 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#endif
10517#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010518 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10519 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010521#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10522 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10523#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010524#if defined(FEAT_CRYPT)
10525 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10526#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010527#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010529#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010530 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010531#ifdef FEAT_LISP
10532 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10533#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010534 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010535#ifdef FEAT_MBYTE
10536 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 }
10539 return NULL; /* "cannot happen" */
10540 }
10541 return get_varp(p);
10542}
10543
10544/*
10545 * Get pointer to option variable.
10546 */
10547 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010548get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549{
10550 /* hidden option, always return NULL */
10551 if (p->var == NULL)
10552 return NULL;
10553
10554 switch ((int)p->indir)
10555 {
10556 case PV_NONE: return p->var;
10557
10558 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010561 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010565 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010569 case PV_TC: return *curbuf->b_p_tc != NUL
10570 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010571 case PV_BKC: return *curbuf->b_p_bkc != NUL
10572 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010574 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010576 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10578#endif
10579#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010580 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010582 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10584#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010585 case PV_FP: return *curbuf->b_p_fp != NUL
10586 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010588 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010590 case PV_GP: return *curbuf->b_p_gp != NUL
10591 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10592 case PV_MP: return *curbuf->b_p_mp != NUL
10593 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010595#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10596 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10597 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10598#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010599#if defined(FEAT_CRYPT)
10600 case PV_CM: return *curbuf->b_p_cm != NUL
10601 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10602#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010603#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010604 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010605 ? (char_u *)&(curwin->w_p_stl) : p->var;
10606#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010607 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10608 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010609#ifdef FEAT_LISP
10610 case PV_LW: return *curbuf->b_p_lw != NUL
10611 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10612#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010613#ifdef FEAT_MBYTE
10614 case PV_MENC: return *curbuf->b_p_menc != NUL
10615 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617
10618#ifdef FEAT_ARABIC
10619 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10620#endif
10621 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010622#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010623 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10624#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010625#ifdef FEAT_SYN_HL
10626 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10627 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010628 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630#ifdef FEAT_DIFF
10631 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10632#endif
10633#ifdef FEAT_FOLDING
10634 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10635 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10636 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10637 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10638 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10639 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10640 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10641# ifdef FEAT_EVAL
10642 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10643 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10644# endif
10645 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10646#endif
10647 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010648 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010649#ifdef FEAT_LINEBREAK
10650 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010653 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010654#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10656#endif
10657#ifdef FEAT_RIGHTLEFT
10658 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10659 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10660#endif
10661 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10662 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10663#ifdef FEAT_LINEBREAK
10664 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010665 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10666 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010669 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010670#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010671 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10672 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10673#endif
10674#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010675 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010676 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678
10679 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10680 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10681#ifdef FEAT_MBYTE
10682 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010684 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10685 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10687 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10688#ifdef FEAT_CINDENT
10689 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10690 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10691 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10692#endif
10693#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10694 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10695#endif
10696#ifdef FEAT_COMMENTS
10697 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10698#endif
10699#ifdef FEAT_FOLDING
10700 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10701#endif
10702#ifdef FEAT_INS_EXPAND
10703 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10704#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010705#ifdef FEAT_COMPL_FUNC
10706 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010707 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010710 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10712#ifdef FEAT_MBYTE
10713 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10714#endif
10715 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010718 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10720 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10721 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10722 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10723#ifdef FEAT_FIND_ID
10724# ifdef FEAT_EVAL
10725 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10726# endif
10727#endif
10728#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10729 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10730 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10731#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010732#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010733 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735#ifdef FEAT_CRYPT
10736 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10737#endif
10738#ifdef FEAT_LISP
10739 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10740#endif
10741 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10742 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10743 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10744 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10745 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010747#ifdef FEAT_TEXTOBJ
10748 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10751#ifdef FEAT_SMARTINDENT
10752 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10756#ifdef FEAT_SEARCHPATH
10757 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10758#endif
10759 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10760#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010761 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010762 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10763#endif
10764#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010765 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10766 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10767 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768#endif
10769 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10770 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10771 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10772 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010773#ifdef FEAT_PERSISTENT_UNDO
10774 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10777#ifdef FEAT_KEYMAP
10778 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10779#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010780#ifdef FEAT_SIGNS
10781 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10782#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010783 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784 }
10785 /* always return a valid pointer to avoid a crash! */
10786 return (char_u *)&(curbuf->b_p_wm);
10787}
10788
10789/*
10790 * Get the value of 'equalprg', either the buffer-local one or the global one.
10791 */
10792 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010793get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794{
10795 if (*curbuf->b_p_ep == NUL)
10796 return p_ep;
10797 return curbuf->b_p_ep;
10798}
10799
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800/*
10801 * Copy options from one window to another.
10802 * Used when splitting a window.
10803 */
10804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010805win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806{
10807 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10808 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10809# ifdef FEAT_RIGHTLEFT
10810# ifdef FEAT_FKMAP
10811 /* Is this right? */
10812 wp_to->w_farsi = wp_from->w_farsi;
10813# endif
10814# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010815#if defined(FEAT_LINEBREAK)
10816 briopt_check(wp_to);
10817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819
10820/*
10821 * Copy the options from one winopt_T to another.
10822 * Doesn't free the old option values in "to", use clear_winopt() for that.
10823 * The 'scroll' option is not copied, because it depends on the window height.
10824 * The 'previewwindow' option is reset, there can be only one preview window.
10825 */
10826 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010827copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828{
10829#ifdef FEAT_ARABIC
10830 to->wo_arab = from->wo_arab;
10831#endif
10832 to->wo_list = from->wo_list;
10833 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010834 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010835#ifdef FEAT_LINEBREAK
10836 to->wo_nuw = from->wo_nuw;
10837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838#ifdef FEAT_RIGHTLEFT
10839 to->wo_rl = from->wo_rl;
10840 to->wo_rlc = vim_strsave(from->wo_rlc);
10841#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010842#ifdef FEAT_STL_OPT
10843 to->wo_stl = vim_strsave(from->wo_stl);
10844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010846#ifdef FEAT_DIFF
10847 to->wo_wrap_save = from->wo_wrap_save;
10848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849#ifdef FEAT_LINEBREAK
10850 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010851 to->wo_bri = from->wo_bri;
10852 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010855 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010856 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010857 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010858#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010859 to->wo_spell = from->wo_spell;
10860#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010861#ifdef FEAT_SYN_HL
10862 to->wo_cuc = from->wo_cuc;
10863 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010864 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010865#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866#ifdef FEAT_DIFF
10867 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010868 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010870#ifdef FEAT_CONCEAL
10871 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010872 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010873#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010874#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010875 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010876 to->wo_tms = vim_strsave(from->wo_tms);
10877#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878#ifdef FEAT_FOLDING
10879 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010880 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010881 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010882 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 to->wo_fdi = vim_strsave(from->wo_fdi);
10884 to->wo_fml = from->wo_fml;
10885 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010886 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010888 to->wo_fdm_save = from->wo_diff_saved
10889 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890 to->wo_fdn = from->wo_fdn;
10891# ifdef FEAT_EVAL
10892 to->wo_fde = vim_strsave(from->wo_fde);
10893 to->wo_fdt = vim_strsave(from->wo_fdt);
10894# endif
10895 to->wo_fmr = vim_strsave(from->wo_fmr);
10896#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010897#ifdef FEAT_SIGNS
10898 to->wo_scl = vim_strsave(from->wo_scl);
10899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900 check_winopt(to); /* don't want NULL pointers */
10901}
10902
10903/*
10904 * Check string options in a window for a NULL value.
10905 */
10906 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010907check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908{
10909 check_winopt(&win->w_onebuf_opt);
10910 check_winopt(&win->w_allbuf_opt);
10911}
10912
10913/*
10914 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10915 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010916 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010917check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918{
10919#ifdef FEAT_FOLDING
10920 check_string_option(&wop->wo_fdi);
10921 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010922 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923# ifdef FEAT_EVAL
10924 check_string_option(&wop->wo_fde);
10925 check_string_option(&wop->wo_fdt);
10926# endif
10927 check_string_option(&wop->wo_fmr);
10928#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010929#ifdef FEAT_SIGNS
10930 check_string_option(&wop->wo_scl);
10931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932#ifdef FEAT_RIGHTLEFT
10933 check_string_option(&wop->wo_rlc);
10934#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010935#ifdef FEAT_STL_OPT
10936 check_string_option(&wop->wo_stl);
10937#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010938#ifdef FEAT_SYN_HL
10939 check_string_option(&wop->wo_cc);
10940#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010941#ifdef FEAT_CONCEAL
10942 check_string_option(&wop->wo_cocu);
10943#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010944#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010945 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010946 check_string_option(&wop->wo_tms);
10947#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010948#ifdef FEAT_LINEBREAK
10949 check_string_option(&wop->wo_briopt);
10950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010951}
10952
10953/*
10954 * Free the allocated memory inside a winopt_T.
10955 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010957clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958{
10959#ifdef FEAT_FOLDING
10960 clear_string_option(&wop->wo_fdi);
10961 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010962 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963# ifdef FEAT_EVAL
10964 clear_string_option(&wop->wo_fde);
10965 clear_string_option(&wop->wo_fdt);
10966# endif
10967 clear_string_option(&wop->wo_fmr);
10968#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010969#ifdef FEAT_SIGNS
10970 clear_string_option(&wop->wo_scl);
10971#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010972#ifdef FEAT_LINEBREAK
10973 clear_string_option(&wop->wo_briopt);
10974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975#ifdef FEAT_RIGHTLEFT
10976 clear_string_option(&wop->wo_rlc);
10977#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010978#ifdef FEAT_STL_OPT
10979 clear_string_option(&wop->wo_stl);
10980#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010981#ifdef FEAT_SYN_HL
10982 clear_string_option(&wop->wo_cc);
10983#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010984#ifdef FEAT_CONCEAL
10985 clear_string_option(&wop->wo_cocu);
10986#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010987#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010988 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010989 clear_string_option(&wop->wo_tms);
10990#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991}
10992
10993/*
10994 * Copy global option values to local options for one buffer.
10995 * Used when creating a new buffer and sometimes when entering a buffer.
10996 * flags:
10997 * BCO_ENTER We will enter the buf buffer.
10998 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10999 * appropriate.
11000 * BCO_NOHELP Don't copy the values to a help buffer.
11001 */
11002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011003buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004{
11005 int should_copy = TRUE;
11006 char_u *save_p_isk = NULL; /* init for GCC */
11007 int dont_do_help;
11008 int did_isk = FALSE;
11009
11010 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011 * Skip this when the option defaults have not been set yet. Happens when
11012 * main() allocates the first buffer.
11013 */
11014 if (p_cpo != NULL)
11015 {
11016 /*
11017 * Always copy when entering and 'cpo' contains 'S'.
11018 * Don't copy when already initialized.
11019 * Don't copy when 'cpo' contains 's' and not entering.
11020 * 'S' BCO_ENTER initialized 's' should_copy
11021 * yes yes X X TRUE
11022 * yes no yes X FALSE
11023 * no X yes X FALSE
11024 * X no no yes FALSE
11025 * X no no no TRUE
11026 * no yes no X TRUE
11027 */
11028 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11029 && (buf->b_p_initialized
11030 || (!(flags & BCO_ENTER)
11031 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11032 should_copy = FALSE;
11033
11034 if (should_copy || (flags & BCO_ALWAYS))
11035 {
11036 /* Don't copy the options specific to a help buffer when
11037 * BCO_NOHELP is given or the options were initialized already
11038 * (jumping back to a help file with CTRL-T or CTRL-O) */
11039 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11040 || buf->b_p_initialized;
11041 if (dont_do_help) /* don't free b_p_isk */
11042 {
11043 save_p_isk = buf->b_p_isk;
11044 buf->b_p_isk = NULL;
11045 }
11046 /*
11047 * Always free the allocated strings.
11048 * If not already initialized, set 'readonly' and copy 'fileformat'.
11049 */
11050 if (!buf->b_p_initialized)
11051 {
11052 free_buf_options(buf, TRUE);
11053 buf->b_p_ro = FALSE; /* don't copy readonly */
11054 buf->b_p_tx = p_tx;
11055#ifdef FEAT_MBYTE
11056 buf->b_p_fenc = vim_strsave(p_fenc);
11057#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011058 switch (*p_ffs)
11059 {
11060 case 'm':
11061 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11062 case 'd':
11063 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11064 case 'u':
11065 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11066 default:
11067 buf->b_p_ff = vim_strsave(p_ff);
11068 }
11069 if (buf->b_p_ff != NULL)
11070 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071 buf->b_p_bh = empty_option;
11072 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 }
11074 else
11075 free_buf_options(buf, FALSE);
11076
11077 buf->b_p_ai = p_ai;
11078 buf->b_p_ai_nopaste = p_ai_nopaste;
11079 buf->b_p_sw = p_sw;
11080 buf->b_p_tw = p_tw;
11081 buf->b_p_tw_nopaste = p_tw_nopaste;
11082 buf->b_p_tw_nobin = p_tw_nobin;
11083 buf->b_p_wm = p_wm;
11084 buf->b_p_wm_nopaste = p_wm_nopaste;
11085 buf->b_p_wm_nobin = p_wm_nobin;
11086 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011087#ifdef FEAT_MBYTE
11088 buf->b_p_bomb = p_bomb;
11089#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011090 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 buf->b_p_et = p_et;
11092 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011093 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094 buf->b_p_ml = p_ml;
11095 buf->b_p_ml_nobin = p_ml_nobin;
11096 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011097 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098#ifdef FEAT_INS_EXPAND
11099 buf->b_p_cpt = vim_strsave(p_cpt);
11100#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011101#ifdef FEAT_COMPL_FUNC
11102 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011103 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011104#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 buf->b_p_sts = p_sts;
11106 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108#ifdef FEAT_COMMENTS
11109 buf->b_p_com = vim_strsave(p_com);
11110#endif
11111#ifdef FEAT_FOLDING
11112 buf->b_p_cms = vim_strsave(p_cms);
11113#endif
11114 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011115 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 buf->b_p_nf = vim_strsave(p_nf);
11117 buf->b_p_mps = vim_strsave(p_mps);
11118#ifdef FEAT_SMARTINDENT
11119 buf->b_p_si = p_si;
11120#endif
11121 buf->b_p_ci = p_ci;
11122#ifdef FEAT_CINDENT
11123 buf->b_p_cin = p_cin;
11124 buf->b_p_cink = vim_strsave(p_cink);
11125 buf->b_p_cino = vim_strsave(p_cino);
11126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127 /* Don't copy 'filetype', it must be detected */
11128 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 buf->b_p_pi = p_pi;
11130#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11131 buf->b_p_cinw = vim_strsave(p_cinw);
11132#endif
11133#ifdef FEAT_LISP
11134 buf->b_p_lisp = p_lisp;
11135#endif
11136#ifdef FEAT_SYN_HL
11137 /* Don't copy 'syntax', it must be set */
11138 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011139 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011140 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011141#endif
11142#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011143 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011144 (void)compile_cap_prog(&buf->b_s);
11145 buf->b_s.b_p_spf = vim_strsave(p_spf);
11146 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147#endif
11148#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11149 buf->b_p_inde = vim_strsave(p_inde);
11150 buf->b_p_indk = vim_strsave(p_indk);
11151#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011152 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011153#if defined(FEAT_EVAL)
11154 buf->b_p_fex = vim_strsave(p_fex);
11155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156#ifdef FEAT_CRYPT
11157 buf->b_p_key = vim_strsave(p_key);
11158#endif
11159#ifdef FEAT_SEARCHPATH
11160 buf->b_p_sua = vim_strsave(p_sua);
11161#endif
11162#ifdef FEAT_KEYMAP
11163 buf->b_p_keymap = vim_strsave(p_keymap);
11164 buf->b_kmap_state |= KEYMAP_INIT;
11165#endif
11166 /* This isn't really an option, but copying the langmap and IME
11167 * state from the current buffer is better than resetting it. */
11168 buf->b_p_iminsert = p_iminsert;
11169 buf->b_p_imsearch = p_imsearch;
11170
11171 /* options that are normally global but also have a local value
11172 * are not copied, start using the global value */
11173 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011174 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011175 buf->b_p_bkc = empty_option;
11176 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011177#ifdef FEAT_QUICKFIX
11178 buf->b_p_gp = empty_option;
11179 buf->b_p_mp = empty_option;
11180 buf->b_p_efm = empty_option;
11181#endif
11182 buf->b_p_ep = empty_option;
11183 buf->b_p_kp = empty_option;
11184 buf->b_p_path = empty_option;
11185 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011186 buf->b_p_tc = empty_option;
11187 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188#ifdef FEAT_FIND_ID
11189 buf->b_p_def = empty_option;
11190 buf->b_p_inc = empty_option;
11191# ifdef FEAT_EVAL
11192 buf->b_p_inex = vim_strsave(p_inex);
11193# endif
11194#endif
11195#ifdef FEAT_INS_EXPAND
11196 buf->b_p_dict = empty_option;
11197 buf->b_p_tsr = empty_option;
11198#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011199#ifdef FEAT_TEXTOBJ
11200 buf->b_p_qe = vim_strsave(p_qe);
11201#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011202#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11203 buf->b_p_bexpr = empty_option;
11204#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011205#if defined(FEAT_CRYPT)
11206 buf->b_p_cm = empty_option;
11207#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011208#ifdef FEAT_PERSISTENT_UNDO
11209 buf->b_p_udf = p_udf;
11210#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011211#ifdef FEAT_LISP
11212 buf->b_p_lw = empty_option;
11213#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011214#ifdef FEAT_MBYTE
11215 buf->b_p_menc = empty_option;
11216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217
11218 /*
11219 * Don't copy the options set by ex_help(), use the saved values,
11220 * when going from a help buffer to a non-help buffer.
11221 * Don't touch these at all when BCO_NOHELP is used and going from
11222 * or to a help buffer.
11223 */
11224 if (dont_do_help)
11225 buf->b_p_isk = save_p_isk;
11226 else
11227 {
11228 buf->b_p_isk = vim_strsave(p_isk);
11229 did_isk = TRUE;
11230 buf->b_p_ts = p_ts;
11231 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232 if (buf->b_p_bt[0] == 'h')
11233 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234 buf->b_p_ma = p_ma;
11235 }
11236 }
11237
11238 /*
11239 * When the options should be copied (ignoring BCO_ALWAYS), set the
11240 * flag that indicates that the options have been initialized.
11241 */
11242 if (should_copy)
11243 buf->b_p_initialized = TRUE;
11244 }
11245
11246 check_buf_options(buf); /* make sure we don't have NULLs */
11247 if (did_isk)
11248 (void)buf_init_chartab(buf, FALSE);
11249}
11250
11251/*
11252 * Reset the 'modifiable' option and its default value.
11253 */
11254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011255reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256{
11257 int opt_idx;
11258
11259 curbuf->b_p_ma = FALSE;
11260 p_ma = FALSE;
11261 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011262 if (opt_idx >= 0)
11263 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264}
11265
11266/*
11267 * Set the global value for 'iminsert' to the local value.
11268 */
11269 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011270set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271{
11272 p_iminsert = curbuf->b_p_iminsert;
11273}
11274
11275/*
11276 * Set the global value for 'imsearch' to the local value.
11277 */
11278 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011279set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011280{
11281 p_imsearch = curbuf->b_p_imsearch;
11282}
11283
11284#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11285static int expand_option_idx = -1;
11286static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11287static int expand_option_flags = 0;
11288
11289 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011290set_context_in_set_cmd(
11291 expand_T *xp,
11292 char_u *arg,
11293 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294{
11295 int nextchar;
11296 long_u flags = 0; /* init for GCC */
11297 int opt_idx = 0; /* init for GCC */
11298 char_u *p;
11299 char_u *s;
11300 int is_term_option = FALSE;
11301 int key;
11302
11303 expand_option_flags = opt_flags;
11304
11305 xp->xp_context = EXPAND_SETTINGS;
11306 if (*arg == NUL)
11307 {
11308 xp->xp_pattern = arg;
11309 return;
11310 }
11311 p = arg + STRLEN(arg) - 1;
11312 if (*p == ' ' && *(p - 1) != '\\')
11313 {
11314 xp->xp_pattern = p + 1;
11315 return;
11316 }
11317 while (p > arg)
11318 {
11319 s = p;
11320 /* count number of backslashes before ' ' or ',' */
11321 if (*p == ' ' || *p == ',')
11322 {
11323 while (s > arg && *(s - 1) == '\\')
11324 --s;
11325 }
11326 /* break at a space with an even number of backslashes */
11327 if (*p == ' ' && ((p - s) & 1) == 0)
11328 {
11329 ++p;
11330 break;
11331 }
11332 --p;
11333 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011334 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011335 {
11336 xp->xp_context = EXPAND_BOOL_SETTINGS;
11337 p += 2;
11338 }
11339 if (STRNCMP(p, "inv", 3) == 0)
11340 {
11341 xp->xp_context = EXPAND_BOOL_SETTINGS;
11342 p += 3;
11343 }
11344 xp->xp_pattern = arg = p;
11345 if (*arg == '<')
11346 {
11347 while (*p != '>')
11348 if (*p++ == NUL) /* expand terminal option name */
11349 return;
11350 key = get_special_key_code(arg + 1);
11351 if (key == 0) /* unknown name */
11352 {
11353 xp->xp_context = EXPAND_NOTHING;
11354 return;
11355 }
11356 nextchar = *++p;
11357 is_term_option = TRUE;
11358 expand_option_name[2] = KEY2TERMCAP0(key);
11359 expand_option_name[3] = KEY2TERMCAP1(key);
11360 }
11361 else
11362 {
11363 if (p[0] == 't' && p[1] == '_')
11364 {
11365 p += 2;
11366 if (*p != NUL)
11367 ++p;
11368 if (*p == NUL)
11369 return; /* expand option name */
11370 nextchar = *++p;
11371 is_term_option = TRUE;
11372 expand_option_name[2] = p[-2];
11373 expand_option_name[3] = p[-1];
11374 }
11375 else
11376 {
11377 /* Allow * wildcard */
11378 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11379 p++;
11380 if (*p == NUL)
11381 return;
11382 nextchar = *p;
11383 *p = NUL;
11384 opt_idx = findoption(arg);
11385 *p = nextchar;
11386 if (opt_idx == -1 || options[opt_idx].var == NULL)
11387 {
11388 xp->xp_context = EXPAND_NOTHING;
11389 return;
11390 }
11391 flags = options[opt_idx].flags;
11392 if (flags & P_BOOL)
11393 {
11394 xp->xp_context = EXPAND_NOTHING;
11395 return;
11396 }
11397 }
11398 }
11399 /* handle "-=" and "+=" */
11400 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11401 {
11402 ++p;
11403 nextchar = '=';
11404 }
11405 if ((nextchar != '=' && nextchar != ':')
11406 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11407 {
11408 xp->xp_context = EXPAND_UNSUCCESSFUL;
11409 return;
11410 }
11411 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11412 {
11413 xp->xp_context = EXPAND_OLD_SETTING;
11414 if (is_term_option)
11415 expand_option_idx = -1;
11416 else
11417 expand_option_idx = opt_idx;
11418 xp->xp_pattern = p + 1;
11419 return;
11420 }
11421 xp->xp_context = EXPAND_NOTHING;
11422 if (is_term_option || (flags & P_NUM))
11423 return;
11424
11425 xp->xp_pattern = p + 1;
11426
11427 if (flags & P_EXPAND)
11428 {
11429 p = options[opt_idx].var;
11430 if (p == (char_u *)&p_bdir
11431 || p == (char_u *)&p_dir
11432 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011433 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 || p == (char_u *)&p_rtp
11435#ifdef FEAT_SEARCHPATH
11436 || p == (char_u *)&p_cdpath
11437#endif
11438#ifdef FEAT_SESSION
11439 || p == (char_u *)&p_vdir
11440#endif
11441 )
11442 {
11443 xp->xp_context = EXPAND_DIRECTORIES;
11444 if (p == (char_u *)&p_path
11445#ifdef FEAT_SEARCHPATH
11446 || p == (char_u *)&p_cdpath
11447#endif
11448 )
11449 xp->xp_backslash = XP_BS_THREE;
11450 else
11451 xp->xp_backslash = XP_BS_ONE;
11452 }
11453 else
11454 {
11455 xp->xp_context = EXPAND_FILES;
11456 /* for 'tags' need three backslashes for a space */
11457 if (p == (char_u *)&p_tags)
11458 xp->xp_backslash = XP_BS_THREE;
11459 else
11460 xp->xp_backslash = XP_BS_ONE;
11461 }
11462 }
11463
11464 /* For an option that is a list of file names, find the start of the
11465 * last file name. */
11466 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11467 {
11468 /* count number of backslashes before ' ' or ',' */
11469 if (*p == ' ' || *p == ',')
11470 {
11471 s = p;
11472 while (s > xp->xp_pattern && *(s - 1) == '\\')
11473 --s;
11474 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11475 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11476 {
11477 xp->xp_pattern = p + 1;
11478 break;
11479 }
11480 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011481
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011482#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011483 /* for 'spellsuggest' start at "file:" */
11484 if (options[opt_idx].var == (char_u *)&p_sps
11485 && STRNCMP(p, "file:", 5) == 0)
11486 {
11487 xp->xp_pattern = p + 5;
11488 break;
11489 }
11490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491 }
11492
11493 return;
11494}
11495
11496 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011497ExpandSettings(
11498 expand_T *xp,
11499 regmatch_T *regmatch,
11500 int *num_file,
11501 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011502{
11503 int num_normal = 0; /* Nr of matching non-term-code settings */
11504 int num_term = 0; /* Nr of matching terminal code settings */
11505 int opt_idx;
11506 int match;
11507 int count = 0;
11508 char_u *str;
11509 int loop;
11510 int is_term_opt;
11511 char_u name_buf[MAX_KEY_NAME_LEN];
11512 static char *(names[]) = {"all", "termcap"};
11513 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11514
11515 /* do this loop twice:
11516 * loop == 0: count the number of matching options
11517 * loop == 1: copy the matching options into allocated memory
11518 */
11519 for (loop = 0; loop <= 1; ++loop)
11520 {
11521 regmatch->rm_ic = ic;
11522 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11523 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011524 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11525 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11527 {
11528 if (loop == 0)
11529 num_normal++;
11530 else
11531 (*file)[count++] = vim_strsave((char_u *)names[match]);
11532 }
11533 }
11534 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11535 opt_idx++)
11536 {
11537 if (options[opt_idx].var == NULL)
11538 continue;
11539 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11540 && !(options[opt_idx].flags & P_BOOL))
11541 continue;
11542 is_term_opt = istermoption(&options[opt_idx]);
11543 if (is_term_opt && num_normal > 0)
11544 continue;
11545 match = FALSE;
11546 if (vim_regexec(regmatch, str, (colnr_T)0)
11547 || (options[opt_idx].shortname != NULL
11548 && vim_regexec(regmatch,
11549 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11550 match = TRUE;
11551 else if (is_term_opt)
11552 {
11553 name_buf[0] = '<';
11554 name_buf[1] = 't';
11555 name_buf[2] = '_';
11556 name_buf[3] = str[2];
11557 name_buf[4] = str[3];
11558 name_buf[5] = '>';
11559 name_buf[6] = NUL;
11560 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11561 {
11562 match = TRUE;
11563 str = name_buf;
11564 }
11565 }
11566 if (match)
11567 {
11568 if (loop == 0)
11569 {
11570 if (is_term_opt)
11571 num_term++;
11572 else
11573 num_normal++;
11574 }
11575 else
11576 (*file)[count++] = vim_strsave(str);
11577 }
11578 }
11579 /*
11580 * Check terminal key codes, these are not in the option table
11581 */
11582 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11583 {
11584 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11585 {
11586 if (!isprint(str[0]) || !isprint(str[1]))
11587 continue;
11588
11589 name_buf[0] = 't';
11590 name_buf[1] = '_';
11591 name_buf[2] = str[0];
11592 name_buf[3] = str[1];
11593 name_buf[4] = NUL;
11594
11595 match = FALSE;
11596 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11597 match = TRUE;
11598 else
11599 {
11600 name_buf[0] = '<';
11601 name_buf[1] = 't';
11602 name_buf[2] = '_';
11603 name_buf[3] = str[0];
11604 name_buf[4] = str[1];
11605 name_buf[5] = '>';
11606 name_buf[6] = NUL;
11607
11608 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11609 match = TRUE;
11610 }
11611 if (match)
11612 {
11613 if (loop == 0)
11614 num_term++;
11615 else
11616 (*file)[count++] = vim_strsave(name_buf);
11617 }
11618 }
11619
11620 /*
11621 * Check special key names.
11622 */
11623 regmatch->rm_ic = TRUE; /* ignore case here */
11624 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11625 {
11626 name_buf[0] = '<';
11627 STRCPY(name_buf + 1, str);
11628 STRCAT(name_buf, ">");
11629
11630 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11631 {
11632 if (loop == 0)
11633 num_term++;
11634 else
11635 (*file)[count++] = vim_strsave(name_buf);
11636 }
11637 }
11638 }
11639 if (loop == 0)
11640 {
11641 if (num_normal > 0)
11642 *num_file = num_normal;
11643 else if (num_term > 0)
11644 *num_file = num_term;
11645 else
11646 return OK;
11647 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11648 if (*file == NULL)
11649 {
11650 *file = (char_u **)"";
11651 return FAIL;
11652 }
11653 }
11654 }
11655 return OK;
11656}
11657
11658 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011659ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660{
11661 char_u *var = NULL; /* init for GCC */
11662 char_u *buf;
11663
11664 *num_file = 0;
11665 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11666 if (*file == NULL)
11667 return FAIL;
11668
11669 /*
11670 * For a terminal key code expand_option_idx is < 0.
11671 */
11672 if (expand_option_idx < 0)
11673 {
11674 var = find_termcode(expand_option_name + 2);
11675 if (var == NULL)
11676 expand_option_idx = findoption(expand_option_name);
11677 }
11678
11679 if (expand_option_idx >= 0)
11680 {
11681 /* put string of option value in NameBuff */
11682 option_value2string(&options[expand_option_idx], expand_option_flags);
11683 var = NameBuff;
11684 }
11685 else if (var == NULL)
11686 var = (char_u *)"";
11687
11688 /* A backslash is required before some characters. This is the reverse of
11689 * what happens in do_set(). */
11690 buf = vim_strsave_escaped(var, escape_chars);
11691
11692 if (buf == NULL)
11693 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011694 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695 return FAIL;
11696 }
11697
11698#ifdef BACKSLASH_IN_FILENAME
11699 /* For MS-Windows et al. we don't double backslashes at the start and
11700 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011701 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702 if (var[0] == '\\' && var[1] == '\\'
11703 && expand_option_idx >= 0
11704 && (options[expand_option_idx].flags & P_EXPAND)
11705 && vim_isfilec(var[2])
11706 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011707 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708#endif
11709
11710 *file[0] = buf;
11711 *num_file = 1;
11712 return OK;
11713}
11714#endif
11715
11716/*
11717 * Get the value for the numeric or string option *opp in a nice format into
11718 * NameBuff[]. Must not be called with a hidden option!
11719 */
11720 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011721option_value2string(
11722 struct vimoption *opp,
11723 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724{
11725 char_u *varp;
11726
11727 varp = get_varp_scope(opp, opt_flags);
11728
11729 if (opp->flags & P_NUM)
11730 {
11731 long wc = 0;
11732
11733 if (wc_use_keyname(varp, &wc))
11734 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11735 else if (wc != 0)
11736 STRCPY(NameBuff, transchar((int)wc));
11737 else
11738 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11739 }
11740 else /* P_STRING */
11741 {
11742 varp = *(char_u **)(varp);
11743 if (varp == NULL) /* just in case */
11744 NameBuff[0] = NUL;
11745#ifdef FEAT_CRYPT
11746 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011747 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011748 STRCPY(NameBuff, "*****");
11749#endif
11750 else if (opp->flags & P_EXPAND)
11751 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11752 /* Translate 'pastetoggle' into special key names */
11753 else if ((char_u **)opp->var == &p_pt)
11754 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11755 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011756 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 }
11758}
11759
11760/*
11761 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11762 * printed as a keyname.
11763 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11764 */
11765 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011766wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767{
11768 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11769 {
11770 *wcp = *(long *)varp;
11771 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11772 return TRUE;
11773 }
11774 return FALSE;
11775}
11776
Bram Moolenaar01615492015-02-03 13:00:38 +010011777#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011779 * Any character has an equivalent 'langmap' character. This is used for
11780 * keyboards that have a special language mode that sends characters above
11781 * 128 (although other characters can be translated too). The "to" field is a
11782 * Vim command character. This avoids having to switch the keyboard back to
11783 * ASCII mode when leaving Insert mode.
11784 *
11785 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11786 * commands.
11787 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11788 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11789 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011791# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011792/*
11793 * With multi-byte support use growarray for 'langmap' chars >= 256
11794 */
11795typedef struct
11796{
11797 int from;
11798 int to;
11799} langmap_entry_T;
11800
11801static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011802static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803
11804/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011805 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11806 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011808 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011809langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011810{
11811 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011812 int a = 0;
11813 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011814
11815 /* Do a binary search for an existing entry. */
11816 while (a != b)
11817 {
11818 int i = (a + b) / 2;
11819 int d = entries[i].from - from;
11820
11821 if (d == 0)
11822 {
11823 entries[i].to = to;
11824 return;
11825 }
11826 if (d < 0)
11827 a = i + 1;
11828 else
11829 b = i;
11830 }
11831
11832 if (ga_grow(&langmap_mapga, 1) != OK)
11833 return; /* out of memory */
11834
11835 /* insert new entry at position "a" */
11836 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11837 mch_memmove(entries + 1, entries,
11838 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11839 ++langmap_mapga.ga_len;
11840 entries[0].from = from;
11841 entries[0].to = to;
11842}
11843
11844/*
11845 * Apply 'langmap' to multi-byte character "c" and return the result.
11846 */
11847 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011848langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011849{
11850 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11851 int a = 0;
11852 int b = langmap_mapga.ga_len;
11853
11854 while (a != b)
11855 {
11856 int i = (a + b) / 2;
11857 int d = entries[i].from - c;
11858
11859 if (d == 0)
11860 return entries[i].to; /* found matching entry */
11861 if (d < 0)
11862 a = i + 1;
11863 else
11864 b = i;
11865 }
11866 return c; /* no entry found, return "c" unmodified */
11867}
11868# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869
11870 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011871langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872{
11873 int i;
11874
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011875 for (i = 0; i < 256; i++)
11876 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11877# ifdef FEAT_MBYTE
11878 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011880}
11881
11882/*
11883 * Called when langmap option is set; the language map can be
11884 * changed at any time!
11885 */
11886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011887langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888{
11889 char_u *p;
11890 char_u *p2;
11891 int from, to;
11892
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011893#ifdef FEAT_MBYTE
11894 ga_clear(&langmap_mapga); /* clear the previous map first */
11895#endif
11896 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897
11898 for (p = p_langmap; p[0] != NUL; )
11899 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011900 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011901 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 {
11903 if (p2[0] == '\\' && p2[1] != NUL)
11904 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905 }
11906 if (p2[0] == ';')
11907 ++p2; /* abcd;ABCD form, p2 points to A */
11908 else
11909 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11910 while (p[0])
11911 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011912 if (p[0] == ',')
11913 {
11914 ++p;
11915 break;
11916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917 if (p[0] == '\\' && p[1] != NUL)
11918 ++p;
11919#ifdef FEAT_MBYTE
11920 from = (*mb_ptr2char)(p);
11921#else
11922 from = p[0];
11923#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011924 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925 if (p2 == NULL)
11926 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011927 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011928 if (p[0] != ',')
11929 {
11930 if (p[0] == '\\')
11931 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011933 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011935 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938 }
11939 else
11940 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011941 if (p2[0] != ',')
11942 {
11943 if (p2[0] == '\\')
11944 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011946 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011948 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011950 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951 }
11952 if (to == NUL)
11953 {
11954 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11955 transchar(from));
11956 return;
11957 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011958
11959#ifdef FEAT_MBYTE
11960 if (from >= 256)
11961 langmap_set_entry(from, to);
11962 else
11963#endif
11964 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965
11966 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011967 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011968 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011970 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971 if (*p == ';')
11972 {
11973 p = p2;
11974 if (p[0] != NUL)
11975 {
11976 if (p[0] != ',')
11977 {
11978 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11979 return;
11980 }
11981 ++p;
11982 }
11983 break;
11984 }
11985 }
11986 }
11987 }
11988}
11989#endif
11990
11991/*
11992 * Return TRUE if format option 'x' is in effect.
11993 * Take care of no formatting when 'paste' is set.
11994 */
11995 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011996has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997{
11998 if (p_paste)
11999 return FALSE;
12000 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12001}
12002
12003/*
12004 * Return TRUE if "x" is present in 'shortmess' option, or
12005 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12006 */
12007 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012008shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012009{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012010 return p_shm != NULL &&
12011 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012 || (vim_strchr(p_shm, 'a') != NULL
12013 && vim_strchr((char_u *)SHM_A, x) != NULL));
12014}
12015
12016/*
12017 * paste_option_changed() - Called after p_paste was set or reset.
12018 */
12019 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012020paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021{
12022 static int old_p_paste = FALSE;
12023 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012024 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025#ifdef FEAT_CMDL_INFO
12026 static int save_ru = 0;
12027#endif
12028#ifdef FEAT_RIGHTLEFT
12029 static int save_ri = 0;
12030 static int save_hkmap = 0;
12031#endif
12032 buf_T *buf;
12033
12034 if (p_paste)
12035 {
12036 /*
12037 * Paste switched from off to on.
12038 * Save the current values, so they can be restored later.
12039 */
12040 if (!old_p_paste)
12041 {
12042 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012043 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044 {
12045 buf->b_p_tw_nopaste = buf->b_p_tw;
12046 buf->b_p_wm_nopaste = buf->b_p_wm;
12047 buf->b_p_sts_nopaste = buf->b_p_sts;
12048 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012049 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 }
12051
12052 /* save global options */
12053 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012054 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055#ifdef FEAT_CMDL_INFO
12056 save_ru = p_ru;
12057#endif
12058#ifdef FEAT_RIGHTLEFT
12059 save_ri = p_ri;
12060 save_hkmap = p_hkmap;
12061#endif
12062 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012063 p_ai_nopaste = p_ai;
12064 p_et_nopaste = p_et;
12065 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066 p_tw_nopaste = p_tw;
12067 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 }
12069
12070 /*
12071 * Always set the option values, also when 'paste' is set when it is
12072 * already on.
12073 */
12074 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012075 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012076 {
12077 buf->b_p_tw = 0; /* textwidth is 0 */
12078 buf->b_p_wm = 0; /* wrapmargin is 0 */
12079 buf->b_p_sts = 0; /* softtabstop is 0 */
12080 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012081 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012082 }
12083
12084 /* set global options */
12085 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012086 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012088 if (p_ru)
12089 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012090 p_ru = 0; /* no ruler */
12091#endif
12092#ifdef FEAT_RIGHTLEFT
12093 p_ri = 0; /* no reverse insert */
12094 p_hkmap = 0; /* no Hebrew keyboard */
12095#endif
12096 /* set global values for local buffer options */
12097 p_tw = 0;
12098 p_wm = 0;
12099 p_sts = 0;
12100 p_ai = 0;
12101 }
12102
12103 /*
12104 * Paste switched from on to off: Restore saved values.
12105 */
12106 else if (old_p_paste)
12107 {
12108 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012109 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110 {
12111 buf->b_p_tw = buf->b_p_tw_nopaste;
12112 buf->b_p_wm = buf->b_p_wm_nopaste;
12113 buf->b_p_sts = buf->b_p_sts_nopaste;
12114 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012115 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 }
12117
12118 /* restore global options */
12119 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012120 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122 if (p_ru != save_ru)
12123 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124 p_ru = save_ru;
12125#endif
12126#ifdef FEAT_RIGHTLEFT
12127 p_ri = save_ri;
12128 p_hkmap = save_hkmap;
12129#endif
12130 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012131 p_ai = p_ai_nopaste;
12132 p_et = p_et_nopaste;
12133 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134 p_tw = p_tw_nopaste;
12135 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 }
12137
12138 old_p_paste = p_paste;
12139}
12140
12141/*
12142 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12143 *
12144 * Reset 'compatible' and set the values for options that didn't get set yet
12145 * to the Vim defaults.
12146 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012147 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148 */
12149 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012150vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012152 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012153 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012154 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155
12156 if (!option_was_set((char_u *)"cp"))
12157 {
12158 p_cp = FALSE;
12159 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12160 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12161 set_option_default(opt_idx, OPT_FREE, FALSE);
12162 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012163 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012165
12166 if (fname != NULL)
12167 {
12168 p = vim_getenv(envname, &dofree);
12169 if (p == NULL)
12170 {
12171 /* Set $MYVIMRC to the first vimrc file found. */
12172 p = FullName_save(fname, FALSE);
12173 if (p != NULL)
12174 {
12175 vim_setenv(envname, p);
12176 vim_free(p);
12177 }
12178 }
12179 else if (dofree)
12180 vim_free(p);
12181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012182}
12183
12184/*
12185 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12186 */
12187 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012188change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012190 int opt_idx;
12191
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192 if (p_cp != on)
12193 {
12194 p_cp = on;
12195 compatible_set();
12196 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012197 opt_idx = findoption((char_u *)"cp");
12198 if (opt_idx >= 0)
12199 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200}
12201
12202/*
12203 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012204 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 */
12206 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012207option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208{
12209 int idx;
12210
12211 idx = findoption(name);
12212 if (idx < 0) /* unknown option */
12213 return FALSE;
12214 if (options[idx].flags & P_WAS_SET)
12215 return TRUE;
12216 return FALSE;
12217}
12218
12219/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012220 * Reset the flag indicating option "name" was set.
12221 */
12222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012223reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012224{
12225 int idx = findoption(name);
12226
12227 if (idx >= 0)
12228 options[idx].flags &= ~P_WAS_SET;
12229}
12230
12231/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232 * compatible_set() - Called when 'compatible' has been set or unset.
12233 *
12234 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12235 * flag) to a Vi compatible value.
12236 * When 'compatible' is unset: Set all options that have a different default
12237 * for Vim (without the P_VI_DEF flag) to that default.
12238 */
12239 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012240compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241{
12242 int opt_idx;
12243
12244 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12245 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12246 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12247 set_option_default(opt_idx, OPT_FREE, p_cp);
12248 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012249 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250}
12251
12252#ifdef FEAT_LINEBREAK
12253
12254# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12255 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012256 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257# endif
12258
12259/*
12260 * fill_breakat_flags() -- called when 'breakat' changes value.
12261 */
12262 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012263fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012265 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012266 int i;
12267
12268 for (i = 0; i < 256; i++)
12269 breakat_flags[i] = FALSE;
12270
12271 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012272 for (p = p_breakat; *p; p++)
12273 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274}
12275
12276# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012277 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278# endif
12279
12280#endif
12281
12282/*
12283 * Check an option that can be a range of string values.
12284 *
12285 * Return OK for correct value, FAIL otherwise.
12286 * Empty is always OK.
12287 */
12288 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012289check_opt_strings(
12290 char_u *val,
12291 char **values,
12292 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012293{
12294 return opt_strings_flags(val, values, NULL, list);
12295}
12296
12297/*
12298 * Handle an option that can be a range of string values.
12299 * Set a flag in "*flagp" for each string present.
12300 *
12301 * Return OK for correct value, FAIL otherwise.
12302 * Empty is always OK.
12303 */
12304 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012305opt_strings_flags(
12306 char_u *val, /* new value */
12307 char **values, /* array of valid string values */
12308 unsigned *flagp,
12309 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012310{
12311 int i;
12312 int len;
12313 unsigned new_flags = 0;
12314
12315 while (*val)
12316 {
12317 for (i = 0; ; ++i)
12318 {
12319 if (values[i] == NULL) /* val not found in values[] */
12320 return FAIL;
12321
12322 len = (int)STRLEN(values[i]);
12323 if (STRNCMP(values[i], val, len) == 0
12324 && ((list && val[len] == ',') || val[len] == NUL))
12325 {
12326 val += len + (val[len] == ',');
12327 new_flags |= (1 << i);
12328 break; /* check next item in val list */
12329 }
12330 }
12331 }
12332 if (flagp != NULL)
12333 *flagp = new_flags;
12334
12335 return OK;
12336}
12337
12338/*
12339 * Read the 'wildmode' option, fill wim_flags[].
12340 */
12341 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012342check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012343{
12344 char_u new_wim_flags[4];
12345 char_u *p;
12346 int i;
12347 int idx = 0;
12348
12349 for (i = 0; i < 4; ++i)
12350 new_wim_flags[i] = 0;
12351
12352 for (p = p_wim; *p; ++p)
12353 {
12354 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12355 ;
12356 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12357 return FAIL;
12358 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12359 new_wim_flags[idx] |= WIM_LONGEST;
12360 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12361 new_wim_flags[idx] |= WIM_FULL;
12362 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12363 new_wim_flags[idx] |= WIM_LIST;
12364 else
12365 return FAIL;
12366 p += i;
12367 if (*p == NUL)
12368 break;
12369 if (*p == ',')
12370 {
12371 if (idx == 3)
12372 return FAIL;
12373 ++idx;
12374 }
12375 }
12376
12377 /* fill remaining entries with last flag */
12378 while (idx < 3)
12379 {
12380 new_wim_flags[idx + 1] = new_wim_flags[idx];
12381 ++idx;
12382 }
12383
12384 /* only when there are no errors, wim_flags[] is changed */
12385 for (i = 0; i < 4; ++i)
12386 wim_flags[i] = new_wim_flags[i];
12387 return OK;
12388}
12389
12390/*
12391 * Check if backspacing over something is allowed.
12392 */
12393 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012394can_bs(
12395 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012396{
12397 switch (*p_bs)
12398 {
12399 case '2': return TRUE;
12400 case '1': return (what != BS_START);
12401 case '0': return FALSE;
12402 }
12403 return vim_strchr(p_bs, what) != NULL;
12404}
12405
12406/*
12407 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12408 * the file must be considered changed when the value is different.
12409 */
12410 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012411save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012412{
12413 buf->b_start_ffc = *buf->b_p_ff;
12414 buf->b_start_eol = buf->b_p_eol;
12415#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012416 buf->b_start_bomb = buf->b_p_bomb;
12417
Bram Moolenaar071d4272004-06-13 20:20:40 +000012418 /* Only use free/alloc when necessary, they take time. */
12419 if (buf->b_start_fenc == NULL
12420 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12421 {
12422 vim_free(buf->b_start_fenc);
12423 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12424 }
12425#endif
12426}
12427
12428/*
12429 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12430 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012431 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12432 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012433 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012434 * When "ignore_empty" is true don't consider a new, empty buffer to be
12435 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436 */
12437 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012438file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012440 /* In a buffer that was never loaded the options are not valid. */
12441 if (buf->b_flags & BF_NEVERLOADED)
12442 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012443 if (ignore_empty
12444 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 && buf->b_ml.ml_line_count == 1
12446 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12447 return FALSE;
12448 if (buf->b_start_ffc != *buf->b_p_ff)
12449 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012450 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012451 return TRUE;
12452#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012453 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12454 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455 if (buf->b_start_fenc == NULL)
12456 return (*buf->b_p_fenc != NUL);
12457 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12458#else
12459 return FALSE;
12460#endif
12461}
12462
12463/*
12464 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12465 */
12466 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012467check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468{
12469 return check_opt_strings(p, p_ff_values, FALSE);
12470}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012471
12472/*
12473 * Return the effective shiftwidth value for current buffer, using the
12474 * 'tabstop' value when 'shiftwidth' is zero.
12475 */
12476 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012477get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012478{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012479 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012480}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012481
12482/*
12483 * Return the effective softtabstop value for the current buffer, using the
12484 * 'tabstop' value when 'softtabstop' is negative.
12485 */
12486 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012487get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012488{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012489 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012490}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012491
12492/*
12493 * Check matchpairs option for "*initc".
12494 * If there is a match set "*initc" to the matching character and "*findc" to
12495 * the opposite character. Set "*backwards" to the direction.
12496 * When "switchit" is TRUE swap the direction.
12497 */
12498 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012499find_mps_values(
12500 int *initc,
12501 int *findc,
12502 int *backwards,
12503 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012504{
12505 char_u *ptr;
12506
12507 ptr = curbuf->b_p_mps;
12508 while (*ptr != NUL)
12509 {
12510#ifdef FEAT_MBYTE
12511 if (has_mbyte)
12512 {
12513 char_u *prev;
12514
12515 if (mb_ptr2char(ptr) == *initc)
12516 {
12517 if (switchit)
12518 {
12519 *findc = *initc;
12520 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12521 *backwards = TRUE;
12522 }
12523 else
12524 {
12525 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12526 *backwards = FALSE;
12527 }
12528 return;
12529 }
12530 prev = ptr;
12531 ptr += mb_ptr2len(ptr) + 1;
12532 if (mb_ptr2char(ptr) == *initc)
12533 {
12534 if (switchit)
12535 {
12536 *findc = *initc;
12537 *initc = mb_ptr2char(prev);
12538 *backwards = FALSE;
12539 }
12540 else
12541 {
12542 *findc = mb_ptr2char(prev);
12543 *backwards = TRUE;
12544 }
12545 return;
12546 }
12547 ptr += mb_ptr2len(ptr);
12548 }
12549 else
12550#endif
12551 {
12552 if (*ptr == *initc)
12553 {
12554 if (switchit)
12555 {
12556 *backwards = TRUE;
12557 *findc = *initc;
12558 *initc = ptr[2];
12559 }
12560 else
12561 {
12562 *backwards = FALSE;
12563 *findc = ptr[2];
12564 }
12565 return;
12566 }
12567 ptr += 2;
12568 if (*ptr == *initc)
12569 {
12570 if (switchit)
12571 {
12572 *backwards = FALSE;
12573 *findc = *initc;
12574 *initc = ptr[-2];
12575 }
12576 else
12577 {
12578 *backwards = TRUE;
12579 *findc = ptr[-2];
12580 }
12581 return;
12582 }
12583 ++ptr;
12584 }
12585 if (*ptr == ',')
12586 ++ptr;
12587 }
12588}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012589
12590#if defined(FEAT_LINEBREAK) || defined(PROTO)
12591/*
12592 * This is called when 'breakindentopt' is changed and when a window is
12593 * initialized.
12594 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012595 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012596briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012597{
12598 char_u *p;
12599 int bri_shift = 0;
12600 long bri_min = 20;
12601 int bri_sbr = FALSE;
12602
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012603 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012604 while (*p != NUL)
12605 {
12606 if (STRNCMP(p, "shift:", 6) == 0
12607 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12608 {
12609 p += 6;
12610 bri_shift = getdigits(&p);
12611 }
12612 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12613 {
12614 p += 4;
12615 bri_min = getdigits(&p);
12616 }
12617 else if (STRNCMP(p, "sbr", 3) == 0)
12618 {
12619 p += 3;
12620 bri_sbr = TRUE;
12621 }
12622 if (*p != ',' && *p != NUL)
12623 return FAIL;
12624 if (*p == ',')
12625 ++p;
12626 }
12627
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012628 wp->w_p_brishift = bri_shift;
12629 wp->w_p_brimin = bri_min;
12630 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012631
12632 return OK;
12633}
12634#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012635
12636/*
12637 * Get the local or global value of 'backupcopy'.
12638 */
12639 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012640get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012641{
12642 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12643}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012644
12645#if defined(FEAT_SIGNS) || defined(PROTO)
12646/*
12647 * Return TRUE when window "wp" has a column to draw signs in.
12648 */
12649 int
12650signcolumn_on(win_T *wp)
12651{
12652 if (*wp->w_p_scl == 'n')
12653 return FALSE;
12654 if (*wp->w_p_scl == 'y')
12655 return TRUE;
12656 return (wp->w_buffer->b_signlist != NULL
12657# ifdef FEAT_NETBEANS_INTG
12658 || wp->w_buffer->b_has_sign_column
12659# endif
12660 );
12661}
12662#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012663
12664#if defined(FEAT_EVAL) || defined(PROTO)
12665/*
12666 * Get window or buffer local options.
12667 */
12668 dict_T *
12669get_winbuf_options(int bufopt)
12670{
12671 dict_T *d;
12672 int opt_idx;
12673
12674 d = dict_alloc();
12675 if (d == NULL)
12676 return NULL;
12677
12678 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12679 {
12680 struct vimoption *opt = &options[opt_idx];
12681
12682 if ((bufopt && (opt->indir & PV_BUF))
12683 || (!bufopt && (opt->indir & PV_WIN)))
12684 {
12685 char_u *varp = get_varp(opt);
12686
12687 if (varp != NULL)
12688 {
12689 if (opt->flags & P_STRING)
12690 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012691 else if (opt->flags & P_NUM)
12692 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012693 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012694 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012695 }
12696 }
12697 }
12698
12699 return d;
12700}
12701#endif