blob: 9ebc51183324a8ea33ef6ac1f8c65c6cddb1edf0 [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 Moolenaar8c041b62018-04-14 18:14:06 +02002753 {"terminalscroll", "tlsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2754#ifdef FEAT_TERMINAL
2755 (char_u *)&p_tlsl, PV_NONE,
2756 {(char_u *)10000L, (char_u *)10000L}
2757#else
2758 (char_u *)NULL, PV_NONE,
2759 {(char_u *)NULL, (char_u *)0L}
2760#endif
2761 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002762 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2763#ifdef FEAT_TERMINAL
2764 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002765 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)NULL, (char_u *)0L}
2769#endif
2770 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002771 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2772#ifdef FEAT_TERMINAL
2773 (char_u *)VAR_WIN, PV_TMS,
2774 {(char_u *)"", (char_u *)NULL}
2775#else
2776 (char_u *)NULL, PV_NONE,
2777 {(char_u *)NULL, (char_u *)0L}
2778#endif
2779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"terse", NULL, P_BOOL|P_VI_DEF,
2781 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textauto", "ta", P_BOOL|P_VIM,
2784 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2788 (char_u *)&p_tx, PV_TX,
2789 {
2790#ifdef USE_CRNL
2791 (char_u *)TRUE,
2792#else
2793 (char_u *)FALSE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002796 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002799 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002801 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2807 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"timeout", "to", P_BOOL|P_VI_DEF,
2810 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2813 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"title", NULL, P_BOOL|P_VI_DEF,
2816#ifdef FEAT_TITLE
2817 (char_u *)&p_title, PV_NONE,
2818#else
2819 (char_u *)NULL, PV_NONE,
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"titlelen", NULL, P_NUM|P_VI_DEF,
2823#ifdef FEAT_TITLE
2824 (char_u *)&p_titlelen, PV_NONE,
2825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002829 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#ifdef FEAT_TITLE
2831 (char_u *)&p_titleold, PV_NONE,
2832 {(char_u *)N_("Thanks for flying Vim"),
2833 (char_u *)0L}
2834#else
2835 (char_u *)NULL, PV_NONE,
2836 {(char_u *)0L, (char_u *)0L}
2837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"titlestring", NULL, P_STRING|P_VI_DEF,
2840#ifdef FEAT_TITLE
2841 (char_u *)&p_titlestring, PV_NONE,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002846 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002856#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858 {(char_u *)"small", (char_u *)0L}
2859#else
2860 (char_u *)NULL, PV_NONE,
2861 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2865 (char_u *)&p_ttimeout, 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 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2868 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2874 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2877#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2878 (char_u *)&p_ttym, PV_NONE,
2879#else
2880 (char_u *)NULL, PV_NONE,
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2884 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2887 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002889 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2890 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udir, PV_NONE,
2893 {(char_u *)".", (char_u *)0L}
2894#else
2895 (char_u *)NULL, PV_NONE,
2896 {(char_u *)0L, (char_u *)0L}
2897#endif
2898 SCRIPTID_INIT},
2899 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2900#ifdef FEAT_PERSISTENT_UNDO
2901 (char_u *)&p_udf, PV_UDF,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
2905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002907 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002909#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 (char_u *)1000L,
2911#else
2912 (char_u *)100L,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002915 {"undoreload", "ur", P_NUM|P_VI_DEF,
2916 (char_u *)&p_ur, PV_NONE,
2917 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"updatecount", "uc", P_NUM|P_VI_DEF,
2919 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"updatetime", "ut", P_NUM|P_VI_DEF,
2922 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"verbose", "vbs", P_NUM|P_VI_DEF,
2925 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002927 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2928 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2931#ifdef FEAT_SESSION
2932 (char_u *)&p_vdir, PV_NONE,
2933 {(char_u *)DFLT_VDIR, (char_u *)0L}
2934#else
2935 (char_u *)NULL, PV_NONE,
2936 {(char_u *)0L, (char_u *)0L}
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002939 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#ifdef FEAT_SESSION
2941 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002942 {(char_u *)"folds,options,cursor,curdir",
2943 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944#else
2945 (char_u *)NULL, PV_NONE,
2946 {(char_u *)0L, (char_u *)0L}
2947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002949 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950#ifdef FEAT_VIMINFO
2951 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002952#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002953 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954#else
2955# ifdef AMIGA
2956 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002957 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002959 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960# endif
2961#endif
2962#else
2963 (char_u *)NULL, PV_NONE,
2964 {(char_u *)0L, (char_u *)0L}
2965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002967 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2968#ifdef FEAT_VIMINFO
2969 (char_u *)&p_viminfofile, PV_NONE,
2970 {(char_u *)"", (char_u *)0L}
2971#else
2972 (char_u *)NULL, PV_NONE,
2973 {(char_u *)0L, (char_u *)0L}
2974#endif
2975 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002976 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2977 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978#ifdef FEAT_VIRTUALEDIT
2979 (char_u *)&p_ve, PV_NONE,
2980 {(char_u *)"", (char_u *)""}
2981#else
2982 (char_u *)NULL, PV_NONE,
2983 {(char_u *)0L, (char_u *)0L}
2984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002985 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2987 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"w300", NULL, P_NUM|P_VI_DEF,
2990 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"w1200", NULL, P_NUM|P_VI_DEF,
2993 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 {"w9600", NULL, P_NUM|P_VI_DEF,
2996 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002997 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"warn", NULL, P_BOOL|P_VI_DEF,
2999 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3002 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003004 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003006 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 {"wildchar", "wc", P_NUM|P_VIM,
3008 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003009 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3010 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003011 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003014 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015#ifdef FEAT_WILDIGN
3016 (char_u *)&p_wig, PV_NONE,
3017#else
3018 (char_u *)NULL, PV_NONE,
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003021 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3022 (char_u *)&p_wic, PV_NONE,
3023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3025#ifdef FEAT_WILDMENU
3026 (char_u *)&p_wmnu, PV_NONE,
3027#else
3028 (char_u *)NULL, PV_NONE,
3029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003031 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003033 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003034 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3035#ifdef FEAT_CMDL_COMPL
3036 (char_u *)&p_wop, PV_NONE,
3037 {(char_u *)"", (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 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3044#ifdef FEAT_WAK
3045 (char_u *)&p_wak, PV_NONE,
3046 {(char_u *)"menu", (char_u *)0L}
3047#else
3048 (char_u *)NULL, PV_NONE,
3049 {(char_u *)NULL, (char_u *)0L}
3050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003053 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 (char_u *)&p_wh, 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 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003060 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003061 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003062 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003066 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003069 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003070 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003071#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003072 (char_u *)&p_winptydll, PV_NONE, {
3073# ifdef _WIN64
3074 (char_u *)"winpty64.dll",
3075# else
3076 (char_u *)"winpty32.dll",
3077# endif
3078 (char_u *)0L}
3079#else
3080 (char_u *)NULL, PV_NONE,
3081 {(char_u *)0L, (char_u *)0L}
3082#endif
3083 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3088 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3091 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3094 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"write", NULL, P_BOOL|P_VI_DEF,
3097 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003098 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"writeany", "wa", P_BOOL|P_VI_DEF,
3100 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3103 (char_u *)&p_wb, PV_NONE,
3104 {
3105#ifdef FEAT_WRITEBACKUP
3106 (char_u *)TRUE,
3107#else
3108 (char_u *)FALSE,
3109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003110 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writedelay", "wd", P_NUM|P_VI_DEF,
3112 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003113 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
3115/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003116#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119
3120 p_term("t_AB", T_CAB)
3121 p_term("t_AF", T_CAF)
3122 p_term("t_AL", T_CAL)
3123 p_term("t_al", T_AL)
3124 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003125 p_term("t_BE", T_BE)
3126 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_cd", T_CD)
3128 p_term("t_ce", T_CE)
3129 p_term("t_cl", T_CL)
3130 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003131 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_Co", T_CCO)
3133 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003134 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_da", T_DA)
3138 p_term("t_db", T_DB)
3139 p_term("t_DL", T_CDL)
3140 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003141 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003142 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003144 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 p_term("t_IE", T_CIE)
3146 p_term("t_IS", T_CIS)
3147 p_term("t_ke", T_KE)
3148 p_term("t_ks", T_KS)
3149 p_term("t_le", T_LE)
3150 p_term("t_mb", T_MB)
3151 p_term("t_md", T_MD)
3152 p_term("t_me", T_ME)
3153 p_term("t_mr", T_MR)
3154 p_term("t_ms", T_MS)
3155 p_term("t_nd", T_ND)
3156 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003157 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003158 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003159 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003161 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_RV", T_CRV)
3163 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003164 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003167 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003168 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003170 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003172 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_te", T_TE)
3174 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003175 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_ts", T_TS)
3177 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_ue", T_UE)
3179 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_vb", T_VB)
3182 p_term("t_ve", T_VE)
3183 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003184 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_vs", T_VS)
3186 p_term("t_WP", T_CWP)
3187 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003188 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_xs", T_XS)
3190 p_term("t_ZH", T_CZH)
3191 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003192 p_term("t_8f", T_8F)
3193 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194
3195/* terminal key codes are not in here */
3196
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003197 /* end marker */
3198 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199};
3200
3201#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3202
3203#ifdef FEAT_MBYTE
3204static char *(p_ambw_values[]) = {"single", "double", NULL};
3205#endif
3206static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003207static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003209#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003210static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003211#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003212#ifdef FEAT_CMDL_COMPL
3213static char *(p_wop_values[]) = {"tagfile", NULL};
3214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215#ifdef FEAT_WAK
3216static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3217#endif
3218static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3220static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222#ifdef FEAT_BROWSE
3223static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003226static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003229static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3231#ifdef FEAT_FOLDING
3232static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003233# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 NULL};
3237static char *(p_fcl_values[]) = {"all", NULL};
3238#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003239#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003240static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003242#ifdef FEAT_SIGNS
3243static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003246static void set_option_default(int, int opt_flags, int compatible);
3247static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003248static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static char_u *term_bg_default(void);
3250static void did_set_option(int opt_idx, int opt_flags, int new_value);
3251static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#endif
3255#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static char_u *option_expand(int opt_idx, char_u *val);
3259static void didset_options(void);
3260static void didset_options2(void);
3261static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003262#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003264#else
3265# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3266#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003267static void set_string_option_global(int opt_idx, char_u **varp);
3268static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3269static 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);
3270static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003271#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003277#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003278static char_u *did_set_spell_option(int is_spellfile);
3279static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003280#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003281#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003283#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3285static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3286static void check_redraw(long_u flags);
3287static int findoption(char_u *);
3288static int find_key_option(char_u *);
3289static void showoptions(int all, int opt_flags);
3290static int optval_default(struct vimoption *, char_u *varp);
3291static void showoneopt(struct vimoption *, int opt_flags);
3292static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3293static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3294static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3295static int istermoption(struct vimoption *);
3296static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3297static char_u *get_varp(struct vimoption *);
3298static void option_value2string(struct vimoption *, int opt_flags);
3299static void check_winopt(winopt_T *wop);
3300static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void langmap_init(void);
3303static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static void paste_option_changed(void);
3306static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003308static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3311static int check_opt_strings(char_u *val, char **values, int);
3312static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003313#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003314static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316
3317/*
3318 * Initialize the options, first part.
3319 *
3320 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003321 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 */
3323 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003324set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325{
3326 char_u *p;
3327 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003328 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
3330#ifdef FEAT_LANGMAP
3331 langmap_init();
3332#endif
3333
3334 /* Be Vi compatible by default */
3335 p_cp = TRUE;
3336
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003337 /* Use POSIX compatibility when $VIM_POSIX is set. */
3338 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003339 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003340 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003341 set_string_default("shm", (char_u *)"A");
3342 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003343
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 /*
3345 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003348 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003349#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003350 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003352 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# endif
3354#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003355 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003356 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357
3358#ifdef FEAT_WILDIGN
3359 /*
3360 * Set the default for 'backupskip' to include environment variables for
3361 * temp files.
3362 */
3363 {
3364# ifdef UNIX
3365 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3366# else
3367 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3368# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003369 int len;
3370 garray_T ga;
3371 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372
3373 ga_init2(&ga, 1, 100);
3374 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3375 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003376 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377# ifdef UNIX
3378 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003379# ifdef MACOS_X
3380 p = (char_u *)"/private/tmp";
3381# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 else
3385# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003386 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 if (p != NULL && *p != NUL)
3388 {
3389 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003390 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 if (ga_grow(&ga, len) == OK)
3392 {
3393 if (ga.ga_len > 0)
3394 STRCAT(ga.ga_data, ",");
3395 STRCAT(ga.ga_data, p);
3396 add_pathsep(ga.ga_data);
3397 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398 ga.ga_len += len;
3399 }
3400 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003401 if (mustfree)
3402 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 }
3404 if (ga.ga_data != NULL)
3405 {
3406 set_string_default("bsk", ga.ga_data);
3407 vim_free(ga.ga_data);
3408 }
3409 }
3410#endif
3411
3412 /*
3413 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3414 */
3415 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003418#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3419 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3420#endif
3421 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003423 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003424 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425#else
3426# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003428 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431# endif
3432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003434 opt_idx = findoption((char_u *)"maxmem");
3435 if (opt_idx >= 0)
3436 {
3437#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003438 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3439 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003440#endif
3441 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3442 }
3443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 }
3445
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446#ifdef FEAT_SEARCHPATH
3447 {
3448 char_u *cdpath;
3449 char_u *buf;
3450 int i;
3451 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003452 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453
3454 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003455 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456 if (cdpath != NULL)
3457 {
3458 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3459 if (buf != NULL)
3460 {
3461 buf[0] = ','; /* start with ",", current dir first */
3462 j = 1;
3463 for (i = 0; cdpath[i] != NUL; ++i)
3464 {
3465 if (vim_ispathlistsep(cdpath[i]))
3466 buf[j++] = ',';
3467 else
3468 {
3469 if (cdpath[i] == ' ' || cdpath[i] == ',')
3470 buf[j++] = '\\';
3471 buf[j++] = cdpath[i];
3472 }
3473 }
3474 buf[j] = NUL;
3475 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003476 if (opt_idx >= 0)
3477 {
3478 options[opt_idx].def_val[VI_DEFAULT] = buf;
3479 options[opt_idx].flags |= P_DEF_ALLOCED;
3480 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003481 else
3482 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003484 if (mustfree)
3485 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 }
3487 }
3488#endif
3489
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003490#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 /* Set print encoding on platforms that don't default to latin1 */
3492 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003493# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494 (char_u *)"cp1252"
3495# else
3496# ifdef VMS
3497 (char_u *)"dec-mcs"
3498# else
3499# ifdef EBCDIC
3500 (char_u *)"ebcdic-uk"
3501# else
3502# ifdef MAC
3503 (char_u *)"mac-roman"
3504# else /* HPUX */
3505 (char_u *)"hp-roman8"
3506# endif
3507# endif
3508# endif
3509# endif
3510 );
3511#endif
3512
3513#ifdef FEAT_POSTSCRIPT
3514 /* 'printexpr' must be allocated to be able to evaluate it. */
3515 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003516# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003517 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518# else
3519# ifdef VMS
3520 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3521
3522# else
3523 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3524# endif
3525# endif
3526 );
3527#endif
3528
3529 /*
3530 * Set all the options (except the terminal options) to their default
3531 * value. Also set the global value for local options.
3532 */
3533 set_options_default(0);
3534
Bram Moolenaar07268702018-03-01 21:57:32 +01003535#ifdef CLEAN_RUNTIMEPATH
3536 if (clean_arg)
3537 {
3538 opt_idx = findoption((char_u *)"runtimepath");
3539 if (opt_idx >= 0)
3540 {
3541 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3542 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3543 }
3544 opt_idx = findoption((char_u *)"packpath");
3545 if (opt_idx >= 0)
3546 {
3547 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3548 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3549 }
3550 }
3551#endif
3552
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553#ifdef FEAT_GUI
3554 if (found_reverse_arg)
3555 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3556#endif
3557
3558 curbuf->b_p_initialized = TRUE;
3559 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003560 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 check_buf_options(curbuf);
3562 check_win_options(curwin);
3563 check_options();
3564
3565 /* Must be before option_expand(), because that one needs vim_isIDc() */
3566 didset_options();
3567
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003568#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003569 /* Use the current chartab for the generic chartab. This is not in
3570 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003571 init_spell_chartab();
3572#endif
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 /*
3575 * Expand environment variables and things like "~" for the defaults.
3576 * If option_expand() returns non-NULL the variable is expanded. This can
3577 * only happen for non-indirect options.
3578 * Also set the default to the expanded value, so ":set" does not list
3579 * them.
3580 * Don't set the P_ALLOCED flag, because we don't want to free the
3581 * default.
3582 */
3583 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3584 {
3585 if ((options[opt_idx].flags & P_GETTEXT)
3586 && options[opt_idx].var != NULL)
3587 p = (char_u *)_(*(char **)options[opt_idx].var);
3588 else
3589 p = option_expand(opt_idx, NULL);
3590 if (p != NULL && (p = vim_strsave(p)) != NULL)
3591 {
3592 *(char_u **)options[opt_idx].var = p;
3593 /* VIMEXP
3594 * Defaults for all expanded options are currently the same for Vi
3595 * and Vim. When this changes, add some code here! Also need to
3596 * split P_DEF_ALLOCED in two.
3597 */
3598 if (options[opt_idx].flags & P_DEF_ALLOCED)
3599 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3600 options[opt_idx].def_val[VI_DEFAULT] = p;
3601 options[opt_idx].flags |= P_DEF_ALLOCED;
3602 }
3603 }
3604
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 save_file_ff(curbuf); /* Buffer is unchanged */
3606
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607#if defined(FEAT_ARABIC)
3608 /* Detect use of mlterm.
3609 * Mlterm is a terminal emulator akin to xterm that has some special
3610 * abilities (bidi namely).
3611 * NOTE: mlterm's author is being asked to 'set' a variable
3612 * instead of an environment variable due to inheritance.
3613 */
3614 if (mch_getenv((char_u *)"MLTERM") != NULL)
3615 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3616#endif
3617
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003618 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003619
3620#ifdef FEAT_MBYTE
3621# if defined(WIN3264) && defined(FEAT_GETTEXT)
3622 /*
3623 * If $LANG isn't set, try to get a good value for it. This makes the
3624 * right language be used automatically. Don't do this for English.
3625 */
3626 if (mch_getenv((char_u *)"LANG") == NULL)
3627 {
3628 char buf[20];
3629
3630 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3631 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3632 * only the first two. */
3633 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3634 (LPTSTR)buf, 20);
3635 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3636 {
3637 /* There are a few exceptions (probably more) */
3638 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3639 STRCPY(buf, "zh_TW");
3640 else if (STRNICMP(buf, "chs", 3) == 0
3641 || STRNICMP(buf, "zhc", 3) == 0)
3642 STRCPY(buf, "zh_CN");
3643 else if (STRNICMP(buf, "jp", 2) == 0)
3644 STRCPY(buf, "ja");
3645 else
3646 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003647 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648 }
3649 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003650# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003651# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003652 /* Moved to os_mac_conv.c to avoid dependency problems. */
3653 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003654# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655# endif
3656
3657 /* enc_locale() will try to find the encoding of the current locale. */
3658 p = enc_locale();
3659 if (p != NULL)
3660 {
3661 char_u *save_enc;
3662
3663 /* Try setting 'encoding' and check if the value is valid.
3664 * If not, go back to the default "latin1". */
3665 save_enc = p_enc;
3666 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003667 if (STRCMP(p_enc, "gb18030") == 0)
3668 {
3669 /* We don't support "gb18030", but "cp936" is a good substitute
3670 * for practical purposes, thus use that. It's not an alias to
3671 * still support conversion between gb18030 and utf-8. */
3672 p_enc = vim_strsave((char_u *)"cp936");
3673 vim_free(p);
3674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675 if (mb_init() == NULL)
3676 {
3677 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 {
3680 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3681 options[opt_idx].flags |= P_DEF_ALLOCED;
3682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683
Bram Moolenaard0573012017-10-28 21:11:06 +02003684#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003685 if (STRCMP(p_enc, "latin1") == 0
3686# ifdef FEAT_MBYTE
3687 || enc_utf8
3688# endif
3689 )
3690 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003691 /* Adjust the default for 'isprint' and 'iskeyword' to match
3692 * latin1. Also set the defaults for when 'nocompatible' is
3693 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003694 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003695 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003696 set_string_option_direct((char_u *)"isk", -1,
3697 ISK_LATIN1, OPT_FREE, SID_NONE);
3698 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003701 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003702 if (opt_idx >= 0)
3703 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003704 (void)init_chartab();
3705 }
3706#endif
3707
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708# if defined(WIN3264) && !defined(FEAT_GUI)
3709 /* Win32 console: When GetACP() returns a different value from
3710 * GetConsoleCP() set 'termencoding'. */
3711 if (GetACP() != GetConsoleCP())
3712 {
3713 char buf[50];
3714
3715 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3716 p_tenc = vim_strsave((char_u *)buf);
3717 if (p_tenc != NULL)
3718 {
3719 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003720 if (opt_idx >= 0)
3721 {
3722 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3723 options[opt_idx].flags |= P_DEF_ALLOCED;
3724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 convert_setup(&input_conv, p_tenc, p_enc);
3726 convert_setup(&output_conv, p_enc, p_tenc);
3727 }
3728 else
3729 p_tenc = empty_option;
3730 }
3731# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003732# if defined(WIN3264) && defined(FEAT_MBYTE)
3733 /* $HOME may have characters in active code page. */
3734 init_homedir();
3735# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736 }
3737 else
3738 {
3739 vim_free(p_enc);
3740 p_enc = save_enc;
3741 }
3742 }
3743#endif
3744
3745#ifdef FEAT_MULTI_LANG
3746 /* Set the default for 'helplang'. */
3747 set_helplang_default(get_mess_lang());
3748#endif
3749}
3750
3751/*
3752 * Set an option to its default value.
3753 * This does not take care of side effects!
3754 */
3755 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003756set_option_default(
3757 int opt_idx,
3758 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3759 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760{
3761 char_u *varp; /* pointer to variable for current option */
3762 int dvi; /* index in def_val[] */
3763 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003764 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3766
3767 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3768 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003769 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 {
3771 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3772 if (flags & P_STRING)
3773 {
3774 /* Use set_string_option_direct() for local options to handle
3775 * freeing and allocating the value. */
3776 if (options[opt_idx].indir != PV_NONE)
3777 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003778 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779 else
3780 {
3781 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3782 free_string_option(*(char_u **)(varp));
3783 *(char_u **)varp = options[opt_idx].def_val[dvi];
3784 options[opt_idx].flags &= ~P_ALLOCED;
3785 }
3786 }
3787 else if (flags & P_NUM)
3788 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003789 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 win_comp_scroll(curwin);
3791 else
3792 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003793 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 /* May also set global value for local option. */
3795 if (both)
3796 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3797 *(long *)varp;
3798 }
3799 }
3800 else /* P_BOOL */
3801 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003802 /* the cast to long is required for Manx C, long_i is needed for
3803 * MSVC */
3804 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003805#ifdef UNIX
3806 /* 'modeline' defaults to off for root */
3807 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3808 *(int *)varp = FALSE;
3809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 /* May also set global value for local option. */
3811 if (both)
3812 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3813 *(int *)varp;
3814 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003815
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003816 /* The default value is not insecure. */
3817 flagsp = insecure_flag(opt_idx, opt_flags);
3818 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819 }
3820
3821#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003822 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823#endif
3824}
3825
3826/*
3827 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003828 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 */
3830 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003831set_options_default(
3832 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833{
3834 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003836 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837
3838 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003839 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003840#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003841 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003842 || (TRUE
3843# if defined(FEAT_MBYTE)
3844 && options[i].var != (char_u *)&p_enc
3845# endif
3846# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003847 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003848 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003849# endif
3850 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003851#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003852 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 set_option_default(i, opt_flags, p_cp);
3854
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003856 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003858#ifdef FEAT_CINDENT
3859 parse_cino(curbuf);
3860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861}
3862
3863/*
3864 * Set the Vi-default value of a string option.
3865 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003866 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003868 static void
3869set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870{
3871 char_u *p;
3872 int opt_idx;
3873
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003874 if (escape && vim_strchr(val, ' ') != NULL)
3875 p = vim_strsave_escaped(val, (char_u *)" ");
3876 else
3877 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 if (p != NULL) /* we don't want a NULL */
3879 {
3880 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (opt_idx >= 0)
3882 {
3883 if (options[opt_idx].flags & P_DEF_ALLOCED)
3884 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3885 options[opt_idx].def_val[VI_DEFAULT] = p;
3886 options[opt_idx].flags |= P_DEF_ALLOCED;
3887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 }
3889}
3890
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003891 void
3892set_string_default(char *name, char_u *val)
3893{
3894 set_string_default_esc(name, val, FALSE);
3895}
3896
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897/*
3898 * Set the Vi-default value of a number option.
3899 * Used for 'lines' and 'columns'.
3900 */
3901 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003902set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003904 int opt_idx;
3905
3906 opt_idx = findoption((char_u *)name);
3907 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003908 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909}
3910
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003911#if defined(EXITFREE) || defined(PROTO)
3912/*
3913 * Free all options.
3914 */
3915 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003916free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003917{
3918 int i;
3919
3920 for (i = 0; !istermoption(&options[i]); i++)
3921 {
3922 if (options[i].indir == PV_NONE)
3923 {
3924 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003925 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003926 free_string_option(*(char_u **)options[i].var);
3927 if (options[i].flags & P_DEF_ALLOCED)
3928 free_string_option(options[i].def_val[VI_DEFAULT]);
3929 }
3930 else if (options[i].var != VAR_WIN
3931 && (options[i].flags & P_STRING))
3932 /* buffer-local option: free global value */
3933 free_string_option(*(char_u **)options[i].var);
3934 }
3935}
3936#endif
3937
3938
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939/*
3940 * Initialize the options, part two: After getting Rows and Columns and
3941 * setting 'term'.
3942 */
3943 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003944set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003946 int idx;
3947
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003949 * 'scroll' defaults to half the window height. The stored default is zero,
3950 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003952 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003953 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003954 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 comp_col();
3956
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003957 /*
3958 * 'window' is only for backwards compatibility with Vi.
3959 * Default is Rows - 1.
3960 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003961 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003962 p_window = Rows - 1;
3963 set_number_default("window", Rows - 1);
3964
Bram Moolenaarf740b292006-02-16 22:11:02 +00003965 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003966#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003967 /*
3968 * If 'background' wasn't set by the user, try guessing the value,
3969 * depending on the terminal name. Only need to check for terminals
3970 * with a dark background, that can handle color.
3971 */
3972 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003973 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3974 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003976 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003977 /* don't mark it as set, when starting the GUI it may be
3978 * changed again */
3979 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980 }
3981#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003982
3983#ifdef CURSOR_SHAPE
3984 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3985#endif
3986#ifdef FEAT_MOUSESHAPE
3987 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3988#endif
3989#ifdef FEAT_PRINTER
3990 (void)parse_printoptions(); /* parse 'printoptions' default value */
3991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992}
3993
3994/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995 * Return "dark" or "light" depending on the kind of terminal.
3996 * This is just guessing! Recognized are:
3997 * "linux" Linux console
3998 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003999 * "cygwin.*" Cygwin shell
4000 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004001 * We also check the COLORFGBG environment variable, which is set by
4002 * rxvt and derivatives. This variable contains either two or three
4003 * values separated by semicolons; we want the last value in either
4004 * case. If this value is 0-6 or 8, our background is dark.
4005 */
4006 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004007term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004008{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004009#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004010 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004011 return (char_u *)"dark";
4012#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004013 char_u *p;
4014
Bram Moolenaarf740b292006-02-16 22:11:02 +00004015 if (STRCMP(T_NAME, "linux") == 0
4016 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004017 || STRNCMP(T_NAME, "cygwin", 6) == 0
4018 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4020 && (p = vim_strrchr(p, ';')) != NULL
4021 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4022 && p[2] == NUL))
4023 return (char_u *)"dark";
4024 return (char_u *)"light";
4025#endif
4026}
4027
4028/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 * Initialize the options, part three: After reading the .vimrc
4030 */
4031 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004032set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004034#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035/*
4036 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4037 * This is done after other initializations, where 'shell' might have been
4038 * set, but only if they have not been set before.
4039 */
4040 char_u *p;
4041 int idx_srr;
4042 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 int idx_sp;
4045 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047
4048 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004049 if (idx_srr < 0)
4050 do_srr = FALSE;
4051 else
4052 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004055 if (idx_sp < 0)
4056 do_sp = FALSE;
4057 else
4058 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004060 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 if (p != NULL)
4062 {
4063 /*
4064 * Default for p_sp is "| tee", for p_srr is ">".
4065 * For known shells it is changed here to include stderr.
4066 */
4067 if ( fnamecmp(p, "csh") == 0
4068 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 || fnamecmp(p, "csh.exe") == 0
4071 || fnamecmp(p, "tcsh.exe") == 0
4072# endif
4073 )
4074 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 if (do_sp)
4077 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4084 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004085# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 if (do_srr)
4087 {
4088 p_srr = (char_u *)">&";
4089 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4090 }
4091 }
4092 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 if ( fnamecmp(p, "sh") == 0
4095 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004096 || fnamecmp(p, "mksh") == 0
4097 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004099 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004101 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 || fnamecmp(p, "cmd") == 0
4104 || fnamecmp(p, "sh.exe") == 0
4105 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004106 || fnamecmp(p, "mksh.exe") == 0
4107 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004109 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 || fnamecmp(p, "bash.exe") == 0
4111 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 if (do_sp)
4117 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004118# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004120# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4124 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004125# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 if (do_srr)
4127 {
4128 p_srr = (char_u *)">%s 2>&1";
4129 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4130 }
4131 }
4132 vim_free(p);
4133 }
4134#endif
4135
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004136#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004138 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4139 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 * This is done after other initializations, where 'shell' might have been
4141 * set, but only if they have not been set before. Default for p_shcf is
4142 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004143 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004145 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 {
4147 int idx3;
4148
4149 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004150 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 {
4152 p_shcf = (char_u *)"-c";
4153 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4154 }
4155
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 /* Somehow Win32 requires the quotes around the redirection too */
4157 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004158 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 {
4160 p_sxq = (char_u *)"\"";
4161 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004164 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4165 {
4166 int idx3;
4167
4168 /*
4169 * cmd.exe on Windows will strip the first and last double quote given
4170 * on the command line, e.g. most of the time things like:
4171 * cmd /c "my path/to/echo" "my args to echo"
4172 * become:
4173 * my path/to/echo" "my args to echo
4174 * when executed.
4175 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004176 * To avoid this, set shellxquote to surround the command in
4177 * parenthesis. This appears to make most commands work, without
4178 * breaking commands that worked previously, such as
4179 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004180 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004181 idx3 = findoption((char_u *)"sxq");
4182 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4183 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004184 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004185 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4186 }
4187
Bram Moolenaara64ba222012-02-12 23:23:31 +01004188 idx3 = findoption((char_u *)"shcf");
4189 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4190 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004191 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004192 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4193 }
4194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195#endif
4196
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004197 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004198 {
4199 int idx_ffs = findoption((char_u *)"ffs");
4200
4201 /* Apply the first entry of 'fileformats' to the initial buffer. */
4202 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4203 set_fileformat(default_fileformat(), OPT_LOCAL);
4204 }
4205
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206#ifdef FEAT_TITLE
4207 set_title_defaults();
4208#endif
4209}
4210
4211#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4212/*
4213 * When 'helplang' is still at its default value, set it to "lang".
4214 * Only the first two characters of "lang" are used.
4215 */
4216 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004217set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218{
4219 int idx;
4220
4221 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4222 return;
4223 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004224 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 {
4226 if (options[idx].flags & P_ALLOCED)
4227 free_string_option(p_hlg);
4228 p_hlg = vim_strsave(lang);
4229 if (p_hlg == NULL)
4230 p_hlg = empty_option;
4231 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004232 {
4233 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4234 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4235 {
4236 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4237 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004240 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 options[idx].flags |= P_ALLOCED;
4242 }
4243}
4244#endif
4245
4246#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004247static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248
4249 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004250gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251{
4252 if (gui_get_lightness(gui.back_pixel) < 127)
4253 return (char_u *)"dark";
4254 return (char_u *)"light";
4255}
4256
4257/*
4258 * Option initializations that can only be done after opening the GUI window.
4259 */
4260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004261init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262{
4263 /* Set the 'background' option according to the lightness of the
4264 * background color, unless the user has set it already. */
4265 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4266 {
4267 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4268 highlight_changed();
4269 }
4270}
4271#endif
4272
4273#ifdef FEAT_TITLE
4274/*
4275 * 'title' and 'icon' only default to true if they have not been set or reset
4276 * in .vimrc and we can read the old value.
4277 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4278 * they can be reset. This reduces startup time when using X on a remote
4279 * machine.
4280 */
4281 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004282set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004283{
4284 int idx1;
4285 long val;
4286
4287 /*
4288 * If GUI is (going to be) used, we can always set the window title and
4289 * icon name. Saves a bit of time, because the X11 display server does
4290 * not need to be contacted.
4291 */
4292 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004293 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004294 {
4295#ifdef FEAT_GUI
4296 if (gui.starting || gui.in_use)
4297 val = TRUE;
4298 else
4299#endif
4300 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004301 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302 p_title = val;
4303 }
4304 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004305 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 {
4307#ifdef FEAT_GUI
4308 if (gui.starting || gui.in_use)
4309 val = TRUE;
4310 else
4311#endif
4312 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004313 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 p_icon = val;
4315 }
4316}
4317#endif
4318
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004319#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004320 static void
4321trigger_optionsset_string(
4322 int opt_idx,
4323 int opt_flags,
4324 char_u *oldval,
4325 char_u *newval)
4326{
4327 if (oldval != NULL && newval != NULL)
4328 {
4329 char_u buf_type[7];
4330
4331 sprintf((char *)buf_type, "%s",
4332 (opt_flags & OPT_LOCAL) ? "local" : "global");
4333 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4334 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4335 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4336 apply_autocmds(EVENT_OPTIONSET,
4337 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4338 reset_v_option_vars();
4339 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004340}
4341#endif
4342
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343/*
4344 * Parse 'arg' for option settings.
4345 *
4346 * 'arg' may be IObuff, but only when no errors can be present and option
4347 * does not need to be expanded with option_expand().
4348 * "opt_flags":
4349 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004350 * OPT_GLOBAL for ":setglobal"
4351 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004353 * OPT_WINONLY to only set window-local options
4354 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 *
4356 * returns FAIL if an error is detected, OK otherwise
4357 */
4358 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004359do_set(
4360 char_u *arg, /* option string (may be written to!) */
4361 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362{
4363 int opt_idx;
4364 char_u *errmsg;
4365 char_u errbuf[80];
4366 char_u *startarg;
4367 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4368 int nextchar; /* next non-white char after option name */
4369 int afterchar; /* character just after option name */
4370 int len;
4371 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004372 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 int key;
4374 long_u flags; /* flags for current option */
4375 char_u *varp = NULL; /* pointer to variable for current option */
4376 int did_show = FALSE; /* already showed one value */
4377 int adding; /* "opt+=arg" */
4378 int prepending; /* "opt^=arg" */
4379 int removing; /* "opt-=arg" */
4380 int cp_val = 0;
4381 char_u key_name[2];
4382
4383 if (*arg == NUL)
4384 {
4385 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004386 did_show = TRUE;
4387 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 }
4389
4390 while (*arg != NUL) /* loop to process all options */
4391 {
4392 errmsg = NULL;
4393 startarg = arg; /* remember for error message */
4394
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004395 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4396 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 {
4398 /*
4399 * ":set all" show all options.
4400 * ":set all&" set all options to their default value.
4401 */
4402 arg += 3;
4403 if (*arg == '&')
4404 {
4405 ++arg;
4406 /* Only for :set command set global value of local options. */
4407 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004408 didset_options();
4409 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004410 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 }
4412 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004413 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004415 did_show = TRUE;
4416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004418 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 {
4420 showoptions(2, opt_flags);
4421 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004422 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 arg += 7;
4424 }
4425 else
4426 {
4427 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004428 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 {
4430 prefix = 0;
4431 arg += 2;
4432 }
4433 else if (STRNCMP(arg, "inv", 3) == 0)
4434 {
4435 prefix = 2;
4436 arg += 3;
4437 }
4438
4439 /* find end of name */
4440 key = 0;
4441 if (*arg == '<')
4442 {
4443 nextchar = 0;
4444 opt_idx = -1;
4445 /* look out for <t_>;> */
4446 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4447 len = 5;
4448 else
4449 {
4450 len = 1;
4451 while (arg[len] != NUL && arg[len] != '>')
4452 ++len;
4453 }
4454 if (arg[len] != '>')
4455 {
4456 errmsg = e_invarg;
4457 goto skip;
4458 }
4459 arg[len] = NUL; /* put NUL after name */
4460 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4461 opt_idx = findoption(arg + 1);
4462 arg[len++] = '>'; /* restore '>' */
4463 if (opt_idx == -1)
4464 key = find_key_option(arg + 1);
4465 }
4466 else
4467 {
4468 len = 0;
4469 /*
4470 * The two characters after "t_" may not be alphanumeric.
4471 */
4472 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4473 len = 4;
4474 else
4475 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4476 ++len;
4477 nextchar = arg[len];
4478 arg[len] = NUL; /* put NUL after name */
4479 opt_idx = findoption(arg);
4480 arg[len] = nextchar; /* restore nextchar */
4481 if (opt_idx == -1)
4482 key = find_key_option(arg);
4483 }
4484
4485 /* remember character after option name */
4486 afterchar = arg[len];
4487
4488 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004489 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004490 ++len;
4491
4492 adding = FALSE;
4493 prepending = FALSE;
4494 removing = FALSE;
4495 if (arg[len] != NUL && arg[len + 1] == '=')
4496 {
4497 if (arg[len] == '+')
4498 {
4499 adding = TRUE; /* "+=" */
4500 ++len;
4501 }
4502 else if (arg[len] == '^')
4503 {
4504 prepending = TRUE; /* "^=" */
4505 ++len;
4506 }
4507 else if (arg[len] == '-')
4508 {
4509 removing = TRUE; /* "-=" */
4510 ++len;
4511 }
4512 }
4513 nextchar = arg[len];
4514
4515 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4516 {
4517 errmsg = (char_u *)N_("E518: Unknown option");
4518 goto skip;
4519 }
4520
4521 if (opt_idx >= 0)
4522 {
4523 if (options[opt_idx].var == NULL) /* hidden option: skip */
4524 {
4525 /* Only give an error message when requesting the value of
4526 * a hidden option, ignore setting it. */
4527 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4528 && (!(options[opt_idx].flags & P_BOOL)
4529 || nextchar == '?'))
4530 errmsg = (char_u *)N_("E519: Option not supported");
4531 goto skip;
4532 }
4533
4534 flags = options[opt_idx].flags;
4535 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4536 }
4537 else
4538 {
4539 flags = P_STRING;
4540 if (key < 0)
4541 {
4542 key_name[0] = KEY2TERMCAP0(key);
4543 key_name[1] = KEY2TERMCAP1(key);
4544 }
4545 else
4546 {
4547 key_name[0] = KS_KEY;
4548 key_name[1] = (key & 0xff);
4549 }
4550 }
4551
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004552 /* Skip all options that are not window-local (used when showing
4553 * an already loaded buffer in a window). */
4554 if ((opt_flags & OPT_WINONLY)
4555 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4556 goto skip;
4557
Bram Moolenaara3227e22006-03-08 21:32:40 +00004558 /* Skip all options that are window-local (used for :vimgrep). */
4559 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4560 && options[opt_idx].var == VAR_WIN)
4561 goto skip;
4562
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004563 /* Disallow changing some options from modelines. */
4564 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004566 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004567 {
4568 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4569 goto skip;
4570 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004571#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004572 /* In diff mode some options are overruled. This avoids that
4573 * 'foldmethod' becomes "marker" instead of "diff" and that
4574 * "wrap" gets set. */
4575 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004576 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004577 && (
4578#ifdef FEAT_FOLDING
4579 options[opt_idx].indir == PV_FDM ||
4580#endif
4581 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004582 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 }
4585
4586#ifdef HAVE_SANDBOX
4587 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004588 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 {
4590 errmsg = (char_u *)_(e_sandbox);
4591 goto skip;
4592 }
4593#endif
4594
4595 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4596 {
4597 arg += len;
4598 cp_val = p_cp;
4599 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4600 {
4601 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4602 {
4603 cp_val = FALSE;
4604 arg += 3;
4605 }
4606 else /* "opt&vi": set to Vi default */
4607 {
4608 cp_val = TRUE;
4609 arg += 2;
4610 }
4611 }
4612 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004613 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 {
4615 errmsg = e_trailing;
4616 goto skip;
4617 }
4618 }
4619
4620 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004621 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4622 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 */
4624 if (nextchar == '?'
4625 || (prefix == 1
4626 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4627 && !(flags & P_BOOL)))
4628 {
4629 /*
4630 * print value
4631 */
4632 if (did_show)
4633 msg_putchar('\n'); /* cursor below last one */
4634 else
4635 {
4636 gotocmdline(TRUE); /* cursor at status line */
4637 did_show = TRUE; /* remember that we did a line */
4638 }
4639 if (opt_idx >= 0)
4640 {
4641 showoneopt(&options[opt_idx], opt_flags);
4642#ifdef FEAT_EVAL
4643 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004644 {
4645 /* Mention where the option was last set. */
4646 if (varp == options[opt_idx].var)
4647 last_set_msg(options[opt_idx].scriptID);
4648 else if ((int)options[opt_idx].indir & PV_WIN)
4649 last_set_msg(curwin->w_p_scriptID[
4650 (int)options[opt_idx].indir & PV_MASK]);
4651 else if ((int)options[opt_idx].indir & PV_BUF)
4652 last_set_msg(curbuf->b_p_scriptID[
4653 (int)options[opt_idx].indir & PV_MASK]);
4654 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004655#endif
4656 }
4657 else
4658 {
4659 char_u *p;
4660
4661 p = find_termcode(key_name);
4662 if (p == NULL)
4663 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004664 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004665 goto skip;
4666 }
4667 else
4668 (void)show_one_termcode(key_name, p, TRUE);
4669 }
4670 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004671 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672 errmsg = e_trailing;
4673 }
4674 else
4675 {
4676 if (flags & P_BOOL) /* boolean */
4677 {
4678 if (nextchar == '=' || nextchar == ':')
4679 {
4680 errmsg = e_invarg;
4681 goto skip;
4682 }
4683
4684 /*
4685 * ":set opt!": invert
4686 * ":set opt&": reset to default value
4687 * ":set opt<": reset to global value
4688 */
4689 if (nextchar == '!')
4690 value = *(int *)(varp) ^ 1;
4691 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004692 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004693 ((flags & P_VI_DEF) || cp_val)
4694 ? VI_DEFAULT : VIM_DEFAULT];
4695 else if (nextchar == '<')
4696 {
4697 /* For 'autoread' -1 means to use global value. */
4698 if ((int *)varp == &curbuf->b_p_ar
4699 && opt_flags == OPT_LOCAL)
4700 value = -1;
4701 else
4702 value = *(int *)get_varp_scope(&(options[opt_idx]),
4703 OPT_GLOBAL);
4704 }
4705 else
4706 {
4707 /*
4708 * ":set invopt": invert
4709 * ":set opt" or ":set noopt": set or reset
4710 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004711 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 {
4713 errmsg = e_trailing;
4714 goto skip;
4715 }
4716 if (prefix == 2) /* inv */
4717 value = *(int *)(varp) ^ 1;
4718 else
4719 value = prefix;
4720 }
4721
4722 errmsg = set_bool_option(opt_idx, varp, (int)value,
4723 opt_flags);
4724 }
4725 else /* numeric or string */
4726 {
4727 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4728 || prefix != 1)
4729 {
4730 errmsg = e_invarg;
4731 goto skip;
4732 }
4733
4734 if (flags & P_NUM) /* numeric */
4735 {
4736 /*
4737 * Different ways to set a number option:
4738 * & set to default value
4739 * < set to global value
4740 * <xx> accept special key codes for 'wildchar'
4741 * c accept any non-digit for 'wildchar'
4742 * [-]0-9 set number
4743 * other error
4744 */
4745 ++arg;
4746 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004747 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 ((flags & P_VI_DEF) || cp_val)
4749 ? VI_DEFAULT : VIM_DEFAULT];
4750 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004751 {
4752 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4753 * use the global value. */
4754 if ((long *)varp == &curbuf->b_p_ul
4755 && opt_flags == OPT_LOCAL)
4756 value = NO_LOCAL_UNDOLEVEL;
4757 else
4758 value = *(long *)get_varp_scope(
4759 &(options[opt_idx]), OPT_GLOBAL);
4760 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 else if (((long *)varp == &p_wc
4762 || (long *)varp == &p_wcm)
4763 && (*arg == '<'
4764 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004765 || (*arg != NUL
4766 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 && !VIM_ISDIGIT(*arg))))
4768 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004769 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 if (value == 0 && (long *)varp != &p_wcm)
4771 {
4772 errmsg = e_invarg;
4773 goto skip;
4774 }
4775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4777 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004778 /* Allow negative (for 'undolevels'), octal and
4779 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004780 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4781 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004782 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004783 {
4784 errmsg = e_invarg;
4785 goto skip;
4786 }
4787 }
4788 else
4789 {
4790 errmsg = (char_u *)N_("E521: Number required after =");
4791 goto skip;
4792 }
4793
4794 if (adding)
4795 value = *(long *)varp + value;
4796 if (prepending)
4797 value = *(long *)varp * value;
4798 if (removing)
4799 value = *(long *)varp - value;
4800 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004801 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 }
4803 else if (opt_idx >= 0) /* string */
4804 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004805 char_u *save_arg = NULL;
4806 char_u *s = NULL;
4807 char_u *oldval = NULL; /* previous value if *varp */
4808 char_u *newval;
4809 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004810#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004811 char_u *saved_origval = NULL;
4812 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004813#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004814 unsigned newlen;
4815 int comma;
4816 int bs;
4817 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004818 was allocated */
4819
4820 /* When using ":set opt=val" for a global option
4821 * with a local value the local value will be
4822 * reset, use the global value here. */
4823 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004824 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004825 varp = options[opt_idx].var;
4826
4827 /* The old value is kept until we are sure that the
4828 * new value is valid. */
4829 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004830
4831 /* When setting the local value of a global
4832 * option, the old value may be the global value. */
4833 if (((int)options[opt_idx].indir & PV_BOTH)
4834 && (opt_flags & OPT_LOCAL))
4835 origval = *(char_u **)get_varp(
4836 &options[opt_idx]);
4837 else
4838 origval = oldval;
4839
Bram Moolenaar071d4272004-06-13 20:20:40 +00004840 if (nextchar == '&') /* set to default val */
4841 {
4842 newval = options[opt_idx].def_val[
4843 ((flags & P_VI_DEF) || cp_val)
4844 ? VI_DEFAULT : VIM_DEFAULT];
4845 if ((char_u **)varp == &p_bg)
4846 {
4847 /* guess the value of 'background' */
4848#ifdef FEAT_GUI
4849 if (gui.in_use)
4850 newval = gui_bg_default();
4851 else
4852#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004853 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 }
4855
4856 /* expand environment variables and ~ (since the
4857 * default value was already expanded, only
4858 * required when an environment variable was set
4859 * later */
4860 if (newval == NULL)
4861 newval = empty_option;
4862 else
4863 {
4864 s = option_expand(opt_idx, newval);
4865 if (s == NULL)
4866 s = newval;
4867 newval = vim_strsave(s);
4868 }
4869 new_value_alloced = TRUE;
4870 }
4871 else if (nextchar == '<') /* set to global val */
4872 {
4873 newval = vim_strsave(*(char_u **)get_varp_scope(
4874 &(options[opt_idx]), OPT_GLOBAL));
4875 new_value_alloced = TRUE;
4876 }
4877 else
4878 {
4879 ++arg; /* jump to after the '=' or ':' */
4880
4881 /*
4882 * Set 'keywordprg' to ":help" if an empty
4883 * value was passed to :set by the user.
4884 * Misuse errbuf[] for the resulting string.
4885 */
4886 if (varp == (char_u *)&p_kp
4887 && (*arg == NUL || *arg == ' '))
4888 {
4889 STRCPY(errbuf, ":help");
4890 save_arg = arg;
4891 arg = errbuf;
4892 }
4893 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004894 * Convert 'backspace' number to string, for
4895 * adding, prepending and removing string.
4896 */
4897 else if (varp == (char_u *)&p_bs
4898 && VIM_ISDIGIT(**(char_u **)varp))
4899 {
4900 i = getdigits((char_u **)varp);
4901 switch (i)
4902 {
4903 case 0:
4904 *(char_u **)varp = empty_option;
4905 break;
4906 case 1:
4907 *(char_u **)varp = vim_strsave(
4908 (char_u *)"indent,eol");
4909 break;
4910 case 2:
4911 *(char_u **)varp = vim_strsave(
4912 (char_u *)"indent,eol,start");
4913 break;
4914 }
4915 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004916 if (origval == oldval)
4917 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004918 oldval = *(char_u **)varp;
4919 }
4920 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 * Convert 'whichwrap' number to string, for
4922 * backwards compatibility with Vim 3.0.
4923 * Misuse errbuf[] for the resulting string.
4924 */
4925 else if (varp == (char_u *)&p_ww
4926 && VIM_ISDIGIT(*arg))
4927 {
4928 *errbuf = NUL;
4929 i = getdigits(&arg);
4930 if (i & 1)
4931 STRCAT(errbuf, "b,");
4932 if (i & 2)
4933 STRCAT(errbuf, "s,");
4934 if (i & 4)
4935 STRCAT(errbuf, "h,l,");
4936 if (i & 8)
4937 STRCAT(errbuf, "<,>,");
4938 if (i & 16)
4939 STRCAT(errbuf, "[,],");
4940 if (*errbuf != NUL) /* remove trailing , */
4941 errbuf[STRLEN(errbuf) - 1] = NUL;
4942 save_arg = arg;
4943 arg = errbuf;
4944 }
4945 /*
4946 * Remove '>' before 'dir' and 'bdir', for
4947 * backwards compatibility with version 3.0
4948 */
4949 else if ( *arg == '>'
4950 && (varp == (char_u *)&p_dir
4951 || varp == (char_u *)&p_bdir))
4952 {
4953 ++arg;
4954 }
4955
Bram Moolenaar071d4272004-06-13 20:20:40 +00004956 /*
4957 * Copy the new string into allocated memory.
4958 * Can't use set_string_option_direct(), because
4959 * we need to remove the backslashes.
4960 */
4961 /* get a bit too much */
4962 newlen = (unsigned)STRLEN(arg) + 1;
4963 if (adding || prepending || removing)
4964 newlen += (unsigned)STRLEN(origval) + 1;
4965 newval = alloc(newlen);
4966 if (newval == NULL) /* out of mem, don't change */
4967 break;
4968 s = newval;
4969
4970 /*
4971 * Copy the string, skip over escaped chars.
4972 * For MS-DOS and WIN32 backslashes before normal
4973 * file name characters are not removed, and keep
4974 * backslash at start, for "\\machine\path", but
4975 * do remove it for "\\\\machine\\path".
4976 * The reverse is found in ExpandOldSetting().
4977 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004978 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004979 {
4980 if (*arg == '\\' && arg[1] != NUL
4981#ifdef BACKSLASH_IN_FILENAME
4982 && !((flags & P_EXPAND)
4983 && vim_isfilec(arg[1])
4984 && (arg[1] != '\\'
4985 || (s == newval
4986 && arg[2] != '\\')))
4987#endif
4988 )
4989 ++arg; /* remove backslash */
4990#ifdef FEAT_MBYTE
4991 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004992 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 {
4994 /* copy multibyte char */
4995 mch_memmove(s, arg, (size_t)i);
4996 arg += i;
4997 s += i;
4998 }
4999 else
5000#endif
5001 *s++ = *arg++;
5002 }
5003 *s = NUL;
5004
5005 /*
5006 * Expand environment variables and ~.
5007 * Don't do it when adding without inserting a
5008 * comma.
5009 */
5010 if (!(adding || prepending || removing)
5011 || (flags & P_COMMA))
5012 {
5013 s = option_expand(opt_idx, newval);
5014 if (s != NULL)
5015 {
5016 vim_free(newval);
5017 newlen = (unsigned)STRLEN(s) + 1;
5018 if (adding || prepending || removing)
5019 newlen += (unsigned)STRLEN(origval) + 1;
5020 newval = alloc(newlen);
5021 if (newval == NULL)
5022 break;
5023 STRCPY(newval, s);
5024 }
5025 }
5026
5027 /* locate newval[] in origval[] when removing it
5028 * and when adding to avoid duplicates */
5029 i = 0; /* init for GCC */
5030 if (removing || (flags & P_NODUP))
5031 {
5032 i = (int)STRLEN(newval);
5033 bs = 0;
5034 for (s = origval; *s; ++s)
5035 {
5036 if ((!(flags & P_COMMA)
5037 || s == origval
5038 || (s[-1] == ',' && !(bs & 1)))
5039 && STRNCMP(s, newval, i) == 0
5040 && (!(flags & P_COMMA)
5041 || s[i] == ','
5042 || s[i] == NUL))
5043 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005044 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005045 * even number of backslashes or a single
5046 * backslash preceded by a comma before it
5047 * is recognized as a separator */
5048 if ((s > origval + 1
5049 && s[-1] == '\\'
5050 && s[-2] != ',')
5051 || (s == origval + 1
5052 && s[-1] == '\\'))
5053
Bram Moolenaar071d4272004-06-13 20:20:40 +00005054 ++bs;
5055 else
5056 bs = 0;
5057 }
5058
5059 /* do not add if already there */
5060 if ((adding || prepending) && *s)
5061 {
5062 prepending = FALSE;
5063 adding = FALSE;
5064 STRCPY(newval, origval);
5065 }
5066 }
5067
5068 /* concatenate the two strings; add a ',' if
5069 * needed */
5070 if (adding || prepending)
5071 {
5072 comma = ((flags & P_COMMA) && *origval != NUL
5073 && *newval != NUL);
5074 if (adding)
5075 {
5076 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005077 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005078 if (comma && i > 1
5079 && (flags & P_ONECOMMA) == P_ONECOMMA
5080 && origval[i - 1] == ','
5081 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005082 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005083 mch_memmove(newval + i + comma, newval,
5084 STRLEN(newval) + 1);
5085 mch_memmove(newval, origval, (size_t)i);
5086 }
5087 else
5088 {
5089 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005090 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091 }
5092 if (comma)
5093 newval[i] = ',';
5094 }
5095
5096 /* Remove newval[] from origval[]. (Note: "i" has
5097 * been set above and is used here). */
5098 if (removing)
5099 {
5100 STRCPY(newval, origval);
5101 if (*s)
5102 {
5103 /* may need to remove a comma */
5104 if (flags & P_COMMA)
5105 {
5106 if (s == origval)
5107 {
5108 /* include comma after string */
5109 if (s[i] == ',')
5110 ++i;
5111 }
5112 else
5113 {
5114 /* include comma before string */
5115 --s;
5116 ++i;
5117 }
5118 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005119 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 }
5121 }
5122
5123 if (flags & P_FLAGLIST)
5124 {
5125 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005126 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005127 {
5128 /* if options have P_FLAGLIST and
5129 * P_ONECOMMA such as 'whichwrap' */
5130 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005132 if (*s != ',' && *(s + 1) == ','
5133 && vim_strchr(s + 2, *s) != NULL)
5134 {
5135 /* Remove the duplicated value and
5136 * the next comma. */
5137 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005138 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005140 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005141 else
5142 {
5143 if ((!(flags & P_COMMA) || *s != ',')
5144 && vim_strchr(s + 1, *s) != NULL)
5145 {
5146 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005147 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005148 }
5149 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005150 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 }
5153
5154 if (save_arg != NULL) /* number for 'whichwrap' */
5155 arg = save_arg;
5156 new_value_alloced = TRUE;
5157 }
5158
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005159 /*
5160 * Set the new value.
5161 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162 *(char_u **)(varp) = newval;
5163
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005164#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005165 if (!starting
5166# ifdef FEAT_CRYPT
5167 && options[opt_idx].indir != PV_KEY
5168# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005169 && origval != NULL && newval != NULL)
5170 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005171 /* origval may be freed by
5172 * did_set_string_option(), make a copy. */
5173 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005174 /* newval (and varp) may become invalid if the
5175 * buffer is closed by autocommands. */
5176 saved_newval = vim_strsave(newval);
5177 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005178#endif
5179
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005181 * ":set" on local options. Note: when setting 'syntax'
5182 * or 'filetype' autocommands may be triggered that can
5183 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5185 new_value_alloced, oldval, errbuf, opt_flags);
5186
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005187#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005188 if (errmsg == NULL)
5189 trigger_optionsset_string(opt_idx, opt_flags,
5190 saved_origval, saved_newval);
5191 vim_free(saved_origval);
5192 vim_free(saved_newval);
5193#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005194 /* If error detected, print the error message. */
5195 if (errmsg != NULL)
5196 goto skip;
5197 }
5198 else /* key code option */
5199 {
5200 char_u *p;
5201
5202 if (nextchar == '&')
5203 {
5204 if (add_termcap_entry(key_name, TRUE) == FAIL)
5205 errmsg = (char_u *)N_("E522: Not found in termcap");
5206 }
5207 else
5208 {
5209 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005210 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 if (*p == '\\' && p[1] != NUL)
5212 ++p;
5213 nextchar = *p;
5214 *p = NUL;
5215 add_termcode(key_name, arg, FALSE);
5216 *p = nextchar;
5217 }
5218 if (full_screen)
5219 ttest(FALSE);
5220 redraw_all_later(CLEAR);
5221 }
5222 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005223
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005225 did_set_option(opt_idx, opt_flags,
5226 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005227 }
5228
5229skip:
5230 /*
5231 * Advance to next argument.
5232 * - skip until a blank found, taking care of backslashes
5233 * - skip blanks
5234 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5235 */
5236 for (i = 0; i < 2 ; ++i)
5237 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005238 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 if (*arg++ == '\\' && *arg != NUL)
5240 ++arg;
5241 arg = skipwhite(arg);
5242 if (*arg != '=')
5243 break;
5244 }
5245 }
5246
5247 if (errmsg != NULL)
5248 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005249 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005250 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 if (i + (arg - startarg) < IOSIZE)
5252 {
5253 /* append the argument with the error */
5254 STRCAT(IObuff, ": ");
5255 mch_memmove(IObuff + i, startarg, (arg - startarg));
5256 IObuff[i + (arg - startarg)] = NUL;
5257 }
5258 /* make sure all characters are printable */
5259 trans_characters(IObuff, IOSIZE);
5260
5261 ++no_wait_return; /* wait_return done later */
5262 emsg(IObuff); /* show error highlighted */
5263 --no_wait_return;
5264
5265 return FAIL;
5266 }
5267
5268 arg = skipwhite(arg);
5269 }
5270
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005271theend:
5272 if (silent_mode && did_show)
5273 {
5274 /* After displaying option values in silent mode. */
5275 silent_mode = FALSE;
5276 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5277 msg_putchar('\n');
5278 cursor_on(); /* msg_start() switches it off */
5279 out_flush();
5280 silent_mode = TRUE;
5281 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5282 }
5283
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284 return OK;
5285}
5286
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005287/*
5288 * Call this when an option has been given a new value through a user command.
5289 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5290 */
5291 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005292did_set_option(
5293 int opt_idx,
5294 int opt_flags, /* possibly with OPT_MODELINE */
5295 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005297 long_u *p;
5298
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299 options[opt_idx].flags |= P_WAS_SET;
5300
5301 /* When an option is set in the sandbox, from a modeline or in secure mode
5302 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005303 * flag. */
5304 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005305 if (secure
5306#ifdef HAVE_SANDBOX
5307 || sandbox != 0
5308#endif
5309 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005310 *p = *p | P_INSECURE;
5311 else if (new_value)
5312 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005313}
5314
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005316illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317{
5318 if (errbuf == NULL)
5319 return (char_u *)"";
5320 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005321 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 return errbuf;
5323}
5324
5325/*
5326 * Convert a key name or string into a key value.
5327 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005328 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005330 int
5331string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332{
5333 if (*arg == '<')
5334 return find_key_option(arg + 1);
5335 if (*arg == '^')
5336 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005337 if (multi_byte)
5338 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339 return *arg;
5340}
5341
5342#ifdef FEAT_CMDWIN
5343/*
5344 * Check value of 'cedit' and set cedit_key.
5345 * Returns NULL if value is OK, error message otherwise.
5346 */
5347 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005348check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349{
5350 int n;
5351
5352 if (*p_cedit == NUL)
5353 cedit_key = -1;
5354 else
5355 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005356 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 if (vim_isprintc(n))
5358 return e_invarg;
5359 cedit_key = n;
5360 }
5361 return NULL;
5362}
5363#endif
5364
5365#ifdef FEAT_TITLE
5366/*
5367 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5368 * maketitle() to create and display it.
5369 * When switching the title or icon off, call mch_restore_title() to get
5370 * the old value back.
5371 */
5372 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005373did_set_title(
5374 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375{
5376 if (starting != NO_SCREEN
5377#ifdef FEAT_GUI
5378 && !gui.starting
5379#endif
5380 )
5381 {
5382 maketitle();
5383 if (icon)
5384 {
5385 if (!p_icon)
5386 mch_restore_title(2);
5387 }
5388 else
5389 {
5390 if (!p_title)
5391 mch_restore_title(1);
5392 }
5393 }
5394}
5395#endif
5396
5397/*
5398 * set_options_bin - called when 'bin' changes value.
5399 */
5400 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005401set_options_bin(
5402 int oldval,
5403 int newval,
5404 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005405{
5406 /*
5407 * The option values that are changed when 'bin' changes are
5408 * copied when 'bin is set and restored when 'bin' is reset.
5409 */
5410 if (newval)
5411 {
5412 if (!oldval) /* switched on */
5413 {
5414 if (!(opt_flags & OPT_GLOBAL))
5415 {
5416 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5417 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5418 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5419 curbuf->b_p_et_nobin = curbuf->b_p_et;
5420 }
5421 if (!(opt_flags & OPT_LOCAL))
5422 {
5423 p_tw_nobin = p_tw;
5424 p_wm_nobin = p_wm;
5425 p_ml_nobin = p_ml;
5426 p_et_nobin = p_et;
5427 }
5428 }
5429
5430 if (!(opt_flags & OPT_GLOBAL))
5431 {
5432 curbuf->b_p_tw = 0; /* no automatic line wrap */
5433 curbuf->b_p_wm = 0; /* no automatic line wrap */
5434 curbuf->b_p_ml = 0; /* no modelines */
5435 curbuf->b_p_et = 0; /* no expandtab */
5436 }
5437 if (!(opt_flags & OPT_LOCAL))
5438 {
5439 p_tw = 0;
5440 p_wm = 0;
5441 p_ml = FALSE;
5442 p_et = FALSE;
5443 p_bin = TRUE; /* needed when called for the "-b" argument */
5444 }
5445 }
5446 else if (oldval) /* switched off */
5447 {
5448 if (!(opt_flags & OPT_GLOBAL))
5449 {
5450 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5451 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5452 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5453 curbuf->b_p_et = curbuf->b_p_et_nobin;
5454 }
5455 if (!(opt_flags & OPT_LOCAL))
5456 {
5457 p_tw = p_tw_nobin;
5458 p_wm = p_wm_nobin;
5459 p_ml = p_ml_nobin;
5460 p_et = p_et_nobin;
5461 }
5462 }
5463}
5464
5465#ifdef FEAT_VIMINFO
5466/*
5467 * Find the parameter represented by the given character (eg ', :, ", or /),
5468 * and return its associated value in the 'viminfo' string.
5469 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005470 * If the parameter is not specified in the string or there is no following
5471 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 */
5473 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005474get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475{
5476 char_u *p;
5477
5478 p = find_viminfo_parameter(type);
5479 if (p != NULL && VIM_ISDIGIT(*p))
5480 return atoi((char *)p);
5481 return -1;
5482}
5483
5484/*
5485 * Find the parameter represented by the given character (eg ''', ':', '"', or
5486 * '/') in the 'viminfo' option and return a pointer to the string after it.
5487 * Return NULL if the parameter is not specified in the string.
5488 */
5489 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005490find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491{
5492 char_u *p;
5493
5494 for (p = p_viminfo; *p; ++p)
5495 {
5496 if (*p == type)
5497 return p + 1;
5498 if (*p == 'n') /* 'n' is always the last one */
5499 break;
5500 p = vim_strchr(p, ','); /* skip until next ',' */
5501 if (p == NULL) /* hit the end without finding parameter */
5502 break;
5503 }
5504 return NULL;
5505}
5506#endif
5507
5508/*
5509 * Expand environment variables for some string options.
5510 * These string options cannot be indirect!
5511 * If "val" is NULL expand the current value of the option.
5512 * Return pointer to NameBuff, or NULL when not expanded.
5513 */
5514 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005515option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516{
5517 /* if option doesn't need expansion nothing to do */
5518 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5519 return NULL;
5520
5521 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5522 * expand_env() would truncate the string. */
5523 if (val != NULL && STRLEN(val) > MAXPATHL)
5524 return NULL;
5525
5526 if (val == NULL)
5527 val = *(char_u **)options[opt_idx].var;
5528
5529 /*
5530 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5531 * Escape spaces when expanding 'tags', they are used to separate file
5532 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005533 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534 */
5535 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005536 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005537#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005538 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5539#endif
5540 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5542 return NULL;
5543
5544 return NameBuff;
5545}
5546
5547/*
5548 * After setting various option values: recompute variables that depend on
5549 * option values.
5550 */
5551 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005552didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553{
5554 /* initialize the table for 'iskeyword' et.al. */
5555 (void)init_chartab();
5556
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005557#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005561 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562#ifdef FEAT_SESSION
5563 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5564 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5565#endif
5566#ifdef FEAT_FOLDING
5567 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5568#endif
5569 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005570 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571#ifdef FEAT_VIRTUALEDIT
5572 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5573#endif
5574#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5575 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5576#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005577#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005578 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005579 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005580 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005581 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5584 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5585#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005586#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5588#endif
5589#ifdef FEAT_CMDWIN
5590 /* set cedit_key */
5591 (void)check_cedit();
5592#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005593#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005594 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005595#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005596#ifdef FEAT_LINEBREAK
5597 /* initialize the table for 'breakat'. */
5598 fill_breakat_flags();
5599#endif
5600
5601}
5602
5603/*
5604 * More side effects of setting options.
5605 */
5606 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005607didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005608{
5609 /* Initialize the highlight_attr[] table. */
5610 (void)highlight_changed();
5611
5612 /* Parse default for 'wildmode' */
5613 check_opt_wim();
5614
5615 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005616 /* Parse default for 'fillchars'. */
5617 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005618
5619#ifdef FEAT_CLIPBOARD
5620 /* Parse default for 'clipboard' */
5621 (void)check_clipboard_option();
5622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005623}
5624
5625/*
5626 * Check for string options that are NULL (normally only termcap options).
5627 */
5628 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005629check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630{
5631 int opt_idx;
5632
5633 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5634 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5635 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5636}
5637
5638/*
5639 * Check string options in a buffer for NULL value.
5640 */
5641 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005642check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644 check_string_option(&buf->b_p_bh);
5645 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646#ifdef FEAT_MBYTE
5647 check_string_option(&buf->b_p_fenc);
5648#endif
5649 check_string_option(&buf->b_p_ff);
5650#ifdef FEAT_FIND_ID
5651 check_string_option(&buf->b_p_def);
5652 check_string_option(&buf->b_p_inc);
5653# ifdef FEAT_EVAL
5654 check_string_option(&buf->b_p_inex);
5655# endif
5656#endif
5657#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5658 check_string_option(&buf->b_p_inde);
5659 check_string_option(&buf->b_p_indk);
5660#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005661#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5662 check_string_option(&buf->b_p_bexpr);
5663#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005664#if defined(FEAT_CRYPT)
5665 check_string_option(&buf->b_p_cm);
5666#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005667 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005668#if defined(FEAT_EVAL)
5669 check_string_option(&buf->b_p_fex);
5670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671#ifdef FEAT_CRYPT
5672 check_string_option(&buf->b_p_key);
5673#endif
5674 check_string_option(&buf->b_p_kp);
5675 check_string_option(&buf->b_p_mps);
5676 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005677 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678 check_string_option(&buf->b_p_isk);
5679#ifdef FEAT_COMMENTS
5680 check_string_option(&buf->b_p_com);
5681#endif
5682#ifdef FEAT_FOLDING
5683 check_string_option(&buf->b_p_cms);
5684#endif
5685 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005686#ifdef FEAT_TEXTOBJ
5687 check_string_option(&buf->b_p_qe);
5688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689#ifdef FEAT_SYN_HL
5690 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005691 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005692#endif
5693#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005694 check_string_option(&buf->b_s.b_p_spc);
5695 check_string_option(&buf->b_s.b_p_spf);
5696 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697#endif
5698#ifdef FEAT_SEARCHPATH
5699 check_string_option(&buf->b_p_sua);
5700#endif
5701#ifdef FEAT_CINDENT
5702 check_string_option(&buf->b_p_cink);
5703 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005704 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5708 check_string_option(&buf->b_p_cinw);
5709#endif
5710#ifdef FEAT_INS_EXPAND
5711 check_string_option(&buf->b_p_cpt);
5712#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005713#ifdef FEAT_COMPL_FUNC
5714 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005715 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717#ifdef FEAT_KEYMAP
5718 check_string_option(&buf->b_p_keymap);
5719#endif
5720#ifdef FEAT_QUICKFIX
5721 check_string_option(&buf->b_p_gp);
5722 check_string_option(&buf->b_p_mp);
5723 check_string_option(&buf->b_p_efm);
5724#endif
5725 check_string_option(&buf->b_p_ep);
5726 check_string_option(&buf->b_p_path);
5727 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005728 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729#ifdef FEAT_INS_EXPAND
5730 check_string_option(&buf->b_p_dict);
5731 check_string_option(&buf->b_p_tsr);
5732#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005733#ifdef FEAT_LISP
5734 check_string_option(&buf->b_p_lw);
5735#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005736 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005737#ifdef FEAT_MBYTE
5738 check_string_option(&buf->b_p_menc);
5739#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740}
5741
5742/*
5743 * Free the string allocated for an option.
5744 * Checks for the string being empty_option. This may happen if we're out of
5745 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5746 * check_options().
5747 * Does NOT check for P_ALLOCED flag!
5748 */
5749 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005750free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751{
5752 if (p != empty_option)
5753 vim_free(p);
5754}
5755
5756 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005757clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758{
5759 if (*pp != empty_option)
5760 vim_free(*pp);
5761 *pp = empty_option;
5762}
5763
5764 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005765check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766{
5767 if (*pp == NULL)
5768 *pp = empty_option;
5769}
5770
5771/*
5772 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5773 */
5774 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776{
5777 int opt_idx;
5778
5779 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5780 if (options[opt_idx].var == (char_u *)p)
5781 {
5782 options[opt_idx].flags |= P_ALLOCED;
5783 return;
5784 }
5785 return; /* cannot happen: didn't find it! */
5786}
5787
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005788#if defined(FEAT_EVAL) || defined(PROTO)
5789/*
5790 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5791 * Return FALSE when it wasn't.
5792 * Return -1 for an unknown option.
5793 */
5794 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005795was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005796{
5797 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005798 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005799
5800 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005801 {
5802 flagp = insecure_flag(idx, opt_flags);
5803 return (*flagp & P_INSECURE) != 0;
5804 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005805 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005806 return -1;
5807}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005808
5809/*
5810 * Get a pointer to the flags used for the P_INSECURE flag of option
5811 * "opt_idx". For some local options a local flags field is used.
5812 */
5813 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005814insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005815{
5816 if (opt_flags & OPT_LOCAL)
5817 switch ((int)options[opt_idx].indir)
5818 {
5819#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005820 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821#endif
5822#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005823# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005824 case PV_FDE: return &curwin->w_p_fde_flags;
5825 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005826# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005827# ifdef FEAT_BEVAL
5828 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5829# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005833 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005834# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005835 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005836# endif
5837#endif
5838 }
5839
5840 /* Nothing special, return global flags field. */
5841 return &options[opt_idx].flags;
5842}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005843#endif
5844
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005845#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005846static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005847
5848/*
5849 * Redraw the window title and/or tab page text later.
5850 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005851static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005852{
5853 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005854 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005855}
5856#endif
5857
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858/*
5859 * Set a string option to a new value (without checking the effect).
5860 * The string is copied into allocated memory.
5861 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005862 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005863 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 */
5865 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005866set_string_option_direct(
5867 char_u *name,
5868 int opt_idx,
5869 char_u *val,
5870 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5871 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872{
5873 char_u *s;
5874 char_u **varp;
5875 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005880 idx = findoption(name);
5881 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005882 {
5883 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005884 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 }
5888
Bram Moolenaar89d40322006-08-29 15:30:07 +00005889 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 return;
5891
5892 s = vim_strsave(val);
5893 if (s != NULL)
5894 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 free_string_option(*varp);
5899 *varp = s;
5900
5901 /* For buffer/window local option may also set the global value. */
5902 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906
5907 /* When setting both values of a global option with a local value,
5908 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 {
5911 free_string_option(*varp);
5912 *varp = empty_option;
5913 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005914# ifdef FEAT_EVAL
5915 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005916 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005917 set_sid == 0 ? current_SID : set_sid);
5918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920}
5921
5922/*
5923 * Set global value for string option when it's a local option.
5924 */
5925 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005926set_string_option_global(
5927 int opt_idx, /* option index */
5928 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929{
5930 char_u **p, *s;
5931
5932 /* the global value is always allocated */
5933 if (options[opt_idx].var == VAR_WIN)
5934 p = (char_u **)GLOBAL_WO(varp);
5935 else
5936 p = (char_u **)options[opt_idx].var;
5937 if (options[opt_idx].indir != PV_NONE
5938 && p != varp
5939 && (s = vim_strsave(*varp)) != NULL)
5940 {
5941 free_string_option(*p);
5942 *p = s;
5943 }
5944}
5945
5946/*
5947 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005948 *
5949 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005951 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005952set_string_option(
5953 int opt_idx,
5954 char_u *value,
5955 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956{
5957 char_u *s;
5958 char_u **varp;
5959 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005960#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005961 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005962 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005963#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005964 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965
5966 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005967 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968
5969 s = vim_strsave(value);
5970 if (s != NULL)
5971 {
5972 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5973 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005974 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 ? OPT_GLOBAL : OPT_LOCAL)
5976 : opt_flags);
5977 oldval = *varp;
5978 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005979
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005980#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005981 if (!starting
5982# ifdef FEAT_CRYPT
5983 && options[opt_idx].indir != PV_KEY
5984# endif
5985 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005986 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005987 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005988 saved_newval = vim_strsave(s);
5989 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005990#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005991 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5992 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005993 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005994
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005995#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005996 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005997 if (r == NULL)
5998 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005999 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006000 vim_free(saved_oldval);
6001 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006004 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005}
6006
6007/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006008 * Return TRUE if "val" is a valid 'filetype' name.
6009 * Also used for 'syntax' and 'keymap'.
6010 */
6011 static int
6012valid_filetype(char_u *val)
6013{
6014 char_u *s;
6015
6016 for (s = val; *s != NUL; ++s)
6017 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6018 return FALSE;
6019 return TRUE;
6020}
6021
6022/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 * Handle string options that need some action to perform when changed.
6024 * Returns NULL for success, or an error message for an error.
6025 */
6026 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006027did_set_string_option(
6028 int opt_idx, /* index in options[] table */
6029 char_u **varp, /* pointer to the option variable */
6030 int new_value_alloced, /* new value was allocated */
6031 char_u *oldval, /* previous value of the option */
6032 char_u *errbuf, /* buffer for errors, or NULL */
6033 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034{
6035 char_u *errmsg = NULL;
6036 char_u *s, *p;
6037 int did_chartab = FALSE;
6038 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006039 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006040#ifdef FEAT_GUI
6041 /* set when changing an option that only requires a redraw in the GUI */
6042 int redraw_gui_only = FALSE;
6043#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006044 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006045
6046 /* Get the global option to compare with, otherwise we would have to check
6047 * two values for all local options. */
6048 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6049
6050 /* Disallow changing some options from secure mode */
6051 if ((secure
6052#ifdef HAVE_SANDBOX
6053 || sandbox != 0
6054#endif
6055 ) && (options[opt_idx].flags & P_SECURE))
6056 {
6057 errmsg = e_secure;
6058 }
6059
Bram Moolenaar7554da42016-11-25 22:04:13 +01006060 /* Check for a "normal" directory or file name in some options. Disallow a
6061 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006062 * are often illegal in a file name. Be more permissive if "secure" is off.
6063 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006064 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006065 && vim_strpbrk(*varp, (char_u *)(secure
6066 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006067 || ((options[opt_idx].flags & P_NDNAME)
6068 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006069 {
6070 errmsg = e_invarg;
6071 }
6072
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 /* 'term' */
6074 else if (varp == &T_NAME)
6075 {
6076 if (T_NAME[0] == NUL)
6077 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6078#ifdef FEAT_GUI
6079 if (gui.in_use)
6080 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6081 else if (term_is_gui(T_NAME))
6082 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6083#endif
6084 else if (set_termname(T_NAME) == FAIL)
6085 errmsg = (char_u *)N_("E522: Not found in termcap");
6086 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006087 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 /* Screen colors may have changed. */
6089 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006090
6091 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6092 * P_ALLOCED flag on 'term'. */
6093 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006094 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096 }
6097
6098 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006099 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006101 char_u *bkc = p_bkc;
6102 unsigned int *flags = &bkc_flags;
6103
6104 if (opt_flags & OPT_LOCAL)
6105 {
6106 bkc = curbuf->b_p_bkc;
6107 flags = &curbuf->b_bkc_flags;
6108 }
6109
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006110 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6111 /* make the local value empty: use the global value */
6112 *flags = 0;
6113 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006115 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6116 errmsg = e_invarg;
6117 if ((((int)*flags & BKC_AUTO) != 0)
6118 + (((int)*flags & BKC_YES) != 0)
6119 + (((int)*flags & BKC_NO) != 0) != 1)
6120 {
6121 /* Must have exactly one of "auto", "yes" and "no". */
6122 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6123 errmsg = e_invarg;
6124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 }
6126 }
6127
6128 /* 'backupext' and 'patchmode' */
6129 else if (varp == &p_bex || varp == &p_pm)
6130 {
6131 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6132 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6133 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6134 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006135#ifdef FEAT_LINEBREAK
6136 /* 'breakindentopt' */
6137 else if (varp == &curwin->w_p_briopt)
6138 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006139 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006140 errmsg = e_invarg;
6141 }
6142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143
6144 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006145 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006147 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 */
6149 else if ( varp == &p_isi
6150 || varp == &(curbuf->b_p_isk)
6151 || varp == &p_isp
6152 || varp == &p_isf)
6153 {
6154 if (init_chartab() == FAIL)
6155 {
6156 did_chartab = TRUE; /* need to restore it below */
6157 errmsg = e_invarg; /* error in value */
6158 }
6159 }
6160
6161 /* 'helpfile' */
6162 else if (varp == &p_hf)
6163 {
6164 /* May compute new values for $VIM and $VIMRUNTIME */
6165 if (didset_vim)
6166 {
6167 vim_setenv((char_u *)"VIM", (char_u *)"");
6168 didset_vim = FALSE;
6169 }
6170 if (didset_vimruntime)
6171 {
6172 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6173 didset_vimruntime = FALSE;
6174 }
6175 }
6176
Bram Moolenaar1a384422010-07-14 19:53:30 +02006177#ifdef FEAT_SYN_HL
6178 /* 'colorcolumn' */
6179 else if (varp == &curwin->w_p_cc)
6180 errmsg = check_colorcolumn(curwin);
6181#endif
6182
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183#ifdef FEAT_MULTI_LANG
6184 /* 'helplang' */
6185 else if (varp == &p_hlg)
6186 {
6187 /* Check for "", "ab", "ab,cd", etc. */
6188 for (s = p_hlg; *s != NUL; s += 3)
6189 {
6190 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6191 {
6192 errmsg = e_invarg;
6193 break;
6194 }
6195 if (s[2] == NUL)
6196 break;
6197 }
6198 }
6199#endif
6200
6201 /* 'highlight' */
6202 else if (varp == &p_hl)
6203 {
6204 if (highlight_changed() == FAIL)
6205 errmsg = e_invarg; /* invalid flags */
6206 }
6207
6208 /* 'nrformats' */
6209 else if (gvarp == &p_nf)
6210 {
6211 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6212 errmsg = e_invarg;
6213 }
6214
6215#ifdef FEAT_SESSION
6216 /* 'sessionoptions' */
6217 else if (varp == &p_ssop)
6218 {
6219 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6220 errmsg = e_invarg;
6221 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6222 {
6223 /* Don't allow both "sesdir" and "curdir". */
6224 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6225 errmsg = e_invarg;
6226 }
6227 }
6228 /* 'viewoptions' */
6229 else if (varp == &p_vop)
6230 {
6231 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6232 errmsg = e_invarg;
6233 }
6234#endif
6235
6236 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 else if (varp == &p_sbo)
6238 {
6239 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6240 errmsg = e_invarg;
6241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242
6243 /* 'ambiwidth' */
6244#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006245 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246 {
6247 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6248 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006249 else if (set_chars_option(&p_lcs) != NULL)
6250 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006251 else if (set_chars_option(&p_fcs) != NULL)
6252 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 }
6254#endif
6255
6256 /* 'background' */
6257 else if (varp == &p_bg)
6258 {
6259 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6260 {
6261#ifdef FEAT_EVAL
6262 int dark = (*p_bg == 'd');
6263#endif
6264
6265 init_highlight(FALSE, FALSE);
6266
6267#ifdef FEAT_EVAL
6268 if (dark != (*p_bg == 'd')
6269 && get_var_value((char_u *)"g:colors_name") != NULL)
6270 {
6271 /* The color scheme must have set 'background' back to another
6272 * value, that's not what we want here. Disable the color
6273 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006274 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275 free_string_option(p_bg);
6276 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6277 check_string_option(&p_bg);
6278 init_highlight(FALSE, FALSE);
6279 }
6280#endif
6281 }
6282 else
6283 errmsg = e_invarg;
6284 }
6285
6286 /* 'wildmode' */
6287 else if (varp == &p_wim)
6288 {
6289 if (check_opt_wim() == FAIL)
6290 errmsg = e_invarg;
6291 }
6292
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006293#ifdef FEAT_CMDL_COMPL
6294 /* 'wildoptions' */
6295 else if (varp == &p_wop)
6296 {
6297 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6298 errmsg = e_invarg;
6299 }
6300#endif
6301
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302#ifdef FEAT_WAK
6303 /* 'winaltkeys' */
6304 else if (varp == &p_wak)
6305 {
6306 if (*p_wak == NUL
6307 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6308 errmsg = e_invarg;
6309# ifdef FEAT_MENU
6310# ifdef FEAT_GUI_MOTIF
6311 else if (gui.in_use)
6312 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6313# else
6314# ifdef FEAT_GUI_GTK
6315 else if (gui.in_use)
6316 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6317# endif
6318# endif
6319# endif
6320 }
6321#endif
6322
Bram Moolenaar071d4272004-06-13 20:20:40 +00006323 /* 'eventignore' */
6324 else if (varp == &p_ei)
6325 {
6326 if (check_ei() == FAIL)
6327 errmsg = e_invarg;
6328 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329
6330#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006331 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6332 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6333 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 {
6335 if (gvarp == &p_fenc)
6336 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006337 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 errmsg = e_modifiable;
6339 else if (vim_strchr(*varp, ',') != NULL)
6340 /* No comma allowed in 'fileencoding'; catches confusing it
6341 * with 'fileencodings'. */
6342 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006344 {
6345# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006347 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006349 /* Add 'fileencoding' to the swap file. */
6350 ml_setflags(curbuf);
6351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006352 }
6353 if (errmsg == NULL)
6354 {
6355 /* canonize the value, so that STRCMP() can be used on it */
6356 p = enc_canonize(*varp);
6357 if (p != NULL)
6358 {
6359 vim_free(*varp);
6360 *varp = p;
6361 }
6362 if (varp == &p_enc)
6363 {
6364 errmsg = mb_init();
6365# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006366 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367# endif
6368 }
6369 }
6370
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006371# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6373 {
6374 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6375 if (STRCMP(p_tenc, "utf-8") != 0)
6376 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6377 }
6378# endif
6379
6380 if (errmsg == NULL)
6381 {
6382# ifdef FEAT_KEYMAP
6383 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6384 * (with another encoding). */
6385 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6386 (void)keymap_init();
6387# endif
6388
6389 /* When 'termencoding' is not empty and 'encoding' changes or when
6390 * 'termencoding' changes, need to setup for keyboard input and
6391 * display output conversion. */
6392 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6393 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006394 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6395 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6396 {
6397 EMSG3(_("E950: Cannot convert between %s and %s"),
6398 p_tenc, p_enc);
6399 errmsg = e_invarg;
6400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006402
6403# if defined(WIN3264) && defined(FEAT_MBYTE)
6404 /* $HOME may have characters in active code page. */
6405 if (varp == &p_enc)
6406 init_homedir();
6407# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
6409 }
6410#endif
6411
6412#if defined(FEAT_POSTSCRIPT)
6413 else if (varp == &p_penc)
6414 {
6415 /* Canonize printencoding if VIM standard one */
6416 p = enc_canonize(p_penc);
6417 if (p != NULL)
6418 {
6419 vim_free(p_penc);
6420 p_penc = p;
6421 }
6422 else
6423 {
6424 /* Ensure lower case and '-' for '_' */
6425 for (s = p_penc; *s != NUL; s++)
6426 {
6427 if (*s == '_')
6428 *s = '-';
6429 else
6430 *s = TOLOWER_ASC(*s);
6431 }
6432 }
6433 }
6434#endif
6435
Bram Moolenaar9372a112005-12-06 19:59:18 +00006436#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 else if (varp == &p_imak)
6438 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006439 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 errmsg = e_invarg;
6441 }
6442#endif
6443
6444#ifdef FEAT_KEYMAP
6445 else if (varp == &curbuf->b_p_keymap)
6446 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006447 if (!valid_filetype(*varp))
6448 errmsg = e_invarg;
6449 else
6450 /* load or unload key mapping tables */
6451 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452
Bram Moolenaarfab06232009-03-04 03:13:35 +00006453 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006455 if (*curbuf->b_p_keymap != NUL)
6456 {
6457 /* Installed a new keymap, switch on using it. */
6458 curbuf->b_p_iminsert = B_IMODE_LMAP;
6459 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6460 curbuf->b_p_imsearch = B_IMODE_LMAP;
6461 }
6462 else
6463 {
6464 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6465 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6466 curbuf->b_p_iminsert = B_IMODE_NONE;
6467 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6468 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6469 }
6470 if ((opt_flags & OPT_LOCAL) == 0)
6471 {
6472 set_iminsert_global();
6473 set_imsearch_global();
6474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006475 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 }
6477 }
6478#endif
6479
6480 /* 'fileformat' */
6481 else if (gvarp == &p_ff)
6482 {
6483 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6484 errmsg = e_modifiable;
6485 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6486 errmsg = e_invarg;
6487 else
6488 {
6489 /* may also change 'textmode' */
6490 if (get_fileformat(curbuf) == EOL_DOS)
6491 curbuf->b_p_tx = TRUE;
6492 else
6493 curbuf->b_p_tx = FALSE;
6494#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006495 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006497 /* update flag in swap file */
6498 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006499 /* Redraw needed when switching to/from "mac": a CR in the text
6500 * will be displayed differently. */
6501 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6502 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503 }
6504 }
6505
6506 /* 'fileformats' */
6507 else if (varp == &p_ffs)
6508 {
6509 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6510 errmsg = e_invarg;
6511 else
6512 {
6513 /* also change 'textauto' */
6514 if (*p_ffs == NUL)
6515 p_ta = FALSE;
6516 else
6517 p_ta = TRUE;
6518 }
6519 }
6520
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006521#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 /* 'cryptkey' */
6523 else if (gvarp == &p_key)
6524 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006525# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006526 /* Make sure the ":set" command doesn't show the new value in the
6527 * history. */
6528 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006529# endif
6530 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6531 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006532 ml_set_crypt_key(curbuf, oldval,
6533 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006534 }
6535
6536 else if (gvarp == &p_cm)
6537 {
6538 if (opt_flags & OPT_LOCAL)
6539 p = curbuf->b_p_cm;
6540 else
6541 p = p_cm;
6542 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6543 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006544 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006545 errmsg = e_invarg;
6546 else
6547 {
6548 /* When setting the global value to empty, make it "zip". */
6549 if (*p_cm == NUL)
6550 {
6551 if (new_value_alloced)
6552 free_string_option(p_cm);
6553 p_cm = vim_strsave((char_u *)"zip");
6554 new_value_alloced = TRUE;
6555 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006556 /* When using ":set cm=name" the local value is going to be empty.
6557 * Do that here, otherwise the crypt functions will still use the
6558 * local value. */
6559 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6560 {
6561 free_string_option(curbuf->b_p_cm);
6562 curbuf->b_p_cm = empty_option;
6563 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006564
6565 /* Need to update the swapfile when the effective method changed.
6566 * Set "s" to the effective old value, "p" to the effective new
6567 * method and compare. */
6568 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6569 s = p_cm; /* was previously using the global value */
6570 else
6571 s = oldval;
6572 if (*curbuf->b_p_cm == NUL)
6573 p = p_cm; /* is now using the global value */
6574 else
6575 p = curbuf->b_p_cm;
6576 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006577 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006578
6579 /* If the global value changes need to update the swapfile for all
6580 * buffers using that value. */
6581 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6582 {
6583 buf_T *buf;
6584
Bram Moolenaar29323592016-07-24 22:04:11 +02006585 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006586 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006587 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006588 }
6589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 }
6591#endif
6592
6593 /* 'matchpairs' */
6594 else if (gvarp == &p_mps)
6595 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006596#ifdef FEAT_MBYTE
6597 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006599 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006601 int x2 = -1;
6602 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006603
6604 if (*p != NUL)
6605 p += mb_ptr2len(p);
6606 if (*p != NUL)
6607 x2 = *p++;
6608 if (*p != NUL)
6609 {
6610 x3 = mb_ptr2char(p);
6611 p += mb_ptr2len(p);
6612 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006613 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006614 {
6615 errmsg = e_invarg;
6616 break;
6617 }
6618 if (*p == NUL)
6619 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006621 }
6622 else
6623#endif
6624 {
6625 /* Check for "x:y,x:y" */
6626 for (p = *varp; *p != NUL; p += 4)
6627 {
6628 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6629 {
6630 errmsg = e_invarg;
6631 break;
6632 }
6633 if (p[3] == NUL)
6634 break;
6635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636 }
6637 }
6638
6639#ifdef FEAT_COMMENTS
6640 /* 'comments' */
6641 else if (gvarp == &p_com)
6642 {
6643 for (s = *varp; *s; )
6644 {
6645 while (*s && *s != ':')
6646 {
6647 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6648 && !VIM_ISDIGIT(*s) && *s != '-')
6649 {
6650 errmsg = illegal_char(errbuf, *s);
6651 break;
6652 }
6653 ++s;
6654 }
6655 if (*s++ == NUL)
6656 errmsg = (char_u *)N_("E524: Missing colon");
6657 else if (*s == ',' || *s == NUL)
6658 errmsg = (char_u *)N_("E525: Zero length string");
6659 if (errmsg != NULL)
6660 break;
6661 while (*s && *s != ',')
6662 {
6663 if (*s == '\\' && s[1] != NUL)
6664 ++s;
6665 ++s;
6666 }
6667 s = skip_to_option_part(s);
6668 }
6669 }
6670#endif
6671
6672 /* 'listchars' */
6673 else if (varp == &p_lcs)
6674 {
6675 errmsg = set_chars_option(varp);
6676 }
6677
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678 /* 'fillchars' */
6679 else if (varp == &p_fcs)
6680 {
6681 errmsg = set_chars_option(varp);
6682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683
6684#ifdef FEAT_CMDWIN
6685 /* 'cedit' */
6686 else if (varp == &p_cedit)
6687 {
6688 errmsg = check_cedit();
6689 }
6690#endif
6691
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006692 /* 'verbosefile' */
6693 else if (varp == &p_vfile)
6694 {
6695 verbose_stop();
6696 if (*p_vfile != NUL && verbose_open() == FAIL)
6697 errmsg = e_invarg;
6698 }
6699
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700#ifdef FEAT_VIMINFO
6701 /* 'viminfo' */
6702 else if (varp == &p_viminfo)
6703 {
6704 for (s = p_viminfo; *s;)
6705 {
6706 /* Check it's a valid character */
6707 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6708 {
6709 errmsg = illegal_char(errbuf, *s);
6710 break;
6711 }
6712 if (*s == 'n') /* name is always last one */
6713 {
6714 break;
6715 }
6716 else if (*s == 'r') /* skip until next ',' */
6717 {
6718 while (*++s && *s != ',')
6719 ;
6720 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006721 else if (*s == '%')
6722 {
6723 /* optional number */
6724 while (vim_isdigit(*++s))
6725 ;
6726 }
6727 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 ++s; /* no extra chars */
6729 else /* must have a number */
6730 {
6731 while (vim_isdigit(*++s))
6732 ;
6733
6734 if (!VIM_ISDIGIT(*(s - 1)))
6735 {
6736 if (errbuf != NULL)
6737 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006738 sprintf((char *)errbuf,
6739 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 transchar_byte(*(s - 1)));
6741 errmsg = errbuf;
6742 }
6743 else
6744 errmsg = (char_u *)"";
6745 break;
6746 }
6747 }
6748 if (*s == ',')
6749 ++s;
6750 else if (*s)
6751 {
6752 if (errbuf != NULL)
6753 errmsg = (char_u *)N_("E527: Missing comma");
6754 else
6755 errmsg = (char_u *)"";
6756 break;
6757 }
6758 }
6759 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6760 errmsg = (char_u *)N_("E528: Must specify a ' value");
6761 }
6762#endif /* FEAT_VIMINFO */
6763
6764 /* terminal options */
6765 else if (istermoption(&options[opt_idx]) && full_screen)
6766 {
6767 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6768 if (varp == &T_CCO)
6769 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006770 int colors = atoi((char *)T_CCO);
6771
6772 /* Only reinitialize colors if t_Co value has really changed to
6773 * avoid expensive reload of colorscheme if t_Co is set to the
6774 * same value multiple times. */
6775 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006777 t_colors = colors;
6778 if (t_colors <= 1)
6779 {
6780 if (new_value_alloced)
6781 vim_free(T_CCO);
6782 T_CCO = empty_option;
6783 }
6784 /* We now have a different color setup, initialize it again. */
6785 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006787 }
6788 ttest(FALSE);
6789 if (varp == &T_ME)
6790 {
6791 out_str(T_ME);
6792 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006793#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 /* Since t_me has been set, this probably means that the user
6795 * wants to use this as default colors. Need to reset default
6796 * background/foreground colors. */
6797 mch_set_normal_colors();
6798#endif
6799 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006800 if (varp == &T_BE && termcap_active)
6801 {
6802 if (*T_BE == NUL)
6803 /* When clearing t_BE we assume the user no longer wants
6804 * bracketed paste, thus disable it by writing t_BD. */
6805 out_str(T_BD);
6806 else
6807 out_str(T_BE);
6808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809 }
6810
6811#ifdef FEAT_LINEBREAK
6812 /* 'showbreak' */
6813 else if (varp == &p_sbr)
6814 {
6815 for (s = p_sbr; *s; )
6816 {
6817 if (ptr2cells(s) != 1)
6818 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006819 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 }
6821 }
6822#endif
6823
6824#ifdef FEAT_GUI
6825 /* 'guifont' */
6826 else if (varp == &p_guifont)
6827 {
6828 if (gui.in_use)
6829 {
6830 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006831# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006832 /*
6833 * Put up a font dialog and let the user select a new value.
6834 * If this is cancelled go back to the old value but don't
6835 * give an error message.
6836 */
6837 if (STRCMP(p, "*") == 0)
6838 {
6839 p = gui_mch_font_dialog(oldval);
6840
6841 if (new_value_alloced)
6842 free_string_option(p_guifont);
6843
6844 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6845 new_value_alloced = TRUE;
6846 }
6847# endif
6848 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6849 {
6850# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6851 if (STRCMP(p_guifont, "*") == 0)
6852 {
6853 /* Dialog was cancelled: Keep the old value without giving
6854 * an error message. */
6855 if (new_value_alloced)
6856 free_string_option(p_guifont);
6857 p_guifont = vim_strsave(oldval);
6858 new_value_alloced = TRUE;
6859 }
6860 else
6861# endif
6862 errmsg = (char_u *)N_("E596: Invalid font(s)");
6863 }
6864 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006865 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 }
6867# ifdef FEAT_XFONTSET
6868 else if (varp == &p_guifontset)
6869 {
6870 if (STRCMP(p_guifontset, "*") == 0)
6871 errmsg = (char_u *)N_("E597: can't select fontset");
6872 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6873 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006874 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 }
6876# endif
6877# ifdef FEAT_MBYTE
6878 else if (varp == &p_guifontwide)
6879 {
6880 if (STRCMP(p_guifontwide, "*") == 0)
6881 errmsg = (char_u *)N_("E533: can't select wide font");
6882 else if (gui_get_wide_font() == FAIL)
6883 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006884 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 }
6886# endif
6887#endif
6888
6889#ifdef CURSOR_SHAPE
6890 /* 'guicursor' */
6891 else if (varp == &p_guicursor)
6892 errmsg = parse_shape_opt(SHAPE_CURSOR);
6893#endif
6894
6895#ifdef FEAT_MOUSESHAPE
6896 /* 'mouseshape' */
6897 else if (varp == &p_mouseshape)
6898 {
6899 errmsg = parse_shape_opt(SHAPE_MOUSE);
6900 update_mouseshape(-1);
6901 }
6902#endif
6903
6904#ifdef FEAT_PRINTER
6905 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006906 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006907# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006908 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006909 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911#endif
6912
6913#ifdef FEAT_LANGMAP
6914 /* 'langmap' */
6915 else if (varp == &p_langmap)
6916 langmap_set();
6917#endif
6918
6919#ifdef FEAT_LINEBREAK
6920 /* 'breakat' */
6921 else if (varp == &p_breakat)
6922 fill_breakat_flags();
6923#endif
6924
6925#ifdef FEAT_TITLE
6926 /* 'titlestring' and 'iconstring' */
6927 else if (varp == &p_titlestring || varp == &p_iconstring)
6928 {
6929# ifdef FEAT_STL_OPT
6930 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6931
6932 /* NULL => statusline syntax */
6933 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6934 stl_syntax |= flagval;
6935 else
6936 stl_syntax &= ~flagval;
6937# endif
6938 did_set_title(varp == &p_iconstring);
6939
6940 }
6941#endif
6942
6943#ifdef FEAT_GUI
6944 /* 'guioptions' */
6945 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006946 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006948 redraw_gui_only = TRUE;
6949 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950#endif
6951
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006952#if defined(FEAT_GUI_TABLINE)
6953 /* 'guitablabel' */
6954 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006955 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006956 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006957 redraw_gui_only = TRUE;
6958 }
6959 /* 'guitabtooltip' */
6960 else if (varp == &p_gtt)
6961 {
6962 redraw_gui_only = TRUE;
6963 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006964#endif
6965
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6967 /* 'ttymouse' */
6968 else if (varp == &p_ttym)
6969 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006970 /* Switch the mouse off before changing the escape sequences used for
6971 * that. */
6972 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6974 errmsg = e_invarg;
6975 else
6976 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006977 if (termcap_active)
6978 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 }
6980#endif
6981
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 /* 'selection' */
6983 else if (varp == &p_sel)
6984 {
6985 if (*p_sel == NUL
6986 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6987 errmsg = e_invarg;
6988 }
6989
6990 /* 'selectmode' */
6991 else if (varp == &p_slm)
6992 {
6993 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6994 errmsg = e_invarg;
6995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996
6997#ifdef FEAT_BROWSE
6998 /* 'browsedir' */
6999 else if (varp == &p_bsdir)
7000 {
7001 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7002 && !mch_isdir(p_bsdir))
7003 errmsg = e_invarg;
7004 }
7005#endif
7006
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 /* 'keymodel' */
7008 else if (varp == &p_km)
7009 {
7010 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7011 errmsg = e_invarg;
7012 else
7013 {
7014 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7015 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7016 }
7017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018
7019 /* 'mousemodel' */
7020 else if (varp == &p_mousem)
7021 {
7022 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7023 errmsg = e_invarg;
7024#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7025 else if (*p_mousem != *oldval)
7026 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7027 * to create or delete the popup menus. */
7028 gui_motif_update_mousemodel(root_menu);
7029#endif
7030 }
7031
7032 /* 'switchbuf' */
7033 else if (varp == &p_swb)
7034 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007035 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 errmsg = e_invarg;
7037 }
7038
7039 /* 'debug' */
7040 else if (varp == &p_debug)
7041 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007042 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 errmsg = e_invarg;
7044 }
7045
7046 /* 'display' */
7047 else if (varp == &p_dy)
7048 {
7049 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7050 errmsg = e_invarg;
7051 else
7052 (void)init_chartab();
7053
7054 }
7055
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 /* 'eadirection' */
7057 else if (varp == &p_ead)
7058 {
7059 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7060 errmsg = e_invarg;
7061 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062
7063#ifdef FEAT_CLIPBOARD
7064 /* 'clipboard' */
7065 else if (varp == &p_cb)
7066 errmsg = check_clipboard_option();
7067#endif
7068
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007069#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007070 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7071 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007072 else if (varp == &(curwin->w_s->b_p_spl)
7073 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007074 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007075 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007076 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007077 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007078 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007079 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007080 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007081 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007082 /* 'spellsuggest' */
7083 else if (varp == &p_sps)
7084 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007085 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007086 errmsg = e_invarg;
7087 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007088 /* 'mkspellmem' */
7089 else if (varp == &p_msm)
7090 {
7091 if (spell_check_msm() != OK)
7092 errmsg = e_invarg;
7093 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007094#endif
7095
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 /* When 'bufhidden' is set, check for valid value. */
7097 else if (gvarp == &p_bh)
7098 {
7099 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7100 errmsg = e_invarg;
7101 }
7102
7103 /* When 'buftype' is set, check for valid value. */
7104 else if (gvarp == &p_bt)
7105 {
7106 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7107 errmsg = e_invarg;
7108 else
7109 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 if (curwin->w_status_height)
7111 {
7112 curwin->w_redr_status = TRUE;
7113 redraw_later(VALID);
7114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007116#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007117 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 }
7120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121
7122#ifdef FEAT_STL_OPT
7123 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007124 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 {
7126 int wid;
7127
7128 if (varp == &p_ruf) /* reset ru_wid first */
7129 ru_wid = 0;
7130 s = *varp;
7131 if (varp == &p_ruf && *s == '%')
7132 {
7133 /* set ru_wid if 'ruf' starts with "%99(" */
7134 if (*++s == '-') /* ignore a '-' */
7135 s++;
7136 wid = getdigits(&s);
7137 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7138 ru_wid = wid;
7139 else
7140 errmsg = check_stl_option(p_ruf);
7141 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007142 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007143 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007145 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 comp_col();
7147 }
7148#endif
7149
7150#ifdef FEAT_INS_EXPAND
7151 /* check if it is a valid value for 'complete' -- Acevedo */
7152 else if (gvarp == &p_cpt)
7153 {
7154 for (s = *varp; *s;)
7155 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007156 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 s++;
7158 if (!*s)
7159 break;
7160 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7161 {
7162 errmsg = illegal_char(errbuf, *s);
7163 break;
7164 }
7165 if (*++s != NUL && *s != ',' && *s != ' ')
7166 {
7167 if (s[-1] == 'k' || s[-1] == 's')
7168 {
7169 /* skip optional filename after 'k' and 's' */
7170 while (*s && *s != ',' && *s != ' ')
7171 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007172 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173 ++s;
7174 ++s;
7175 }
7176 }
7177 else
7178 {
7179 if (errbuf != NULL)
7180 {
7181 sprintf((char *)errbuf,
7182 _("E535: Illegal character after <%c>"),
7183 *--s);
7184 errmsg = errbuf;
7185 }
7186 else
7187 errmsg = (char_u *)"";
7188 break;
7189 }
7190 }
7191 }
7192 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007193
7194 /* 'completeopt' */
7195 else if (varp == &p_cot)
7196 {
7197 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7198 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007199 else
7200 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202#endif /* FEAT_INS_EXPAND */
7203
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007204#ifdef FEAT_SIGNS
7205 /* 'signcolumn' */
7206 else if (varp == &curwin->w_p_scl)
7207 {
7208 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7209 errmsg = e_invarg;
7210 }
7211#endif
7212
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213
7214#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007215 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 else if (varp == &p_toolbar)
7217 {
7218 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7219 &toolbar_flags, TRUE) != OK)
7220 errmsg = e_invarg;
7221 else
7222 {
7223 out_flush();
7224 gui_mch_show_toolbar((toolbar_flags &
7225 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7226 }
7227 }
7228#endif
7229
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007230#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 /* 'toolbariconsize': GTK+ 2 only */
7232 else if (varp == &p_tbis)
7233 {
7234 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7235 errmsg = e_invarg;
7236 else
7237 {
7238 out_flush();
7239 gui_mch_show_toolbar((toolbar_flags &
7240 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7241 }
7242 }
7243#endif
7244
7245 /* 'pastetoggle': translate key codes like in a mapping */
7246 else if (varp == &p_pt)
7247 {
7248 if (*p_pt)
7249 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007250 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 if (p != NULL)
7252 {
7253 if (new_value_alloced)
7254 free_string_option(p_pt);
7255 p_pt = p;
7256 new_value_alloced = TRUE;
7257 }
7258 }
7259 }
7260
7261 /* 'backspace' */
7262 else if (varp == &p_bs)
7263 {
7264 if (VIM_ISDIGIT(*p_bs))
7265 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007266 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 errmsg = e_invarg;
7268 }
7269 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7270 errmsg = e_invarg;
7271 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007272 else if (varp == &p_bo)
7273 {
7274 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7275 errmsg = e_invarg;
7276 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007278 /* 'tagcase' */
7279 else if (gvarp == &p_tc)
7280 {
7281 unsigned int *flags;
7282
7283 if (opt_flags & OPT_LOCAL)
7284 {
7285 p = curbuf->b_p_tc;
7286 flags = &curbuf->b_tc_flags;
7287 }
7288 else
7289 {
7290 p = p_tc;
7291 flags = &tc_flags;
7292 }
7293
7294 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7295 /* make the local value empty: use the global value */
7296 *flags = 0;
7297 else if (*p == NUL
7298 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7299 errmsg = e_invarg;
7300 }
7301
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007302#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 /* 'casemap' */
7304 else if (varp == &p_cmp)
7305 {
7306 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7307 errmsg = e_invarg;
7308 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310
7311#ifdef FEAT_DIFF
7312 /* 'diffopt' */
7313 else if (varp == &p_dip)
7314 {
7315 if (diffopt_changed() == FAIL)
7316 errmsg = e_invarg;
7317 }
7318#endif
7319
7320#ifdef FEAT_FOLDING
7321 /* 'foldmethod' */
7322 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7323 {
7324 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7325 || *curwin->w_p_fdm == NUL)
7326 errmsg = e_invarg;
7327 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007328 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007330 if (foldmethodIsDiff(curwin))
7331 newFoldLevel();
7332 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333 }
7334# ifdef FEAT_EVAL
7335 /* 'foldexpr' */
7336 else if (varp == &curwin->w_p_fde)
7337 {
7338 if (foldmethodIsExpr(curwin))
7339 foldUpdateAll(curwin);
7340 }
7341# endif
7342 /* 'foldmarker' */
7343 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7344 {
7345 p = vim_strchr(*varp, ',');
7346 if (p == NULL)
7347 errmsg = (char_u *)N_("E536: comma required");
7348 else if (p == *varp || p[1] == NUL)
7349 errmsg = e_invarg;
7350 else if (foldmethodIsMarker(curwin))
7351 foldUpdateAll(curwin);
7352 }
7353 /* 'commentstring' */
7354 else if (gvarp == &p_cms)
7355 {
7356 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7357 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7358 }
7359 /* 'foldopen' */
7360 else if (varp == &p_fdo)
7361 {
7362 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7363 errmsg = e_invarg;
7364 }
7365 /* 'foldclose' */
7366 else if (varp == &p_fcl)
7367 {
7368 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7369 errmsg = e_invarg;
7370 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007371 /* 'foldignore' */
7372 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7373 {
7374 if (foldmethodIsIndent(curwin))
7375 foldUpdateAll(curwin);
7376 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377#endif
7378
7379#ifdef FEAT_VIRTUALEDIT
7380 /* 'virtualedit' */
7381 else if (varp == &p_ve)
7382 {
7383 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7384 errmsg = e_invarg;
7385 else if (STRCMP(p_ve, oldval) != 0)
7386 {
7387 /* Recompute cursor position in case the new 've' setting
7388 * changes something. */
7389 validate_virtcol();
7390 coladvance(curwin->w_virtcol);
7391 }
7392 }
7393#endif
7394
7395#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7396 else if (varp == &p_csqf)
7397 {
7398 if (p_csqf != NULL)
7399 {
7400 p = p_csqf;
7401 while (*p != NUL)
7402 {
7403 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7404 || p[1] == NUL
7405 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7406 || (p[2] != NUL && p[2] != ','))
7407 {
7408 errmsg = e_invarg;
7409 break;
7410 }
7411 else if (p[2] == NUL)
7412 break;
7413 else
7414 p += 3;
7415 }
7416 }
7417 }
7418#endif
7419
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007420#ifdef FEAT_CINDENT
7421 /* 'cinoptions' */
7422 else if (gvarp == &p_cino)
7423 {
7424 /* TODO: recognize errors */
7425 parse_cino(curbuf);
7426 }
7427#endif
7428
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007429#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007430 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007431 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007432 {
7433 if (!gui_mch_set_rendering_options(p_rop))
7434 errmsg = e_invarg;
7435 }
7436#endif
7437
Bram Moolenaard0b51382016-11-04 15:23:45 +01007438 else if (gvarp == &p_ft)
7439 {
7440 if (!valid_filetype(*varp))
7441 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007442 else
7443 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007444 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007445
7446#ifdef FEAT_SYN_HL
7447 else if (gvarp == &p_syn)
7448 {
7449 if (!valid_filetype(*varp))
7450 errmsg = e_invarg;
7451 }
7452#endif
7453
Bram Moolenaar825680f2017-07-22 17:04:02 +02007454#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007455 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007456 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007457 {
7458 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7459 errmsg = e_invarg;
7460 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007461 /* 'termsize' */
7462 else if (varp == &curwin->w_p_tms)
7463 {
7464 if (*curwin->w_p_tms != NUL)
7465 {
7466 p = skipdigits(curwin->w_p_tms);
7467 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7468 errmsg = e_invarg;
7469 }
7470 }
7471#endif
7472
Bram Moolenaar071d4272004-06-13 20:20:40 +00007473 /* Options that are a list of flags. */
7474 else
7475 {
7476 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007477 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007479 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007481 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007483 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007484 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007485#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007486 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007487 p = (char_u *)COCU_ALL;
7488#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007489 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 {
7491#ifdef FEAT_MOUSE
7492 p = (char_u *)MOUSE_ALL;
7493#else
7494 if (*p_mouse != NUL)
7495 errmsg = (char_u *)N_("E538: No mouse support");
7496#endif
7497 }
7498#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007499 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 p = (char_u *)GO_ALL;
7501#endif
7502 if (p != NULL)
7503 {
7504 for (s = *varp; *s; ++s)
7505 if (vim_strchr(p, *s) == NULL)
7506 {
7507 errmsg = illegal_char(errbuf, *s);
7508 break;
7509 }
7510 }
7511 }
7512
7513 /*
7514 * If error detected, restore the previous value.
7515 */
7516 if (errmsg != NULL)
7517 {
7518 if (new_value_alloced)
7519 free_string_option(*varp);
7520 *varp = oldval;
7521 /*
7522 * When resetting some values, need to act on it.
7523 */
7524 if (did_chartab)
7525 (void)init_chartab();
7526 if (varp == &p_hl)
7527 (void)highlight_changed();
7528 }
7529 else
7530 {
7531#ifdef FEAT_EVAL
7532 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007533 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534#endif
7535 /*
7536 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007537 * Use "free_oldval", because recursiveness may change the flags under
7538 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007540 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 free_string_option(oldval);
7542 if (new_value_alloced)
7543 options[opt_idx].flags |= P_ALLOCED;
7544 else
7545 options[opt_idx].flags &= ~P_ALLOCED;
7546
7547 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007548 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 {
7550 /* global option with local value set to use global value; free
7551 * the local value and make it empty */
7552 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7553 free_string_option(*(char_u **)p);
7554 *(char_u **)p = empty_option;
7555 }
7556
7557 /* May set global value for local option. */
7558 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7559 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007560
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007561 /*
7562 * Trigger the autocommand only after setting the flags.
7563 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007564#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007565 /* When 'syntax' is set, load the syntax of that name */
7566 if (varp == &(curbuf->b_p_syn))
7567 {
7568 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7569 curbuf->b_fname, TRUE, curbuf);
7570 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007571#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007572 else if (varp == &(curbuf->b_p_ft))
7573 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007574 /* 'filetype' is set, trigger the FileType autocommand.
7575 * Skip this when called from a modeline and the filetype was
7576 * already set to this value. */
7577 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7578 {
7579 did_filetype = TRUE;
7580 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007581 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007582 /* Just in case the old "curbuf" is now invalid. */
7583 if (varp != &(curbuf->b_p_ft))
7584 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007585 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007586 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007587#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007588 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007589 {
7590 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007591 char_u *q = curwin->w_s->b_p_spl;
7592
7593 /* Skip the first name if it is "cjk". */
7594 if (STRNCMP(q, "cjk,", 4) == 0)
7595 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007596
7597 /*
7598 * Source the spell/LANG.vim in 'runtimepath'.
7599 * They could set 'spellcapcheck' depending on the language.
7600 * Use the first name in 'spelllang' up to '_region' or
7601 * '.encoding'.
7602 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007603 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007604 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7605 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007606 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007607 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007608 }
7609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610 }
7611
7612#ifdef FEAT_MOUSE
7613 if (varp == &p_mouse)
7614 {
7615# ifdef FEAT_MOUSE_TTY
7616 if (*p_mouse == NUL)
7617 mch_setmouse(FALSE); /* switch mouse off */
7618 else
7619# endif
7620 setmouse(); /* in case 'mouse' changed */
7621 }
7622#endif
7623
Bram Moolenaar913077c2012-03-28 19:59:04 +02007624 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007625 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007626 curwin->w_set_curswant = TRUE;
7627
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007628#ifdef FEAT_GUI
7629 /* check redraw when it's not a GUI option or the GUI is active. */
7630 if (!redraw_gui_only || gui.in_use)
7631#endif
7632 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633
7634 return errmsg;
7635}
7636
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007637#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007638/*
7639 * Simple int comparison function for use with qsort()
7640 */
7641 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007642int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007643{
7644 return *(const int *)a - *(const int *)b;
7645}
7646
7647/*
7648 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7649 * Returns error message, NULL if it's OK.
7650 */
7651 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007652check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007653{
7654 char_u *s;
7655 int col;
7656 int count = 0;
7657 int color_cols[256];
7658 int i;
7659 int j = 0;
7660
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007661 if (wp->w_buffer == NULL)
7662 return NULL; /* buffer was closed */
7663
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007664 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007665 {
7666 if (*s == '-' || *s == '+')
7667 {
7668 /* -N and +N: add to 'textwidth' */
7669 col = (*s == '-') ? -1 : 1;
7670 ++s;
7671 if (!VIM_ISDIGIT(*s))
7672 return e_invarg;
7673 col = col * getdigits(&s);
7674 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007675 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007676 col += wp->w_buffer->b_p_tw;
7677 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007678 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007679 }
7680 else if (VIM_ISDIGIT(*s))
7681 col = getdigits(&s);
7682 else
7683 return e_invarg;
7684 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007685skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007686 if (*s == NUL)
7687 break;
7688 if (*s != ',')
7689 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007690 if (*++s == NUL)
7691 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007692 }
7693
7694 vim_free(wp->w_p_cc_cols);
7695 if (count == 0)
7696 wp->w_p_cc_cols = NULL;
7697 else
7698 {
7699 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7700 if (wp->w_p_cc_cols != NULL)
7701 {
7702 /* sort the columns for faster usage on screen redraw inside
7703 * win_line() */
7704 qsort(color_cols, count, sizeof(int), int_cmp);
7705
7706 for (i = 0; i < count; ++i)
7707 /* skip duplicates */
7708 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7709 wp->w_p_cc_cols[j++] = color_cols[i];
7710 wp->w_p_cc_cols[j] = -1; /* end marker */
7711 }
7712 }
7713
7714 return NULL; /* no error */
7715}
7716#endif
7717
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718/*
7719 * Handle setting 'listchars' or 'fillchars'.
7720 * Returns error message, NULL if it's OK.
7721 */
7722 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007723set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724{
7725 int round, i, len, entries;
7726 char_u *p, *s;
7727 int c1, c2 = 0;
7728 struct charstab
7729 {
7730 int *cp;
7731 char *name;
7732 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 static struct charstab filltab[] =
7734 {
7735 {&fill_stl, "stl"},
7736 {&fill_stlnc, "stlnc"},
7737 {&fill_vert, "vert"},
7738 {&fill_fold, "fold"},
7739 {&fill_diff, "diff"},
7740 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 static struct charstab lcstab[] =
7742 {
7743 {&lcs_eol, "eol"},
7744 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007745 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007747 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 {&lcs_tab2, "tab"},
7749 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007750#ifdef FEAT_CONCEAL
7751 {&lcs_conceal, "conceal"},
7752#else
7753 {NULL, "conceal"},
7754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 };
7756 struct charstab *tab;
7757
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 {
7760 tab = lcstab;
7761 entries = sizeof(lcstab) / sizeof(struct charstab);
7762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 else
7764 {
7765 tab = filltab;
7766 entries = sizeof(filltab) / sizeof(struct charstab);
7767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768
7769 /* first round: check for valid value, second round: assign values */
7770 for (round = 0; round <= 1; ++round)
7771 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007772 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773 {
7774 /* After checking that the value is valid: set defaults: space for
7775 * 'fillchars', NUL for 'listchars' */
7776 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 if (tab[i].cp != NULL)
7778 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 if (varp == &p_lcs)
7780 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 else
7782 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 }
7784 p = *varp;
7785 while (*p)
7786 {
7787 for (i = 0; i < entries; ++i)
7788 {
7789 len = (int)STRLEN(tab[i].name);
7790 if (STRNCMP(p, tab[i].name, len) == 0
7791 && p[len] == ':'
7792 && p[len + 1] != NUL)
7793 {
7794 s = p + len + 1;
7795#ifdef FEAT_MBYTE
7796 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007797 if (mb_char2cells(c1) > 1)
7798 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799#else
7800 c1 = *s++;
7801#endif
7802 if (tab[i].cp == &lcs_tab2)
7803 {
7804 if (*s == NUL)
7805 continue;
7806#ifdef FEAT_MBYTE
7807 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007808 if (mb_char2cells(c2) > 1)
7809 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810#else
7811 c2 = *s++;
7812#endif
7813 }
7814 if (*s == ',' || *s == NUL)
7815 {
7816 if (round)
7817 {
7818 if (tab[i].cp == &lcs_tab2)
7819 {
7820 lcs_tab1 = c1;
7821 lcs_tab2 = c2;
7822 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007823 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824 *(tab[i].cp) = c1;
7825
7826 }
7827 p = s;
7828 break;
7829 }
7830 }
7831 }
7832
7833 if (i == entries)
7834 return e_invarg;
7835 if (*p == ',')
7836 ++p;
7837 }
7838 }
7839
7840 return NULL; /* no error */
7841}
7842
7843#ifdef FEAT_STL_OPT
7844/*
7845 * Check validity of options with the 'statusline' format.
7846 * Return error message or NULL.
7847 */
7848 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007849check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850{
7851 int itemcnt = 0;
7852 int groupdepth = 0;
7853 static char_u errbuf[80];
7854
7855 while (*s && itemcnt < STL_MAX_ITEM)
7856 {
7857 /* Check for valid keys after % sequences */
7858 while (*s && *s != '%')
7859 s++;
7860 if (!*s)
7861 break;
7862 s++;
7863 if (*s != '%' && *s != ')')
7864 ++itemcnt;
7865 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7866 {
7867 s++;
7868 continue;
7869 }
7870 if (*s == ')')
7871 {
7872 s++;
7873 if (--groupdepth < 0)
7874 break;
7875 continue;
7876 }
7877 if (*s == '-')
7878 s++;
7879 while (VIM_ISDIGIT(*s))
7880 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007881 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 continue;
7883 if (*s == '.')
7884 {
7885 s++;
7886 while (*s && VIM_ISDIGIT(*s))
7887 s++;
7888 }
7889 if (*s == '(')
7890 {
7891 groupdepth++;
7892 continue;
7893 }
7894 if (vim_strchr(STL_ALL, *s) == NULL)
7895 {
7896 return illegal_char(errbuf, *s);
7897 }
7898 if (*s == '{')
7899 {
7900 s++;
7901 while (*s != '}' && *s)
7902 s++;
7903 if (*s != '}')
7904 return (char_u *)N_("E540: Unclosed expression sequence");
7905 }
7906 }
7907 if (itemcnt >= STL_MAX_ITEM)
7908 return (char_u *)N_("E541: too many items");
7909 if (groupdepth != 0)
7910 return (char_u *)N_("E542: unbalanced groups");
7911 return NULL;
7912}
7913#endif
7914
7915#ifdef FEAT_CLIPBOARD
7916/*
7917 * Extract the items in the 'clipboard' option and set global values.
7918 */
7919 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007920check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007922 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007923 int new_autoselect_star = FALSE;
7924 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007926 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 regprog_T *new_exclude_prog = NULL;
7928 char_u *errmsg = NULL;
7929 char_u *p;
7930
7931 for (p = p_cb; *p != NUL; )
7932 {
7933 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7934 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007935 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 p += 7;
7937 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007938 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007939 && (p[11] == ',' || p[11] == NUL))
7940 {
7941 new_unnamed |= CLIP_UNNAMED_PLUS;
7942 p += 11;
7943 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007945 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007947 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 p += 10;
7949 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007950 else if (STRNCMP(p, "autoselectplus", 14) == 0
7951 && (p[14] == ',' || p[14] == NUL))
7952 {
7953 new_autoselect_plus = TRUE;
7954 p += 14;
7955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007957 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 {
7959 new_autoselectml = TRUE;
7960 p += 12;
7961 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007962 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7963 {
7964 new_html = TRUE;
7965 p += 4;
7966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7968 {
7969 p += 8;
7970 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7971 if (new_exclude_prog == NULL)
7972 errmsg = e_invarg;
7973 break;
7974 }
7975 else
7976 {
7977 errmsg = e_invarg;
7978 break;
7979 }
7980 if (*p == ',')
7981 ++p;
7982 }
7983 if (errmsg == NULL)
7984 {
7985 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007986 clip_autoselect_star = new_autoselect_star;
7987 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007989 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007990 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007992#ifdef FEAT_GUI_GTK
7993 if (gui.in_use)
7994 {
7995 gui_gtk_set_selection_targets();
7996 gui_gtk_set_dnd_targets();
7997 }
7998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 }
8000 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008001 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002
8003 return errmsg;
8004}
8005#endif
8006
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008007#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008008 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008009did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008010{
8011 char_u *errmsg = NULL;
8012 win_T *wp;
8013 int l;
8014
8015 if (is_spellfile)
8016 {
8017 l = (int)STRLEN(curwin->w_s->b_p_spf);
8018 if (l > 0 && (l < 4
8019 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8020 errmsg = e_invarg;
8021 }
8022
8023 if (errmsg == NULL)
8024 {
8025 FOR_ALL_WINDOWS(wp)
8026 if (wp->w_buffer == curbuf && wp->w_p_spell)
8027 {
8028 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008029 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008030 }
8031 }
8032 return errmsg;
8033}
8034
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008035/*
8036 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8037 * Return error message when failed, NULL when OK.
8038 */
8039 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008040compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008041{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008042 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008043 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008044
Bram Moolenaar860cae12010-06-05 23:22:07 +02008045 if (*synblock->b_p_spc == NUL)
8046 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008047 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008048 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008049 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008050 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008051 if (re != NULL)
8052 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008053 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008054 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008055 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008056 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008057 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008058 return e_invarg;
8059 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008060 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008061 }
8062
Bram Moolenaar473de612013-06-08 18:19:48 +02008063 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008064 return NULL;
8065}
8066#endif
8067
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008068#if defined(FEAT_EVAL) || defined(PROTO)
8069/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008070 * Set the scriptID for an option, taking care of setting the buffer- or
8071 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008072 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008073 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008074set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008075{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008076 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8077 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008078
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008079 /* Remember where the option was set. For local options need to do that
8080 * in the buffer or window structure. */
8081 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008082 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008083 if (both || (opt_flags & OPT_LOCAL))
8084 {
8085 if (indir & PV_BUF)
8086 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8087 else if (indir & PV_WIN)
8088 curwin->w_p_scriptID[indir & PV_MASK] = id;
8089 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008090}
8091#endif
8092
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093/*
8094 * Set the value of a boolean option, and take care of side effects.
8095 * Returns NULL for success, or an error message for an error.
8096 */
8097 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008098set_bool_option(
8099 int opt_idx, /* index in options[] table */
8100 char_u *varp, /* pointer to the option variable */
8101 int value, /* new value */
8102 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103{
8104 int old_value = *(int *)varp;
8105
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 /* Disallow changing some options from secure mode */
8107 if ((secure
8108#ifdef HAVE_SANDBOX
8109 || sandbox != 0
8110#endif
8111 ) && (options[opt_idx].flags & P_SECURE))
8112 return e_secure;
8113
8114 *(int *)varp = value; /* set the new value */
8115#ifdef FEAT_EVAL
8116 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008117 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118#endif
8119
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008120#ifdef FEAT_GUI
8121 need_mouse_correct = TRUE;
8122#endif
8123
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 /* May set global value for local option. */
8125 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8126 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8127
8128 /*
8129 * Handle side effects of changing a bool option.
8130 */
8131
8132 /* 'compatible' */
8133 if ((int *)varp == &p_cp)
8134 {
8135 compatible_set();
8136 }
8137
Bram Moolenaar920694c2016-08-21 17:45:02 +02008138#ifdef FEAT_LANGMAP
8139 if ((int *)varp == &p_lrm)
8140 /* 'langremap' -> !'langnoremap' */
8141 p_lnr = !p_lrm;
8142 else if ((int *)varp == &p_lnr)
8143 /* 'langnoremap' -> !'langremap' */
8144 p_lrm = !p_lnr;
8145#endif
8146
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008147#ifdef FEAT_PERSISTENT_UNDO
8148 /* 'undofile' */
8149 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8150 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008151 /* Only take action when the option was set. When reset we do not
8152 * delete the undo file, the option may be set again without making
8153 * any changes in between. */
8154 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008155 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008156 char_u hash[UNDO_HASH_SIZE];
8157 buf_T *save_curbuf = curbuf;
8158
Bram Moolenaar29323592016-07-24 22:04:11 +02008159 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008160 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008161 /* When 'undofile' is set globally: for every buffer, otherwise
8162 * only for the current buffer: Try to read in the undofile,
8163 * if one exists, the buffer wasn't changed and the buffer was
8164 * loaded */
8165 if ((curbuf == save_curbuf
8166 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8167 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8168 {
8169 u_compute_hash(hash);
8170 u_read_undo(NULL, hash, curbuf->b_fname);
8171 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008172 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008173 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008174 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008175 }
8176#endif
8177
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 else if ((int *)varp == &curbuf->b_p_ro)
8179 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008180 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8182 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008183
8184 /* when 'readonly' is set may give W10 again */
8185 if (curbuf->b_p_ro)
8186 curbuf->b_did_warn = FALSE;
8187
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008189 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190#endif
8191 }
8192
Bram Moolenaar9c449722010-07-20 18:44:27 +02008193#ifdef FEAT_GUI
8194 else if ((int *)varp == &p_mh)
8195 {
8196 if (!p_mh)
8197 gui_mch_mousehide(FALSE);
8198 }
8199#endif
8200
Bram Moolenaara539df02010-08-01 14:35:05 +02008201 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008203 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008204# ifdef FEAT_TERMINAL
8205 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008206 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8207 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008208 {
8209 curbuf->b_p_ma = FALSE;
8210 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8211 }
8212# endif
8213# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008214 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008215# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008216 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008217#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 /* when 'endofline' is changed, redraw the window title */
8219 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008220 {
8221 redraw_titles();
8222 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008223 /* when 'fixeol' is changed, redraw the window title */
8224 else if ((int *)varp == &curbuf->b_p_fixeol)
8225 {
8226 redraw_titles();
8227 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008228# ifdef FEAT_MBYTE
8229 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008230 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008231 {
8232 redraw_titles();
8233 }
8234# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008235#endif
8236
8237 /* when 'bin' is set also set some other options */
8238 else if ((int *)varp == &curbuf->b_p_bin)
8239 {
8240 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8241#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008242 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243#endif
8244 }
8245
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246 /* when 'buflisted' changes, trigger autocommands */
8247 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8248 {
8249 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8250 NULL, NULL, TRUE, curbuf);
8251 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252
8253 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8254 else if ((int *)varp == &curbuf->b_p_swf)
8255 {
8256 if (curbuf->b_p_swf && p_uc)
8257 ml_open_file(curbuf); /* create the swap file */
8258 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008259 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8260 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 mf_close_file(curbuf, TRUE); /* remove the swap file */
8262 }
8263
8264 /* when 'terse' is set change 'shortmess' */
8265 else if ((int *)varp == &p_terse)
8266 {
8267 char_u *p;
8268
8269 p = vim_strchr(p_shm, SHM_SEARCH);
8270
8271 /* insert 's' in p_shm */
8272 if (p_terse && p == NULL)
8273 {
8274 STRCPY(IObuff, p_shm);
8275 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008276 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 }
8278 /* remove 's' from p_shm */
8279 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008280 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008281 }
8282
8283 /* when 'paste' is set or reset also change other options */
8284 else if ((int *)varp == &p_paste)
8285 {
8286 paste_option_changed();
8287 }
8288
8289 /* when 'insertmode' is set from an autocommand need to do work here */
8290 else if ((int *)varp == &p_im)
8291 {
8292 if (p_im)
8293 {
8294 if ((State & INSERT) == 0)
8295 need_start_insertmode = TRUE;
8296 stop_insert_mode = FALSE;
8297 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008298 /* only reset if it was set previously */
8299 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 {
8301 need_start_insertmode = FALSE;
8302 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008303 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 clear_cmdline = TRUE; /* remove "(insert)" */
8305 restart_edit = 0;
8306 }
8307 }
8308
8309 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8310 else if ((int *)varp == &p_ic && p_hls)
8311 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008312 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 }
8314
8315#ifdef FEAT_SEARCH_EXTRA
8316 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8317 else if ((int *)varp == &p_hls)
8318 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008319 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321#endif
8322
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8324 * at the end of normal_cmd() */
8325 else if ((int *)varp == &curwin->w_p_scb)
8326 {
8327 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008328 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008330 curwin->w_scbind_pos = curwin->w_topline;
8331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333
Bram Moolenaar4033c552017-09-16 20:54:51 +02008334#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335 /* There can be only one window with 'previewwindow' set. */
8336 else if ((int *)varp == &curwin->w_p_pvw)
8337 {
8338 if (curwin->w_p_pvw)
8339 {
8340 win_T *win;
8341
Bram Moolenaar29323592016-07-24 22:04:11 +02008342 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 if (win->w_p_pvw && win != curwin)
8344 {
8345 curwin->w_p_pvw = FALSE;
8346 return (char_u *)N_("E590: A preview window already exists");
8347 }
8348 }
8349 }
8350#endif
8351
8352 /* when 'textmode' is set or reset also change 'fileformat' */
8353 else if ((int *)varp == &curbuf->b_p_tx)
8354 {
8355 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8356 }
8357
8358 /* when 'textauto' is set or reset also change 'fileformats' */
8359 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 set_string_option_direct((char_u *)"ffs", -1,
8361 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008362 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363
8364 /*
8365 * When 'lisp' option changes include/exclude '-' in
8366 * keyword characters.
8367 */
8368#ifdef FEAT_LISP
8369 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8370 {
8371 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8372 }
8373#endif
8374
8375#ifdef FEAT_TITLE
8376 /* when 'title' changed, may need to change the title; same for 'icon' */
8377 else if ((int *)varp == &p_title)
8378 {
8379 did_set_title(FALSE);
8380 }
8381
8382 else if ((int *)varp == &p_icon)
8383 {
8384 did_set_title(TRUE);
8385 }
8386#endif
8387
8388 else if ((int *)varp == &curbuf->b_changed)
8389 {
8390 if (!value)
8391 save_file_ff(curbuf); /* Buffer is unchanged */
8392#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008393 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 }
8397
8398#ifdef BACKSLASH_IN_FILENAME
8399 else if ((int *)varp == &p_ssl)
8400 {
8401 if (p_ssl)
8402 {
8403 psepc = '/';
8404 psepcN = '\\';
8405 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 }
8407 else
8408 {
8409 psepc = '\\';
8410 psepcN = '/';
8411 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 }
8413
8414 /* need to adjust the file name arguments and buffer names. */
8415 buflist_slash_adjust();
8416 alist_slash_adjust();
8417# ifdef FEAT_EVAL
8418 scriptnames_slash_adjust();
8419# endif
8420 }
8421#endif
8422
8423 /* If 'wrap' is set, set w_leftcol to zero. */
8424 else if ((int *)varp == &curwin->w_p_wrap)
8425 {
8426 if (curwin->w_p_wrap)
8427 curwin->w_leftcol = 0;
8428 }
8429
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 else if ((int *)varp == &p_ea)
8431 {
8432 if (p_ea && !old_value)
8433 win_equal(curwin, FALSE, 0);
8434 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435
8436 else if ((int *)varp == &p_wiv)
8437 {
8438 /*
8439 * When 'weirdinvert' changed, set/reset 't_xs'.
8440 * Then set 'weirdinvert' according to value of 't_xs'.
8441 */
8442 if (p_wiv && !old_value)
8443 T_XS = (char_u *)"y";
8444 else if (!p_wiv && old_value)
8445 T_XS = empty_option;
8446 p_wiv = (*T_XS != NUL);
8447 }
8448
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008449#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 else if ((int *)varp == &p_beval)
8451 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008452 if (!balloonEvalForTerm)
8453 {
8454 if (p_beval && !old_value)
8455 gui_mch_enable_beval_area(balloonEval);
8456 else if (!p_beval && old_value)
8457 gui_mch_disable_beval_area(balloonEval);
8458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008460#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008461#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008462 else if ((int *)varp == &p_bevalterm)
8463 {
8464 mch_bevalterm_changed();
8465 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008468#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 else if ((int *)varp == &p_acd)
8470 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008471 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008472 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 }
8474#endif
8475
8476#ifdef FEAT_DIFF
8477 /* 'diff' */
8478 else if ((int *)varp == &curwin->w_p_diff)
8479 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008480 /* May add or remove the buffer from the list of diff buffers. */
8481 diff_buf_adjust(curwin);
8482# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 if (foldmethodIsDiff(curwin))
8484 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008485# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 }
8487#endif
8488
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008489#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 /* 'imdisable' */
8491 else if ((int *)varp == &p_imdisable)
8492 {
8493 /* Only de-activate it here, it will be enabled when changing mode. */
8494 if (p_imdisable)
8495 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008496 else if (State & INSERT)
8497 /* When the option is set from an autocommand, it may need to take
8498 * effect right away. */
8499 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 }
8501#endif
8502
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008503#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008504 /* 'spell' */
8505 else if ((int *)varp == &curwin->w_p_spell)
8506 {
8507 if (curwin->w_p_spell)
8508 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008509 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008510 if (errmsg != NULL)
8511 EMSG(_(errmsg));
8512 }
8513 }
8514#endif
8515
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516#ifdef FEAT_FKMAP
8517 else if ((int *)varp == &p_altkeymap)
8518 {
8519 if (old_value != p_altkeymap)
8520 {
8521 if (!p_altkeymap)
8522 {
8523 p_hkmap = p_fkmap;
8524 p_fkmap = 0;
8525 }
8526 else
8527 {
8528 p_fkmap = p_hkmap;
8529 p_hkmap = 0;
8530 }
8531 (void)init_chartab();
8532 }
8533 }
8534
8535 /*
8536 * In case some second language keymapping options have changed, check
8537 * and correct the setting in a consistent way.
8538 */
8539
8540 /*
8541 * If hkmap or fkmap are set, reset Arabic keymapping.
8542 */
8543 if ((p_hkmap || p_fkmap) && p_altkeymap)
8544 {
8545 p_altkeymap = p_fkmap;
8546# ifdef FEAT_ARABIC
8547 curwin->w_p_arab = FALSE;
8548# endif
8549 (void)init_chartab();
8550 }
8551
8552 /*
8553 * If hkmap set, reset Farsi keymapping.
8554 */
8555 if (p_hkmap && p_altkeymap)
8556 {
8557 p_altkeymap = 0;
8558 p_fkmap = 0;
8559# ifdef FEAT_ARABIC
8560 curwin->w_p_arab = FALSE;
8561# endif
8562 (void)init_chartab();
8563 }
8564
8565 /*
8566 * If fkmap set, reset Hebrew keymapping.
8567 */
8568 if (p_fkmap && !p_altkeymap)
8569 {
8570 p_altkeymap = 1;
8571 p_hkmap = 0;
8572# ifdef FEAT_ARABIC
8573 curwin->w_p_arab = FALSE;
8574# endif
8575 (void)init_chartab();
8576 }
8577#endif
8578
8579#ifdef FEAT_ARABIC
8580 if ((int *)varp == &curwin->w_p_arab)
8581 {
8582 if (curwin->w_p_arab)
8583 {
8584 /*
8585 * 'arabic' is set, handle various sub-settings.
8586 */
8587 if (!p_tbidi)
8588 {
8589 /* set rightleft mode */
8590 if (!curwin->w_p_rl)
8591 {
8592 curwin->w_p_rl = TRUE;
8593 changed_window_setting();
8594 }
8595
8596 /* Enable Arabic shaping (major part of what Arabic requires) */
8597 if (!p_arshape)
8598 {
8599 p_arshape = TRUE;
8600 redraw_later_clear();
8601 }
8602 }
8603
8604 /* Arabic requires a utf-8 encoding, inform the user if its not
8605 * set. */
8606 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008607 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008608 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8609
Bram Moolenaar8820b482017-03-16 17:23:31 +01008610 msg_source(HL_ATTR(HLF_W));
8611 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008612#ifdef FEAT_EVAL
8613 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8614#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616
8617# ifdef FEAT_MBYTE
8618 /* set 'delcombine' */
8619 p_deco = TRUE;
8620# endif
8621
8622# ifdef FEAT_KEYMAP
8623 /* Force-set the necessary keymap for arabic */
8624 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8625 OPT_LOCAL);
8626# endif
8627# ifdef FEAT_FKMAP
8628 p_altkeymap = 0;
8629 p_hkmap = 0;
8630 p_fkmap = 0;
8631 (void)init_chartab();
8632# endif
8633 }
8634 else
8635 {
8636 /*
8637 * 'arabic' is reset, handle various sub-settings.
8638 */
8639 if (!p_tbidi)
8640 {
8641 /* reset rightleft mode */
8642 if (curwin->w_p_rl)
8643 {
8644 curwin->w_p_rl = FALSE;
8645 changed_window_setting();
8646 }
8647
8648 /* 'arabicshape' isn't reset, it is a global option and
8649 * another window may still need it "on". */
8650 }
8651
8652 /* 'delcombine' isn't reset, it is a global option and another
8653 * window may still want it "on". */
8654
8655# ifdef FEAT_KEYMAP
8656 /* Revert to the default keymap */
8657 curbuf->b_p_iminsert = B_IMODE_NONE;
8658 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8659# endif
8660 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008661 }
8662
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008663#endif
8664
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008665#ifdef FEAT_TERMGUICOLORS
8666 /* 'termguicolors' */
8667 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008668 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008669# ifdef FEAT_VTP
8670 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8671 if (!has_vtp_working())
8672 {
8673 p_tgc = 0;
8674 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8675 }
8676 swap_tcap();
8677# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008678# ifdef FEAT_GUI
8679 if (!gui.in_use && !gui.starting)
8680# endif
8681 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008682# ifdef FEAT_VTP
8683 control_console_color_rgb();
8684 /* reset t_Co */
8685 if (STRCMP(T_NAME, "win32") == 0)
8686 set_termname(T_NAME);
8687# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008688 }
8689#endif
8690
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 /*
8692 * End of handling side effects for bool options.
8693 */
8694
Bram Moolenaar53744302015-07-17 17:38:22 +02008695 /* after handling side effects, call autocommand */
8696
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 options[opt_idx].flags |= P_WAS_SET;
8698
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008699#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008700 if (!starting)
8701 {
8702 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008703 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8704 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8705 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008706 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8707 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8708 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8709 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8710 reset_v_option_vars();
8711 }
8712#endif
8713
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008715 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008716 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008717 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 check_redraw(options[opt_idx].flags);
8719
8720 return NULL;
8721}
8722
8723/*
8724 * Set the value of a number option, and take care of side effects.
8725 * Returns NULL for success, or an error message for an error.
8726 */
8727 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008728set_num_option(
8729 int opt_idx, /* index in options[] table */
8730 char_u *varp, /* pointer to the option variable */
8731 long value, /* new value */
8732 char_u *errbuf, /* buffer for error messages */
8733 size_t errbuflen, /* length of "errbuf" */
8734 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735 OPT_MODELINE */
8736{
8737 char_u *errmsg = NULL;
8738 long old_value = *(long *)varp;
8739 long old_Rows = Rows; /* remember old Rows */
8740 long old_Columns = Columns; /* remember old Columns */
8741 long *pp = (long *)varp;
8742
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008743 /* Disallow changing some options from secure mode. */
8744 if ((secure
8745#ifdef HAVE_SANDBOX
8746 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008748 ) && (options[opt_idx].flags & P_SECURE))
8749 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750
8751 *pp = value;
8752#ifdef FEAT_EVAL
8753 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008754 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008756#ifdef FEAT_GUI
8757 need_mouse_correct = TRUE;
8758#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759
Bram Moolenaar14f24742012-08-08 18:01:05 +02008760 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 {
8762 errmsg = e_positive;
8763 curbuf->b_p_sw = curbuf->b_p_ts;
8764 }
8765
8766 /*
8767 * Number options that need some action when changed
8768 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769 if (pp == &p_wh || pp == &p_hh)
8770 {
8771 if (p_wh < 1)
8772 {
8773 errmsg = e_positive;
8774 p_wh = 1;
8775 }
8776 if (p_wmh > p_wh)
8777 {
8778 errmsg = e_winheight;
8779 p_wh = p_wmh;
8780 }
8781 if (p_hh < 0)
8782 {
8783 errmsg = e_positive;
8784 p_hh = 0;
8785 }
8786
8787 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008788 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 {
8790 if (pp == &p_wh && curwin->w_height < p_wh)
8791 win_setheight((int)p_wh);
8792 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8793 win_setheight((int)p_hh);
8794 }
8795 }
8796
8797 /* 'winminheight' */
8798 else if (pp == &p_wmh)
8799 {
8800 if (p_wmh < 0)
8801 {
8802 errmsg = e_positive;
8803 p_wmh = 0;
8804 }
8805 if (p_wmh > p_wh)
8806 {
8807 errmsg = e_winheight;
8808 p_wmh = p_wh;
8809 }
8810 win_setminheight();
8811 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008812 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 {
8814 if (p_wiw < 1)
8815 {
8816 errmsg = e_positive;
8817 p_wiw = 1;
8818 }
8819 if (p_wmw > p_wiw)
8820 {
8821 errmsg = e_winwidth;
8822 p_wiw = p_wmw;
8823 }
8824
8825 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008826 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 win_setwidth((int)p_wiw);
8828 }
8829
8830 /* 'winminwidth' */
8831 else if (pp == &p_wmw)
8832 {
8833 if (p_wmw < 0)
8834 {
8835 errmsg = e_positive;
8836 p_wmw = 0;
8837 }
8838 if (p_wmw > p_wiw)
8839 {
8840 errmsg = e_winwidth;
8841 p_wmw = p_wiw;
8842 }
8843 win_setminheight();
8844 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 /* (re)set last window status line */
8847 else if (pp == &p_ls)
8848 {
8849 last_status(FALSE);
8850 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008851
8852 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008853 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008854 {
8855 shell_new_rows(); /* recompute window positions and heights */
8856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857
8858#ifdef FEAT_GUI
8859 else if (pp == &p_linespace)
8860 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008861 /* Recompute gui.char_height and resize the Vim window to keep the
8862 * same number of lines. */
8863 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008864 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 }
8866#endif
8867
8868#ifdef FEAT_FOLDING
8869 /* 'foldlevel' */
8870 else if (pp == &curwin->w_p_fdl)
8871 {
8872 if (curwin->w_p_fdl < 0)
8873 curwin->w_p_fdl = 0;
8874 newFoldLevel();
8875 }
8876
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008877 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 else if (pp == &curwin->w_p_fml)
8879 {
8880 foldUpdateAll(curwin);
8881 }
8882
8883 /* 'foldnestmax' */
8884 else if (pp == &curwin->w_p_fdn)
8885 {
8886 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8887 foldUpdateAll(curwin);
8888 }
8889
8890 /* 'foldcolumn' */
8891 else if (pp == &curwin->w_p_fdc)
8892 {
8893 if (curwin->w_p_fdc < 0)
8894 {
8895 errmsg = e_positive;
8896 curwin->w_p_fdc = 0;
8897 }
8898 else if (curwin->w_p_fdc > 12)
8899 {
8900 errmsg = e_invarg;
8901 curwin->w_p_fdc = 12;
8902 }
8903 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008904#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008906#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 /* 'shiftwidth' or 'tabstop' */
8908 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8909 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008910# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 if (foldmethodIsIndent(curwin))
8912 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008913# endif
8914# ifdef FEAT_CINDENT
8915 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8916 * parse 'cinoptions'. */
8917 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8918 parse_cino(curbuf);
8919# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008923#ifdef FEAT_MBYTE
8924 /* 'maxcombine' */
8925 else if (pp == &p_mco)
8926 {
8927 if (p_mco > MAX_MCO)
8928 p_mco = MAX_MCO;
8929 else if (p_mco < 0)
8930 p_mco = 0;
8931 screenclear(); /* will re-allocate the screen */
8932 }
8933#endif
8934
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 else if (pp == &curbuf->b_p_iminsert)
8936 {
8937 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8938 {
8939 errmsg = e_invarg;
8940 curbuf->b_p_iminsert = B_IMODE_NONE;
8941 }
8942 p_iminsert = curbuf->b_p_iminsert;
8943 if (termcap_active) /* don't do this in the alternate screen */
8944 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008945#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946 /* Show/unshow value of 'keymap' in status lines. */
8947 status_redraw_curbuf();
8948#endif
8949 }
8950
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008951#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8952 /* 'imstyle' */
8953 else if (pp == &p_imst)
8954 {
8955 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8956 errmsg = e_invarg;
8957 }
8958#endif
8959
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008960 else if (pp == &p_window)
8961 {
8962 if (p_window < 1)
8963 p_window = 1;
8964 else if (p_window >= Rows)
8965 p_window = Rows - 1;
8966 }
8967
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968 else if (pp == &curbuf->b_p_imsearch)
8969 {
8970 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8971 {
8972 errmsg = e_invarg;
8973 curbuf->b_p_imsearch = B_IMODE_NONE;
8974 }
8975 p_imsearch = curbuf->b_p_imsearch;
8976 }
8977
8978#ifdef FEAT_TITLE
8979 /* if 'titlelen' has changed, redraw the title */
8980 else if (pp == &p_titlelen)
8981 {
8982 if (p_titlelen < 0)
8983 {
8984 errmsg = e_positive;
8985 p_titlelen = 85;
8986 }
8987 if (starting != NO_SCREEN && old_value != p_titlelen)
8988 need_maketitle = TRUE;
8989 }
8990#endif
8991
8992 /* if p_ch changed value, change the command line height */
8993 else if (pp == &p_ch)
8994 {
8995 if (p_ch < 1)
8996 {
8997 errmsg = e_positive;
8998 p_ch = 1;
8999 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009000 if (p_ch > Rows - min_rows() + 1)
9001 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002
9003 /* Only compute the new window layout when startup has been
9004 * completed. Otherwise the frame sizes may be wrong. */
9005 if (p_ch != old_value && full_screen
9006#ifdef FEAT_GUI
9007 && !gui.starting
9008#endif
9009 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009010 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 }
9012
9013 /* when 'updatecount' changes from zero to non-zero, open swap files */
9014 else if (pp == &p_uc)
9015 {
9016 if (p_uc < 0)
9017 {
9018 errmsg = e_positive;
9019 p_uc = 100;
9020 }
9021 if (p_uc && !old_value)
9022 ml_open_files();
9023 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009024#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009025 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009026 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009027 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009028 {
9029 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009030 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009031 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009032 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009033 {
9034 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009035 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009036 }
9037 }
9038#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009039#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009040 else if (pp == &p_mzq)
9041 mzvim_reset_timer();
9042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009044#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9045 /* 'pyxversion' */
9046 else if (pp == &p_pyx)
9047 {
9048 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9049 errmsg = e_invarg;
9050 }
9051#endif
9052
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053 /* sync undo before 'undolevels' changes */
9054 else if (pp == &p_ul)
9055 {
9056 /* use the old value, otherwise u_sync() may not work properly */
9057 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009058 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059 p_ul = value;
9060 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009061 else if (pp == &curbuf->b_p_ul)
9062 {
9063 /* use the old value, otherwise u_sync() may not work properly */
9064 curbuf->b_p_ul = old_value;
9065 u_sync(TRUE);
9066 curbuf->b_p_ul = value;
9067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009069#ifdef FEAT_LINEBREAK
9070 /* 'numberwidth' must be positive */
9071 else if (pp == &curwin->w_p_nuw)
9072 {
9073 if (curwin->w_p_nuw < 1)
9074 {
9075 errmsg = e_positive;
9076 curwin->w_p_nuw = 1;
9077 }
9078 if (curwin->w_p_nuw > 10)
9079 {
9080 errmsg = e_invarg;
9081 curwin->w_p_nuw = 10;
9082 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009083 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009084 }
9085#endif
9086
Bram Moolenaar1a384422010-07-14 19:53:30 +02009087 else if (pp == &curbuf->b_p_tw)
9088 {
9089 if (curbuf->b_p_tw < 0)
9090 {
9091 errmsg = e_positive;
9092 curbuf->b_p_tw = 0;
9093 }
9094#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009095 {
9096 win_T *wp;
9097 tabpage_T *tp;
9098
9099 FOR_ALL_TAB_WINDOWS(tp, wp)
9100 check_colorcolumn(wp);
9101 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009102#endif
9103 }
9104
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 /*
9106 * Check the bounds for numeric options here
9107 */
9108 if (Rows < min_rows() && full_screen)
9109 {
9110 if (errbuf != NULL)
9111 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009112 vim_snprintf((char *)errbuf, errbuflen,
9113 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114 errmsg = errbuf;
9115 }
9116 Rows = min_rows();
9117 }
9118 if (Columns < MIN_COLUMNS && full_screen)
9119 {
9120 if (errbuf != NULL)
9121 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009122 vim_snprintf((char *)errbuf, errbuflen,
9123 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 errmsg = errbuf;
9125 }
9126 Columns = MIN_COLUMNS;
9127 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009128 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 /*
9131 * If the screen (shell) height has been changed, assume it is the
9132 * physical screenheight.
9133 */
9134 if (old_Rows != Rows || old_Columns != Columns)
9135 {
9136 /* Changing the screen size is not allowed while updating the screen. */
9137 if (updating_screen)
9138 *pp = old_value;
9139 else if (full_screen
9140#ifdef FEAT_GUI
9141 && !gui.starting
9142#endif
9143 )
9144 set_shellsize((int)Columns, (int)Rows, TRUE);
9145 else
9146 {
9147 /* Postpone the resizing; check the size and cmdline position for
9148 * messages. */
9149 check_shellsize();
9150 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9151 cmdline_row = Rows - p_ch;
9152 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009153 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009154 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155 }
9156
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 if (curbuf->b_p_ts <= 0)
9158 {
9159 errmsg = e_positive;
9160 curbuf->b_p_ts = 8;
9161 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 if (p_tm < 0)
9163 {
9164 errmsg = e_positive;
9165 p_tm = 0;
9166 }
9167 if ((curwin->w_p_scr <= 0
9168 || (curwin->w_p_scr > curwin->w_height
9169 && curwin->w_height > 0))
9170 && full_screen)
9171 {
9172 if (pp == &(curwin->w_p_scr))
9173 {
9174 if (curwin->w_p_scr != 0)
9175 errmsg = e_scroll;
9176 win_comp_scroll(curwin);
9177 }
9178 /* If 'scroll' became invalid because of a side effect silently adjust
9179 * it. */
9180 else if (curwin->w_p_scr <= 0)
9181 curwin->w_p_scr = 1;
9182 else /* curwin->w_p_scr > curwin->w_height */
9183 curwin->w_p_scr = curwin->w_height;
9184 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009185 if (p_hi < 0)
9186 {
9187 errmsg = e_positive;
9188 p_hi = 0;
9189 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009190 else if (p_hi > 10000)
9191 {
9192 errmsg = e_invarg;
9193 p_hi = 10000;
9194 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009195 if (p_re < 0 || p_re > 2)
9196 {
9197 errmsg = e_invarg;
9198 p_re = 0;
9199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 if (p_report < 0)
9201 {
9202 errmsg = e_positive;
9203 p_report = 1;
9204 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009205 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 {
9207 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9208 p_sj = Rows / 2;
9209 else
9210 {
9211 errmsg = e_scroll;
9212 p_sj = 1;
9213 }
9214 }
9215 if (p_so < 0 && full_screen)
9216 {
9217 errmsg = e_scroll;
9218 p_so = 0;
9219 }
9220 if (p_siso < 0 && full_screen)
9221 {
9222 errmsg = e_positive;
9223 p_siso = 0;
9224 }
9225#ifdef FEAT_CMDWIN
9226 if (p_cwh < 1)
9227 {
9228 errmsg = e_positive;
9229 p_cwh = 1;
9230 }
9231#endif
9232 if (p_ut < 0)
9233 {
9234 errmsg = e_positive;
9235 p_ut = 2000;
9236 }
9237 if (p_ss < 0)
9238 {
9239 errmsg = e_positive;
9240 p_ss = 0;
9241 }
9242
9243 /* May set global value for local option. */
9244 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9245 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9246
9247 options[opt_idx].flags |= P_WAS_SET;
9248
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009249#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009250 if (!starting && errmsg == NULL)
9251 {
9252 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009253 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9254 vim_snprintf((char *)buf_new, 10, "%ld", value);
9255 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009256 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9257 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9258 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9259 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9260 reset_v_option_vars();
9261 }
9262#endif
9263
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009265 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009266 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009267 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268 check_redraw(options[opt_idx].flags);
9269
9270 return errmsg;
9271}
9272
9273/*
9274 * Called after an option changed: check if something needs to be redrawn.
9275 */
9276 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009277check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278{
9279 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009280 int doclear = (flags & P_RCLR) == P_RCLR;
9281 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9284 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009285
9286 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9287 changed_window_setting();
9288 if (flags & P_RBUF)
9289 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009290 if (flags & P_RWINONLY)
9291 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009292 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293 redraw_all_later(CLEAR);
9294 else if (all)
9295 redraw_all_later(NOT_VALID);
9296}
9297
9298/*
9299 * Find index for option 'arg'.
9300 * Return -1 if not found.
9301 */
9302 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009303findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304{
9305 int opt_idx;
9306 char *s, *p;
9307 static short quick_tab[27] = {0, 0}; /* quick access table */
9308 int is_term_opt;
9309
9310 /*
9311 * For first call: Initialize the quick-access table.
9312 * It contains the index for the first option that starts with a certain
9313 * letter. There are 26 letters, plus the first "t_" option.
9314 */
9315 if (quick_tab[1] == 0)
9316 {
9317 p = options[0].fullname;
9318 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9319 {
9320 if (s[0] != p[0])
9321 {
9322 if (s[0] == 't' && s[1] == '_')
9323 quick_tab[26] = opt_idx;
9324 else
9325 quick_tab[CharOrdLow(s[0])] = opt_idx;
9326 }
9327 p = s;
9328 }
9329 }
9330
9331 /*
9332 * Check for name starting with an illegal character.
9333 */
9334#ifdef EBCDIC
9335 if (!islower(arg[0]))
9336#else
9337 if (arg[0] < 'a' || arg[0] > 'z')
9338#endif
9339 return -1;
9340
9341 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9342 if (is_term_opt)
9343 opt_idx = quick_tab[26];
9344 else
9345 opt_idx = quick_tab[CharOrdLow(arg[0])];
9346 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9347 {
9348 if (STRCMP(arg, s) == 0) /* match full name */
9349 break;
9350 }
9351 if (s == NULL && !is_term_opt)
9352 {
9353 opt_idx = quick_tab[CharOrdLow(arg[0])];
9354 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9355 {
9356 s = options[opt_idx].shortname;
9357 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9358 break;
9359 s = NULL;
9360 }
9361 }
9362 if (s == NULL)
9363 opt_idx = -1;
9364 return opt_idx;
9365}
9366
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009367#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368/*
9369 * Get the value for an option.
9370 *
9371 * Returns:
9372 * Number or Toggle option: 1, *numval gets value.
9373 * String option: 0, *stringval gets allocated string.
9374 * Hidden Number or Toggle option: -1.
9375 * hidden String option: -2.
9376 * unknown option: -3.
9377 */
9378 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009379get_option_value(
9380 char_u *name,
9381 long *numval,
9382 char_u **stringval, /* NULL when only checking existence */
9383 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384{
9385 int opt_idx;
9386 char_u *varp;
9387
9388 opt_idx = findoption(name);
9389 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009390 {
9391 int key;
9392
9393 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9394 && (key = find_key_option(name)) != 0)
9395 {
9396 char_u key_name[2];
9397 char_u *p;
9398
9399 if (key < 0)
9400 {
9401 key_name[0] = KEY2TERMCAP0(key);
9402 key_name[1] = KEY2TERMCAP1(key);
9403 }
9404 else
9405 {
9406 key_name[0] = KS_KEY;
9407 key_name[1] = (key & 0xff);
9408 }
9409 p = find_termcode(key_name);
9410 if (p != NULL)
9411 {
9412 if (stringval != NULL)
9413 *stringval = vim_strsave(p);
9414 return 0;
9415 }
9416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419
9420 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9421
9422 if (options[opt_idx].flags & P_STRING)
9423 {
9424 if (varp == NULL) /* hidden option */
9425 return -2;
9426 if (stringval != NULL)
9427 {
9428#ifdef FEAT_CRYPT
9429 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009430 if ((char_u **)varp == &curbuf->b_p_key
9431 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 *stringval = vim_strsave((char_u *)"*****");
9433 else
9434#endif
9435 *stringval = vim_strsave(*(char_u **)(varp));
9436 }
9437 return 0;
9438 }
9439
9440 if (varp == NULL) /* hidden option */
9441 return -1;
9442 if (options[opt_idx].flags & P_NUM)
9443 *numval = *(long *)varp;
9444 else
9445 {
9446 /* Special case: 'modified' is b_changed, but we also want to consider
9447 * it set when 'ff' or 'fenc' changed. */
9448 if ((int *)varp == &curbuf->b_changed)
9449 *numval = curbufIsChanged();
9450 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009451 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009452 }
9453 return 1;
9454}
9455#endif
9456
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009457#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009458/*
9459 * Returns the option attributes and its value. Unlike the above function it
9460 * will return either global value or local value of the option depending on
9461 * what was requested, but it will never return global value if it was
9462 * requested to return local one and vice versa. Neither it will return
9463 * buffer-local value if it was requested to return window-local one.
9464 *
9465 * Pretends that option is absent if it is not present in the requested scope
9466 * (i.e. has no global, window-local or buffer-local value depending on
9467 * opt_type). Uses
9468 *
9469 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009470 * 0 hidden or unknown option, also option that does not have requested
9471 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009472 * see SOPT_* in vim.h for other flags
9473 *
9474 * Possible opt_type values: see SREQ_* in vim.h
9475 */
9476 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009477get_option_value_strict(
9478 char_u *name,
9479 long *numval,
9480 char_u **stringval, /* NULL when only obtaining attributes */
9481 int opt_type,
9482 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009483{
9484 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009485 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009486 struct vimoption *p;
9487 int r = 0;
9488
9489 opt_idx = findoption(name);
9490 if (opt_idx < 0)
9491 return 0;
9492
9493 p = &(options[opt_idx]);
9494
9495 /* Hidden option */
9496 if (p->var == NULL)
9497 return 0;
9498
9499 if (p->flags & P_BOOL)
9500 r |= SOPT_BOOL;
9501 else if (p->flags & P_NUM)
9502 r |= SOPT_NUM;
9503 else if (p->flags & P_STRING)
9504 r |= SOPT_STRING;
9505
9506 if (p->indir == PV_NONE)
9507 {
9508 if (opt_type == SREQ_GLOBAL)
9509 r |= SOPT_GLOBAL;
9510 else
9511 return 0; /* Did not request global-only option */
9512 }
9513 else
9514 {
9515 if (p->indir & PV_BOTH)
9516 r |= SOPT_GLOBAL;
9517 else if (opt_type == SREQ_GLOBAL)
9518 return 0; /* Requested global option */
9519
9520 if (p->indir & PV_WIN)
9521 {
9522 if (opt_type == SREQ_BUF)
9523 return 0; /* Did not request window-local option */
9524 else
9525 r |= SOPT_WIN;
9526 }
9527 else if (p->indir & PV_BUF)
9528 {
9529 if (opt_type == SREQ_WIN)
9530 return 0; /* Did not request buffer-local option */
9531 else
9532 r |= SOPT_BUF;
9533 }
9534 }
9535
9536 if (stringval == NULL)
9537 return r;
9538
9539 if (opt_type == SREQ_GLOBAL)
9540 varp = p->var;
9541 else
9542 {
9543 if (opt_type == SREQ_BUF)
9544 {
9545 /* Special case: 'modified' is b_changed, but we also want to
9546 * consider it set when 'ff' or 'fenc' changed. */
9547 if (p->indir == PV_MOD)
9548 {
9549 *numval = bufIsChanged((buf_T *) from);
9550 varp = NULL;
9551 }
9552#ifdef FEAT_CRYPT
9553 else if (p->indir == PV_KEY)
9554 {
9555 /* never return the value of the crypt key */
9556 *stringval = NULL;
9557 varp = NULL;
9558 }
9559#endif
9560 else
9561 {
9562 aco_save_T aco;
9563 aucmd_prepbuf(&aco, (buf_T *) from);
9564 varp = get_varp(p);
9565 aucmd_restbuf(&aco);
9566 }
9567 }
9568 else if (opt_type == SREQ_WIN)
9569 {
9570 win_T *save_curwin;
9571 save_curwin = curwin;
9572 curwin = (win_T *) from;
9573 curbuf = curwin->w_buffer;
9574 varp = get_varp(p);
9575 curwin = save_curwin;
9576 curbuf = curwin->w_buffer;
9577 }
9578 if (varp == p->var)
9579 return (r | SOPT_UNSET);
9580 }
9581
9582 if (varp != NULL)
9583 {
9584 if (p->flags & P_STRING)
9585 *stringval = vim_strsave(*(char_u **)(varp));
9586 else if (p->flags & P_NUM)
9587 *numval = *(long *) varp;
9588 else
9589 *numval = *(int *)varp;
9590 }
9591
9592 return r;
9593}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009594
9595/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009596 * Iterate over options. First argument is a pointer to a pointer to a
9597 * structure inside options[] array, second is option type like in the above
9598 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009599 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009600 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009601 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009602 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009603 * first argument to NULL.
9604 *
9605 * Returns full option name for current option on each call.
9606 */
9607 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009608option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009609{
9610 struct vimoption *ret = NULL;
9611 do
9612 {
9613 if (*option == NULL)
9614 *option = (void *) options;
9615 else if (((struct vimoption *) (*option))->fullname == NULL)
9616 {
9617 *option = NULL;
9618 return NULL;
9619 }
9620 else
9621 *option = (void *) (((struct vimoption *) (*option)) + 1);
9622
9623 ret = ((struct vimoption *) (*option));
9624
9625 /* Hidden option */
9626 if (ret->var == NULL)
9627 {
9628 ret = NULL;
9629 continue;
9630 }
9631
9632 switch (opt_type)
9633 {
9634 case SREQ_GLOBAL:
9635 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9636 ret = NULL;
9637 break;
9638 case SREQ_BUF:
9639 if (!(ret->indir & PV_BUF))
9640 ret = NULL;
9641 break;
9642 case SREQ_WIN:
9643 if (!(ret->indir & PV_WIN))
9644 ret = NULL;
9645 break;
9646 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009647 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009648 return NULL;
9649 }
9650 }
9651 while (ret == NULL);
9652
9653 return (char_u *)ret->fullname;
9654}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009655#endif
9656
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657/*
9658 * Set the value of option "name".
9659 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009660 *
9661 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009663 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009664set_option_value(
9665 char_u *name,
9666 long number,
9667 char_u *string,
9668 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669{
9670 int opt_idx;
9671 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009672 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673
9674 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009675 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009676 {
9677 int key;
9678
9679 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9680 && (key = find_key_option(name)) != 0)
9681 {
9682 char_u key_name[2];
9683
9684 if (key < 0)
9685 {
9686 key_name[0] = KEY2TERMCAP0(key);
9687 key_name[1] = KEY2TERMCAP1(key);
9688 }
9689 else
9690 {
9691 key_name[0] = KS_KEY;
9692 key_name[1] = (key & 0xff);
9693 }
9694 add_termcode(key_name, string, FALSE);
9695 if (full_screen)
9696 ttest(FALSE);
9697 redraw_all_later(CLEAR);
9698 return NULL;
9699 }
9700
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 else
9704 {
9705 flags = options[opt_idx].flags;
9706#ifdef HAVE_SANDBOX
9707 /* Disallow changing some options in the sandbox */
9708 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009709 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009711 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009714 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009715 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 else
9717 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009718 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719 if (varp != NULL) /* hidden option is not changed */
9720 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009721 if (number == 0 && string != NULL)
9722 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009723 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009724
9725 /* Either we are given a string or we are setting option
9726 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009727 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009728 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009729 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009730 {
9731 /* There's another character after zeros or the string
9732 * is empty. In both cases, we are trying to set a
9733 * num option using a string. */
9734 EMSG3(_("E521: Number required: &%s = '%s'"),
9735 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009736 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009737
9738 }
9739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009741 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009742 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009744 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009745 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 }
9747 }
9748 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009749 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750}
9751
9752/*
9753 * Get the terminal code for a terminal option.
9754 * Returns NULL when not found.
9755 */
9756 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009757get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758{
9759 int opt_idx;
9760 char_u *varp;
9761
9762 if (tname[0] != 't' || tname[1] != '_' ||
9763 tname[2] == NUL || tname[3] == NUL)
9764 return NULL;
9765 if ((opt_idx = findoption(tname)) >= 0)
9766 {
9767 varp = get_varp(&(options[opt_idx]));
9768 if (varp != NULL)
9769 varp = *(char_u **)(varp);
9770 return varp;
9771 }
9772 return find_termcode(tname + 2);
9773}
9774
9775 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009776get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777{
9778 int i;
9779
9780 i = findoption((char_u *)"hl");
9781 if (i >= 0)
9782 return options[i].def_val[VI_DEFAULT];
9783 return (char_u *)NULL;
9784}
9785
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009786#if defined(FEAT_MBYTE) || defined(PROTO)
9787 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009788get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009789{
9790 int i;
9791
9792 i = findoption((char_u *)"enc");
9793 if (i >= 0)
9794 return options[i].def_val[VI_DEFAULT];
9795 return (char_u *)NULL;
9796}
9797#endif
9798
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799/*
9800 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9801 */
9802 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009803find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009804{
9805 int key;
9806 int modifiers;
9807
9808 /*
9809 * Don't use get_special_key_code() for t_xx, we don't want it to call
9810 * add_termcap_entry().
9811 */
9812 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9813 key = TERMCAP2KEY(arg[2], arg[3]);
9814 else
9815 {
9816 --arg; /* put arg at the '<' */
9817 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009818 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009819 if (modifiers) /* can't handle modifiers here */
9820 key = 0;
9821 }
9822 return key;
9823}
9824
9825/*
9826 * if 'all' == 0: show changed options
9827 * if 'all' == 1: show all normal options
9828 * if 'all' == 2: show all terminal options
9829 */
9830 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009831showoptions(
9832 int all,
9833 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834{
9835 struct vimoption *p;
9836 int col;
9837 int isterm;
9838 char_u *varp;
9839 struct vimoption **items;
9840 int item_count;
9841 int run;
9842 int row, rows;
9843 int cols;
9844 int i;
9845 int len;
9846
9847#define INC 20
9848#define GAP 3
9849
9850 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9851 PARAM_COUNT));
9852 if (items == NULL)
9853 return;
9854
9855 /* Highlight title */
9856 if (all == 2)
9857 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9858 else if (opt_flags & OPT_GLOBAL)
9859 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9860 else if (opt_flags & OPT_LOCAL)
9861 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9862 else
9863 MSG_PUTS_TITLE(_("\n--- Options ---"));
9864
9865 /*
9866 * do the loop two times:
9867 * 1. display the short items
9868 * 2. display the long items (only strings and numbers)
9869 */
9870 for (run = 1; run <= 2 && !got_int; ++run)
9871 {
9872 /*
9873 * collect the items in items[]
9874 */
9875 item_count = 0;
9876 for (p = &options[0]; p->fullname != NULL; p++)
9877 {
9878 varp = NULL;
9879 isterm = istermoption(p);
9880 if (opt_flags != 0)
9881 {
9882 if (p->indir != PV_NONE && !isterm)
9883 varp = get_varp_scope(p, opt_flags);
9884 }
9885 else
9886 varp = get_varp(p);
9887 if (varp != NULL
9888 && ((all == 2 && isterm)
9889 || (all == 1 && !isterm)
9890 || (all == 0 && !optval_default(p, varp))))
9891 {
9892 if (p->flags & P_BOOL)
9893 len = 1; /* a toggle option fits always */
9894 else
9895 {
9896 option_value2string(p, opt_flags);
9897 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9898 }
9899 if ((len <= INC - GAP && run == 1) ||
9900 (len > INC - GAP && run == 2))
9901 items[item_count++] = p;
9902 }
9903 }
9904
9905 /*
9906 * display the items
9907 */
9908 if (run == 1)
9909 {
9910 cols = (Columns + GAP - 3) / INC;
9911 if (cols == 0)
9912 cols = 1;
9913 rows = (item_count + cols - 1) / cols;
9914 }
9915 else /* run == 2 */
9916 rows = item_count;
9917 for (row = 0; row < rows && !got_int; ++row)
9918 {
9919 msg_putchar('\n'); /* go to next line */
9920 if (got_int) /* 'q' typed in more */
9921 break;
9922 col = 0;
9923 for (i = row; i < item_count; i += rows)
9924 {
9925 msg_col = col; /* make columns */
9926 showoneopt(items[i], opt_flags);
9927 col += INC;
9928 }
9929 out_flush();
9930 ui_breakcheck();
9931 }
9932 }
9933 vim_free(items);
9934}
9935
9936/*
9937 * Return TRUE if option "p" has its default value.
9938 */
9939 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009940optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009941{
9942 int dvi;
9943
9944 if (varp == NULL)
9945 return TRUE; /* hidden option is always at default */
9946 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9947 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009948 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009949 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009950 /* the cast to long is required for Manx C, long_i is
9951 * needed for MSVC */
9952 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953 /* P_STRING */
9954 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9955}
9956
9957/*
9958 * showoneopt: show the value of one option
9959 * must not be called with a hidden option!
9960 */
9961 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009962showoneopt(
9963 struct vimoption *p,
9964 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009966 char_u *varp;
9967 int save_silent = silent_mode;
9968
9969 silent_mode = FALSE;
9970 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971
9972 varp = get_varp_scope(p, opt_flags);
9973
9974 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9975 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9976 ? !curbufIsChanged() : !*(int *)varp))
9977 MSG_PUTS("no");
9978 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9979 MSG_PUTS("--");
9980 else
9981 MSG_PUTS(" ");
9982 MSG_PUTS(p->fullname);
9983 if (!(p->flags & P_BOOL))
9984 {
9985 msg_putchar('=');
9986 /* put value string in NameBuff */
9987 option_value2string(p, opt_flags);
9988 msg_outtrans(NameBuff);
9989 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009990
9991 silent_mode = save_silent;
9992 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993}
9994
9995/*
9996 * Write modified options as ":set" commands to a file.
9997 *
9998 * There are three values for "opt_flags":
9999 * OPT_GLOBAL: Write global option values and fresh values of
10000 * buffer-local options (used for start of a session
10001 * file).
10002 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10003 * curwin (used for a vimrc file).
10004 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10005 * and local values for window-local options of
10006 * curwin. Local values are also written when at the
10007 * default value, because a modeline or autocommand
10008 * may have set them when doing ":edit file" and the
10009 * user has set them back at the default or fresh
10010 * value.
10011 * When "local_only" is TRUE, don't write fresh
10012 * values, only local values (for ":mkview").
10013 * (fresh value = value used for a new buffer or window for a local option).
10014 *
10015 * Return FAIL on error, OK otherwise.
10016 */
10017 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010018makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019{
10020 struct vimoption *p;
10021 char_u *varp; /* currently used value */
10022 char_u *varp_fresh; /* local value */
10023 char_u *varp_local = NULL; /* fresh value */
10024 char *cmd;
10025 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010026 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010027
10028 /*
10029 * The options that don't have a default (terminal name, columns, lines)
10030 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010031 * Do the loop over "options[]" twice: once for options with the
10032 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010034 for (pri = 1; pri >= 0; --pri)
10035 {
10036 for (p = &options[0]; !istermoption(p); p++)
10037 if (!(p->flags & P_NO_MKRC)
10038 && !istermoption(p)
10039 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040 {
10041 /* skip global option when only doing locals */
10042 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10043 continue;
10044
10045 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10046 * file, they are always buffer-specific. */
10047 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10048 continue;
10049
10050 /* Global values are only written when not at the default value. */
10051 varp = get_varp_scope(p, opt_flags);
10052 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10053 continue;
10054
10055 round = 2;
10056 if (p->indir != PV_NONE)
10057 {
10058 if (p->var == VAR_WIN)
10059 {
10060 /* skip window-local option when only doing globals */
10061 if (!(opt_flags & OPT_LOCAL))
10062 continue;
10063 /* When fresh value of window-local option is not at the
10064 * default, need to write it too. */
10065 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10066 {
10067 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10068 if (!optval_default(p, varp_fresh))
10069 {
10070 round = 1;
10071 varp_local = varp;
10072 varp = varp_fresh;
10073 }
10074 }
10075 }
10076 }
10077
10078 /* Round 1: fresh value for window-local options.
10079 * Round 2: other values */
10080 for ( ; round <= 2; varp = varp_local, ++round)
10081 {
10082 if (round == 1 || (opt_flags & OPT_GLOBAL))
10083 cmd = "set";
10084 else
10085 cmd = "setlocal";
10086
10087 if (p->flags & P_BOOL)
10088 {
10089 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10090 return FAIL;
10091 }
10092 else if (p->flags & P_NUM)
10093 {
10094 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10095 return FAIL;
10096 }
10097 else /* P_STRING */
10098 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010099 int do_endif = FALSE;
10100
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 /* Don't set 'syntax' and 'filetype' again if the value is
10102 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010103 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010104#if defined(FEAT_SYN_HL)
10105 p->indir == PV_SYN ||
10106#endif
10107 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010108 {
10109 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10110 *(char_u **)(varp)) < 0
10111 || put_eol(fd) < 0)
10112 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010113 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114 }
10115 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10116 (p->flags & P_EXPAND) != 0) == FAIL)
10117 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010118 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119 {
10120 if (put_line(fd, "endif") == FAIL)
10121 return FAIL;
10122 }
10123 }
10124 }
10125 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 return OK;
10128}
10129
10130#if defined(FEAT_FOLDING) || defined(PROTO)
10131/*
10132 * Generate set commands for the local fold options only. Used when
10133 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10134 */
10135 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010136makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137{
10138 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10139# ifdef FEAT_EVAL
10140 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10141 == FAIL
10142# endif
10143 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10144 == FAIL
10145 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10146 == FAIL
10147 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10148 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10149 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10150 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10151 )
10152 return FAIL;
10153
10154 return OK;
10155}
10156#endif
10157
10158 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010159put_setstring(
10160 FILE *fd,
10161 char *cmd,
10162 char *name,
10163 char_u **valuep,
10164 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165{
10166 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010167 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168
10169 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10170 return FAIL;
10171 if (*valuep != NULL)
10172 {
10173 /* Output 'pastetoggle' as key names. For other
10174 * options some characters have to be escaped with
10175 * CTRL-V or backslash */
10176 if (valuep == &p_pt)
10177 {
10178 s = *valuep;
10179 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010180 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181 return FAIL;
10182 }
10183 else if (expand)
10184 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010185 buf = alloc(MAXPATHL);
10186 if (buf == NULL)
10187 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10189 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010190 {
10191 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010193 }
10194 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 }
10196 else if (put_escstr(fd, *valuep, 2) == FAIL)
10197 return FAIL;
10198 }
10199 if (put_eol(fd) < 0)
10200 return FAIL;
10201 return OK;
10202}
10203
10204 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010205put_setnum(
10206 FILE *fd,
10207 char *cmd,
10208 char *name,
10209 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210{
10211 long wc;
10212
10213 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10214 return FAIL;
10215 if (wc_use_keyname((char_u *)valuep, &wc))
10216 {
10217 /* print 'wildchar' and 'wildcharm' as a key name */
10218 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10219 return FAIL;
10220 }
10221 else if (fprintf(fd, "%ld", *valuep) < 0)
10222 return FAIL;
10223 if (put_eol(fd) < 0)
10224 return FAIL;
10225 return OK;
10226}
10227
10228 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010229put_setbool(
10230 FILE *fd,
10231 char *cmd,
10232 char *name,
10233 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234{
Bram Moolenaar893de922007-10-02 18:40:57 +000010235 if (value < 0) /* global/local option using global value */
10236 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10238 || put_eol(fd) < 0)
10239 return FAIL;
10240 return OK;
10241}
10242
10243/*
10244 * Clear all the terminal options.
10245 * If the option has been allocated, free the memory.
10246 * Terminal options are never hidden or indirect.
10247 */
10248 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010249clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251 /*
10252 * Reset a few things before clearing the old options. This may cause
10253 * outputting a few things that the terminal doesn't understand, but the
10254 * screen will be cleared later, so this is OK.
10255 */
10256#ifdef FEAT_MOUSE_TTY
10257 mch_setmouse(FALSE); /* switch mouse off */
10258#endif
10259#ifdef FEAT_TITLE
10260 mch_restore_title(3); /* restore window titles */
10261#endif
10262#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10263 /* When starting the GUI close the display opened for the clipboard.
10264 * After restoring the title, because that will need the display. */
10265 if (gui.starting)
10266 clear_xterm_clip();
10267#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010268 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010270 free_termoptions();
10271}
10272
10273 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010274free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010275{
10276 struct vimoption *p;
10277
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278 for (p = &options[0]; p->fullname != NULL; p++)
10279 if (istermoption(p))
10280 {
10281 if (p->flags & P_ALLOCED)
10282 free_string_option(*(char_u **)(p->var));
10283 if (p->flags & P_DEF_ALLOCED)
10284 free_string_option(p->def_val[VI_DEFAULT]);
10285 *(char_u **)(p->var) = empty_option;
10286 p->def_val[VI_DEFAULT] = empty_option;
10287 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10288 }
10289 clear_termcodes();
10290}
10291
10292/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010293 * Free the string for one term option, if it was allocated.
10294 * Set the string to empty_option and clear allocated flag.
10295 * "var" points to the option value.
10296 */
10297 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010298free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010299{
10300 struct vimoption *p;
10301
10302 for (p = &options[0]; p->fullname != NULL; p++)
10303 if (p->var == var)
10304 {
10305 if (p->flags & P_ALLOCED)
10306 free_string_option(*(char_u **)(p->var));
10307 *(char_u **)(p->var) = empty_option;
10308 p->flags &= ~P_ALLOCED;
10309 break;
10310 }
10311}
10312
10313/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 * Set the terminal option defaults to the current value.
10315 * Used after setting the terminal name.
10316 */
10317 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010318set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319{
10320 struct vimoption *p;
10321
10322 for (p = &options[0]; p->fullname != NULL; p++)
10323 {
10324 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10325 {
10326 if (p->flags & P_DEF_ALLOCED)
10327 {
10328 free_string_option(p->def_val[VI_DEFAULT]);
10329 p->flags &= ~P_DEF_ALLOCED;
10330 }
10331 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10332 if (p->flags & P_ALLOCED)
10333 {
10334 p->flags |= P_DEF_ALLOCED;
10335 p->flags &= ~P_ALLOCED; /* don't free the value now */
10336 }
10337 }
10338 }
10339}
10340
10341/*
10342 * return TRUE if 'p' starts with 't_'
10343 */
10344 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010345istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346{
10347 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10348}
10349
10350/*
10351 * Compute columns for ruler and shown command. 'sc_col' is also used to
10352 * decide what the maximum length of a message on the status line can be.
10353 * If there is a status line for the last window, 'sc_col' is independent
10354 * of 'ru_col'.
10355 */
10356
10357#define COL_RULER 17 /* columns needed by standard ruler */
10358
10359 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010360comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010362#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010363 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010364
10365 sc_col = 0;
10366 ru_col = 0;
10367 if (p_ru)
10368 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010369# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010371# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010373# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010374 /* no last status line, adjust sc_col */
10375 if (!last_has_status)
10376 sc_col = ru_col;
10377 }
10378 if (p_sc)
10379 {
10380 sc_col += SHOWCMD_COLS;
10381 if (!p_ru || last_has_status) /* no need for separating space */
10382 ++sc_col;
10383 }
10384 sc_col = Columns - sc_col;
10385 ru_col = Columns - ru_col;
10386 if (sc_col <= 0) /* screen too narrow, will become a mess */
10387 sc_col = 1;
10388 if (ru_col <= 0)
10389 ru_col = 1;
10390#else
10391 sc_col = Columns;
10392 ru_col = Columns;
10393#endif
10394}
10395
10396/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 * Unset local option value, similar to ":set opt<".
10398 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010399 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010400unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010401{
10402 struct vimoption *p;
10403 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010404 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405
10406 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010407 if (opt_idx < 0)
10408 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 p = &(options[opt_idx]);
10410
10411 switch ((int)p->indir)
10412 {
10413 /* global option with local value: use local value if it's been set */
10414 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010415 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010416 break;
10417 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
10420 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010421 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010422 break;
10423 case PV_AR:
10424 buf->b_p_ar = -1;
10425 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010426 case PV_BKC:
10427 clear_string_option(&buf->b_p_bkc);
10428 buf->b_bkc_flags = 0;
10429 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010430 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010431 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010432 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010433 case PV_TC:
10434 clear_string_option(&buf->b_p_tc);
10435 buf->b_tc_flags = 0;
10436 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010437#ifdef FEAT_FIND_ID
10438 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010439 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010440 break;
10441 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010442 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010443 break;
10444#endif
10445#ifdef FEAT_INS_EXPAND
10446 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010447 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010448 break;
10449 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010450 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010451 break;
10452#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010453 case PV_FP:
10454 clear_string_option(&buf->b_p_fp);
10455 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456#ifdef FEAT_QUICKFIX
10457 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010458 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010459 break;
10460 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010461 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462 break;
10463 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010464 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010465 break;
10466#endif
10467#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10468 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010469 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010470 break;
10471#endif
10472#if defined(FEAT_CRYPT)
10473 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010474 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010475 break;
10476#endif
10477#ifdef FEAT_STL_OPT
10478 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010479 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010480 break;
10481#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010482 case PV_UL:
10483 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10484 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010485#ifdef FEAT_LISP
10486 case PV_LW:
10487 clear_string_option(&buf->b_p_lw);
10488 break;
10489#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010490#ifdef FEAT_MBYTE
10491 case PV_MENC:
10492 clear_string_option(&buf->b_p_menc);
10493 break;
10494#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010495 }
10496}
10497
10498/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 * Get pointer to option variable, depending on local or global scope.
10500 */
10501 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010502get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503{
10504 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10505 {
10506 if (p->var == VAR_WIN)
10507 return (char_u *)GLOBAL_WO(get_varp(p));
10508 return p->var;
10509 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010510 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 {
10512 switch ((int)p->indir)
10513 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010514 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010516 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10517 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10518 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010520 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10521 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10522 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010523 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010524 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010525 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010527 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10528 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529#endif
10530#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10532 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010534#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10535 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10536#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010537#if defined(FEAT_CRYPT)
10538 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10539#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010540#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010542#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010543 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010544#ifdef FEAT_LISP
10545 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10546#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010547 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010548#ifdef FEAT_MBYTE
10549 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 }
10552 return NULL; /* "cannot happen" */
10553 }
10554 return get_varp(p);
10555}
10556
10557/*
10558 * Get pointer to option variable.
10559 */
10560 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010561get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562{
10563 /* hidden option, always return NULL */
10564 if (p->var == NULL)
10565 return NULL;
10566
10567 switch ((int)p->indir)
10568 {
10569 case PV_NONE: return p->var;
10570
10571 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010572 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010574 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010576 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010578 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010580 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010582 case PV_TC: return *curbuf->b_p_tc != NUL
10583 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010584 case PV_BKC: return *curbuf->b_p_bkc != NUL
10585 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010587 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010589 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10591#endif
10592#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010593 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010595 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10597#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010598 case PV_FP: return *curbuf->b_p_fp != NUL
10599 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010601 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010603 case PV_GP: return *curbuf->b_p_gp != NUL
10604 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10605 case PV_MP: return *curbuf->b_p_mp != NUL
10606 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010608#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10609 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10610 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10611#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010612#if defined(FEAT_CRYPT)
10613 case PV_CM: return *curbuf->b_p_cm != NUL
10614 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10615#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010616#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010617 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010618 ? (char_u *)&(curwin->w_p_stl) : p->var;
10619#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010620 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10621 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010622#ifdef FEAT_LISP
10623 case PV_LW: return *curbuf->b_p_lw != NUL
10624 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10625#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010626#ifdef FEAT_MBYTE
10627 case PV_MENC: return *curbuf->b_p_menc != NUL
10628 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630
10631#ifdef FEAT_ARABIC
10632 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10633#endif
10634 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010635#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010636 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10637#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010638#ifdef FEAT_SYN_HL
10639 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10640 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010641 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643#ifdef FEAT_DIFF
10644 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10645#endif
10646#ifdef FEAT_FOLDING
10647 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10648 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10649 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10650 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10651 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10652 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10653 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10654# ifdef FEAT_EVAL
10655 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10656 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10657# endif
10658 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10659#endif
10660 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010661 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010662#ifdef FEAT_LINEBREAK
10663 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010666 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010667#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10669#endif
10670#ifdef FEAT_RIGHTLEFT
10671 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10672 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10673#endif
10674 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10675 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10676#ifdef FEAT_LINEBREAK
10677 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010678 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10679 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010682 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010683#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010684 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10685 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10686#endif
10687#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010688 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010689 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691
10692 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10693 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10694#ifdef FEAT_MBYTE
10695 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10696#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10698 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10700 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10701#ifdef FEAT_CINDENT
10702 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10703 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10704 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10705#endif
10706#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10707 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10708#endif
10709#ifdef FEAT_COMMENTS
10710 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10711#endif
10712#ifdef FEAT_FOLDING
10713 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10714#endif
10715#ifdef FEAT_INS_EXPAND
10716 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10717#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010718#ifdef FEAT_COMPL_FUNC
10719 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010720 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010721#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010723 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10725#ifdef FEAT_MBYTE
10726 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10727#endif
10728 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010731 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10733 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10734 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10735 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10736#ifdef FEAT_FIND_ID
10737# ifdef FEAT_EVAL
10738 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10739# endif
10740#endif
10741#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10742 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10743 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10744#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010745#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010746 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10747#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#ifdef FEAT_CRYPT
10749 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10750#endif
10751#ifdef FEAT_LISP
10752 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10753#endif
10754 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10755 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10756 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10757 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10758 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010760#ifdef FEAT_TEXTOBJ
10761 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10764#ifdef FEAT_SMARTINDENT
10765 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10769#ifdef FEAT_SEARCHPATH
10770 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10771#endif
10772 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10773#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010774 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010775 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10776#endif
10777#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010778 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10779 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10780 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781#endif
10782 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10783 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10784 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10785 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010786#ifdef FEAT_PERSISTENT_UNDO
10787 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10790#ifdef FEAT_KEYMAP
10791 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10792#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010793#ifdef FEAT_SIGNS
10794 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10795#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010796 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 }
10798 /* always return a valid pointer to avoid a crash! */
10799 return (char_u *)&(curbuf->b_p_wm);
10800}
10801
10802/*
10803 * Get the value of 'equalprg', either the buffer-local one or the global one.
10804 */
10805 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010806get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807{
10808 if (*curbuf->b_p_ep == NUL)
10809 return p_ep;
10810 return curbuf->b_p_ep;
10811}
10812
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813/*
10814 * Copy options from one window to another.
10815 * Used when splitting a window.
10816 */
10817 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010818win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819{
10820 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10821 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10822# ifdef FEAT_RIGHTLEFT
10823# ifdef FEAT_FKMAP
10824 /* Is this right? */
10825 wp_to->w_farsi = wp_from->w_farsi;
10826# endif
10827# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010828#if defined(FEAT_LINEBREAK)
10829 briopt_check(wp_to);
10830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832
10833/*
10834 * Copy the options from one winopt_T to another.
10835 * Doesn't free the old option values in "to", use clear_winopt() for that.
10836 * The 'scroll' option is not copied, because it depends on the window height.
10837 * The 'previewwindow' option is reset, there can be only one preview window.
10838 */
10839 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010840copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841{
10842#ifdef FEAT_ARABIC
10843 to->wo_arab = from->wo_arab;
10844#endif
10845 to->wo_list = from->wo_list;
10846 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010847 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010848#ifdef FEAT_LINEBREAK
10849 to->wo_nuw = from->wo_nuw;
10850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851#ifdef FEAT_RIGHTLEFT
10852 to->wo_rl = from->wo_rl;
10853 to->wo_rlc = vim_strsave(from->wo_rlc);
10854#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010855#ifdef FEAT_STL_OPT
10856 to->wo_stl = vim_strsave(from->wo_stl);
10857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010859#ifdef FEAT_DIFF
10860 to->wo_wrap_save = from->wo_wrap_save;
10861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862#ifdef FEAT_LINEBREAK
10863 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010864 to->wo_bri = from->wo_bri;
10865 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010868 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010869 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010870 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010871#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010872 to->wo_spell = from->wo_spell;
10873#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010874#ifdef FEAT_SYN_HL
10875 to->wo_cuc = from->wo_cuc;
10876 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010877 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879#ifdef FEAT_DIFF
10880 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010881 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010883#ifdef FEAT_CONCEAL
10884 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010885 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010886#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010887#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010888 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010889 to->wo_tms = vim_strsave(from->wo_tms);
10890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891#ifdef FEAT_FOLDING
10892 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010893 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010895 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896 to->wo_fdi = vim_strsave(from->wo_fdi);
10897 to->wo_fml = from->wo_fml;
10898 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010899 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010901 to->wo_fdm_save = from->wo_diff_saved
10902 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010903 to->wo_fdn = from->wo_fdn;
10904# ifdef FEAT_EVAL
10905 to->wo_fde = vim_strsave(from->wo_fde);
10906 to->wo_fdt = vim_strsave(from->wo_fdt);
10907# endif
10908 to->wo_fmr = vim_strsave(from->wo_fmr);
10909#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010910#ifdef FEAT_SIGNS
10911 to->wo_scl = vim_strsave(from->wo_scl);
10912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 check_winopt(to); /* don't want NULL pointers */
10914}
10915
10916/*
10917 * Check string options in a window for a NULL value.
10918 */
10919 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010920check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921{
10922 check_winopt(&win->w_onebuf_opt);
10923 check_winopt(&win->w_allbuf_opt);
10924}
10925
10926/*
10927 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10928 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010929 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010930check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931{
10932#ifdef FEAT_FOLDING
10933 check_string_option(&wop->wo_fdi);
10934 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010935 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936# ifdef FEAT_EVAL
10937 check_string_option(&wop->wo_fde);
10938 check_string_option(&wop->wo_fdt);
10939# endif
10940 check_string_option(&wop->wo_fmr);
10941#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010942#ifdef FEAT_SIGNS
10943 check_string_option(&wop->wo_scl);
10944#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945#ifdef FEAT_RIGHTLEFT
10946 check_string_option(&wop->wo_rlc);
10947#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010948#ifdef FEAT_STL_OPT
10949 check_string_option(&wop->wo_stl);
10950#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010951#ifdef FEAT_SYN_HL
10952 check_string_option(&wop->wo_cc);
10953#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010954#ifdef FEAT_CONCEAL
10955 check_string_option(&wop->wo_cocu);
10956#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010957#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010958 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010959 check_string_option(&wop->wo_tms);
10960#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010961#ifdef FEAT_LINEBREAK
10962 check_string_option(&wop->wo_briopt);
10963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010964}
10965
10966/*
10967 * Free the allocated memory inside a winopt_T.
10968 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010970clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971{
10972#ifdef FEAT_FOLDING
10973 clear_string_option(&wop->wo_fdi);
10974 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010975 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976# ifdef FEAT_EVAL
10977 clear_string_option(&wop->wo_fde);
10978 clear_string_option(&wop->wo_fdt);
10979# endif
10980 clear_string_option(&wop->wo_fmr);
10981#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010982#ifdef FEAT_SIGNS
10983 clear_string_option(&wop->wo_scl);
10984#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010985#ifdef FEAT_LINEBREAK
10986 clear_string_option(&wop->wo_briopt);
10987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988#ifdef FEAT_RIGHTLEFT
10989 clear_string_option(&wop->wo_rlc);
10990#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010991#ifdef FEAT_STL_OPT
10992 clear_string_option(&wop->wo_stl);
10993#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010994#ifdef FEAT_SYN_HL
10995 clear_string_option(&wop->wo_cc);
10996#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010997#ifdef FEAT_CONCEAL
10998 clear_string_option(&wop->wo_cocu);
10999#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011000#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011001 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011002 clear_string_option(&wop->wo_tms);
11003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004}
11005
11006/*
11007 * Copy global option values to local options for one buffer.
11008 * Used when creating a new buffer and sometimes when entering a buffer.
11009 * flags:
11010 * BCO_ENTER We will enter the buf buffer.
11011 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11012 * appropriate.
11013 * BCO_NOHELP Don't copy the values to a help buffer.
11014 */
11015 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011016buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017{
11018 int should_copy = TRUE;
11019 char_u *save_p_isk = NULL; /* init for GCC */
11020 int dont_do_help;
11021 int did_isk = FALSE;
11022
11023 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024 * Skip this when the option defaults have not been set yet. Happens when
11025 * main() allocates the first buffer.
11026 */
11027 if (p_cpo != NULL)
11028 {
11029 /*
11030 * Always copy when entering and 'cpo' contains 'S'.
11031 * Don't copy when already initialized.
11032 * Don't copy when 'cpo' contains 's' and not entering.
11033 * 'S' BCO_ENTER initialized 's' should_copy
11034 * yes yes X X TRUE
11035 * yes no yes X FALSE
11036 * no X yes X FALSE
11037 * X no no yes FALSE
11038 * X no no no TRUE
11039 * no yes no X TRUE
11040 */
11041 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11042 && (buf->b_p_initialized
11043 || (!(flags & BCO_ENTER)
11044 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11045 should_copy = FALSE;
11046
11047 if (should_copy || (flags & BCO_ALWAYS))
11048 {
11049 /* Don't copy the options specific to a help buffer when
11050 * BCO_NOHELP is given or the options were initialized already
11051 * (jumping back to a help file with CTRL-T or CTRL-O) */
11052 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11053 || buf->b_p_initialized;
11054 if (dont_do_help) /* don't free b_p_isk */
11055 {
11056 save_p_isk = buf->b_p_isk;
11057 buf->b_p_isk = NULL;
11058 }
11059 /*
11060 * Always free the allocated strings.
11061 * If not already initialized, set 'readonly' and copy 'fileformat'.
11062 */
11063 if (!buf->b_p_initialized)
11064 {
11065 free_buf_options(buf, TRUE);
11066 buf->b_p_ro = FALSE; /* don't copy readonly */
11067 buf->b_p_tx = p_tx;
11068#ifdef FEAT_MBYTE
11069 buf->b_p_fenc = vim_strsave(p_fenc);
11070#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011071 switch (*p_ffs)
11072 {
11073 case 'm':
11074 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11075 case 'd':
11076 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11077 case 'u':
11078 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11079 default:
11080 buf->b_p_ff = vim_strsave(p_ff);
11081 }
11082 if (buf->b_p_ff != NULL)
11083 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084 buf->b_p_bh = empty_option;
11085 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086 }
11087 else
11088 free_buf_options(buf, FALSE);
11089
11090 buf->b_p_ai = p_ai;
11091 buf->b_p_ai_nopaste = p_ai_nopaste;
11092 buf->b_p_sw = p_sw;
11093 buf->b_p_tw = p_tw;
11094 buf->b_p_tw_nopaste = p_tw_nopaste;
11095 buf->b_p_tw_nobin = p_tw_nobin;
11096 buf->b_p_wm = p_wm;
11097 buf->b_p_wm_nopaste = p_wm_nopaste;
11098 buf->b_p_wm_nobin = p_wm_nobin;
11099 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011100#ifdef FEAT_MBYTE
11101 buf->b_p_bomb = p_bomb;
11102#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011103 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 buf->b_p_et = p_et;
11105 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011106 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107 buf->b_p_ml = p_ml;
11108 buf->b_p_ml_nobin = p_ml_nobin;
11109 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011110 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111#ifdef FEAT_INS_EXPAND
11112 buf->b_p_cpt = vim_strsave(p_cpt);
11113#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011114#ifdef FEAT_COMPL_FUNC
11115 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011116 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 buf->b_p_sts = p_sts;
11119 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121#ifdef FEAT_COMMENTS
11122 buf->b_p_com = vim_strsave(p_com);
11123#endif
11124#ifdef FEAT_FOLDING
11125 buf->b_p_cms = vim_strsave(p_cms);
11126#endif
11127 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011128 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 buf->b_p_nf = vim_strsave(p_nf);
11130 buf->b_p_mps = vim_strsave(p_mps);
11131#ifdef FEAT_SMARTINDENT
11132 buf->b_p_si = p_si;
11133#endif
11134 buf->b_p_ci = p_ci;
11135#ifdef FEAT_CINDENT
11136 buf->b_p_cin = p_cin;
11137 buf->b_p_cink = vim_strsave(p_cink);
11138 buf->b_p_cino = vim_strsave(p_cino);
11139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 /* Don't copy 'filetype', it must be detected */
11141 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142 buf->b_p_pi = p_pi;
11143#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11144 buf->b_p_cinw = vim_strsave(p_cinw);
11145#endif
11146#ifdef FEAT_LISP
11147 buf->b_p_lisp = p_lisp;
11148#endif
11149#ifdef FEAT_SYN_HL
11150 /* Don't copy 'syntax', it must be set */
11151 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011152 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011153 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011154#endif
11155#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011156 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011157 (void)compile_cap_prog(&buf->b_s);
11158 buf->b_s.b_p_spf = vim_strsave(p_spf);
11159 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160#endif
11161#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11162 buf->b_p_inde = vim_strsave(p_inde);
11163 buf->b_p_indk = vim_strsave(p_indk);
11164#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011165 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011166#if defined(FEAT_EVAL)
11167 buf->b_p_fex = vim_strsave(p_fex);
11168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169#ifdef FEAT_CRYPT
11170 buf->b_p_key = vim_strsave(p_key);
11171#endif
11172#ifdef FEAT_SEARCHPATH
11173 buf->b_p_sua = vim_strsave(p_sua);
11174#endif
11175#ifdef FEAT_KEYMAP
11176 buf->b_p_keymap = vim_strsave(p_keymap);
11177 buf->b_kmap_state |= KEYMAP_INIT;
11178#endif
11179 /* This isn't really an option, but copying the langmap and IME
11180 * state from the current buffer is better than resetting it. */
11181 buf->b_p_iminsert = p_iminsert;
11182 buf->b_p_imsearch = p_imsearch;
11183
11184 /* options that are normally global but also have a local value
11185 * are not copied, start using the global value */
11186 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011187 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011188 buf->b_p_bkc = empty_option;
11189 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190#ifdef FEAT_QUICKFIX
11191 buf->b_p_gp = empty_option;
11192 buf->b_p_mp = empty_option;
11193 buf->b_p_efm = empty_option;
11194#endif
11195 buf->b_p_ep = empty_option;
11196 buf->b_p_kp = empty_option;
11197 buf->b_p_path = empty_option;
11198 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011199 buf->b_p_tc = empty_option;
11200 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201#ifdef FEAT_FIND_ID
11202 buf->b_p_def = empty_option;
11203 buf->b_p_inc = empty_option;
11204# ifdef FEAT_EVAL
11205 buf->b_p_inex = vim_strsave(p_inex);
11206# endif
11207#endif
11208#ifdef FEAT_INS_EXPAND
11209 buf->b_p_dict = empty_option;
11210 buf->b_p_tsr = empty_option;
11211#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011212#ifdef FEAT_TEXTOBJ
11213 buf->b_p_qe = vim_strsave(p_qe);
11214#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011215#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11216 buf->b_p_bexpr = empty_option;
11217#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011218#if defined(FEAT_CRYPT)
11219 buf->b_p_cm = empty_option;
11220#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011221#ifdef FEAT_PERSISTENT_UNDO
11222 buf->b_p_udf = p_udf;
11223#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011224#ifdef FEAT_LISP
11225 buf->b_p_lw = empty_option;
11226#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011227#ifdef FEAT_MBYTE
11228 buf->b_p_menc = empty_option;
11229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230
11231 /*
11232 * Don't copy the options set by ex_help(), use the saved values,
11233 * when going from a help buffer to a non-help buffer.
11234 * Don't touch these at all when BCO_NOHELP is used and going from
11235 * or to a help buffer.
11236 */
11237 if (dont_do_help)
11238 buf->b_p_isk = save_p_isk;
11239 else
11240 {
11241 buf->b_p_isk = vim_strsave(p_isk);
11242 did_isk = TRUE;
11243 buf->b_p_ts = p_ts;
11244 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 if (buf->b_p_bt[0] == 'h')
11246 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 buf->b_p_ma = p_ma;
11248 }
11249 }
11250
11251 /*
11252 * When the options should be copied (ignoring BCO_ALWAYS), set the
11253 * flag that indicates that the options have been initialized.
11254 */
11255 if (should_copy)
11256 buf->b_p_initialized = TRUE;
11257 }
11258
11259 check_buf_options(buf); /* make sure we don't have NULLs */
11260 if (did_isk)
11261 (void)buf_init_chartab(buf, FALSE);
11262}
11263
11264/*
11265 * Reset the 'modifiable' option and its default value.
11266 */
11267 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011268reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269{
11270 int opt_idx;
11271
11272 curbuf->b_p_ma = FALSE;
11273 p_ma = FALSE;
11274 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011275 if (opt_idx >= 0)
11276 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277}
11278
11279/*
11280 * Set the global value for 'iminsert' to the local value.
11281 */
11282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011283set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284{
11285 p_iminsert = curbuf->b_p_iminsert;
11286}
11287
11288/*
11289 * Set the global value for 'imsearch' to the local value.
11290 */
11291 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011292set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293{
11294 p_imsearch = curbuf->b_p_imsearch;
11295}
11296
11297#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11298static int expand_option_idx = -1;
11299static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11300static int expand_option_flags = 0;
11301
11302 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011303set_context_in_set_cmd(
11304 expand_T *xp,
11305 char_u *arg,
11306 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011307{
11308 int nextchar;
11309 long_u flags = 0; /* init for GCC */
11310 int opt_idx = 0; /* init for GCC */
11311 char_u *p;
11312 char_u *s;
11313 int is_term_option = FALSE;
11314 int key;
11315
11316 expand_option_flags = opt_flags;
11317
11318 xp->xp_context = EXPAND_SETTINGS;
11319 if (*arg == NUL)
11320 {
11321 xp->xp_pattern = arg;
11322 return;
11323 }
11324 p = arg + STRLEN(arg) - 1;
11325 if (*p == ' ' && *(p - 1) != '\\')
11326 {
11327 xp->xp_pattern = p + 1;
11328 return;
11329 }
11330 while (p > arg)
11331 {
11332 s = p;
11333 /* count number of backslashes before ' ' or ',' */
11334 if (*p == ' ' || *p == ',')
11335 {
11336 while (s > arg && *(s - 1) == '\\')
11337 --s;
11338 }
11339 /* break at a space with an even number of backslashes */
11340 if (*p == ' ' && ((p - s) & 1) == 0)
11341 {
11342 ++p;
11343 break;
11344 }
11345 --p;
11346 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011347 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348 {
11349 xp->xp_context = EXPAND_BOOL_SETTINGS;
11350 p += 2;
11351 }
11352 if (STRNCMP(p, "inv", 3) == 0)
11353 {
11354 xp->xp_context = EXPAND_BOOL_SETTINGS;
11355 p += 3;
11356 }
11357 xp->xp_pattern = arg = p;
11358 if (*arg == '<')
11359 {
11360 while (*p != '>')
11361 if (*p++ == NUL) /* expand terminal option name */
11362 return;
11363 key = get_special_key_code(arg + 1);
11364 if (key == 0) /* unknown name */
11365 {
11366 xp->xp_context = EXPAND_NOTHING;
11367 return;
11368 }
11369 nextchar = *++p;
11370 is_term_option = TRUE;
11371 expand_option_name[2] = KEY2TERMCAP0(key);
11372 expand_option_name[3] = KEY2TERMCAP1(key);
11373 }
11374 else
11375 {
11376 if (p[0] == 't' && p[1] == '_')
11377 {
11378 p += 2;
11379 if (*p != NUL)
11380 ++p;
11381 if (*p == NUL)
11382 return; /* expand option name */
11383 nextchar = *++p;
11384 is_term_option = TRUE;
11385 expand_option_name[2] = p[-2];
11386 expand_option_name[3] = p[-1];
11387 }
11388 else
11389 {
11390 /* Allow * wildcard */
11391 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11392 p++;
11393 if (*p == NUL)
11394 return;
11395 nextchar = *p;
11396 *p = NUL;
11397 opt_idx = findoption(arg);
11398 *p = nextchar;
11399 if (opt_idx == -1 || options[opt_idx].var == NULL)
11400 {
11401 xp->xp_context = EXPAND_NOTHING;
11402 return;
11403 }
11404 flags = options[opt_idx].flags;
11405 if (flags & P_BOOL)
11406 {
11407 xp->xp_context = EXPAND_NOTHING;
11408 return;
11409 }
11410 }
11411 }
11412 /* handle "-=" and "+=" */
11413 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11414 {
11415 ++p;
11416 nextchar = '=';
11417 }
11418 if ((nextchar != '=' && nextchar != ':')
11419 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11420 {
11421 xp->xp_context = EXPAND_UNSUCCESSFUL;
11422 return;
11423 }
11424 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11425 {
11426 xp->xp_context = EXPAND_OLD_SETTING;
11427 if (is_term_option)
11428 expand_option_idx = -1;
11429 else
11430 expand_option_idx = opt_idx;
11431 xp->xp_pattern = p + 1;
11432 return;
11433 }
11434 xp->xp_context = EXPAND_NOTHING;
11435 if (is_term_option || (flags & P_NUM))
11436 return;
11437
11438 xp->xp_pattern = p + 1;
11439
11440 if (flags & P_EXPAND)
11441 {
11442 p = options[opt_idx].var;
11443 if (p == (char_u *)&p_bdir
11444 || p == (char_u *)&p_dir
11445 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011446 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011447 || p == (char_u *)&p_rtp
11448#ifdef FEAT_SEARCHPATH
11449 || p == (char_u *)&p_cdpath
11450#endif
11451#ifdef FEAT_SESSION
11452 || p == (char_u *)&p_vdir
11453#endif
11454 )
11455 {
11456 xp->xp_context = EXPAND_DIRECTORIES;
11457 if (p == (char_u *)&p_path
11458#ifdef FEAT_SEARCHPATH
11459 || p == (char_u *)&p_cdpath
11460#endif
11461 )
11462 xp->xp_backslash = XP_BS_THREE;
11463 else
11464 xp->xp_backslash = XP_BS_ONE;
11465 }
11466 else
11467 {
11468 xp->xp_context = EXPAND_FILES;
11469 /* for 'tags' need three backslashes for a space */
11470 if (p == (char_u *)&p_tags)
11471 xp->xp_backslash = XP_BS_THREE;
11472 else
11473 xp->xp_backslash = XP_BS_ONE;
11474 }
11475 }
11476
11477 /* For an option that is a list of file names, find the start of the
11478 * last file name. */
11479 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11480 {
11481 /* count number of backslashes before ' ' or ',' */
11482 if (*p == ' ' || *p == ',')
11483 {
11484 s = p;
11485 while (s > xp->xp_pattern && *(s - 1) == '\\')
11486 --s;
11487 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11488 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11489 {
11490 xp->xp_pattern = p + 1;
11491 break;
11492 }
11493 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011494
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011495#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011496 /* for 'spellsuggest' start at "file:" */
11497 if (options[opt_idx].var == (char_u *)&p_sps
11498 && STRNCMP(p, "file:", 5) == 0)
11499 {
11500 xp->xp_pattern = p + 5;
11501 break;
11502 }
11503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011504 }
11505
11506 return;
11507}
11508
11509 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011510ExpandSettings(
11511 expand_T *xp,
11512 regmatch_T *regmatch,
11513 int *num_file,
11514 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515{
11516 int num_normal = 0; /* Nr of matching non-term-code settings */
11517 int num_term = 0; /* Nr of matching terminal code settings */
11518 int opt_idx;
11519 int match;
11520 int count = 0;
11521 char_u *str;
11522 int loop;
11523 int is_term_opt;
11524 char_u name_buf[MAX_KEY_NAME_LEN];
11525 static char *(names[]) = {"all", "termcap"};
11526 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11527
11528 /* do this loop twice:
11529 * loop == 0: count the number of matching options
11530 * loop == 1: copy the matching options into allocated memory
11531 */
11532 for (loop = 0; loop <= 1; ++loop)
11533 {
11534 regmatch->rm_ic = ic;
11535 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11536 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011537 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11538 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11540 {
11541 if (loop == 0)
11542 num_normal++;
11543 else
11544 (*file)[count++] = vim_strsave((char_u *)names[match]);
11545 }
11546 }
11547 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11548 opt_idx++)
11549 {
11550 if (options[opt_idx].var == NULL)
11551 continue;
11552 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11553 && !(options[opt_idx].flags & P_BOOL))
11554 continue;
11555 is_term_opt = istermoption(&options[opt_idx]);
11556 if (is_term_opt && num_normal > 0)
11557 continue;
11558 match = FALSE;
11559 if (vim_regexec(regmatch, str, (colnr_T)0)
11560 || (options[opt_idx].shortname != NULL
11561 && vim_regexec(regmatch,
11562 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11563 match = TRUE;
11564 else if (is_term_opt)
11565 {
11566 name_buf[0] = '<';
11567 name_buf[1] = 't';
11568 name_buf[2] = '_';
11569 name_buf[3] = str[2];
11570 name_buf[4] = str[3];
11571 name_buf[5] = '>';
11572 name_buf[6] = NUL;
11573 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11574 {
11575 match = TRUE;
11576 str = name_buf;
11577 }
11578 }
11579 if (match)
11580 {
11581 if (loop == 0)
11582 {
11583 if (is_term_opt)
11584 num_term++;
11585 else
11586 num_normal++;
11587 }
11588 else
11589 (*file)[count++] = vim_strsave(str);
11590 }
11591 }
11592 /*
11593 * Check terminal key codes, these are not in the option table
11594 */
11595 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11596 {
11597 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11598 {
11599 if (!isprint(str[0]) || !isprint(str[1]))
11600 continue;
11601
11602 name_buf[0] = 't';
11603 name_buf[1] = '_';
11604 name_buf[2] = str[0];
11605 name_buf[3] = str[1];
11606 name_buf[4] = NUL;
11607
11608 match = FALSE;
11609 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11610 match = TRUE;
11611 else
11612 {
11613 name_buf[0] = '<';
11614 name_buf[1] = 't';
11615 name_buf[2] = '_';
11616 name_buf[3] = str[0];
11617 name_buf[4] = str[1];
11618 name_buf[5] = '>';
11619 name_buf[6] = NUL;
11620
11621 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11622 match = TRUE;
11623 }
11624 if (match)
11625 {
11626 if (loop == 0)
11627 num_term++;
11628 else
11629 (*file)[count++] = vim_strsave(name_buf);
11630 }
11631 }
11632
11633 /*
11634 * Check special key names.
11635 */
11636 regmatch->rm_ic = TRUE; /* ignore case here */
11637 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11638 {
11639 name_buf[0] = '<';
11640 STRCPY(name_buf + 1, str);
11641 STRCAT(name_buf, ">");
11642
11643 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11644 {
11645 if (loop == 0)
11646 num_term++;
11647 else
11648 (*file)[count++] = vim_strsave(name_buf);
11649 }
11650 }
11651 }
11652 if (loop == 0)
11653 {
11654 if (num_normal > 0)
11655 *num_file = num_normal;
11656 else if (num_term > 0)
11657 *num_file = num_term;
11658 else
11659 return OK;
11660 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11661 if (*file == NULL)
11662 {
11663 *file = (char_u **)"";
11664 return FAIL;
11665 }
11666 }
11667 }
11668 return OK;
11669}
11670
11671 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011672ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673{
11674 char_u *var = NULL; /* init for GCC */
11675 char_u *buf;
11676
11677 *num_file = 0;
11678 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11679 if (*file == NULL)
11680 return FAIL;
11681
11682 /*
11683 * For a terminal key code expand_option_idx is < 0.
11684 */
11685 if (expand_option_idx < 0)
11686 {
11687 var = find_termcode(expand_option_name + 2);
11688 if (var == NULL)
11689 expand_option_idx = findoption(expand_option_name);
11690 }
11691
11692 if (expand_option_idx >= 0)
11693 {
11694 /* put string of option value in NameBuff */
11695 option_value2string(&options[expand_option_idx], expand_option_flags);
11696 var = NameBuff;
11697 }
11698 else if (var == NULL)
11699 var = (char_u *)"";
11700
11701 /* A backslash is required before some characters. This is the reverse of
11702 * what happens in do_set(). */
11703 buf = vim_strsave_escaped(var, escape_chars);
11704
11705 if (buf == NULL)
11706 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011707 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708 return FAIL;
11709 }
11710
11711#ifdef BACKSLASH_IN_FILENAME
11712 /* For MS-Windows et al. we don't double backslashes at the start and
11713 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011714 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715 if (var[0] == '\\' && var[1] == '\\'
11716 && expand_option_idx >= 0
11717 && (options[expand_option_idx].flags & P_EXPAND)
11718 && vim_isfilec(var[2])
11719 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011720 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011721#endif
11722
11723 *file[0] = buf;
11724 *num_file = 1;
11725 return OK;
11726}
11727#endif
11728
11729/*
11730 * Get the value for the numeric or string option *opp in a nice format into
11731 * NameBuff[]. Must not be called with a hidden option!
11732 */
11733 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011734option_value2string(
11735 struct vimoption *opp,
11736 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737{
11738 char_u *varp;
11739
11740 varp = get_varp_scope(opp, opt_flags);
11741
11742 if (opp->flags & P_NUM)
11743 {
11744 long wc = 0;
11745
11746 if (wc_use_keyname(varp, &wc))
11747 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11748 else if (wc != 0)
11749 STRCPY(NameBuff, transchar((int)wc));
11750 else
11751 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11752 }
11753 else /* P_STRING */
11754 {
11755 varp = *(char_u **)(varp);
11756 if (varp == NULL) /* just in case */
11757 NameBuff[0] = NUL;
11758#ifdef FEAT_CRYPT
11759 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011760 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 STRCPY(NameBuff, "*****");
11762#endif
11763 else if (opp->flags & P_EXPAND)
11764 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11765 /* Translate 'pastetoggle' into special key names */
11766 else if ((char_u **)opp->var == &p_pt)
11767 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11768 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011769 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770 }
11771}
11772
11773/*
11774 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11775 * printed as a keyname.
11776 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11777 */
11778 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011779wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780{
11781 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11782 {
11783 *wcp = *(long *)varp;
11784 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11785 return TRUE;
11786 }
11787 return FALSE;
11788}
11789
Bram Moolenaar01615492015-02-03 13:00:38 +010011790#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011792 * Any character has an equivalent 'langmap' character. This is used for
11793 * keyboards that have a special language mode that sends characters above
11794 * 128 (although other characters can be translated too). The "to" field is a
11795 * Vim command character. This avoids having to switch the keyboard back to
11796 * ASCII mode when leaving Insert mode.
11797 *
11798 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11799 * commands.
11800 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11801 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11802 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011804# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011805/*
11806 * With multi-byte support use growarray for 'langmap' chars >= 256
11807 */
11808typedef struct
11809{
11810 int from;
11811 int to;
11812} langmap_entry_T;
11813
11814static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011815static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816
11817/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011818 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11819 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011822langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011823{
11824 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011825 int a = 0;
11826 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011827
11828 /* Do a binary search for an existing entry. */
11829 while (a != b)
11830 {
11831 int i = (a + b) / 2;
11832 int d = entries[i].from - from;
11833
11834 if (d == 0)
11835 {
11836 entries[i].to = to;
11837 return;
11838 }
11839 if (d < 0)
11840 a = i + 1;
11841 else
11842 b = i;
11843 }
11844
11845 if (ga_grow(&langmap_mapga, 1) != OK)
11846 return; /* out of memory */
11847
11848 /* insert new entry at position "a" */
11849 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11850 mch_memmove(entries + 1, entries,
11851 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11852 ++langmap_mapga.ga_len;
11853 entries[0].from = from;
11854 entries[0].to = to;
11855}
11856
11857/*
11858 * Apply 'langmap' to multi-byte character "c" and return the result.
11859 */
11860 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011861langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011862{
11863 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11864 int a = 0;
11865 int b = langmap_mapga.ga_len;
11866
11867 while (a != b)
11868 {
11869 int i = (a + b) / 2;
11870 int d = entries[i].from - c;
11871
11872 if (d == 0)
11873 return entries[i].to; /* found matching entry */
11874 if (d < 0)
11875 a = i + 1;
11876 else
11877 b = i;
11878 }
11879 return c; /* no entry found, return "c" unmodified */
11880}
11881# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882
11883 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011884langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885{
11886 int i;
11887
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011888 for (i = 0; i < 256; i++)
11889 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11890# ifdef FEAT_MBYTE
11891 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11892# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893}
11894
11895/*
11896 * Called when langmap option is set; the language map can be
11897 * changed at any time!
11898 */
11899 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011900langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901{
11902 char_u *p;
11903 char_u *p2;
11904 int from, to;
11905
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011906#ifdef FEAT_MBYTE
11907 ga_clear(&langmap_mapga); /* clear the previous map first */
11908#endif
11909 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910
11911 for (p = p_langmap; p[0] != NUL; )
11912 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011913 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011914 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915 {
11916 if (p2[0] == '\\' && p2[1] != NUL)
11917 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918 }
11919 if (p2[0] == ';')
11920 ++p2; /* abcd;ABCD form, p2 points to A */
11921 else
11922 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11923 while (p[0])
11924 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011925 if (p[0] == ',')
11926 {
11927 ++p;
11928 break;
11929 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011930 if (p[0] == '\\' && p[1] != NUL)
11931 ++p;
11932#ifdef FEAT_MBYTE
11933 from = (*mb_ptr2char)(p);
11934#else
11935 from = p[0];
11936#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938 if (p2 == NULL)
11939 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011940 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011941 if (p[0] != ',')
11942 {
11943 if (p[0] == '\\')
11944 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011946 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011948 to = p[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 else
11953 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011954 if (p2[0] != ',')
11955 {
11956 if (p2[0] == '\\')
11957 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011959 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011960#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011961 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011964 }
11965 if (to == NUL)
11966 {
11967 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11968 transchar(from));
11969 return;
11970 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011971
11972#ifdef FEAT_MBYTE
11973 if (from >= 256)
11974 langmap_set_entry(from, to);
11975 else
11976#endif
11977 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978
11979 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011980 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011981 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011982 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011983 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984 if (*p == ';')
11985 {
11986 p = p2;
11987 if (p[0] != NUL)
11988 {
11989 if (p[0] != ',')
11990 {
11991 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11992 return;
11993 }
11994 ++p;
11995 }
11996 break;
11997 }
11998 }
11999 }
12000 }
12001}
12002#endif
12003
12004/*
12005 * Return TRUE if format option 'x' is in effect.
12006 * Take care of no formatting when 'paste' is set.
12007 */
12008 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012009has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010{
12011 if (p_paste)
12012 return FALSE;
12013 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12014}
12015
12016/*
12017 * Return TRUE if "x" is present in 'shortmess' option, or
12018 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12019 */
12020 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012021shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012023 return p_shm != NULL &&
12024 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025 || (vim_strchr(p_shm, 'a') != NULL
12026 && vim_strchr((char_u *)SHM_A, x) != NULL));
12027}
12028
12029/*
12030 * paste_option_changed() - Called after p_paste was set or reset.
12031 */
12032 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012033paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012034{
12035 static int old_p_paste = FALSE;
12036 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012037 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038#ifdef FEAT_CMDL_INFO
12039 static int save_ru = 0;
12040#endif
12041#ifdef FEAT_RIGHTLEFT
12042 static int save_ri = 0;
12043 static int save_hkmap = 0;
12044#endif
12045 buf_T *buf;
12046
12047 if (p_paste)
12048 {
12049 /*
12050 * Paste switched from off to on.
12051 * Save the current values, so they can be restored later.
12052 */
12053 if (!old_p_paste)
12054 {
12055 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012056 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057 {
12058 buf->b_p_tw_nopaste = buf->b_p_tw;
12059 buf->b_p_wm_nopaste = buf->b_p_wm;
12060 buf->b_p_sts_nopaste = buf->b_p_sts;
12061 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012062 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063 }
12064
12065 /* save global options */
12066 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012067 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068#ifdef FEAT_CMDL_INFO
12069 save_ru = p_ru;
12070#endif
12071#ifdef FEAT_RIGHTLEFT
12072 save_ri = p_ri;
12073 save_hkmap = p_hkmap;
12074#endif
12075 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012076 p_ai_nopaste = p_ai;
12077 p_et_nopaste = p_et;
12078 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079 p_tw_nopaste = p_tw;
12080 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081 }
12082
12083 /*
12084 * Always set the option values, also when 'paste' is set when it is
12085 * already on.
12086 */
12087 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012088 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089 {
12090 buf->b_p_tw = 0; /* textwidth is 0 */
12091 buf->b_p_wm = 0; /* wrapmargin is 0 */
12092 buf->b_p_sts = 0; /* softtabstop is 0 */
12093 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012094 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 }
12096
12097 /* set global options */
12098 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012099 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101 if (p_ru)
12102 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 p_ru = 0; /* no ruler */
12104#endif
12105#ifdef FEAT_RIGHTLEFT
12106 p_ri = 0; /* no reverse insert */
12107 p_hkmap = 0; /* no Hebrew keyboard */
12108#endif
12109 /* set global values for local buffer options */
12110 p_tw = 0;
12111 p_wm = 0;
12112 p_sts = 0;
12113 p_ai = 0;
12114 }
12115
12116 /*
12117 * Paste switched from on to off: Restore saved values.
12118 */
12119 else if (old_p_paste)
12120 {
12121 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012122 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123 {
12124 buf->b_p_tw = buf->b_p_tw_nopaste;
12125 buf->b_p_wm = buf->b_p_wm_nopaste;
12126 buf->b_p_sts = buf->b_p_sts_nopaste;
12127 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012128 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129 }
12130
12131 /* restore global options */
12132 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012133 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135 if (p_ru != save_ru)
12136 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 p_ru = save_ru;
12138#endif
12139#ifdef FEAT_RIGHTLEFT
12140 p_ri = save_ri;
12141 p_hkmap = save_hkmap;
12142#endif
12143 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012144 p_ai = p_ai_nopaste;
12145 p_et = p_et_nopaste;
12146 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 p_tw = p_tw_nopaste;
12148 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
12150
12151 old_p_paste = p_paste;
12152}
12153
12154/*
12155 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12156 *
12157 * Reset 'compatible' and set the values for options that didn't get set yet
12158 * to the Vim defaults.
12159 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012160 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161 */
12162 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012163vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012165 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012166 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012167 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168
12169 if (!option_was_set((char_u *)"cp"))
12170 {
12171 p_cp = FALSE;
12172 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12173 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12174 set_option_default(opt_idx, OPT_FREE, FALSE);
12175 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012176 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012178
12179 if (fname != NULL)
12180 {
12181 p = vim_getenv(envname, &dofree);
12182 if (p == NULL)
12183 {
12184 /* Set $MYVIMRC to the first vimrc file found. */
12185 p = FullName_save(fname, FALSE);
12186 if (p != NULL)
12187 {
12188 vim_setenv(envname, p);
12189 vim_free(p);
12190 }
12191 }
12192 else if (dofree)
12193 vim_free(p);
12194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195}
12196
12197/*
12198 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12199 */
12200 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012201change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012203 int opt_idx;
12204
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 if (p_cp != on)
12206 {
12207 p_cp = on;
12208 compatible_set();
12209 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012210 opt_idx = findoption((char_u *)"cp");
12211 if (opt_idx >= 0)
12212 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213}
12214
12215/*
12216 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012217 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218 */
12219 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012220option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221{
12222 int idx;
12223
12224 idx = findoption(name);
12225 if (idx < 0) /* unknown option */
12226 return FALSE;
12227 if (options[idx].flags & P_WAS_SET)
12228 return TRUE;
12229 return FALSE;
12230}
12231
12232/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012233 * Reset the flag indicating option "name" was set.
12234 */
12235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012236reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012237{
12238 int idx = findoption(name);
12239
12240 if (idx >= 0)
12241 options[idx].flags &= ~P_WAS_SET;
12242}
12243
12244/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245 * compatible_set() - Called when 'compatible' has been set or unset.
12246 *
12247 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12248 * flag) to a Vi compatible value.
12249 * When 'compatible' is unset: Set all options that have a different default
12250 * for Vim (without the P_VI_DEF flag) to that default.
12251 */
12252 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012253compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254{
12255 int opt_idx;
12256
12257 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12258 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12259 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12260 set_option_default(opt_idx, OPT_FREE, p_cp);
12261 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012262 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263}
12264
12265#ifdef FEAT_LINEBREAK
12266
12267# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12268 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012269 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270# endif
12271
12272/*
12273 * fill_breakat_flags() -- called when 'breakat' changes value.
12274 */
12275 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012276fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012278 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279 int i;
12280
12281 for (i = 0; i < 256; i++)
12282 breakat_flags[i] = FALSE;
12283
12284 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012285 for (p = p_breakat; *p; p++)
12286 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287}
12288
12289# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012290 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291# endif
12292
12293#endif
12294
12295/*
12296 * Check an option that can be a range of string values.
12297 *
12298 * Return OK for correct value, FAIL otherwise.
12299 * Empty is always OK.
12300 */
12301 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012302check_opt_strings(
12303 char_u *val,
12304 char **values,
12305 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306{
12307 return opt_strings_flags(val, values, NULL, list);
12308}
12309
12310/*
12311 * Handle an option that can be a range of string values.
12312 * Set a flag in "*flagp" for each string present.
12313 *
12314 * Return OK for correct value, FAIL otherwise.
12315 * Empty is always OK.
12316 */
12317 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012318opt_strings_flags(
12319 char_u *val, /* new value */
12320 char **values, /* array of valid string values */
12321 unsigned *flagp,
12322 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012323{
12324 int i;
12325 int len;
12326 unsigned new_flags = 0;
12327
12328 while (*val)
12329 {
12330 for (i = 0; ; ++i)
12331 {
12332 if (values[i] == NULL) /* val not found in values[] */
12333 return FAIL;
12334
12335 len = (int)STRLEN(values[i]);
12336 if (STRNCMP(values[i], val, len) == 0
12337 && ((list && val[len] == ',') || val[len] == NUL))
12338 {
12339 val += len + (val[len] == ',');
12340 new_flags |= (1 << i);
12341 break; /* check next item in val list */
12342 }
12343 }
12344 }
12345 if (flagp != NULL)
12346 *flagp = new_flags;
12347
12348 return OK;
12349}
12350
12351/*
12352 * Read the 'wildmode' option, fill wim_flags[].
12353 */
12354 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012355check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356{
12357 char_u new_wim_flags[4];
12358 char_u *p;
12359 int i;
12360 int idx = 0;
12361
12362 for (i = 0; i < 4; ++i)
12363 new_wim_flags[i] = 0;
12364
12365 for (p = p_wim; *p; ++p)
12366 {
12367 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12368 ;
12369 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12370 return FAIL;
12371 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12372 new_wim_flags[idx] |= WIM_LONGEST;
12373 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12374 new_wim_flags[idx] |= WIM_FULL;
12375 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12376 new_wim_flags[idx] |= WIM_LIST;
12377 else
12378 return FAIL;
12379 p += i;
12380 if (*p == NUL)
12381 break;
12382 if (*p == ',')
12383 {
12384 if (idx == 3)
12385 return FAIL;
12386 ++idx;
12387 }
12388 }
12389
12390 /* fill remaining entries with last flag */
12391 while (idx < 3)
12392 {
12393 new_wim_flags[idx + 1] = new_wim_flags[idx];
12394 ++idx;
12395 }
12396
12397 /* only when there are no errors, wim_flags[] is changed */
12398 for (i = 0; i < 4; ++i)
12399 wim_flags[i] = new_wim_flags[i];
12400 return OK;
12401}
12402
12403/*
12404 * Check if backspacing over something is allowed.
12405 */
12406 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012407can_bs(
12408 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409{
12410 switch (*p_bs)
12411 {
12412 case '2': return TRUE;
12413 case '1': return (what != BS_START);
12414 case '0': return FALSE;
12415 }
12416 return vim_strchr(p_bs, what) != NULL;
12417}
12418
12419/*
12420 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12421 * the file must be considered changed when the value is different.
12422 */
12423 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012424save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425{
12426 buf->b_start_ffc = *buf->b_p_ff;
12427 buf->b_start_eol = buf->b_p_eol;
12428#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012429 buf->b_start_bomb = buf->b_p_bomb;
12430
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431 /* Only use free/alloc when necessary, they take time. */
12432 if (buf->b_start_fenc == NULL
12433 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12434 {
12435 vim_free(buf->b_start_fenc);
12436 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12437 }
12438#endif
12439}
12440
12441/*
12442 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12443 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012444 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12445 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012446 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012447 * When "ignore_empty" is true don't consider a new, empty buffer to be
12448 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449 */
12450 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012451file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012452{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012453 /* In a buffer that was never loaded the options are not valid. */
12454 if (buf->b_flags & BF_NEVERLOADED)
12455 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012456 if (ignore_empty
12457 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012458 && buf->b_ml.ml_line_count == 1
12459 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12460 return FALSE;
12461 if (buf->b_start_ffc != *buf->b_p_ff)
12462 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012463 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012464 return TRUE;
12465#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012466 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12467 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468 if (buf->b_start_fenc == NULL)
12469 return (*buf->b_p_fenc != NUL);
12470 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12471#else
12472 return FALSE;
12473#endif
12474}
12475
12476/*
12477 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12478 */
12479 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012480check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481{
12482 return check_opt_strings(p, p_ff_values, FALSE);
12483}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012484
12485/*
12486 * Return the effective shiftwidth value for current buffer, using the
12487 * 'tabstop' value when 'shiftwidth' is zero.
12488 */
12489 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012490get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012491{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012492 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012493}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012494
12495/*
12496 * Return the effective softtabstop value for the current buffer, using the
12497 * 'tabstop' value when 'softtabstop' is negative.
12498 */
12499 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012500get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012501{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012502 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012503}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012504
12505/*
12506 * Check matchpairs option for "*initc".
12507 * If there is a match set "*initc" to the matching character and "*findc" to
12508 * the opposite character. Set "*backwards" to the direction.
12509 * When "switchit" is TRUE swap the direction.
12510 */
12511 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012512find_mps_values(
12513 int *initc,
12514 int *findc,
12515 int *backwards,
12516 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012517{
12518 char_u *ptr;
12519
12520 ptr = curbuf->b_p_mps;
12521 while (*ptr != NUL)
12522 {
12523#ifdef FEAT_MBYTE
12524 if (has_mbyte)
12525 {
12526 char_u *prev;
12527
12528 if (mb_ptr2char(ptr) == *initc)
12529 {
12530 if (switchit)
12531 {
12532 *findc = *initc;
12533 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12534 *backwards = TRUE;
12535 }
12536 else
12537 {
12538 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12539 *backwards = FALSE;
12540 }
12541 return;
12542 }
12543 prev = ptr;
12544 ptr += mb_ptr2len(ptr) + 1;
12545 if (mb_ptr2char(ptr) == *initc)
12546 {
12547 if (switchit)
12548 {
12549 *findc = *initc;
12550 *initc = mb_ptr2char(prev);
12551 *backwards = FALSE;
12552 }
12553 else
12554 {
12555 *findc = mb_ptr2char(prev);
12556 *backwards = TRUE;
12557 }
12558 return;
12559 }
12560 ptr += mb_ptr2len(ptr);
12561 }
12562 else
12563#endif
12564 {
12565 if (*ptr == *initc)
12566 {
12567 if (switchit)
12568 {
12569 *backwards = TRUE;
12570 *findc = *initc;
12571 *initc = ptr[2];
12572 }
12573 else
12574 {
12575 *backwards = FALSE;
12576 *findc = ptr[2];
12577 }
12578 return;
12579 }
12580 ptr += 2;
12581 if (*ptr == *initc)
12582 {
12583 if (switchit)
12584 {
12585 *backwards = FALSE;
12586 *findc = *initc;
12587 *initc = ptr[-2];
12588 }
12589 else
12590 {
12591 *backwards = TRUE;
12592 *findc = ptr[-2];
12593 }
12594 return;
12595 }
12596 ++ptr;
12597 }
12598 if (*ptr == ',')
12599 ++ptr;
12600 }
12601}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012602
12603#if defined(FEAT_LINEBREAK) || defined(PROTO)
12604/*
12605 * This is called when 'breakindentopt' is changed and when a window is
12606 * initialized.
12607 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012608 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012609briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012610{
12611 char_u *p;
12612 int bri_shift = 0;
12613 long bri_min = 20;
12614 int bri_sbr = FALSE;
12615
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012616 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012617 while (*p != NUL)
12618 {
12619 if (STRNCMP(p, "shift:", 6) == 0
12620 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12621 {
12622 p += 6;
12623 bri_shift = getdigits(&p);
12624 }
12625 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12626 {
12627 p += 4;
12628 bri_min = getdigits(&p);
12629 }
12630 else if (STRNCMP(p, "sbr", 3) == 0)
12631 {
12632 p += 3;
12633 bri_sbr = TRUE;
12634 }
12635 if (*p != ',' && *p != NUL)
12636 return FAIL;
12637 if (*p == ',')
12638 ++p;
12639 }
12640
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012641 wp->w_p_brishift = bri_shift;
12642 wp->w_p_brimin = bri_min;
12643 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012644
12645 return OK;
12646}
12647#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012648
12649/*
12650 * Get the local or global value of 'backupcopy'.
12651 */
12652 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012653get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012654{
12655 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12656}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012657
12658#if defined(FEAT_SIGNS) || defined(PROTO)
12659/*
12660 * Return TRUE when window "wp" has a column to draw signs in.
12661 */
12662 int
12663signcolumn_on(win_T *wp)
12664{
12665 if (*wp->w_p_scl == 'n')
12666 return FALSE;
12667 if (*wp->w_p_scl == 'y')
12668 return TRUE;
12669 return (wp->w_buffer->b_signlist != NULL
12670# ifdef FEAT_NETBEANS_INTG
12671 || wp->w_buffer->b_has_sign_column
12672# endif
12673 );
12674}
12675#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012676
12677#if defined(FEAT_EVAL) || defined(PROTO)
12678/*
12679 * Get window or buffer local options.
12680 */
12681 dict_T *
12682get_winbuf_options(int bufopt)
12683{
12684 dict_T *d;
12685 int opt_idx;
12686
12687 d = dict_alloc();
12688 if (d == NULL)
12689 return NULL;
12690
12691 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12692 {
12693 struct vimoption *opt = &options[opt_idx];
12694
12695 if ((bufopt && (opt->indir & PV_BUF))
12696 || (!bufopt && (opt->indir & PV_WIN)))
12697 {
12698 char_u *varp = get_varp(opt);
12699
12700 if (varp != NULL)
12701 {
12702 if (opt->flags & P_STRING)
12703 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012704 else if (opt->flags & P_NUM)
12705 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012706 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012707 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012708 }
12709 }
12710 }
12711
12712 return d;
12713}
12714#endif