blob: 5ef346c8d4a1a9e7e62c38b1bde974b5d4f2677e [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100117#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100140#ifdef FEAT_MBYTE
141# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
142#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#define PV_MA OPT_BUF(BV_MA)
144#define PV_ML OPT_BUF(BV_ML)
145#define PV_MOD OPT_BUF(BV_MOD)
146#define PV_MPS OPT_BUF(BV_MPS)
147#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000148#ifdef FEAT_COMPL_FUNC
149# define PV_OFU OPT_BUF(BV_OFU)
150#endif
151#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
152#define PV_PI OPT_BUF(BV_PI)
153#ifdef FEAT_TEXTOBJ
154# define PV_QE OPT_BUF(BV_QE)
155#endif
156#define PV_RO OPT_BUF(BV_RO)
157#ifdef FEAT_SMARTINDENT
158# define PV_SI OPT_BUF(BV_SI)
159#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100160#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200223#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100230#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200253# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200254# define PV_TMS OPT_WIN(WV_TMS)
255#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200256#ifdef FEAT_SIGNS
257# define PV_SCL OPT_WIN(WV_SCL)
258#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000259
260/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261typedef enum
262{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000263 PV_NONE = 0,
264 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265} idopt_T;
266
267/*
268 * Options local to a window have a value local to a buffer and global to all
269 * buffers. Indicate this by setting "var" to VAR_WIN.
270 */
271#define VAR_WIN ((char_u *)-1)
272
273/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000274 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * Only to be used in option.c!
276 */
277static int p_ai;
278static int p_bin;
279#ifdef FEAT_MBYTE
280static int p_bomb;
281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282static char_u *p_bh;
283static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200308static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_et;
310#ifdef FEAT_MBYTE
311static char_u *p_fenc;
312#endif
313static char_u *p_ff;
314static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000315static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static long p_iminsert;
318static long p_imsearch;
319#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
320static char_u *p_inex;
321#endif
322#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
323static char_u *p_inde;
324static char_u *p_indk;
325#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000326#if defined(FEAT_EVAL)
327static char_u *p_fex;
328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000329static int p_inf;
330static char_u *p_isk;
331#ifdef FEAT_CRYPT
332static char_u *p_key;
333#endif
334#ifdef FEAT_LISP
335static int p_lisp;
336#endif
337static int p_ml;
338static int p_ma;
339static int p_mod;
340static char_u *p_mps;
341static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000343#ifdef FEAT_TEXTOBJ
344static char_u *p_qe;
345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_ro;
347#ifdef FEAT_SMARTINDENT
348static int p_si;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static long p_sts;
352#if defined(FEAT_SEARCHPATH)
353static char_u *p_sua;
354#endif
355static long p_sw;
356static int p_swf;
357#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000358static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000360#endif
361#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000362static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000363static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000364static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365#endif
366static long p_ts;
367static long p_tw;
368static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200369#ifdef FEAT_PERSISTENT_UNDO
370static int p_udf;
371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372static long p_wm;
373#ifdef FEAT_KEYMAP
374static char_u *p_keymap;
375#endif
376
377/* Saved values for when 'bin' is set. */
378static int p_et_nobin;
379static int p_ml_nobin;
380static long p_tw_nobin;
381static long p_wm_nobin;
382
383/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200384static int p_ai_nopaste;
385static int p_et_nopaste;
386static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387static long p_tw_nopaste;
388static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389
390struct vimoption
391{
392 char *fullname; /* full option name */
393 char *shortname; /* permissible abbreviation */
394 long_u flags; /* see below */
395 char_u *var; /* global option: pointer to variable;
396 * window-local option: VAR_WIN;
397 * buffer-local option: global value */
398 idopt_T indir; /* global option: PV_NONE;
399 * local option: indirect option index */
400 char_u *def_val[2]; /* default values for variable (vi and vim) */
401#ifdef FEAT_EVAL
402 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000403# define SCRIPTID_INIT , 0
404#else
405# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000406#endif
407};
408
409#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
410#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
411
412/*
413 * Flags
414 */
415#define P_BOOL 0x01 /* the option is boolean */
416#define P_NUM 0x02 /* the option is numeric */
417#define P_STRING 0x04 /* the option is a string */
418#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000419 must use free_string_option() when
420 assigning new value. Not set if default is
421 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
423 never be used for local or hidden options! */
424#define P_NODEFAULT 0x40 /* don't set to default value */
425#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
426 use vim_free() when assigning new value */
427#define P_WAS_SET 0x100 /* option has been set/reset */
428#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
429#define P_VI_DEF 0x400 /* Use Vi default for Vim */
430#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
431
432 /* when option changed, what to display: */
433#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100434#define P_RWIN 0x2000 /* redraw current window and recompute text */
435#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436#define P_RALL 0x6000 /* redraw all windows */
437#define P_RCLR 0x7000 /* clear and redraw all */
438
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200439#define P_COMMA 0x8000 /* comma separated list */
440#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
441 * commas */
442#define P_NODUP 0x20000L /* don't allow duplicate strings */
443#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200445#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x100000L /* expand default value with _() */
447#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
448#define P_NFNAME 0x400000L /* only normal file name chars allowed */
449#define P_INSECURE 0x800000L /* option was set from a modeline */
450#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100451 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_NO_ML 0x2000000L /* not allowed in modeline */
453#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200454 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100455#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100456#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000458#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
459
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000460/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
461 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100462#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000463# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000464#else
465# define ISP_LATIN1 (char_u *)"@,161-255"
466#endif
467
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200468# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000469
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100470/* Default python version for pyx* commands */
471#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
472# define DEFAULT_PYTHON_VER 0
473#elif defined(FEAT_PYTHON3)
474# define DEFAULT_PYTHON_VER 3
475#elif defined(FEAT_PYTHON)
476# define DEFAULT_PYTHON_VER 2
477#else
478# define DEFAULT_PYTHON_VER 0
479#endif
480
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481/*
482 * options[] is initialized here.
483 * The order of the options MUST be alphabetic for ":set all" and findoption().
484 * All option names MUST start with a lowercase letter (for findoption()).
485 * Exception: "t_" options are at the end.
486 * The options with a NULL variable are 'hidden': a set command for them is
487 * ignored and they are not printed.
488 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100489static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200491 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492#ifdef FEAT_RIGHTLEFT
493 (char_u *)&p_aleph, PV_NONE,
494#else
495 (char_u *)NULL, PV_NONE,
496#endif
497 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100498#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 (char_u *)128L,
500#else
501 (char_u *)224L,
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200505#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 (char_u *)&p_antialias, PV_NONE,
507 {(char_u *)FALSE, (char_u *)FALSE}
508#else
509 (char_u *)NULL, PV_NONE,
510 {(char_u *)FALSE, (char_u *)FALSE}
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200513 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514#ifdef FEAT_ARABIC
515 (char_u *)VAR_WIN, PV_ARAB,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521#ifdef FEAT_ARABIC
522 (char_u *)&p_arshape, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
528#ifdef FEAT_RIGHTLEFT
529 (char_u *)&p_ari, PV_NONE,
530#else
531 (char_u *)NULL, PV_NONE,
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
535#ifdef FEAT_FKMAP
536 (char_u *)&p_altkeymap, PV_NONE,
537#else
538 (char_u *)NULL, PV_NONE,
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
542#if defined(FEAT_MBYTE)
543 (char_u *)&p_ambw, PV_NONE,
544 {(char_u *)"single", (char_u *)0L}
545#else
546 (char_u *)NULL, PV_NONE,
547 {(char_u *)0L, (char_u *)0L}
548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100551#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100553 {(char_u *)FALSE, (char_u *)0L}
554#else
555 (char_u *)NULL, PV_NONE,
556 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000566 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
576 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100577#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 (char_u *)"dark",
579#else
580 (char_u *)"light",
581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200590 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591#ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593#else
594 {(char_u *)"auto", (char_u *)"auto"}
595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
598 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000601 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bex, PV_NONE,
603 {
604#ifdef VMS
605 (char_u *)"_",
606#else
607 (char_u *)"~",
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200610 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_WILDIGN
612 (char_u *)&p_bsk, PV_NONE,
613 {(char_u *)"", (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100620#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100622 {(char_u *)600L, (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100627 SCRIPTID_INIT},
628 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100629#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 (char_u *)&p_beval, PV_NONE,
631 {(char_u *)FALSE, (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
635#endif
636 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100637 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100638#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100639 (char_u *)&p_bevalterm, PV_NONE,
640 {(char_u *)FALSE, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
644#endif
645 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
647#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
648 (char_u *)&p_bexpr, PV_BEXPR,
649 {(char_u *)"", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 {"beautify", "bf", P_BOOL|P_VI_DEF,
656 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200658 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
659 (char_u *)&p_bo, PV_NONE,
660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
662 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000666 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
668#ifdef FEAT_MBYTE
669 (char_u *)&p_bomb, PV_BOMB,
670#else
671 (char_u *)NULL, PV_NONE,
672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
675#ifdef FEAT_LINEBREAK
676 (char_u *)&p_breakat, PV_NONE,
677 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)0L, (char_u *)0L}
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200683 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
684#ifdef FEAT_LINEBREAK
685 (char_u *)VAR_WIN, PV_BRI,
686 {(char_u *)FALSE, (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
691 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200692 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
693 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRIOPT,
696 {(char_u *)"", (char_u *)NULL}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)"", (char_u *)NULL}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
703#ifdef FEAT_BROWSE
704 (char_u *)&p_bsdir, PV_NONE,
705 {(char_u *)"last", (char_u *)0L}
706#else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)0L, (char_u *)0L}
709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000710 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 (char_u *)&p_bh, PV_BH,
713 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
716 (char_u *)&p_bl, PV_BL,
717 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bt, PV_BT,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200723 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000724#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 (char_u *)&p_cmp, PV_NONE,
726 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
733#ifdef FEAT_SEARCHPATH
734 (char_u *)&p_cdpath, PV_NONE,
735 {(char_u *)",,", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cedit", NULL, P_STRING,
742#ifdef FEAT_CMDWIN
743 (char_u *)&p_cedit, PV_NONE,
744 {(char_u *)"", (char_u *)CTRL_F_STR}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
751#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
752 (char_u *)&p_ccv, PV_NONE,
753 {(char_u *)"", (char_u *)0L}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
760#ifdef FEAT_CINDENT
761 (char_u *)&p_cin, PV_CIN,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cink, PV_CINK,
769 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cino, PV_CINO,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000781 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
784 (char_u *)&p_cinw, PV_CINW,
785 {(char_u *)"if,else,while,do,for,switch",
786 (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#ifdef FEAT_CLIPBOARD
794 (char_u *)&p_cb, PV_NONE,
795# ifdef FEAT_XCLIPBOARD
796 {(char_u *)"autoselect,exclude:cons\\|linux",
797 (char_u *)0L}
798# else
799 {(char_u *)"", (char_u *)0L}
800# endif
801#else
802 (char_u *)NULL, PV_NONE,
803 {(char_u *)"", (char_u *)0L}
804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000805 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
807 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
810#ifdef FEAT_CMDWIN
811 (char_u *)&p_cwh, PV_NONE,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200816 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200817#ifdef FEAT_SYN_HL
818 (char_u *)VAR_WIN, PV_CC,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
822 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
824 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
827 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828#ifdef FEAT_COMMENTS
829 (char_u *)&p_com, PV_COM,
830 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
831 (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200837 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_FOLDING
839 (char_u *)&p_cms, PV_CMS,
840 {(char_u *)"/*%s*/", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000846 /* P_PRI_MKRC isn't needed here, optval_default()
847 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"compatible", "cp", P_BOOL|P_RALL,
849 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000850 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200851 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852#ifdef FEAT_INS_EXPAND
853 (char_u *)&p_cpt, PV_CPT,
854 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)0L, (char_u *)0L}
858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200862 (char_u *)VAR_WIN, PV_COCU,
863 {(char_u *)"", (char_u *)NULL}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)NULL, (char_u *)0L}
867#endif
868 SCRIPTID_INIT},
869 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
870#ifdef FEAT_CONCEAL
871 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)0L, (char_u *)0L}
876 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000877 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
878#ifdef FEAT_COMPL_FUNC
879 (char_u *)&p_cfu, PV_CFU,
880 {(char_u *)"", (char_u *)0L}
881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200886 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000887#ifdef FEAT_INS_EXPAND
888 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000889 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"confirm", "cf", P_BOOL|P_VI_DEF,
896#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
897 (char_u *)&p_confirm, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
906 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
909 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
911 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200914 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#else
917 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200918 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200919#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_cspc, PV_NONE,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000927 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
929#ifdef FEAT_CSCOPE
930 (char_u *)&p_csprg, PV_NONE,
931 {(char_u *)"cscope", (char_u *)0L}
932#else
933 (char_u *)NULL, PV_NONE,
934 {(char_u *)0L, (char_u *)0L}
935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000936 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200937 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
939 (char_u *)&p_csqf, PV_NONE,
940 {(char_u *)"", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200946 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_csre, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
952 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_cst, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csto, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_CSCOPE
969 (char_u *)&p_csverbose, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200974 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200975 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200976 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000977 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
978#ifdef FEAT_SYN_HL
979 (char_u *)VAR_WIN, PV_CUC,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100984 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985#ifdef FEAT_SYN_HL
986 (char_u *)VAR_WIN, PV_CUL,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"debug", NULL, P_STRING|P_VI_DEF,
992 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200994 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000996 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000997 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1004#ifdef FEAT_MBYTE
1005 (char_u *)&p_deco, PV_NONE,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001010 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001012 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#else
1014 (char_u *)NULL, PV_NONE,
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1018#ifdef FEAT_DIFF
1019 (char_u *)VAR_WIN, PV_DIFF,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001024 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1026 (char_u *)&p_dex, PV_NONE,
1027 {(char_u *)"", (char_u *)0L}
1028#else
1029 (char_u *)NULL, PV_NONE,
1030 {(char_u *)0L, (char_u *)0L}
1031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001033 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1034 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035#ifdef FEAT_DIFF
1036 (char_u *)&p_dip, PV_NONE,
1037 {(char_u *)"filler", (char_u *)NULL}
1038#else
1039 (char_u *)NULL, PV_NONE,
1040 {(char_u *)"", (char_u *)NULL}
1041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1044#ifdef FEAT_DIGRAPHS
1045 (char_u *)&p_dg, PV_NONE,
1046#else
1047 (char_u *)NULL, PV_NONE,
1048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1051 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_ead, PV_NONE,
1059 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1062 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001064 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1065#if defined(FEAT_MBYTE)
1066 (char_u *)&p_emoji, PV_NONE,
1067 {(char_u *)TRUE, (char_u *)0L}
1068#else
1069 (char_u *)NULL, PV_NONE,
1070 {(char_u *)0L, (char_u *)0L}
1071#endif
1072 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001073 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074#ifdef FEAT_MBYTE
1075 (char_u *)&p_enc, PV_NONE,
1076 {(char_u *)ENC_DFLT, (char_u *)0L}
1077#else
1078 (char_u *)NULL, PV_NONE,
1079 {(char_u *)0L, (char_u *)0L}
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1083 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1086 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001089 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1092 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1095#ifdef FEAT_QUICKFIX
1096 (char_u *)&p_ef, PV_NONE,
1097 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1098#else
1099 (char_u *)NULL, PV_NONE,
1100 {(char_u *)NULL, (char_u *)0L}
1101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001103 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001105 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#else
1108 (char_u *)NULL, PV_NONE,
1109 {(char_u *)NULL, (char_u *)0L}
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"esckeys", "ek", P_BOOL|P_VIM,
1113 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 (char_u *)&p_ei, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1119 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1122 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001124 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1125 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fenc, PV_FENC,
1128 {(char_u *)"", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_MBYTE
1136 (char_u *)&p_fencs, PV_NONE,
1137 {(char_u *)"ucs-bom", (char_u *)0L}
1138#else
1139 (char_u *)NULL, PV_NONE,
1140 {(char_u *)0L, (char_u *)0L}
1141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001143 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1144 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1150 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001151 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1152 (char_u *)&p_fic, PV_NONE,
1153 {
1154#ifdef CASE_INSENSITIVE_FILENAME
1155 (char_u *)TRUE,
1156#else
1157 (char_u *)FALSE,
1158#endif
1159 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001160 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ft, PV_FT,
1162 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001164 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 (char_u *)&p_fcs, PV_NONE,
1166 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001168 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1169 (char_u *)&p_fixeol, PV_FIXEOL,
1170 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1172#ifdef FEAT_FKMAP
1173 (char_u *)&p_fkmap, PV_NONE,
1174#else
1175 (char_u *)NULL, PV_NONE,
1176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"flash", "fl", P_BOOL|P_VI_DEF,
1179 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001181 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001182#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001184 {(char_u *)"", (char_u *)0L}
1185#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188#endif
1189 SCRIPTID_INIT},
1190 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1191#ifdef FEAT_FOLDING
1192 (char_u *)VAR_WIN, PV_FDC,
1193 {(char_u *)FALSE, (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
1198 SCRIPTID_INIT},
1199 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1200#ifdef FEAT_FOLDING
1201 (char_u *)VAR_WIN, PV_FEN,
1202 {(char_u *)TRUE, (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
1207 SCRIPTID_INIT},
1208 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1209#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1210 (char_u *)VAR_WIN, PV_FDE,
1211 {(char_u *)"0", (char_u *)NULL}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)"#", (char_u *)NULL}
1221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
1225 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001229 {(char_u *)0L, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
1234 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001235 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001238 {(char_u *)-1L, (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
1243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001244 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001245 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001246#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001249#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 SCRIPTID_INIT},
1254 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1255#ifdef FEAT_FOLDING
1256 (char_u *)VAR_WIN, PV_FDM,
1257 {(char_u *)"manual", (char_u *)NULL}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
1262 SCRIPTID_INIT},
1263 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1264#ifdef FEAT_FOLDING
1265 (char_u *)VAR_WIN, PV_FML,
1266 {(char_u *)1L, (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
1271 SCRIPTID_INIT},
1272 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1273#ifdef FEAT_FOLDING
1274 (char_u *)VAR_WIN, PV_FDN,
1275 {(char_u *)20L, (char_u *)0L}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)NULL, (char_u *)0L}
1279#endif
1280 SCRIPTID_INIT},
1281 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1282#ifdef FEAT_FOLDING
1283 (char_u *)&p_fdo, PV_NONE,
1284 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1285 (char_u *)0L}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
1290 SCRIPTID_INIT},
1291 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1292#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1293 (char_u *)VAR_WIN, PV_FDT,
1294 {(char_u *)"foldtext()", (char_u *)NULL}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)NULL, (char_u *)0L}
1298#endif
1299 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001300 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001301#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001302 (char_u *)&p_fex, PV_FEX,
1303 {(char_u *)"", (char_u *)0L}
1304#else
1305 (char_u *)NULL, PV_NONE,
1306 {(char_u *)0L, (char_u *)0L}
1307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1310 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1312 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001313 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1314 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1316 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001318 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001320 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1321#ifdef HAVE_FSYNC
1322 (char_u *)&p_fs, PV_NONE,
1323 {(char_u *)TRUE, (char_u *)0L}
1324#else
1325 (char_u *)NULL, PV_NONE,
1326 {(char_u *)FALSE, (char_u *)0L}
1327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1330 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"graphic", "gr", P_BOOL|P_VI_DEF,
1333 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001335 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#ifdef FEAT_QUICKFIX
1337 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)NULL, (char_u *)0L}
1342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1345#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001346 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {
1348# ifdef WIN3264
1349 /* may be changed to "grep -n" in os_win32.c */
1350 (char_u *)"findstr /n",
1351# else
1352# ifdef UNIX
1353 /* Add an extra file name so that grep will always
1354 * insert a file name in the match line. */
1355 (char_u *)"grep -n $* /dev/null",
1356# else
1357# ifdef VMS
1358 (char_u *)"SEARCH/NUMBERS ",
1359# else
1360 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361# endif
1362# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001370 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371#ifdef CURSOR_SHAPE
1372 (char_u *)&p_guicursor, PV_NONE,
1373 {
1374# ifdef FEAT_GUI
1375 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001376# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1378# endif
1379 (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001385 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#ifdef FEAT_GUI
1387 (char_u *)&p_guifont, PV_NONE,
1388 {(char_u *)"", (char_u *)0L}
1389#else
1390 (char_u *)NULL, PV_NONE,
1391 {(char_u *)NULL, (char_u *)0L}
1392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001394 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1396 (char_u *)&p_guifontset, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001403 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1405 (char_u *)&p_guifontwide, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)NULL, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001413#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 (char_u *)&p_ghr, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001418 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001420#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001422# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001423 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001425 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426# endif
1427#else
1428 (char_u *)NULL, PV_NONE,
1429 {(char_u *)NULL, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"guipty", NULL, P_BOOL|P_VI_DEF,
1433#if defined(FEAT_GUI)
1434 (char_u *)&p_guipty, PV_NONE,
1435#else
1436 (char_u *)NULL, PV_NONE,
1437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001438 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001439 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001440#if defined(FEAT_GUI_TABLINE)
1441 (char_u *)&p_gtl, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)NULL, (char_u *)0L}
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001448 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001449#if defined(FEAT_GUI_TABLINE)
1450 (char_u *)&p_gtt, PV_NONE,
1451 {(char_u *)"", (char_u *)0L}
1452#else
1453 (char_u *)NULL, PV_NONE,
1454 {(char_u *)NULL, (char_u *)0L}
1455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001456 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1458 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1461 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001462 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1463 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001467 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468#ifdef FEAT_MULTI_LANG
1469 (char_u *)&p_hlg, PV_NONE,
1470 {(char_u *)"", (char_u *)0L}
1471#else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)0L, (char_u *)0L}
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"hidden", "hid", P_BOOL|P_VI_DEF,
1477 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001481 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1482 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 {"history", "hi", P_NUM|P_VIM,
1484 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001485 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1487#ifdef FEAT_RIGHTLEFT
1488 (char_u *)&p_hkmap, PV_NONE,
1489#else
1490 (char_u *)NULL, PV_NONE,
1491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1494#ifdef FEAT_RIGHTLEFT
1495 (char_u *)&p_hkmapp, PV_NONE,
1496#else
1497 (char_u *)NULL, PV_NONE,
1498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1501 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"icon", NULL, P_BOOL|P_VI_DEF,
1504#ifdef FEAT_TITLE
1505 (char_u *)&p_icon, PV_NONE,
1506#else
1507 (char_u *)NULL, PV_NONE,
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 {"iconstring", NULL, P_STRING|P_VI_DEF,
1511#ifdef FEAT_TITLE
1512 (char_u *)&p_iconstring, PV_NONE,
1513#else
1514 (char_u *)NULL, PV_NONE,
1515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001516 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1518 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001520 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001521#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001522 (char_u *)&p_imaf, PV_NONE,
1523 {(char_u *)"", (char_u *)NULL}
1524# else
1525 (char_u *)NULL, PV_NONE,
1526 {(char_u *)NULL, (char_u *)0L}
1527# endif
1528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001530#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 (char_u *)&p_imak, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001537#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 (char_u *)&p_imcmdline, PV_NONE,
1539#else
1540 (char_u *)NULL, PV_NONE,
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001544#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 (char_u *)&p_imdisable, PV_NONE,
1546#else
1547 (char_u *)NULL, PV_NONE,
1548#endif
1549#ifdef __sgi
1550 {(char_u *)TRUE, (char_u *)0L}
1551#else
1552 {(char_u *)FALSE, (char_u *)0L}
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"iminsert", "imi", P_NUM|P_VI_DEF,
1556 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 {"imsearch", "ims", P_NUM|P_VI_DEF,
1560 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001561 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001563 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001564#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001565 (char_u *)&p_imsf, PV_NONE,
1566 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001567#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001570#endif
1571 SCRIPTID_INIT},
1572 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1573#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1574 (char_u *)&p_imst, PV_NONE,
1575 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1576#else
1577 (char_u *)NULL, PV_NONE,
1578 {(char_u *)0L, (char_u *)0L}
1579#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1582#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001583 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1585#else
1586 (char_u *)NULL, PV_NONE,
1587 {(char_u *)0L, (char_u *)0L}
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1591#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1592 (char_u *)&p_inex, PV_INEX,
1593 {(char_u *)"", (char_u *)0L}
1594#else
1595 (char_u *)NULL, PV_NONE,
1596 {(char_u *)0L, (char_u *)0L}
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1600 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1603#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1604 (char_u *)&p_inde, PV_INDE,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001611 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1613 (char_u *)&p_indk, PV_INDK,
1614 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"infercase", "inf", P_BOOL|P_VI_DEF,
1621 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1624 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1627 (char_u *)&p_isf, PV_NONE,
1628 {
1629#ifdef BACKSLASH_IN_FILENAME
1630 /* Excluded are: & and ^ are special in cmd.exe
1631 * ( and ) are used in text separating fnames */
1632 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1633#else
1634# ifdef AMIGA
1635 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1636# else
1637# ifdef VMS
1638 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1639# else /* UNIX et al. */
1640# ifdef EBCDIC
1641 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1642# else
1643 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1644# endif
1645# endif
1646# endif
1647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001648 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1650 (char_u *)&p_isi, PV_NONE,
1651 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001652#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,48-57,_,128-167,224-235",
1654#else
1655# ifdef EBCDIC
1656 /* TODO: EBCDIC Check this! @ == isalpha()*/
1657 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1658 "112-120,128,140-142,156,158,172,"
1659 "174,186,191,203-207,219-225,235-239,"
1660 "251-254",
1661# else
1662 (char_u *)"@,48-57,_,192-255",
1663# endif
1664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001665 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1667 (char_u *)&p_isk, PV_ISK,
1668 {
1669#ifdef EBCDIC
1670 (char_u *)"@,240-249,_",
1671 /* TODO: EBCDIC Check this! @ == isalpha()*/
1672 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1673 "112-120,128,140-142,156,158,172,"
1674 "174,186,191,203-207,219-225,235-239,"
1675 "251-254",
1676#else
1677 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001678# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 (char_u *)"@,48-57,_,128-167,224-235"
1680# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001681 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682# endif
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1686 (char_u *)&p_isp, PV_NONE,
1687 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001688#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)"@,~-255",
1690#else
1691# ifdef EBCDIC
1692 /* all chars above 63 are printable */
1693 (char_u *)"63-255",
1694# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001695 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696# endif
1697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001698 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1700 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1703#ifdef FEAT_CRYPT
1704 (char_u *)&p_key, PV_KEY,
1705 {(char_u *)"", (char_u *)0L}
1706#else
1707 (char_u *)NULL, PV_NONE,
1708 {(char_u *)0L, (char_u *)0L}
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001711 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712#ifdef FEAT_KEYMAP
1713 (char_u *)&p_keymap, PV_KMAP,
1714 {(char_u *)"", (char_u *)0L}
1715#else
1716 (char_u *)NULL, PV_NONE,
1717 {(char_u *)"", (char_u *)0L}
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001720 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001724 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001726#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 (char_u *)":help",
1728#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001729# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001731# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001732# ifdef USEMAN_S
1733 (char_u *)"man -s",
1734# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001736# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737# endif
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001740 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741#ifdef FEAT_LANGMAP
1742 (char_u *)&p_langmap, PV_NONE,
1743 {(char_u *)"", /* unmatched } */
1744#else
1745 (char_u *)NULL, PV_NONE,
1746 {(char_u *)NULL,
1747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001749 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1751 (char_u *)&p_lm, PV_NONE,
1752#else
1753 (char_u *)NULL, PV_NONE,
1754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001756 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1757#ifdef FEAT_LANGMAP
1758 (char_u *)&p_lnr, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
1762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001763 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1764#ifdef FEAT_LANGMAP
1765 (char_u *)&p_lrm, PV_NONE,
1766#else
1767 (char_u *)NULL, PV_NONE,
1768#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001769 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1774 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1777#ifdef FEAT_LINEBREAK
1778 (char_u *)VAR_WIN, PV_LBR,
1779#else
1780 (char_u *)NULL, PV_NONE,
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1784 (char_u *)&Rows, PV_NONE,
1785 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001786#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 (char_u *)25L,
1788#else
1789 (char_u *)24L,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1793#ifdef FEAT_GUI
1794 (char_u *)&p_linespace, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
1798#ifdef FEAT_GUI_W32
1799 {(char_u *)1L, (char_u *)0L}
1800#else
1801 {(char_u *)0L, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lisp", NULL, P_BOOL|P_VI_DEF,
1805#ifdef FEAT_LISP
1806 (char_u *)&p_lisp, PV_LISP,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001811 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001813 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1815#else
1816 (char_u *)NULL, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1821 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001823 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1827 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001829 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001830#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001831 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001832 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001833#else
1834 (char_u *)NULL, PV_NONE,
1835 {(char_u *)"", (char_u *)0L}
1836#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001837 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001838 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001839#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001840 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001841 {(char_u *)TRUE, (char_u *)0L}
1842#else
1843 (char_u *)NULL, PV_NONE,
1844 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001845#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001846 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"magic", NULL, P_BOOL|P_VI_DEF,
1848 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001850 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851#ifdef FEAT_QUICKFIX
1852 (char_u *)&p_mef, PV_NONE,
1853 {(char_u *)"", (char_u *)0L}
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)NULL, (char_u *)0L}
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001859 {"makeencoding","menc", P_STRING|P_VI_DEF,
1860#ifdef FEAT_MBYTE
1861 (char_u *)&p_menc, PV_MENC,
1862 {(char_u *)"", (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
1867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1869#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001870 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871# ifdef VMS
1872 {(char_u *)"MMS", (char_u *)0L}
1873# else
1874 {(char_u *)"make", (char_u *)0L}
1875# endif
1876#else
1877 (char_u *)NULL, PV_NONE,
1878 {(char_u *)NULL, (char_u *)0L}
1879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001881 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1884 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"matchtime", "mat", P_NUM|P_VI_DEF,
1886 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001888 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001889#ifdef FEAT_MBYTE
1890 (char_u *)&p_mco, PV_NONE,
1891#else
1892 (char_u *)NULL, PV_NONE,
1893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1896#ifdef FEAT_EVAL
1897 (char_u *)&p_mfd, PV_NONE,
1898#else
1899 (char_u *)NULL, PV_NONE,
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1903 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"maxmem", "mm", P_NUM|P_VI_DEF,
1906 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1908 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001909 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1910 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1913 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"menuitems", "mis", P_NUM|P_VI_DEF,
1917#ifdef FEAT_MENU
1918 (char_u *)&p_mis, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"mesg", NULL, P_BOOL|P_VI_DEF,
1924 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001926 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001927#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001928 (char_u *)&p_msm, PV_NONE,
1929 {(char_u *)"460000,2000,500", (char_u *)0L}
1930#else
1931 (char_u *)NULL, PV_NONE,
1932 {(char_u *)0L, (char_u *)0L}
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"modeline", "ml", P_BOOL|P_VIM,
1936 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"modelines", "mls", P_NUM|P_VI_DEF,
1939 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1942 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1945 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"more", NULL, P_BOOL|P_VIM,
1948 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1951 (char_u *)&p_mouse, PV_NONE,
1952 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001953#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)"a",
1955#else
1956 (char_u *)"",
1957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1960#ifdef FEAT_GUI
1961 (char_u *)&p_mousef, PV_NONE,
1962#else
1963 (char_u *)NULL, PV_NONE,
1964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1967#ifdef FEAT_GUI
1968 (char_u *)&p_mh, PV_NONE,
1969#else
1970 (char_u *)NULL, PV_NONE,
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1974 (char_u *)&p_mousem, PV_NONE,
1975 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001976#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 (char_u *)"popup",
1978#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001979# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 (char_u *)"popup_setpos",
1981# else
1982 (char_u *)"extend",
1983# endif
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001986 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987#ifdef FEAT_MOUSESHAPE
1988 (char_u *)&p_mouseshape, PV_NONE,
1989 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1990#else
1991 (char_u *)NULL, PV_NONE,
1992 {(char_u *)NULL, (char_u *)0L}
1993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1996 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001998 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1999#if defined(DYNAMIC_MZSCHEME)
2000 (char_u *)&p_mzschemedll, PV_NONE,
2001 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)"", (char_u *)0L}
2005#endif
2006 SCRIPTID_INIT},
2007 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2008#if defined(DYNAMIC_MZSCHEME)
2009 (char_u *)&p_mzschemegcdll, PV_NONE,
2010 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)"", (char_u *)0L}
2014#endif
2015 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002016 {"mzquantum", "mzq", P_NUM,
2017#ifdef FEAT_MZSCHEME
2018 (char_u *)&p_mzq, PV_NONE,
2019#else
2020 (char_u *)NULL, PV_NONE,
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"novice", NULL, P_BOOL|P_VI_DEF,
2024 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002026 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002028 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2031 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002033 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2034#ifdef FEAT_LINEBREAK
2035 (char_u *)VAR_WIN, PV_NUW,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002040 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002041#ifdef FEAT_COMPL_FUNC
2042 (char_u *)&p_ofu, PV_OFU,
2043 {(char_u *)"", (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)0L, (char_u *)0L}
2047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"open", NULL, P_BOOL|P_VI_DEF,
2050 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002052 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002053#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002054 (char_u *)&p_odev, PV_NONE,
2055#else
2056 (char_u *)NULL, PV_NONE,
2057#endif
2058 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002060 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2061 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"optimize", "opt", P_BOOL|P_VI_DEF,
2064 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002068 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002069 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2070 |P_SECURE,
2071 (char_u *)&p_pp, PV_NONE,
2072 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 {"paragraphs", "para", P_STRING|P_VI_DEF,
2075 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002076 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002078 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2082 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2085#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2086 (char_u *)&p_pex, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)0L, (char_u *)0L}
2091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002093 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002097 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002099#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)".,,",
2101#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002105 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002106#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002107 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002108 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002112#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002113 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2115 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002117 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002118#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 (char_u *)&p_pvh, PV_NONE,
2120#else
2121 (char_u *)NULL, PV_NONE,
2122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002125#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 (char_u *)VAR_WIN, PV_PVW,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002131 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#ifdef FEAT_PRINTER
2133 (char_u *)&p_pdev, PV_NONE,
2134 {(char_u *)"", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"printencoding", "penc", P_STRING|P_VI_DEF,
2141#ifdef FEAT_POSTSCRIPT
2142 (char_u *)&p_penc, PV_NONE,
2143 {(char_u *)"", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002149 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150#ifdef FEAT_POSTSCRIPT
2151 (char_u *)&p_pexpr, PV_NONE,
2152 {(char_u *)"", (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)NULL, (char_u *)0L}
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"printfont", "pfn", P_STRING|P_VI_DEF,
2159#ifdef FEAT_PRINTER
2160 (char_u *)&p_pfn, PV_NONE,
2161 {
2162# ifdef MSWIN
2163 (char_u *)"Courier_New:h10",
2164# else
2165 (char_u *)"courier",
2166# endif
2167 (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2174#ifdef FEAT_PRINTER
2175 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002176 /* untranslated to avoid problems when 'encoding'
2177 * is changed */
2178 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#else
2180 (char_u *)NULL, PV_NONE,
2181 {(char_u *)NULL, (char_u *)0L}
2182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002184 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2185#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2186 (char_u *)&p_pmcs, PV_NONE,
2187 {(char_u *)"", (char_u *)0L}
2188#else
2189 (char_u *)NULL, PV_NONE,
2190 {(char_u *)NULL, (char_u *)0L}
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002193 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2194#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2195 (char_u *)&p_pmfn, PV_NONE,
2196 {(char_u *)"", (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002202 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203#ifdef FEAT_PRINTER
2204 (char_u *)&p_popt, PV_NONE,
2205 {(char_u *)"", (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002212 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002214 {"pumheight", "ph", P_NUM|P_VI_DEF,
2215#ifdef FEAT_INS_EXPAND
2216 (char_u *)&p_ph, PV_NONE,
2217#else
2218 (char_u *)NULL, PV_NONE,
2219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002221 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2222#ifdef FEAT_INS_EXPAND
2223 (char_u *)&p_pw, PV_NONE,
2224#else
2225 (char_u *)NULL, PV_NONE,
2226#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002227 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002228 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002229#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002230 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002231 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002232#else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002235#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002237 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2238#if defined(FEAT_PYTHON3)
2239 (char_u *)&p_py3home, PV_NONE,
2240 {(char_u *)"", (char_u *)0L}
2241#else
2242 (char_u *)NULL, PV_NONE,
2243 {(char_u *)NULL, (char_u *)0L}
2244#endif
2245 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002246 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002247#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002248 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002249 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250#else
2251 (char_u *)NULL, PV_NONE,
2252 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002253#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002255 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2256#if defined(FEAT_PYTHON)
2257 (char_u *)&p_pyhome, PV_NONE,
2258 {(char_u *)"", (char_u *)0L}
2259#else
2260 (char_u *)NULL, PV_NONE,
2261 {(char_u *)NULL, (char_u *)0L}
2262#endif
2263 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002264 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2265#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2266 (char_u *)&p_pyx, PV_NONE,
2267#else
2268 (char_u *)NULL, PV_NONE,
2269#endif
2270 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2271 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002272 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2273#ifdef FEAT_TEXTOBJ
2274 (char_u *)&p_qe, PV_QE,
2275 {(char_u *)"\\", (char_u *)0L}
2276#else
2277 (char_u *)NULL, PV_NONE,
2278 {(char_u *)NULL, (char_u *)0L}
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2282 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"redraw", NULL, P_BOOL|P_VI_DEF,
2285 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002287 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2288#ifdef FEAT_RELTIME
2289 (char_u *)&p_rdt, PV_NONE,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002294 {"regexpengine", "re", P_NUM|P_VI_DEF,
2295 (char_u *)&p_re, PV_NONE,
2296 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002297 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2298 (char_u *)VAR_WIN, PV_RNU,
2299 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"remap", NULL, P_BOOL|P_VI_DEF,
2301 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002303 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002304#ifdef FEAT_RENDER_OPTIONS
2305 (char_u *)&p_rop, PV_NONE,
2306 {(char_u *)"", (char_u *)0L}
2307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)NULL, (char_u *)0L}
2310#endif
2311 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"report", NULL, P_NUM|P_VI_DEF,
2313 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2316#ifdef WIN3264
2317 (char_u *)&p_rs, PV_NONE,
2318#else
2319 (char_u *)NULL, PV_NONE,
2320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2323#ifdef FEAT_RIGHTLEFT
2324 (char_u *)&p_ri, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2330#ifdef FEAT_RIGHTLEFT
2331 (char_u *)VAR_WIN, PV_RL,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2337#ifdef FEAT_RIGHTLEFT
2338 (char_u *)VAR_WIN, PV_RLC,
2339 {(char_u *)"search", (char_u *)NULL}
2340#else
2341 (char_u *)NULL, PV_NONE,
2342 {(char_u *)NULL, (char_u *)0L}
2343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002345 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002346#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002347 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002348 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349#else
2350 (char_u *)NULL, PV_NONE,
2351 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002352#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2355#ifdef FEAT_CMDL_INFO
2356 (char_u *)&p_ru, PV_NONE,
2357#else
2358 (char_u *)NULL, PV_NONE,
2359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2362#ifdef FEAT_STL_OPT
2363 (char_u *)&p_ruf, PV_NONE,
2364#else
2365 (char_u *)NULL, PV_NONE,
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002368 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2369 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2374 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002375 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002385 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 (char_u *)&p_sbo, PV_NONE,
2387 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"sections", "sect", P_STRING|P_VI_DEF,
2390 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2394 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"inclusive", (char_u *)0L}
2399 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002400 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002403 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404#ifdef FEAT_SESSION
2405 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002406 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 (char_u *)0L}
2408#else
2409 (char_u *)NULL, PV_NONE,
2410 {(char_u *)0L, (char_u *)0L}
2411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2414 (char_u *)&p_sh, PV_NONE,
2415 {
2416#ifdef VMS
2417 (char_u *)"-",
2418#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002419# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002421# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423# endif
2424#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2427 (char_u *)&p_shcf, PV_NONE,
2428 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002429#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)"/c",
2431#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2436#ifdef FEAT_QUICKFIX
2437 (char_u *)&p_sp, PV_NONE,
2438 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002439#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441#else
2442 (char_u *)">",
2443#endif
2444 (char_u *)0L}
2445#else
2446 (char_u *)NULL, PV_NONE,
2447 {(char_u *)0L, (char_u *)0L}
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2451 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2454 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2457#ifdef BACKSLASH_IN_FILENAME
2458 (char_u *)&p_ssl, PV_NONE,
2459#else
2460 (char_u *)NULL, PV_NONE,
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002463 {"shelltemp", "stmp", P_BOOL,
2464 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"shelltype", "st", P_NUM|P_VI_DEF,
2467#ifdef AMIGA
2468 (char_u *)&p_st, PV_NONE,
2469#else
2470 (char_u *)NULL, PV_NONE,
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2474 (char_u *)&p_sxq, PV_NONE,
2475 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002476#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 (char_u *)"\"",
2478#else
2479 (char_u *)"",
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002482 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2483 (char_u *)&p_sxe, PV_NONE,
2484 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002485#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002486 (char_u *)"\"&|<>()@^",
2487#else
2488 (char_u *)"",
2489#endif
2490 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2492 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2495 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2498 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)"", (char_u *)"filnxtToO"}
2500 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2505#ifdef FEAT_LINEBREAK
2506 (char_u *)&p_sbr, PV_NONE,
2507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"showcmd", "sc", P_BOOL|P_VIM,
2512#ifdef FEAT_CMDL_INFO
2513 (char_u *)&p_sc, PV_NONE,
2514#else
2515 (char_u *)NULL, PV_NONE,
2516#endif
2517 {(char_u *)FALSE,
2518#ifdef UNIX
2519 (char_u *)FALSE
2520#else
2521 (char_u *)TRUE
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2525 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2528 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"showmode", "smd", P_BOOL|P_VIM,
2531 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002533 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002534 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2537 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2540 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002542 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2543#ifdef FEAT_SIGNS
2544 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002545 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002546#else
2547 (char_u *)NULL, PV_NONE,
2548 {(char_u *)NULL, (char_u *)0L}
2549#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2552 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2555 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2558#ifdef FEAT_SMARTINDENT
2559 (char_u *)&p_si, PV_SI,
2560#else
2561 (char_u *)NULL, PV_NONE,
2562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2565 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2568 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002573 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002574#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002575 (char_u *)VAR_WIN, PV_SPELL,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002580 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002581#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002582 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002583 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002584#else
2585 (char_u *)NULL, PV_NONE,
2586 {(char_u *)0L, (char_u *)0L}
2587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002589 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2590 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002591#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002592 (char_u *)&p_spf, PV_SPF,
2593 {(char_u *)"", (char_u *)0L}
2594#else
2595 (char_u *)NULL, PV_NONE,
2596 {(char_u *)0L, (char_u *)0L}
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002599 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2600 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002601#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002602 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002603 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002604#else
2605 (char_u *)NULL, PV_NONE,
2606 {(char_u *)0L, (char_u *)0L}
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002609 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002610#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002611 (char_u *)&p_sps, PV_NONE,
2612 {(char_u *)"best", (char_u *)0L}
2613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2625 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2628#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002629 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002634 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 (char_u *)&p_su, PV_NONE,
2636 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002639#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_sua, PV_SUA,
2641 {(char_u *)"", (char_u *)0L}
2642#else
2643 (char_u *)NULL, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2648 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"swapsync", "sws", P_STRING|P_VI_DEF,
2651 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002653 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002656 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2657#ifdef FEAT_SYN_HL
2658 (char_u *)&p_smc, PV_SMC,
2659 {(char_u *)3000L, (char_u *)0L}
2660#else
2661 (char_u *)NULL, PV_NONE,
2662 {(char_u *)0L, (char_u *)0L}
2663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002665 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666#ifdef FEAT_SYN_HL
2667 (char_u *)&p_syn, PV_SYN,
2668 {(char_u *)"", (char_u *)0L}
2669#else
2670 (char_u *)NULL, PV_NONE,
2671 {(char_u *)0L, (char_u *)0L}
2672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002674 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2675#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002676 (char_u *)&p_tal, PV_NONE,
2677#else
2678 (char_u *)NULL, PV_NONE,
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002681 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002682 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2685 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2688 (char_u *)&p_tbs, PV_NONE,
2689#ifdef VMS /* binary searching doesn't appear to work on VMS */
2690 {(char_u *)0L, (char_u *)0L}
2691#else
2692 {(char_u *)TRUE, (char_u *)0L}
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002695 {"tagcase", "tc", P_STRING|P_VIM,
2696 (char_u *)&p_tc, PV_TC,
2697 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {"taglength", "tl", P_NUM|P_VI_DEF,
2699 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"tagrelative", "tr", P_BOOL|P_VIM,
2702 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002704 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002705 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {
2707#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2708 (char_u *)"./tags,./TAGS,tags,TAGS",
2709#else
2710 (char_u *)"./tags,tags",
2711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2714 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002716 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002717#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002718 (char_u *)&p_tcldll, PV_NONE,
2719 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002720#else
2721 (char_u *)NULL, PV_NONE,
2722 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002723#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2726 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2729#ifdef FEAT_ARABIC
2730 (char_u *)&p_tbidi, PV_NONE,
2731#else
2732 (char_u *)NULL, PV_NONE,
2733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2736#ifdef FEAT_MBYTE
2737 (char_u *)&p_tenc, PV_NONE,
2738 {(char_u *)"", (char_u *)0L}
2739#else
2740 (char_u *)NULL, PV_NONE,
2741 {(char_u *)0L, (char_u *)0L}
2742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002744 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2745#ifdef FEAT_TERMGUICOLORS
2746 (char_u *)&p_tgc, PV_NONE,
2747 {(char_u *)FALSE, (char_u *)FALSE}
2748#else
2749 (char_u*)NULL, PV_NONE,
2750 {(char_u *)FALSE, (char_u *)FALSE}
2751#endif
2752 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002753 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2754#ifdef FEAT_TERMINAL
2755 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002756 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002757#else
2758 (char_u *)NULL, PV_NONE,
2759 {(char_u *)NULL, (char_u *)0L}
2760#endif
2761 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002762 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2763#ifdef FEAT_TERMINAL
2764 (char_u *)VAR_WIN, PV_TMS,
2765 {(char_u *)"", (char_u *)NULL}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)NULL, (char_u *)0L}
2769#endif
2770 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"terse", NULL, P_BOOL|P_VI_DEF,
2772 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"textauto", "ta", P_BOOL|P_VIM,
2775 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2777 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2779 (char_u *)&p_tx, PV_TX,
2780 {
2781#ifdef USE_CRNL
2782 (char_u *)TRUE,
2783#else
2784 (char_u *)FALSE,
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002787 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002790 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002792 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793#else
2794 (char_u *)NULL, PV_NONE,
2795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2798 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"timeout", "to", P_BOOL|P_VI_DEF,
2801 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2804 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"title", NULL, P_BOOL|P_VI_DEF,
2807#ifdef FEAT_TITLE
2808 (char_u *)&p_title, PV_NONE,
2809#else
2810 (char_u *)NULL, PV_NONE,
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"titlelen", NULL, P_NUM|P_VI_DEF,
2814#ifdef FEAT_TITLE
2815 (char_u *)&p_titlelen, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002820 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821#ifdef FEAT_TITLE
2822 (char_u *)&p_titleold, PV_NONE,
2823 {(char_u *)N_("Thanks for flying Vim"),
2824 (char_u *)0L}
2825#else
2826 (char_u *)NULL, PV_NONE,
2827 {(char_u *)0L, (char_u *)0L}
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"titlestring", NULL, P_STRING|P_VI_DEF,
2831#ifdef FEAT_TITLE
2832 (char_u *)&p_titlestring, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002837 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002838#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002841#else
2842 (char_u *)NULL, PV_NONE,
2843 {(char_u *)0L, (char_u *)0L}
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002849 {(char_u *)"small", (char_u *)0L}
2850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2856 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2859 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2862 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2865 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2868#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2869 (char_u *)&p_ttym, PV_NONE,
2870#else
2871 (char_u *)NULL, PV_NONE,
2872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2875 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2878 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2881 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002882#ifdef FEAT_PERSISTENT_UNDO
2883 (char_u *)&p_udir, PV_NONE,
2884 {(char_u *)".", (char_u *)0L}
2885#else
2886 (char_u *)NULL, PV_NONE,
2887 {(char_u *)0L, (char_u *)0L}
2888#endif
2889 SCRIPTID_INIT},
2890 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udf, PV_UDF,
2893#else
2894 (char_u *)NULL, PV_NONE,
2895#endif
2896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002898 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002900#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 (char_u *)1000L,
2902#else
2903 (char_u *)100L,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002906 {"undoreload", "ur", P_NUM|P_VI_DEF,
2907 (char_u *)&p_ur, PV_NONE,
2908 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"updatecount", "uc", P_NUM|P_VI_DEF,
2910 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"updatetime", "ut", P_NUM|P_VI_DEF,
2913 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 {"verbose", "vbs", P_NUM|P_VI_DEF,
2916 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002918 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2919 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2922#ifdef FEAT_SESSION
2923 (char_u *)&p_vdir, PV_NONE,
2924 {(char_u *)DFLT_VDIR, (char_u *)0L}
2925#else
2926 (char_u *)NULL, PV_NONE,
2927 {(char_u *)0L, (char_u *)0L}
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002930 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931#ifdef FEAT_SESSION
2932 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002933 {(char_u *)"folds,options,cursor,curdir",
2934 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935#else
2936 (char_u *)NULL, PV_NONE,
2937 {(char_u *)0L, (char_u *)0L}
2938#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002940 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#ifdef FEAT_VIMINFO
2942 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002943#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002944 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945#else
2946# ifdef AMIGA
2947 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002948 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002950 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951# endif
2952#endif
2953#else
2954 (char_u *)NULL, PV_NONE,
2955 {(char_u *)0L, (char_u *)0L}
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002958 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2959#ifdef FEAT_VIMINFO
2960 (char_u *)&p_viminfofile, PV_NONE,
2961 {(char_u *)"", (char_u *)0L}
2962#else
2963 (char_u *)NULL, PV_NONE,
2964 {(char_u *)0L, (char_u *)0L}
2965#endif
2966 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002967 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2968 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969#ifdef FEAT_VIRTUALEDIT
2970 (char_u *)&p_ve, PV_NONE,
2971 {(char_u *)"", (char_u *)""}
2972#else
2973 (char_u *)NULL, PV_NONE,
2974 {(char_u *)0L, (char_u *)0L}
2975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w300", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"w1200", NULL, P_NUM|P_VI_DEF,
2984 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002985 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"w9600", NULL, P_NUM|P_VI_DEF,
2987 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"warn", NULL, P_BOOL|P_VI_DEF,
2990 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2993 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002997 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"wildchar", "wc", P_NUM|P_VIM,
2999 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3001 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003002 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003005 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006#ifdef FEAT_WILDIGN
3007 (char_u *)&p_wig, PV_NONE,
3008#else
3009 (char_u *)NULL, PV_NONE,
3010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003012 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3013 (char_u *)&p_wic, PV_NONE,
3014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3016#ifdef FEAT_WILDMENU
3017 (char_u *)&p_wmnu, PV_NONE,
3018#else
3019 (char_u *)NULL, PV_NONE,
3020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003022 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003025 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3026#ifdef FEAT_CMDL_COMPL
3027 (char_u *)&p_wop, PV_NONE,
3028 {(char_u *)"", (char_u *)0L}
3029#else
3030 (char_u *)NULL, PV_NONE,
3031 {(char_u *)NULL, (char_u *)0L}
3032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3035#ifdef FEAT_WAK
3036 (char_u *)&p_wak, PV_NONE,
3037 {(char_u *)"menu", (char_u *)0L}
3038#else
3039 (char_u *)NULL, PV_NONE,
3040 {(char_u *)NULL, (char_u *)0L}
3041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003044 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003045 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003048 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003052 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003053 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003057 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003060 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003061 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003062#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003063 (char_u *)&p_winptydll, PV_NONE, {
3064# ifdef _WIN64
3065 (char_u *)"winpty64.dll",
3066# else
3067 (char_u *)"winpty32.dll",
3068# endif
3069 (char_u *)0L}
3070#else
3071 (char_u *)NULL, PV_NONE,
3072 {(char_u *)0L, (char_u *)0L}
3073#endif
3074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003077 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3079 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3082 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3085 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"write", NULL, P_BOOL|P_VI_DEF,
3088 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"writeany", "wa", P_BOOL|P_VI_DEF,
3091 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3094 (char_u *)&p_wb, PV_NONE,
3095 {
3096#ifdef FEAT_WRITEBACKUP
3097 (char_u *)TRUE,
3098#else
3099 (char_u *)FALSE,
3100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writedelay", "wd", P_NUM|P_VI_DEF,
3103 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105
3106/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003107#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
3111 p_term("t_AB", T_CAB)
3112 p_term("t_AF", T_CAF)
3113 p_term("t_AL", T_CAL)
3114 p_term("t_al", T_AL)
3115 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003116 p_term("t_BE", T_BE)
3117 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_cd", T_CD)
3119 p_term("t_ce", T_CE)
3120 p_term("t_cl", T_CL)
3121 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003122 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_Co", T_CCO)
3124 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003125 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_da", T_DA)
3129 p_term("t_db", T_DB)
3130 p_term("t_DL", T_CDL)
3131 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003132 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003133 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003135 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_IE", T_CIE)
3137 p_term("t_IS", T_CIS)
3138 p_term("t_ke", T_KE)
3139 p_term("t_ks", T_KS)
3140 p_term("t_le", T_LE)
3141 p_term("t_mb", T_MB)
3142 p_term("t_md", T_MD)
3143 p_term("t_me", T_ME)
3144 p_term("t_mr", T_MR)
3145 p_term("t_ms", T_MS)
3146 p_term("t_nd", T_ND)
3147 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003148 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003149 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003150 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_RV", T_CRV)
3154 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003155 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003159 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003161 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003163 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_te", T_TE)
3165 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003166 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ts", T_TS)
3168 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_ue", T_UE)
3170 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vb", T_VB)
3173 p_term("t_ve", T_VE)
3174 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_vs", T_VS)
3177 p_term("t_WP", T_CWP)
3178 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003179 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 p_term("t_xs", T_XS)
3181 p_term("t_ZH", T_CZH)
3182 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003183 p_term("t_8f", T_8F)
3184 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185
3186/* terminal key codes are not in here */
3187
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003188 /* end marker */
3189 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190};
3191
3192#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3193
3194#ifdef FEAT_MBYTE
3195static char *(p_ambw_values[]) = {"single", "double", NULL};
3196#endif
3197static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003198static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003200#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003201static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003202#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003203#ifdef FEAT_CMDL_COMPL
3204static char *(p_wop_values[]) = {"tagfile", NULL};
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206#ifdef FEAT_WAK
3207static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3208#endif
3209static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3211static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213#ifdef FEAT_BROWSE
3214static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003217static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003220static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3222#ifdef FEAT_FOLDING
3223static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003224# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 NULL};
3228static char *(p_fcl_values[]) = {"all", NULL};
3229#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003230#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003231static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003233#ifdef FEAT_SIGNS
3234static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3235#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003237static void set_option_default(int, int opt_flags, int compatible);
3238static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003239static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static char_u *term_bg_default(void);
3241static void did_set_option(int opt_idx, int opt_flags, int new_value);
3242static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245#endif
3246#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static char_u *option_expand(int opt_idx, char_u *val);
3250static void didset_options(void);
3251static void didset_options2(void);
3252static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003253#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003255#else
3256# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3257#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void set_string_option_global(int opt_idx, char_u **varp);
3259static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3260static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3261static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003262#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static char_u *did_set_spell_option(int is_spellfile);
3270static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003272#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003274#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3277static void check_redraw(long_u flags);
3278static int findoption(char_u *);
3279static int find_key_option(char_u *);
3280static void showoptions(int all, int opt_flags);
3281static int optval_default(struct vimoption *, char_u *varp);
3282static void showoneopt(struct vimoption *, int opt_flags);
3283static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3284static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286static int istermoption(struct vimoption *);
3287static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288static char_u *get_varp(struct vimoption *);
3289static void option_value2string(struct vimoption *, int opt_flags);
3290static void check_winopt(winopt_T *wop);
3291static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void langmap_init(void);
3294static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static void paste_option_changed(void);
3297static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302static int check_opt_strings(char_u *val, char **values, int);
3303static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003304#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308/*
3309 * Initialize the options, first part.
3310 *
3311 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003312 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 */
3314 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003315set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316{
3317 char_u *p;
3318 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003319 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321#ifdef FEAT_LANGMAP
3322 langmap_init();
3323#endif
3324
3325 /* Be Vi compatible by default */
3326 p_cp = TRUE;
3327
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003328 /* Use POSIX compatibility when $VIM_POSIX is set. */
3329 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003330 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003331 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003332 set_string_default("shm", (char_u *)"A");
3333 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003334
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 /*
3336 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003337 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003339 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003340#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003341 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003343 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344# endif
3345#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003347 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349#ifdef FEAT_WILDIGN
3350 /*
3351 * Set the default for 'backupskip' to include environment variables for
3352 * temp files.
3353 */
3354 {
3355# ifdef UNIX
3356 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3357# else
3358 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3359# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003360 int len;
3361 garray_T ga;
3362 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364 ga_init2(&ga, 1, 100);
3365 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3366 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003367 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368# ifdef UNIX
3369 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003370# ifdef MACOS_X
3371 p = (char_u *)"/private/tmp";
3372# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 else
3376# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 if (p != NULL && *p != NUL)
3379 {
3380 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003381 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 if (ga_grow(&ga, len) == OK)
3383 {
3384 if (ga.ga_len > 0)
3385 STRCAT(ga.ga_data, ",");
3386 STRCAT(ga.ga_data, p);
3387 add_pathsep(ga.ga_data);
3388 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 ga.ga_len += len;
3390 }
3391 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003392 if (mustfree)
3393 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394 }
3395 if (ga.ga_data != NULL)
3396 {
3397 set_string_default("bsk", ga.ga_data);
3398 vim_free(ga.ga_data);
3399 }
3400 }
3401#endif
3402
3403 /*
3404 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3405 */
3406 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003409#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3410 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3411#endif
3412 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003415 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416#else
3417# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003418 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003419 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003421 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422# endif
3423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003425 opt_idx = findoption((char_u *)"maxmem");
3426 if (opt_idx >= 0)
3427 {
3428#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003429 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3430 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431#endif
3432 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3433 }
3434 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 }
3436
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437#ifdef FEAT_SEARCHPATH
3438 {
3439 char_u *cdpath;
3440 char_u *buf;
3441 int i;
3442 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003443 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444
3445 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003446 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447 if (cdpath != NULL)
3448 {
3449 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3450 if (buf != NULL)
3451 {
3452 buf[0] = ','; /* start with ",", current dir first */
3453 j = 1;
3454 for (i = 0; cdpath[i] != NUL; ++i)
3455 {
3456 if (vim_ispathlistsep(cdpath[i]))
3457 buf[j++] = ',';
3458 else
3459 {
3460 if (cdpath[i] == ' ' || cdpath[i] == ',')
3461 buf[j++] = '\\';
3462 buf[j++] = cdpath[i];
3463 }
3464 }
3465 buf[j] = NUL;
3466 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003467 if (opt_idx >= 0)
3468 {
3469 options[opt_idx].def_val[VI_DEFAULT] = buf;
3470 options[opt_idx].flags |= P_DEF_ALLOCED;
3471 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003472 else
3473 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003475 if (mustfree)
3476 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 }
3478 }
3479#endif
3480
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003481#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 /* Set print encoding on platforms that don't default to latin1 */
3483 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003484# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485 (char_u *)"cp1252"
3486# else
3487# ifdef VMS
3488 (char_u *)"dec-mcs"
3489# else
3490# ifdef EBCDIC
3491 (char_u *)"ebcdic-uk"
3492# else
3493# ifdef MAC
3494 (char_u *)"mac-roman"
3495# else /* HPUX */
3496 (char_u *)"hp-roman8"
3497# endif
3498# endif
3499# endif
3500# endif
3501 );
3502#endif
3503
3504#ifdef FEAT_POSTSCRIPT
3505 /* 'printexpr' must be allocated to be able to evaluate it. */
3506 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003507# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003508 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509# else
3510# ifdef VMS
3511 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3512
3513# else
3514 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3515# endif
3516# endif
3517 );
3518#endif
3519
3520 /*
3521 * Set all the options (except the terminal options) to their default
3522 * value. Also set the global value for local options.
3523 */
3524 set_options_default(0);
3525
Bram Moolenaar07268702018-03-01 21:57:32 +01003526#ifdef CLEAN_RUNTIMEPATH
3527 if (clean_arg)
3528 {
3529 opt_idx = findoption((char_u *)"runtimepath");
3530 if (opt_idx >= 0)
3531 {
3532 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3533 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3534 }
3535 opt_idx = findoption((char_u *)"packpath");
3536 if (opt_idx >= 0)
3537 {
3538 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3539 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3540 }
3541 }
3542#endif
3543
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544#ifdef FEAT_GUI
3545 if (found_reverse_arg)
3546 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3547#endif
3548
3549 curbuf->b_p_initialized = TRUE;
3550 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003551 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552 check_buf_options(curbuf);
3553 check_win_options(curwin);
3554 check_options();
3555
3556 /* Must be before option_expand(), because that one needs vim_isIDc() */
3557 didset_options();
3558
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003559#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003560 /* Use the current chartab for the generic chartab. This is not in
3561 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003562 init_spell_chartab();
3563#endif
3564
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 /*
3566 * Expand environment variables and things like "~" for the defaults.
3567 * If option_expand() returns non-NULL the variable is expanded. This can
3568 * only happen for non-indirect options.
3569 * Also set the default to the expanded value, so ":set" does not list
3570 * them.
3571 * Don't set the P_ALLOCED flag, because we don't want to free the
3572 * default.
3573 */
3574 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3575 {
3576 if ((options[opt_idx].flags & P_GETTEXT)
3577 && options[opt_idx].var != NULL)
3578 p = (char_u *)_(*(char **)options[opt_idx].var);
3579 else
3580 p = option_expand(opt_idx, NULL);
3581 if (p != NULL && (p = vim_strsave(p)) != NULL)
3582 {
3583 *(char_u **)options[opt_idx].var = p;
3584 /* VIMEXP
3585 * Defaults for all expanded options are currently the same for Vi
3586 * and Vim. When this changes, add some code here! Also need to
3587 * split P_DEF_ALLOCED in two.
3588 */
3589 if (options[opt_idx].flags & P_DEF_ALLOCED)
3590 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3591 options[opt_idx].def_val[VI_DEFAULT] = p;
3592 options[opt_idx].flags |= P_DEF_ALLOCED;
3593 }
3594 }
3595
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 save_file_ff(curbuf); /* Buffer is unchanged */
3597
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598#if defined(FEAT_ARABIC)
3599 /* Detect use of mlterm.
3600 * Mlterm is a terminal emulator akin to xterm that has some special
3601 * abilities (bidi namely).
3602 * NOTE: mlterm's author is being asked to 'set' a variable
3603 * instead of an environment variable due to inheritance.
3604 */
3605 if (mch_getenv((char_u *)"MLTERM") != NULL)
3606 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3607#endif
3608
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003609 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610
3611#ifdef FEAT_MBYTE
3612# if defined(WIN3264) && defined(FEAT_GETTEXT)
3613 /*
3614 * If $LANG isn't set, try to get a good value for it. This makes the
3615 * right language be used automatically. Don't do this for English.
3616 */
3617 if (mch_getenv((char_u *)"LANG") == NULL)
3618 {
3619 char buf[20];
3620
3621 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3622 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3623 * only the first two. */
3624 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3625 (LPTSTR)buf, 20);
3626 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3627 {
3628 /* There are a few exceptions (probably more) */
3629 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3630 STRCPY(buf, "zh_TW");
3631 else if (STRNICMP(buf, "chs", 3) == 0
3632 || STRNICMP(buf, "zhc", 3) == 0)
3633 STRCPY(buf, "zh_CN");
3634 else if (STRNICMP(buf, "jp", 2) == 0)
3635 STRCPY(buf, "ja");
3636 else
3637 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003638 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639 }
3640 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003641# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003642# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003643 /* Moved to os_mac_conv.c to avoid dependency problems. */
3644 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003645# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646# endif
3647
3648 /* enc_locale() will try to find the encoding of the current locale. */
3649 p = enc_locale();
3650 if (p != NULL)
3651 {
3652 char_u *save_enc;
3653
3654 /* Try setting 'encoding' and check if the value is valid.
3655 * If not, go back to the default "latin1". */
3656 save_enc = p_enc;
3657 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003658 if (STRCMP(p_enc, "gb18030") == 0)
3659 {
3660 /* We don't support "gb18030", but "cp936" is a good substitute
3661 * for practical purposes, thus use that. It's not an alias to
3662 * still support conversion between gb18030 and utf-8. */
3663 p_enc = vim_strsave((char_u *)"cp936");
3664 vim_free(p);
3665 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666 if (mb_init() == NULL)
3667 {
3668 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 {
3671 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3672 options[opt_idx].flags |= P_DEF_ALLOCED;
3673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674
Bram Moolenaard0573012017-10-28 21:11:06 +02003675#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003676 if (STRCMP(p_enc, "latin1") == 0
3677# ifdef FEAT_MBYTE
3678 || enc_utf8
3679# endif
3680 )
3681 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003682 /* Adjust the default for 'isprint' and 'iskeyword' to match
3683 * latin1. Also set the defaults for when 'nocompatible' is
3684 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003685 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003686 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003687 set_string_option_direct((char_u *)"isk", -1,
3688 ISK_LATIN1, OPT_FREE, SID_NONE);
3689 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003690 if (opt_idx >= 0)
3691 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003692 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003693 if (opt_idx >= 0)
3694 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003695 (void)init_chartab();
3696 }
3697#endif
3698
Bram Moolenaar071d4272004-06-13 20:20:40 +00003699# if defined(WIN3264) && !defined(FEAT_GUI)
3700 /* Win32 console: When GetACP() returns a different value from
3701 * GetConsoleCP() set 'termencoding'. */
3702 if (GetACP() != GetConsoleCP())
3703 {
3704 char buf[50];
3705
3706 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3707 p_tenc = vim_strsave((char_u *)buf);
3708 if (p_tenc != NULL)
3709 {
3710 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003711 if (opt_idx >= 0)
3712 {
3713 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3714 options[opt_idx].flags |= P_DEF_ALLOCED;
3715 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 convert_setup(&input_conv, p_tenc, p_enc);
3717 convert_setup(&output_conv, p_enc, p_tenc);
3718 }
3719 else
3720 p_tenc = empty_option;
3721 }
3722# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003723# if defined(WIN3264) && defined(FEAT_MBYTE)
3724 /* $HOME may have characters in active code page. */
3725 init_homedir();
3726# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 }
3728 else
3729 {
3730 vim_free(p_enc);
3731 p_enc = save_enc;
3732 }
3733 }
3734#endif
3735
3736#ifdef FEAT_MULTI_LANG
3737 /* Set the default for 'helplang'. */
3738 set_helplang_default(get_mess_lang());
3739#endif
3740}
3741
3742/*
3743 * Set an option to its default value.
3744 * This does not take care of side effects!
3745 */
3746 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003747set_option_default(
3748 int opt_idx,
3749 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3750 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751{
3752 char_u *varp; /* pointer to variable for current option */
3753 int dvi; /* index in def_val[] */
3754 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003755 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3757
3758 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3759 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003760 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 {
3762 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3763 if (flags & P_STRING)
3764 {
3765 /* Use set_string_option_direct() for local options to handle
3766 * freeing and allocating the value. */
3767 if (options[opt_idx].indir != PV_NONE)
3768 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003769 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 else
3771 {
3772 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3773 free_string_option(*(char_u **)(varp));
3774 *(char_u **)varp = options[opt_idx].def_val[dvi];
3775 options[opt_idx].flags &= ~P_ALLOCED;
3776 }
3777 }
3778 else if (flags & P_NUM)
3779 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003780 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 win_comp_scroll(curwin);
3782 else
3783 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003784 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 /* May also set global value for local option. */
3786 if (both)
3787 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3788 *(long *)varp;
3789 }
3790 }
3791 else /* P_BOOL */
3792 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003793 /* the cast to long is required for Manx C, long_i is needed for
3794 * MSVC */
3795 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003796#ifdef UNIX
3797 /* 'modeline' defaults to off for root */
3798 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3799 *(int *)varp = FALSE;
3800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 /* May also set global value for local option. */
3802 if (both)
3803 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3804 *(int *)varp;
3805 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003806
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003807 /* The default value is not insecure. */
3808 flagsp = insecure_flag(opt_idx, opt_flags);
3809 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 }
3811
3812#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003813 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814#endif
3815}
3816
3817/*
3818 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003819 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 */
3821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003822set_options_default(
3823 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824{
3825 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003827 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828
3829 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003830 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003831#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003832 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833 || (TRUE
3834# if defined(FEAT_MBYTE)
3835 && options[i].var != (char_u *)&p_enc
3836# endif
3837# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003838 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003839 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003840# endif
3841 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003842#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003843 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 set_option_default(i, opt_flags, p_cp);
3845
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003847 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003849#ifdef FEAT_CINDENT
3850 parse_cino(curbuf);
3851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852}
3853
3854/*
3855 * Set the Vi-default value of a string option.
3856 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003857 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003859 static void
3860set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861{
3862 char_u *p;
3863 int opt_idx;
3864
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003865 if (escape && vim_strchr(val, ' ') != NULL)
3866 p = vim_strsave_escaped(val, (char_u *)" ");
3867 else
3868 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 if (p != NULL) /* we don't want a NULL */
3870 {
3871 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003872 if (opt_idx >= 0)
3873 {
3874 if (options[opt_idx].flags & P_DEF_ALLOCED)
3875 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3876 options[opt_idx].def_val[VI_DEFAULT] = p;
3877 options[opt_idx].flags |= P_DEF_ALLOCED;
3878 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 }
3880}
3881
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003882 void
3883set_string_default(char *name, char_u *val)
3884{
3885 set_string_default_esc(name, val, FALSE);
3886}
3887
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888/*
3889 * Set the Vi-default value of a number option.
3890 * Used for 'lines' and 'columns'.
3891 */
3892 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003893set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 int opt_idx;
3896
3897 opt_idx = findoption((char_u *)name);
3898 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003899 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900}
3901
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003902#if defined(EXITFREE) || defined(PROTO)
3903/*
3904 * Free all options.
3905 */
3906 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003907free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003908{
3909 int i;
3910
3911 for (i = 0; !istermoption(&options[i]); i++)
3912 {
3913 if (options[i].indir == PV_NONE)
3914 {
3915 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003916 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003917 free_string_option(*(char_u **)options[i].var);
3918 if (options[i].flags & P_DEF_ALLOCED)
3919 free_string_option(options[i].def_val[VI_DEFAULT]);
3920 }
3921 else if (options[i].var != VAR_WIN
3922 && (options[i].flags & P_STRING))
3923 /* buffer-local option: free global value */
3924 free_string_option(*(char_u **)options[i].var);
3925 }
3926}
3927#endif
3928
3929
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930/*
3931 * Initialize the options, part two: After getting Rows and Columns and
3932 * setting 'term'.
3933 */
3934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003935set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003937 int idx;
3938
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003940 * 'scroll' defaults to half the window height. The stored default is zero,
3941 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003943 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003944 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003945 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 comp_col();
3947
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003948 /*
3949 * 'window' is only for backwards compatibility with Vi.
3950 * Default is Rows - 1.
3951 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003952 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003953 p_window = Rows - 1;
3954 set_number_default("window", Rows - 1);
3955
Bram Moolenaarf740b292006-02-16 22:11:02 +00003956 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003957#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003958 /*
3959 * If 'background' wasn't set by the user, try guessing the value,
3960 * depending on the terminal name. Only need to check for terminals
3961 * with a dark background, that can handle color.
3962 */
3963 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003964 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3965 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003967 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003968 /* don't mark it as set, when starting the GUI it may be
3969 * changed again */
3970 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 }
3972#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003973
3974#ifdef CURSOR_SHAPE
3975 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3976#endif
3977#ifdef FEAT_MOUSESHAPE
3978 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3979#endif
3980#ifdef FEAT_PRINTER
3981 (void)parse_printoptions(); /* parse 'printoptions' default value */
3982#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983}
3984
3985/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 * Return "dark" or "light" depending on the kind of terminal.
3987 * This is just guessing! Recognized are:
3988 * "linux" Linux console
3989 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003990 * "cygwin.*" Cygwin shell
3991 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003992 * We also check the COLORFGBG environment variable, which is set by
3993 * rxvt and derivatives. This variable contains either two or three
3994 * values separated by semicolons; we want the last value in either
3995 * case. If this value is 0-6 or 8, our background is dark.
3996 */
3997 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003998term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003999{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004000#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004001 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002 return (char_u *)"dark";
4003#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004004 char_u *p;
4005
Bram Moolenaarf740b292006-02-16 22:11:02 +00004006 if (STRCMP(T_NAME, "linux") == 0
4007 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004008 || STRNCMP(T_NAME, "cygwin", 6) == 0
4009 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4011 && (p = vim_strrchr(p, ';')) != NULL
4012 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4013 && p[2] == NUL))
4014 return (char_u *)"dark";
4015 return (char_u *)"light";
4016#endif
4017}
4018
4019/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 * Initialize the options, part three: After reading the .vimrc
4021 */
4022 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004023set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004025#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026/*
4027 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4028 * This is done after other initializations, where 'shell' might have been
4029 * set, but only if they have not been set before.
4030 */
4031 char_u *p;
4032 int idx_srr;
4033 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004034# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 int idx_sp;
4036 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038
4039 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004040 if (idx_srr < 0)
4041 do_srr = FALSE;
4042 else
4043 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004046 if (idx_sp < 0)
4047 do_sp = FALSE;
4048 else
4049 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004051 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if (p != NULL)
4053 {
4054 /*
4055 * Default for p_sp is "| tee", for p_srr is ">".
4056 * For known shells it is changed here to include stderr.
4057 */
4058 if ( fnamecmp(p, "csh") == 0
4059 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 || fnamecmp(p, "csh.exe") == 0
4062 || fnamecmp(p, "tcsh.exe") == 0
4063# endif
4064 )
4065 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 if (do_sp)
4068 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004071# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4075 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 if (do_srr)
4078 {
4079 p_srr = (char_u *)">&";
4080 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4081 }
4082 }
4083 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 if ( fnamecmp(p, "sh") == 0
4086 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004087 || fnamecmp(p, "mksh") == 0
4088 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004090 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004092 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 || fnamecmp(p, "cmd") == 0
4095 || fnamecmp(p, "sh.exe") == 0
4096 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004097 || fnamecmp(p, "mksh.exe") == 0
4098 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004100 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 || fnamecmp(p, "bash.exe") == 0
4102 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 if (do_sp)
4108 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004111# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4115 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 if (do_srr)
4118 {
4119 p_srr = (char_u *)">%s 2>&1";
4120 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4121 }
4122 }
4123 vim_free(p);
4124 }
4125#endif
4126
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004127#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004129 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4130 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 * This is done after other initializations, where 'shell' might have been
4132 * set, but only if they have not been set before. Default for p_shcf is
4133 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004134 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004136 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 {
4138 int idx3;
4139
4140 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004141 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 {
4143 p_shcf = (char_u *)"-c";
4144 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4145 }
4146
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 /* Somehow Win32 requires the quotes around the redirection too */
4148 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004149 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 {
4151 p_sxq = (char_u *)"\"";
4152 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004155 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4156 {
4157 int idx3;
4158
4159 /*
4160 * cmd.exe on Windows will strip the first and last double quote given
4161 * on the command line, e.g. most of the time things like:
4162 * cmd /c "my path/to/echo" "my args to echo"
4163 * become:
4164 * my path/to/echo" "my args to echo
4165 * when executed.
4166 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004167 * To avoid this, set shellxquote to surround the command in
4168 * parenthesis. This appears to make most commands work, without
4169 * breaking commands that worked previously, such as
4170 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004171 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004172 idx3 = findoption((char_u *)"sxq");
4173 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4174 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004175 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004176 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4177 }
4178
Bram Moolenaara64ba222012-02-12 23:23:31 +01004179 idx3 = findoption((char_u *)"shcf");
4180 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4181 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004182 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004183 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4184 }
4185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186#endif
4187
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004188 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004189 {
4190 int idx_ffs = findoption((char_u *)"ffs");
4191
4192 /* Apply the first entry of 'fileformats' to the initial buffer. */
4193 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4194 set_fileformat(default_fileformat(), OPT_LOCAL);
4195 }
4196
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197#ifdef FEAT_TITLE
4198 set_title_defaults();
4199#endif
4200}
4201
4202#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4203/*
4204 * When 'helplang' is still at its default value, set it to "lang".
4205 * Only the first two characters of "lang" are used.
4206 */
4207 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004208set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209{
4210 int idx;
4211
4212 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4213 return;
4214 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004215 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 {
4217 if (options[idx].flags & P_ALLOCED)
4218 free_string_option(p_hlg);
4219 p_hlg = vim_strsave(lang);
4220 if (p_hlg == NULL)
4221 p_hlg = empty_option;
4222 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004223 {
4224 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4225 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4226 {
4227 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4228 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 options[idx].flags |= P_ALLOCED;
4233 }
4234}
4235#endif
4236
4237#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004238static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239
4240 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004241gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242{
4243 if (gui_get_lightness(gui.back_pixel) < 127)
4244 return (char_u *)"dark";
4245 return (char_u *)"light";
4246}
4247
4248/*
4249 * Option initializations that can only be done after opening the GUI window.
4250 */
4251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004252init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253{
4254 /* Set the 'background' option according to the lightness of the
4255 * background color, unless the user has set it already. */
4256 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4257 {
4258 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4259 highlight_changed();
4260 }
4261}
4262#endif
4263
4264#ifdef FEAT_TITLE
4265/*
4266 * 'title' and 'icon' only default to true if they have not been set or reset
4267 * in .vimrc and we can read the old value.
4268 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4269 * they can be reset. This reduces startup time when using X on a remote
4270 * machine.
4271 */
4272 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004273set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274{
4275 int idx1;
4276 long val;
4277
4278 /*
4279 * If GUI is (going to be) used, we can always set the window title and
4280 * icon name. Saves a bit of time, because the X11 display server does
4281 * not need to be contacted.
4282 */
4283 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004284 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004285 {
4286#ifdef FEAT_GUI
4287 if (gui.starting || gui.in_use)
4288 val = TRUE;
4289 else
4290#endif
4291 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004292 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293 p_title = val;
4294 }
4295 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004296 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004297 {
4298#ifdef FEAT_GUI
4299 if (gui.starting || gui.in_use)
4300 val = TRUE;
4301 else
4302#endif
4303 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004304 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004305 p_icon = val;
4306 }
4307}
4308#endif
4309
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004310#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004311 static void
4312trigger_optionsset_string(
4313 int opt_idx,
4314 int opt_flags,
4315 char_u *oldval,
4316 char_u *newval)
4317{
4318 if (oldval != NULL && newval != NULL)
4319 {
4320 char_u buf_type[7];
4321
4322 sprintf((char *)buf_type, "%s",
4323 (opt_flags & OPT_LOCAL) ? "local" : "global");
4324 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4325 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4326 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4327 apply_autocmds(EVENT_OPTIONSET,
4328 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4329 reset_v_option_vars();
4330 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004331}
4332#endif
4333
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334/*
4335 * Parse 'arg' for option settings.
4336 *
4337 * 'arg' may be IObuff, but only when no errors can be present and option
4338 * does not need to be expanded with option_expand().
4339 * "opt_flags":
4340 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004341 * OPT_GLOBAL for ":setglobal"
4342 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004344 * OPT_WINONLY to only set window-local options
4345 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 *
4347 * returns FAIL if an error is detected, OK otherwise
4348 */
4349 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004350do_set(
4351 char_u *arg, /* option string (may be written to!) */
4352 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353{
4354 int opt_idx;
4355 char_u *errmsg;
4356 char_u errbuf[80];
4357 char_u *startarg;
4358 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4359 int nextchar; /* next non-white char after option name */
4360 int afterchar; /* character just after option name */
4361 int len;
4362 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004363 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364 int key;
4365 long_u flags; /* flags for current option */
4366 char_u *varp = NULL; /* pointer to variable for current option */
4367 int did_show = FALSE; /* already showed one value */
4368 int adding; /* "opt+=arg" */
4369 int prepending; /* "opt^=arg" */
4370 int removing; /* "opt-=arg" */
4371 int cp_val = 0;
4372 char_u key_name[2];
4373
4374 if (*arg == NUL)
4375 {
4376 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004377 did_show = TRUE;
4378 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 }
4380
4381 while (*arg != NUL) /* loop to process all options */
4382 {
4383 errmsg = NULL;
4384 startarg = arg; /* remember for error message */
4385
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004386 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4387 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 {
4389 /*
4390 * ":set all" show all options.
4391 * ":set all&" set all options to their default value.
4392 */
4393 arg += 3;
4394 if (*arg == '&')
4395 {
4396 ++arg;
4397 /* Only for :set command set global value of local options. */
4398 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004399 didset_options();
4400 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004401 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 }
4403 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004404 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004406 did_show = TRUE;
4407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004409 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 {
4411 showoptions(2, opt_flags);
4412 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004413 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 arg += 7;
4415 }
4416 else
4417 {
4418 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004419 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 {
4421 prefix = 0;
4422 arg += 2;
4423 }
4424 else if (STRNCMP(arg, "inv", 3) == 0)
4425 {
4426 prefix = 2;
4427 arg += 3;
4428 }
4429
4430 /* find end of name */
4431 key = 0;
4432 if (*arg == '<')
4433 {
4434 nextchar = 0;
4435 opt_idx = -1;
4436 /* look out for <t_>;> */
4437 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4438 len = 5;
4439 else
4440 {
4441 len = 1;
4442 while (arg[len] != NUL && arg[len] != '>')
4443 ++len;
4444 }
4445 if (arg[len] != '>')
4446 {
4447 errmsg = e_invarg;
4448 goto skip;
4449 }
4450 arg[len] = NUL; /* put NUL after name */
4451 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4452 opt_idx = findoption(arg + 1);
4453 arg[len++] = '>'; /* restore '>' */
4454 if (opt_idx == -1)
4455 key = find_key_option(arg + 1);
4456 }
4457 else
4458 {
4459 len = 0;
4460 /*
4461 * The two characters after "t_" may not be alphanumeric.
4462 */
4463 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4464 len = 4;
4465 else
4466 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4467 ++len;
4468 nextchar = arg[len];
4469 arg[len] = NUL; /* put NUL after name */
4470 opt_idx = findoption(arg);
4471 arg[len] = nextchar; /* restore nextchar */
4472 if (opt_idx == -1)
4473 key = find_key_option(arg);
4474 }
4475
4476 /* remember character after option name */
4477 afterchar = arg[len];
4478
4479 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004480 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004481 ++len;
4482
4483 adding = FALSE;
4484 prepending = FALSE;
4485 removing = FALSE;
4486 if (arg[len] != NUL && arg[len + 1] == '=')
4487 {
4488 if (arg[len] == '+')
4489 {
4490 adding = TRUE; /* "+=" */
4491 ++len;
4492 }
4493 else if (arg[len] == '^')
4494 {
4495 prepending = TRUE; /* "^=" */
4496 ++len;
4497 }
4498 else if (arg[len] == '-')
4499 {
4500 removing = TRUE; /* "-=" */
4501 ++len;
4502 }
4503 }
4504 nextchar = arg[len];
4505
4506 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4507 {
4508 errmsg = (char_u *)N_("E518: Unknown option");
4509 goto skip;
4510 }
4511
4512 if (opt_idx >= 0)
4513 {
4514 if (options[opt_idx].var == NULL) /* hidden option: skip */
4515 {
4516 /* Only give an error message when requesting the value of
4517 * a hidden option, ignore setting it. */
4518 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4519 && (!(options[opt_idx].flags & P_BOOL)
4520 || nextchar == '?'))
4521 errmsg = (char_u *)N_("E519: Option not supported");
4522 goto skip;
4523 }
4524
4525 flags = options[opt_idx].flags;
4526 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4527 }
4528 else
4529 {
4530 flags = P_STRING;
4531 if (key < 0)
4532 {
4533 key_name[0] = KEY2TERMCAP0(key);
4534 key_name[1] = KEY2TERMCAP1(key);
4535 }
4536 else
4537 {
4538 key_name[0] = KS_KEY;
4539 key_name[1] = (key & 0xff);
4540 }
4541 }
4542
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004543 /* Skip all options that are not window-local (used when showing
4544 * an already loaded buffer in a window). */
4545 if ((opt_flags & OPT_WINONLY)
4546 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4547 goto skip;
4548
Bram Moolenaara3227e22006-03-08 21:32:40 +00004549 /* Skip all options that are window-local (used for :vimgrep). */
4550 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4551 && options[opt_idx].var == VAR_WIN)
4552 goto skip;
4553
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004554 /* Disallow changing some options from modelines. */
4555 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004556 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004557 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004558 {
4559 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4560 goto skip;
4561 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004562#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004563 /* In diff mode some options are overruled. This avoids that
4564 * 'foldmethod' becomes "marker" instead of "diff" and that
4565 * "wrap" gets set. */
4566 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004567 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004568 && (
4569#ifdef FEAT_FOLDING
4570 options[opt_idx].indir == PV_FDM ||
4571#endif
4572 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004573 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004574#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 }
4576
4577#ifdef HAVE_SANDBOX
4578 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004579 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004580 {
4581 errmsg = (char_u *)_(e_sandbox);
4582 goto skip;
4583 }
4584#endif
4585
4586 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4587 {
4588 arg += len;
4589 cp_val = p_cp;
4590 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4591 {
4592 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4593 {
4594 cp_val = FALSE;
4595 arg += 3;
4596 }
4597 else /* "opt&vi": set to Vi default */
4598 {
4599 cp_val = TRUE;
4600 arg += 2;
4601 }
4602 }
4603 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004604 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004605 {
4606 errmsg = e_trailing;
4607 goto skip;
4608 }
4609 }
4610
4611 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004612 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4613 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 */
4615 if (nextchar == '?'
4616 || (prefix == 1
4617 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4618 && !(flags & P_BOOL)))
4619 {
4620 /*
4621 * print value
4622 */
4623 if (did_show)
4624 msg_putchar('\n'); /* cursor below last one */
4625 else
4626 {
4627 gotocmdline(TRUE); /* cursor at status line */
4628 did_show = TRUE; /* remember that we did a line */
4629 }
4630 if (opt_idx >= 0)
4631 {
4632 showoneopt(&options[opt_idx], opt_flags);
4633#ifdef FEAT_EVAL
4634 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004635 {
4636 /* Mention where the option was last set. */
4637 if (varp == options[opt_idx].var)
4638 last_set_msg(options[opt_idx].scriptID);
4639 else if ((int)options[opt_idx].indir & PV_WIN)
4640 last_set_msg(curwin->w_p_scriptID[
4641 (int)options[opt_idx].indir & PV_MASK]);
4642 else if ((int)options[opt_idx].indir & PV_BUF)
4643 last_set_msg(curbuf->b_p_scriptID[
4644 (int)options[opt_idx].indir & PV_MASK]);
4645 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646#endif
4647 }
4648 else
4649 {
4650 char_u *p;
4651
4652 p = find_termcode(key_name);
4653 if (p == NULL)
4654 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004655 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004656 goto skip;
4657 }
4658 else
4659 (void)show_one_termcode(key_name, p, TRUE);
4660 }
4661 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004662 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004663 errmsg = e_trailing;
4664 }
4665 else
4666 {
4667 if (flags & P_BOOL) /* boolean */
4668 {
4669 if (nextchar == '=' || nextchar == ':')
4670 {
4671 errmsg = e_invarg;
4672 goto skip;
4673 }
4674
4675 /*
4676 * ":set opt!": invert
4677 * ":set opt&": reset to default value
4678 * ":set opt<": reset to global value
4679 */
4680 if (nextchar == '!')
4681 value = *(int *)(varp) ^ 1;
4682 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004683 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004684 ((flags & P_VI_DEF) || cp_val)
4685 ? VI_DEFAULT : VIM_DEFAULT];
4686 else if (nextchar == '<')
4687 {
4688 /* For 'autoread' -1 means to use global value. */
4689 if ((int *)varp == &curbuf->b_p_ar
4690 && opt_flags == OPT_LOCAL)
4691 value = -1;
4692 else
4693 value = *(int *)get_varp_scope(&(options[opt_idx]),
4694 OPT_GLOBAL);
4695 }
4696 else
4697 {
4698 /*
4699 * ":set invopt": invert
4700 * ":set opt" or ":set noopt": set or reset
4701 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004702 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703 {
4704 errmsg = e_trailing;
4705 goto skip;
4706 }
4707 if (prefix == 2) /* inv */
4708 value = *(int *)(varp) ^ 1;
4709 else
4710 value = prefix;
4711 }
4712
4713 errmsg = set_bool_option(opt_idx, varp, (int)value,
4714 opt_flags);
4715 }
4716 else /* numeric or string */
4717 {
4718 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4719 || prefix != 1)
4720 {
4721 errmsg = e_invarg;
4722 goto skip;
4723 }
4724
4725 if (flags & P_NUM) /* numeric */
4726 {
4727 /*
4728 * Different ways to set a number option:
4729 * & set to default value
4730 * < set to global value
4731 * <xx> accept special key codes for 'wildchar'
4732 * c accept any non-digit for 'wildchar'
4733 * [-]0-9 set number
4734 * other error
4735 */
4736 ++arg;
4737 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004738 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739 ((flags & P_VI_DEF) || cp_val)
4740 ? VI_DEFAULT : VIM_DEFAULT];
4741 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004742 {
4743 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4744 * use the global value. */
4745 if ((long *)varp == &curbuf->b_p_ul
4746 && opt_flags == OPT_LOCAL)
4747 value = NO_LOCAL_UNDOLEVEL;
4748 else
4749 value = *(long *)get_varp_scope(
4750 &(options[opt_idx]), OPT_GLOBAL);
4751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 else if (((long *)varp == &p_wc
4753 || (long *)varp == &p_wcm)
4754 && (*arg == '<'
4755 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004756 || (*arg != NUL
4757 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 && !VIM_ISDIGIT(*arg))))
4759 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004760 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 if (value == 0 && (long *)varp != &p_wcm)
4762 {
4763 errmsg = e_invarg;
4764 goto skip;
4765 }
4766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4768 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004769 /* Allow negative (for 'undolevels'), octal and
4770 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004771 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4772 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004773 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 {
4775 errmsg = e_invarg;
4776 goto skip;
4777 }
4778 }
4779 else
4780 {
4781 errmsg = (char_u *)N_("E521: Number required after =");
4782 goto skip;
4783 }
4784
4785 if (adding)
4786 value = *(long *)varp + value;
4787 if (prepending)
4788 value = *(long *)varp * value;
4789 if (removing)
4790 value = *(long *)varp - value;
4791 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004792 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 }
4794 else if (opt_idx >= 0) /* string */
4795 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004796 char_u *save_arg = NULL;
4797 char_u *s = NULL;
4798 char_u *oldval = NULL; /* previous value if *varp */
4799 char_u *newval;
4800 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004801#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004802 char_u *saved_origval = NULL;
4803 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004804#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004805 unsigned newlen;
4806 int comma;
4807 int bs;
4808 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004809 was allocated */
4810
4811 /* When using ":set opt=val" for a global option
4812 * with a local value the local value will be
4813 * reset, use the global value here. */
4814 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004815 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004816 varp = options[opt_idx].var;
4817
4818 /* The old value is kept until we are sure that the
4819 * new value is valid. */
4820 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004821
4822 /* When setting the local value of a global
4823 * option, the old value may be the global value. */
4824 if (((int)options[opt_idx].indir & PV_BOTH)
4825 && (opt_flags & OPT_LOCAL))
4826 origval = *(char_u **)get_varp(
4827 &options[opt_idx]);
4828 else
4829 origval = oldval;
4830
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 if (nextchar == '&') /* set to default val */
4832 {
4833 newval = options[opt_idx].def_val[
4834 ((flags & P_VI_DEF) || cp_val)
4835 ? VI_DEFAULT : VIM_DEFAULT];
4836 if ((char_u **)varp == &p_bg)
4837 {
4838 /* guess the value of 'background' */
4839#ifdef FEAT_GUI
4840 if (gui.in_use)
4841 newval = gui_bg_default();
4842 else
4843#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004844 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004845 }
4846
4847 /* expand environment variables and ~ (since the
4848 * default value was already expanded, only
4849 * required when an environment variable was set
4850 * later */
4851 if (newval == NULL)
4852 newval = empty_option;
4853 else
4854 {
4855 s = option_expand(opt_idx, newval);
4856 if (s == NULL)
4857 s = newval;
4858 newval = vim_strsave(s);
4859 }
4860 new_value_alloced = TRUE;
4861 }
4862 else if (nextchar == '<') /* set to global val */
4863 {
4864 newval = vim_strsave(*(char_u **)get_varp_scope(
4865 &(options[opt_idx]), OPT_GLOBAL));
4866 new_value_alloced = TRUE;
4867 }
4868 else
4869 {
4870 ++arg; /* jump to after the '=' or ':' */
4871
4872 /*
4873 * Set 'keywordprg' to ":help" if an empty
4874 * value was passed to :set by the user.
4875 * Misuse errbuf[] for the resulting string.
4876 */
4877 if (varp == (char_u *)&p_kp
4878 && (*arg == NUL || *arg == ' '))
4879 {
4880 STRCPY(errbuf, ":help");
4881 save_arg = arg;
4882 arg = errbuf;
4883 }
4884 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004885 * Convert 'backspace' number to string, for
4886 * adding, prepending and removing string.
4887 */
4888 else if (varp == (char_u *)&p_bs
4889 && VIM_ISDIGIT(**(char_u **)varp))
4890 {
4891 i = getdigits((char_u **)varp);
4892 switch (i)
4893 {
4894 case 0:
4895 *(char_u **)varp = empty_option;
4896 break;
4897 case 1:
4898 *(char_u **)varp = vim_strsave(
4899 (char_u *)"indent,eol");
4900 break;
4901 case 2:
4902 *(char_u **)varp = vim_strsave(
4903 (char_u *)"indent,eol,start");
4904 break;
4905 }
4906 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004907 if (origval == oldval)
4908 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004909 oldval = *(char_u **)varp;
4910 }
4911 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004912 * Convert 'whichwrap' number to string, for
4913 * backwards compatibility with Vim 3.0.
4914 * Misuse errbuf[] for the resulting string.
4915 */
4916 else if (varp == (char_u *)&p_ww
4917 && VIM_ISDIGIT(*arg))
4918 {
4919 *errbuf = NUL;
4920 i = getdigits(&arg);
4921 if (i & 1)
4922 STRCAT(errbuf, "b,");
4923 if (i & 2)
4924 STRCAT(errbuf, "s,");
4925 if (i & 4)
4926 STRCAT(errbuf, "h,l,");
4927 if (i & 8)
4928 STRCAT(errbuf, "<,>,");
4929 if (i & 16)
4930 STRCAT(errbuf, "[,],");
4931 if (*errbuf != NUL) /* remove trailing , */
4932 errbuf[STRLEN(errbuf) - 1] = NUL;
4933 save_arg = arg;
4934 arg = errbuf;
4935 }
4936 /*
4937 * Remove '>' before 'dir' and 'bdir', for
4938 * backwards compatibility with version 3.0
4939 */
4940 else if ( *arg == '>'
4941 && (varp == (char_u *)&p_dir
4942 || varp == (char_u *)&p_bdir))
4943 {
4944 ++arg;
4945 }
4946
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 /*
4948 * Copy the new string into allocated memory.
4949 * Can't use set_string_option_direct(), because
4950 * we need to remove the backslashes.
4951 */
4952 /* get a bit too much */
4953 newlen = (unsigned)STRLEN(arg) + 1;
4954 if (adding || prepending || removing)
4955 newlen += (unsigned)STRLEN(origval) + 1;
4956 newval = alloc(newlen);
4957 if (newval == NULL) /* out of mem, don't change */
4958 break;
4959 s = newval;
4960
4961 /*
4962 * Copy the string, skip over escaped chars.
4963 * For MS-DOS and WIN32 backslashes before normal
4964 * file name characters are not removed, and keep
4965 * backslash at start, for "\\machine\path", but
4966 * do remove it for "\\\\machine\\path".
4967 * The reverse is found in ExpandOldSetting().
4968 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004969 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004970 {
4971 if (*arg == '\\' && arg[1] != NUL
4972#ifdef BACKSLASH_IN_FILENAME
4973 && !((flags & P_EXPAND)
4974 && vim_isfilec(arg[1])
4975 && (arg[1] != '\\'
4976 || (s == newval
4977 && arg[2] != '\\')))
4978#endif
4979 )
4980 ++arg; /* remove backslash */
4981#ifdef FEAT_MBYTE
4982 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004983 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 {
4985 /* copy multibyte char */
4986 mch_memmove(s, arg, (size_t)i);
4987 arg += i;
4988 s += i;
4989 }
4990 else
4991#endif
4992 *s++ = *arg++;
4993 }
4994 *s = NUL;
4995
4996 /*
4997 * Expand environment variables and ~.
4998 * Don't do it when adding without inserting a
4999 * comma.
5000 */
5001 if (!(adding || prepending || removing)
5002 || (flags & P_COMMA))
5003 {
5004 s = option_expand(opt_idx, newval);
5005 if (s != NULL)
5006 {
5007 vim_free(newval);
5008 newlen = (unsigned)STRLEN(s) + 1;
5009 if (adding || prepending || removing)
5010 newlen += (unsigned)STRLEN(origval) + 1;
5011 newval = alloc(newlen);
5012 if (newval == NULL)
5013 break;
5014 STRCPY(newval, s);
5015 }
5016 }
5017
5018 /* locate newval[] in origval[] when removing it
5019 * and when adding to avoid duplicates */
5020 i = 0; /* init for GCC */
5021 if (removing || (flags & P_NODUP))
5022 {
5023 i = (int)STRLEN(newval);
5024 bs = 0;
5025 for (s = origval; *s; ++s)
5026 {
5027 if ((!(flags & P_COMMA)
5028 || s == origval
5029 || (s[-1] == ',' && !(bs & 1)))
5030 && STRNCMP(s, newval, i) == 0
5031 && (!(flags & P_COMMA)
5032 || s[i] == ','
5033 || s[i] == NUL))
5034 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005035 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005036 * even number of backslashes or a single
5037 * backslash preceded by a comma before it
5038 * is recognized as a separator */
5039 if ((s > origval + 1
5040 && s[-1] == '\\'
5041 && s[-2] != ',')
5042 || (s == origval + 1
5043 && s[-1] == '\\'))
5044
Bram Moolenaar071d4272004-06-13 20:20:40 +00005045 ++bs;
5046 else
5047 bs = 0;
5048 }
5049
5050 /* do not add if already there */
5051 if ((adding || prepending) && *s)
5052 {
5053 prepending = FALSE;
5054 adding = FALSE;
5055 STRCPY(newval, origval);
5056 }
5057 }
5058
5059 /* concatenate the two strings; add a ',' if
5060 * needed */
5061 if (adding || prepending)
5062 {
5063 comma = ((flags & P_COMMA) && *origval != NUL
5064 && *newval != NUL);
5065 if (adding)
5066 {
5067 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005068 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005069 if (comma && i > 1
5070 && (flags & P_ONECOMMA) == P_ONECOMMA
5071 && origval[i - 1] == ','
5072 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005073 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 mch_memmove(newval + i + comma, newval,
5075 STRLEN(newval) + 1);
5076 mch_memmove(newval, origval, (size_t)i);
5077 }
5078 else
5079 {
5080 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005081 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082 }
5083 if (comma)
5084 newval[i] = ',';
5085 }
5086
5087 /* Remove newval[] from origval[]. (Note: "i" has
5088 * been set above and is used here). */
5089 if (removing)
5090 {
5091 STRCPY(newval, origval);
5092 if (*s)
5093 {
5094 /* may need to remove a comma */
5095 if (flags & P_COMMA)
5096 {
5097 if (s == origval)
5098 {
5099 /* include comma after string */
5100 if (s[i] == ',')
5101 ++i;
5102 }
5103 else
5104 {
5105 /* include comma before string */
5106 --s;
5107 ++i;
5108 }
5109 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005110 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112 }
5113
5114 if (flags & P_FLAGLIST)
5115 {
5116 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005117 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005118 {
5119 /* if options have P_FLAGLIST and
5120 * P_ONECOMMA such as 'whichwrap' */
5121 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005123 if (*s != ',' && *(s + 1) == ','
5124 && vim_strchr(s + 2, *s) != NULL)
5125 {
5126 /* Remove the duplicated value and
5127 * the next comma. */
5128 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005129 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005132 else
5133 {
5134 if ((!(flags & P_COMMA) || *s != ',')
5135 && vim_strchr(s + 1, *s) != NULL)
5136 {
5137 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005138 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005139 }
5140 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005141 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 }
5144
5145 if (save_arg != NULL) /* number for 'whichwrap' */
5146 arg = save_arg;
5147 new_value_alloced = TRUE;
5148 }
5149
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005150 /*
5151 * Set the new value.
5152 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 *(char_u **)(varp) = newval;
5154
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005155#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005156 if (!starting
5157# ifdef FEAT_CRYPT
5158 && options[opt_idx].indir != PV_KEY
5159# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005160 && origval != NULL && newval != NULL)
5161 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005162 /* origval may be freed by
5163 * did_set_string_option(), make a copy. */
5164 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005165 /* newval (and varp) may become invalid if the
5166 * buffer is closed by autocommands. */
5167 saved_newval = vim_strsave(newval);
5168 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005169#endif
5170
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005172 * ":set" on local options. Note: when setting 'syntax'
5173 * or 'filetype' autocommands may be triggered that can
5174 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5176 new_value_alloced, oldval, errbuf, opt_flags);
5177
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005178#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005179 if (errmsg == NULL)
5180 trigger_optionsset_string(opt_idx, opt_flags,
5181 saved_origval, saved_newval);
5182 vim_free(saved_origval);
5183 vim_free(saved_newval);
5184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 /* If error detected, print the error message. */
5186 if (errmsg != NULL)
5187 goto skip;
5188 }
5189 else /* key code option */
5190 {
5191 char_u *p;
5192
5193 if (nextchar == '&')
5194 {
5195 if (add_termcap_entry(key_name, TRUE) == FAIL)
5196 errmsg = (char_u *)N_("E522: Not found in termcap");
5197 }
5198 else
5199 {
5200 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005201 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005202 if (*p == '\\' && p[1] != NUL)
5203 ++p;
5204 nextchar = *p;
5205 *p = NUL;
5206 add_termcode(key_name, arg, FALSE);
5207 *p = nextchar;
5208 }
5209 if (full_screen)
5210 ttest(FALSE);
5211 redraw_all_later(CLEAR);
5212 }
5213 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005214
Bram Moolenaar071d4272004-06-13 20:20:40 +00005215 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005216 did_set_option(opt_idx, opt_flags,
5217 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218 }
5219
5220skip:
5221 /*
5222 * Advance to next argument.
5223 * - skip until a blank found, taking care of backslashes
5224 * - skip blanks
5225 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5226 */
5227 for (i = 0; i < 2 ; ++i)
5228 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005229 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005230 if (*arg++ == '\\' && *arg != NUL)
5231 ++arg;
5232 arg = skipwhite(arg);
5233 if (*arg != '=')
5234 break;
5235 }
5236 }
5237
5238 if (errmsg != NULL)
5239 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005240 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005241 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 if (i + (arg - startarg) < IOSIZE)
5243 {
5244 /* append the argument with the error */
5245 STRCAT(IObuff, ": ");
5246 mch_memmove(IObuff + i, startarg, (arg - startarg));
5247 IObuff[i + (arg - startarg)] = NUL;
5248 }
5249 /* make sure all characters are printable */
5250 trans_characters(IObuff, IOSIZE);
5251
5252 ++no_wait_return; /* wait_return done later */
5253 emsg(IObuff); /* show error highlighted */
5254 --no_wait_return;
5255
5256 return FAIL;
5257 }
5258
5259 arg = skipwhite(arg);
5260 }
5261
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005262theend:
5263 if (silent_mode && did_show)
5264 {
5265 /* After displaying option values in silent mode. */
5266 silent_mode = FALSE;
5267 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5268 msg_putchar('\n');
5269 cursor_on(); /* msg_start() switches it off */
5270 out_flush();
5271 silent_mode = TRUE;
5272 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5273 }
5274
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 return OK;
5276}
5277
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005278/*
5279 * Call this when an option has been given a new value through a user command.
5280 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5281 */
5282 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005283did_set_option(
5284 int opt_idx,
5285 int opt_flags, /* possibly with OPT_MODELINE */
5286 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005287{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005288 long_u *p;
5289
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005290 options[opt_idx].flags |= P_WAS_SET;
5291
5292 /* When an option is set in the sandbox, from a modeline or in secure mode
5293 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005294 * flag. */
5295 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296 if (secure
5297#ifdef HAVE_SANDBOX
5298 || sandbox != 0
5299#endif
5300 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005301 *p = *p | P_INSECURE;
5302 else if (new_value)
5303 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005304}
5305
Bram Moolenaar071d4272004-06-13 20:20:40 +00005306 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005307illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308{
5309 if (errbuf == NULL)
5310 return (char_u *)"";
5311 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005312 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005313 return errbuf;
5314}
5315
5316/*
5317 * Convert a key name or string into a key value.
5318 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005319 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005321 int
5322string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323{
5324 if (*arg == '<')
5325 return find_key_option(arg + 1);
5326 if (*arg == '^')
5327 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005328 if (multi_byte)
5329 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330 return *arg;
5331}
5332
5333#ifdef FEAT_CMDWIN
5334/*
5335 * Check value of 'cedit' and set cedit_key.
5336 * Returns NULL if value is OK, error message otherwise.
5337 */
5338 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005339check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340{
5341 int n;
5342
5343 if (*p_cedit == NUL)
5344 cedit_key = -1;
5345 else
5346 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005347 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 if (vim_isprintc(n))
5349 return e_invarg;
5350 cedit_key = n;
5351 }
5352 return NULL;
5353}
5354#endif
5355
5356#ifdef FEAT_TITLE
5357/*
5358 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5359 * maketitle() to create and display it.
5360 * When switching the title or icon off, call mch_restore_title() to get
5361 * the old value back.
5362 */
5363 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005364did_set_title(
5365 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366{
5367 if (starting != NO_SCREEN
5368#ifdef FEAT_GUI
5369 && !gui.starting
5370#endif
5371 )
5372 {
5373 maketitle();
5374 if (icon)
5375 {
5376 if (!p_icon)
5377 mch_restore_title(2);
5378 }
5379 else
5380 {
5381 if (!p_title)
5382 mch_restore_title(1);
5383 }
5384 }
5385}
5386#endif
5387
5388/*
5389 * set_options_bin - called when 'bin' changes value.
5390 */
5391 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005392set_options_bin(
5393 int oldval,
5394 int newval,
5395 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396{
5397 /*
5398 * The option values that are changed when 'bin' changes are
5399 * copied when 'bin is set and restored when 'bin' is reset.
5400 */
5401 if (newval)
5402 {
5403 if (!oldval) /* switched on */
5404 {
5405 if (!(opt_flags & OPT_GLOBAL))
5406 {
5407 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5408 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5409 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5410 curbuf->b_p_et_nobin = curbuf->b_p_et;
5411 }
5412 if (!(opt_flags & OPT_LOCAL))
5413 {
5414 p_tw_nobin = p_tw;
5415 p_wm_nobin = p_wm;
5416 p_ml_nobin = p_ml;
5417 p_et_nobin = p_et;
5418 }
5419 }
5420
5421 if (!(opt_flags & OPT_GLOBAL))
5422 {
5423 curbuf->b_p_tw = 0; /* no automatic line wrap */
5424 curbuf->b_p_wm = 0; /* no automatic line wrap */
5425 curbuf->b_p_ml = 0; /* no modelines */
5426 curbuf->b_p_et = 0; /* no expandtab */
5427 }
5428 if (!(opt_flags & OPT_LOCAL))
5429 {
5430 p_tw = 0;
5431 p_wm = 0;
5432 p_ml = FALSE;
5433 p_et = FALSE;
5434 p_bin = TRUE; /* needed when called for the "-b" argument */
5435 }
5436 }
5437 else if (oldval) /* switched off */
5438 {
5439 if (!(opt_flags & OPT_GLOBAL))
5440 {
5441 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5442 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5443 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5444 curbuf->b_p_et = curbuf->b_p_et_nobin;
5445 }
5446 if (!(opt_flags & OPT_LOCAL))
5447 {
5448 p_tw = p_tw_nobin;
5449 p_wm = p_wm_nobin;
5450 p_ml = p_ml_nobin;
5451 p_et = p_et_nobin;
5452 }
5453 }
5454}
5455
5456#ifdef FEAT_VIMINFO
5457/*
5458 * Find the parameter represented by the given character (eg ', :, ", or /),
5459 * and return its associated value in the 'viminfo' string.
5460 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005461 * If the parameter is not specified in the string or there is no following
5462 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 */
5464 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005465get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466{
5467 char_u *p;
5468
5469 p = find_viminfo_parameter(type);
5470 if (p != NULL && VIM_ISDIGIT(*p))
5471 return atoi((char *)p);
5472 return -1;
5473}
5474
5475/*
5476 * Find the parameter represented by the given character (eg ''', ':', '"', or
5477 * '/') in the 'viminfo' option and return a pointer to the string after it.
5478 * Return NULL if the parameter is not specified in the string.
5479 */
5480 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005481find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482{
5483 char_u *p;
5484
5485 for (p = p_viminfo; *p; ++p)
5486 {
5487 if (*p == type)
5488 return p + 1;
5489 if (*p == 'n') /* 'n' is always the last one */
5490 break;
5491 p = vim_strchr(p, ','); /* skip until next ',' */
5492 if (p == NULL) /* hit the end without finding parameter */
5493 break;
5494 }
5495 return NULL;
5496}
5497#endif
5498
5499/*
5500 * Expand environment variables for some string options.
5501 * These string options cannot be indirect!
5502 * If "val" is NULL expand the current value of the option.
5503 * Return pointer to NameBuff, or NULL when not expanded.
5504 */
5505 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005506option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507{
5508 /* if option doesn't need expansion nothing to do */
5509 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5510 return NULL;
5511
5512 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5513 * expand_env() would truncate the string. */
5514 if (val != NULL && STRLEN(val) > MAXPATHL)
5515 return NULL;
5516
5517 if (val == NULL)
5518 val = *(char_u **)options[opt_idx].var;
5519
5520 /*
5521 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5522 * Escape spaces when expanding 'tags', they are used to separate file
5523 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005524 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525 */
5526 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005527 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005528#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005529 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5530#endif
5531 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005532 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5533 return NULL;
5534
5535 return NameBuff;
5536}
5537
5538/*
5539 * After setting various option values: recompute variables that depend on
5540 * option values.
5541 */
5542 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005543didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544{
5545 /* initialize the table for 'iskeyword' et.al. */
5546 (void)init_chartab();
5547
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005548#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005552 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553#ifdef FEAT_SESSION
5554 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5555 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5556#endif
5557#ifdef FEAT_FOLDING
5558 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5559#endif
5560 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005561 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562#ifdef FEAT_VIRTUALEDIT
5563 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5564#endif
5565#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5566 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5567#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005568#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005569 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005570 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005571 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005572 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5575 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5576#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005577#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5579#endif
5580#ifdef FEAT_CMDWIN
5581 /* set cedit_key */
5582 (void)check_cedit();
5583#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005584#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005585 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005586#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005587#ifdef FEAT_LINEBREAK
5588 /* initialize the table for 'breakat'. */
5589 fill_breakat_flags();
5590#endif
5591
5592}
5593
5594/*
5595 * More side effects of setting options.
5596 */
5597 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005598didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005599{
5600 /* Initialize the highlight_attr[] table. */
5601 (void)highlight_changed();
5602
5603 /* Parse default for 'wildmode' */
5604 check_opt_wim();
5605
5606 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005607 /* Parse default for 'fillchars'. */
5608 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005609
5610#ifdef FEAT_CLIPBOARD
5611 /* Parse default for 'clipboard' */
5612 (void)check_clipboard_option();
5613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614}
5615
5616/*
5617 * Check for string options that are NULL (normally only termcap options).
5618 */
5619 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005620check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621{
5622 int opt_idx;
5623
5624 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5625 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5626 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5627}
5628
5629/*
5630 * Check string options in a buffer for NULL value.
5631 */
5632 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635 check_string_option(&buf->b_p_bh);
5636 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637#ifdef FEAT_MBYTE
5638 check_string_option(&buf->b_p_fenc);
5639#endif
5640 check_string_option(&buf->b_p_ff);
5641#ifdef FEAT_FIND_ID
5642 check_string_option(&buf->b_p_def);
5643 check_string_option(&buf->b_p_inc);
5644# ifdef FEAT_EVAL
5645 check_string_option(&buf->b_p_inex);
5646# endif
5647#endif
5648#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5649 check_string_option(&buf->b_p_inde);
5650 check_string_option(&buf->b_p_indk);
5651#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005652#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5653 check_string_option(&buf->b_p_bexpr);
5654#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005655#if defined(FEAT_CRYPT)
5656 check_string_option(&buf->b_p_cm);
5657#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005658 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005659#if defined(FEAT_EVAL)
5660 check_string_option(&buf->b_p_fex);
5661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662#ifdef FEAT_CRYPT
5663 check_string_option(&buf->b_p_key);
5664#endif
5665 check_string_option(&buf->b_p_kp);
5666 check_string_option(&buf->b_p_mps);
5667 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005668 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669 check_string_option(&buf->b_p_isk);
5670#ifdef FEAT_COMMENTS
5671 check_string_option(&buf->b_p_com);
5672#endif
5673#ifdef FEAT_FOLDING
5674 check_string_option(&buf->b_p_cms);
5675#endif
5676 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005677#ifdef FEAT_TEXTOBJ
5678 check_string_option(&buf->b_p_qe);
5679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680#ifdef FEAT_SYN_HL
5681 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005682 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005683#endif
5684#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005685 check_string_option(&buf->b_s.b_p_spc);
5686 check_string_option(&buf->b_s.b_p_spf);
5687 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688#endif
5689#ifdef FEAT_SEARCHPATH
5690 check_string_option(&buf->b_p_sua);
5691#endif
5692#ifdef FEAT_CINDENT
5693 check_string_option(&buf->b_p_cink);
5694 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005695 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5699 check_string_option(&buf->b_p_cinw);
5700#endif
5701#ifdef FEAT_INS_EXPAND
5702 check_string_option(&buf->b_p_cpt);
5703#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005704#ifdef FEAT_COMPL_FUNC
5705 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005706 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708#ifdef FEAT_KEYMAP
5709 check_string_option(&buf->b_p_keymap);
5710#endif
5711#ifdef FEAT_QUICKFIX
5712 check_string_option(&buf->b_p_gp);
5713 check_string_option(&buf->b_p_mp);
5714 check_string_option(&buf->b_p_efm);
5715#endif
5716 check_string_option(&buf->b_p_ep);
5717 check_string_option(&buf->b_p_path);
5718 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005719 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720#ifdef FEAT_INS_EXPAND
5721 check_string_option(&buf->b_p_dict);
5722 check_string_option(&buf->b_p_tsr);
5723#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005724#ifdef FEAT_LISP
5725 check_string_option(&buf->b_p_lw);
5726#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005727 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005728#ifdef FEAT_MBYTE
5729 check_string_option(&buf->b_p_menc);
5730#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731}
5732
5733/*
5734 * Free the string allocated for an option.
5735 * Checks for the string being empty_option. This may happen if we're out of
5736 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5737 * check_options().
5738 * Does NOT check for P_ALLOCED flag!
5739 */
5740 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005741free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742{
5743 if (p != empty_option)
5744 vim_free(p);
5745}
5746
5747 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005748clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749{
5750 if (*pp != empty_option)
5751 vim_free(*pp);
5752 *pp = empty_option;
5753}
5754
5755 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (*pp == NULL)
5759 *pp = empty_option;
5760}
5761
5762/*
5763 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5764 */
5765 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005766set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767{
5768 int opt_idx;
5769
5770 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5771 if (options[opt_idx].var == (char_u *)p)
5772 {
5773 options[opt_idx].flags |= P_ALLOCED;
5774 return;
5775 }
5776 return; /* cannot happen: didn't find it! */
5777}
5778
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005779#if defined(FEAT_EVAL) || defined(PROTO)
5780/*
5781 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5782 * Return FALSE when it wasn't.
5783 * Return -1 for an unknown option.
5784 */
5785 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005786was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005787{
5788 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005789 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005790
5791 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005792 {
5793 flagp = insecure_flag(idx, opt_flags);
5794 return (*flagp & P_INSECURE) != 0;
5795 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005796 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005797 return -1;
5798}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005799
5800/*
5801 * Get a pointer to the flags used for the P_INSECURE flag of option
5802 * "opt_idx". For some local options a local flags field is used.
5803 */
5804 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005805insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806{
5807 if (opt_flags & OPT_LOCAL)
5808 switch ((int)options[opt_idx].indir)
5809 {
5810#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005811 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005812#endif
5813#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005814# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005815 case PV_FDE: return &curwin->w_p_fde_flags;
5816 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005817# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005818# ifdef FEAT_BEVAL
5819 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5820# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005823# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005824 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005825# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005826 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827# endif
5828#endif
5829 }
5830
5831 /* Nothing special, return global flags field. */
5832 return &options[opt_idx].flags;
5833}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005834#endif
5835
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005836#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005837static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005838
5839/*
5840 * Redraw the window title and/or tab page text later.
5841 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005842static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843{
5844 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005845 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005846}
5847#endif
5848
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849/*
5850 * Set a string option to a new value (without checking the effect).
5851 * The string is copied into allocated memory.
5852 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005853 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005854 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 */
5856 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005857set_string_option_direct(
5858 char_u *name,
5859 int opt_idx,
5860 char_u *val,
5861 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5862 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863{
5864 char_u *s;
5865 char_u **varp;
5866 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868
Bram Moolenaar89d40322006-08-29 15:30:07 +00005869 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005871 idx = findoption(name);
5872 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005873 {
5874 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005875 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005877 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 }
5879
Bram Moolenaar89d40322006-08-29 15:30:07 +00005880 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 return;
5882
5883 s = vim_strsave(val);
5884 if (s != NULL)
5885 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005888 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 free_string_option(*varp);
5890 *varp = s;
5891
5892 /* For buffer/window local option may also set the global value. */
5893 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005894 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895
Bram Moolenaar89d40322006-08-29 15:30:07 +00005896 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897
5898 /* When setting both values of a global option with a local value,
5899 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005900 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 {
5902 free_string_option(*varp);
5903 *varp = empty_option;
5904 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005905# ifdef FEAT_EVAL
5906 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005907 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005908 set_sid == 0 ? current_SID : set_sid);
5909# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 }
5911}
5912
5913/*
5914 * Set global value for string option when it's a local option.
5915 */
5916 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005917set_string_option_global(
5918 int opt_idx, /* option index */
5919 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920{
5921 char_u **p, *s;
5922
5923 /* the global value is always allocated */
5924 if (options[opt_idx].var == VAR_WIN)
5925 p = (char_u **)GLOBAL_WO(varp);
5926 else
5927 p = (char_u **)options[opt_idx].var;
5928 if (options[opt_idx].indir != PV_NONE
5929 && p != varp
5930 && (s = vim_strsave(*varp)) != NULL)
5931 {
5932 free_string_option(*p);
5933 *p = s;
5934 }
5935}
5936
5937/*
5938 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005939 *
5940 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005942 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005943set_string_option(
5944 int opt_idx,
5945 char_u *value,
5946 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947{
5948 char_u *s;
5949 char_u **varp;
5950 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005951#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005952 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005953 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005954#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005955 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956
5957 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005958 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959
5960 s = vim_strsave(value);
5961 if (s != NULL)
5962 {
5963 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5964 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005965 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 ? OPT_GLOBAL : OPT_LOCAL)
5967 : opt_flags);
5968 oldval = *varp;
5969 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005970
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005971#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005972 if (!starting
5973# ifdef FEAT_CRYPT
5974 && options[opt_idx].indir != PV_KEY
5975# endif
5976 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005977 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005978 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005979 saved_newval = vim_strsave(s);
5980 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005981#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005982 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5983 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005984 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005985
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005986#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005988 if (r == NULL)
5989 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005990 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005991 vim_free(saved_oldval);
5992 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005995 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996}
5997
5998/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005999 * Return TRUE if "val" is a valid 'filetype' name.
6000 * Also used for 'syntax' and 'keymap'.
6001 */
6002 static int
6003valid_filetype(char_u *val)
6004{
6005 char_u *s;
6006
6007 for (s = val; *s != NUL; ++s)
6008 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6009 return FALSE;
6010 return TRUE;
6011}
6012
6013/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 * Handle string options that need some action to perform when changed.
6015 * Returns NULL for success, or an error message for an error.
6016 */
6017 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006018did_set_string_option(
6019 int opt_idx, /* index in options[] table */
6020 char_u **varp, /* pointer to the option variable */
6021 int new_value_alloced, /* new value was allocated */
6022 char_u *oldval, /* previous value of the option */
6023 char_u *errbuf, /* buffer for errors, or NULL */
6024 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006025{
6026 char_u *errmsg = NULL;
6027 char_u *s, *p;
6028 int did_chartab = FALSE;
6029 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006030 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006031#ifdef FEAT_GUI
6032 /* set when changing an option that only requires a redraw in the GUI */
6033 int redraw_gui_only = FALSE;
6034#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006035 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036
6037 /* Get the global option to compare with, otherwise we would have to check
6038 * two values for all local options. */
6039 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6040
6041 /* Disallow changing some options from secure mode */
6042 if ((secure
6043#ifdef HAVE_SANDBOX
6044 || sandbox != 0
6045#endif
6046 ) && (options[opt_idx].flags & P_SECURE))
6047 {
6048 errmsg = e_secure;
6049 }
6050
Bram Moolenaar7554da42016-11-25 22:04:13 +01006051 /* Check for a "normal" directory or file name in some options. Disallow a
6052 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006053 * are often illegal in a file name. Be more permissive if "secure" is off.
6054 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006055 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006056 && vim_strpbrk(*varp, (char_u *)(secure
6057 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006058 || ((options[opt_idx].flags & P_NDNAME)
6059 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006060 {
6061 errmsg = e_invarg;
6062 }
6063
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 /* 'term' */
6065 else if (varp == &T_NAME)
6066 {
6067 if (T_NAME[0] == NUL)
6068 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6069#ifdef FEAT_GUI
6070 if (gui.in_use)
6071 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6072 else if (term_is_gui(T_NAME))
6073 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6074#endif
6075 else if (set_termname(T_NAME) == FAIL)
6076 errmsg = (char_u *)N_("E522: Not found in termcap");
6077 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006078 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 /* Screen colors may have changed. */
6080 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006081
6082 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6083 * P_ALLOCED flag on 'term'. */
6084 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006085 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 }
6088
6089 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006090 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006092 char_u *bkc = p_bkc;
6093 unsigned int *flags = &bkc_flags;
6094
6095 if (opt_flags & OPT_LOCAL)
6096 {
6097 bkc = curbuf->b_p_bkc;
6098 flags = &curbuf->b_bkc_flags;
6099 }
6100
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006101 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6102 /* make the local value empty: use the global value */
6103 *flags = 0;
6104 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006106 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6107 errmsg = e_invarg;
6108 if ((((int)*flags & BKC_AUTO) != 0)
6109 + (((int)*flags & BKC_YES) != 0)
6110 + (((int)*flags & BKC_NO) != 0) != 1)
6111 {
6112 /* Must have exactly one of "auto", "yes" and "no". */
6113 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6114 errmsg = e_invarg;
6115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 }
6117 }
6118
6119 /* 'backupext' and 'patchmode' */
6120 else if (varp == &p_bex || varp == &p_pm)
6121 {
6122 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6123 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6124 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6125 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006126#ifdef FEAT_LINEBREAK
6127 /* 'breakindentopt' */
6128 else if (varp == &curwin->w_p_briopt)
6129 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006130 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006131 errmsg = e_invarg;
6132 }
6133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134
6135 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006136 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006138 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 */
6140 else if ( varp == &p_isi
6141 || varp == &(curbuf->b_p_isk)
6142 || varp == &p_isp
6143 || varp == &p_isf)
6144 {
6145 if (init_chartab() == FAIL)
6146 {
6147 did_chartab = TRUE; /* need to restore it below */
6148 errmsg = e_invarg; /* error in value */
6149 }
6150 }
6151
6152 /* 'helpfile' */
6153 else if (varp == &p_hf)
6154 {
6155 /* May compute new values for $VIM and $VIMRUNTIME */
6156 if (didset_vim)
6157 {
6158 vim_setenv((char_u *)"VIM", (char_u *)"");
6159 didset_vim = FALSE;
6160 }
6161 if (didset_vimruntime)
6162 {
6163 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6164 didset_vimruntime = FALSE;
6165 }
6166 }
6167
Bram Moolenaar1a384422010-07-14 19:53:30 +02006168#ifdef FEAT_SYN_HL
6169 /* 'colorcolumn' */
6170 else if (varp == &curwin->w_p_cc)
6171 errmsg = check_colorcolumn(curwin);
6172#endif
6173
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174#ifdef FEAT_MULTI_LANG
6175 /* 'helplang' */
6176 else if (varp == &p_hlg)
6177 {
6178 /* Check for "", "ab", "ab,cd", etc. */
6179 for (s = p_hlg; *s != NUL; s += 3)
6180 {
6181 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6182 {
6183 errmsg = e_invarg;
6184 break;
6185 }
6186 if (s[2] == NUL)
6187 break;
6188 }
6189 }
6190#endif
6191
6192 /* 'highlight' */
6193 else if (varp == &p_hl)
6194 {
6195 if (highlight_changed() == FAIL)
6196 errmsg = e_invarg; /* invalid flags */
6197 }
6198
6199 /* 'nrformats' */
6200 else if (gvarp == &p_nf)
6201 {
6202 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6203 errmsg = e_invarg;
6204 }
6205
6206#ifdef FEAT_SESSION
6207 /* 'sessionoptions' */
6208 else if (varp == &p_ssop)
6209 {
6210 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6211 errmsg = e_invarg;
6212 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6213 {
6214 /* Don't allow both "sesdir" and "curdir". */
6215 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6216 errmsg = e_invarg;
6217 }
6218 }
6219 /* 'viewoptions' */
6220 else if (varp == &p_vop)
6221 {
6222 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6223 errmsg = e_invarg;
6224 }
6225#endif
6226
6227 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006228 else if (varp == &p_sbo)
6229 {
6230 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6231 errmsg = e_invarg;
6232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233
6234 /* 'ambiwidth' */
6235#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006236 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 {
6238 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6239 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006240 else if (set_chars_option(&p_lcs) != NULL)
6241 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006242 else if (set_chars_option(&p_fcs) != NULL)
6243 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 }
6245#endif
6246
6247 /* 'background' */
6248 else if (varp == &p_bg)
6249 {
6250 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6251 {
6252#ifdef FEAT_EVAL
6253 int dark = (*p_bg == 'd');
6254#endif
6255
6256 init_highlight(FALSE, FALSE);
6257
6258#ifdef FEAT_EVAL
6259 if (dark != (*p_bg == 'd')
6260 && get_var_value((char_u *)"g:colors_name") != NULL)
6261 {
6262 /* The color scheme must have set 'background' back to another
6263 * value, that's not what we want here. Disable the color
6264 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006265 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 free_string_option(p_bg);
6267 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6268 check_string_option(&p_bg);
6269 init_highlight(FALSE, FALSE);
6270 }
6271#endif
6272 }
6273 else
6274 errmsg = e_invarg;
6275 }
6276
6277 /* 'wildmode' */
6278 else if (varp == &p_wim)
6279 {
6280 if (check_opt_wim() == FAIL)
6281 errmsg = e_invarg;
6282 }
6283
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006284#ifdef FEAT_CMDL_COMPL
6285 /* 'wildoptions' */
6286 else if (varp == &p_wop)
6287 {
6288 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6289 errmsg = e_invarg;
6290 }
6291#endif
6292
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293#ifdef FEAT_WAK
6294 /* 'winaltkeys' */
6295 else if (varp == &p_wak)
6296 {
6297 if (*p_wak == NUL
6298 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6299 errmsg = e_invarg;
6300# ifdef FEAT_MENU
6301# ifdef FEAT_GUI_MOTIF
6302 else if (gui.in_use)
6303 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6304# else
6305# ifdef FEAT_GUI_GTK
6306 else if (gui.in_use)
6307 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6308# endif
6309# endif
6310# endif
6311 }
6312#endif
6313
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 /* 'eventignore' */
6315 else if (varp == &p_ei)
6316 {
6317 if (check_ei() == FAIL)
6318 errmsg = e_invarg;
6319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320
6321#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006322 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6323 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6324 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 {
6326 if (gvarp == &p_fenc)
6327 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006328 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 errmsg = e_modifiable;
6330 else if (vim_strchr(*varp, ',') != NULL)
6331 /* No comma allowed in 'fileencoding'; catches confusing it
6332 * with 'fileencodings'. */
6333 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006335 {
6336# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006338 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006340 /* Add 'fileencoding' to the swap file. */
6341 ml_setflags(curbuf);
6342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 }
6344 if (errmsg == NULL)
6345 {
6346 /* canonize the value, so that STRCMP() can be used on it */
6347 p = enc_canonize(*varp);
6348 if (p != NULL)
6349 {
6350 vim_free(*varp);
6351 *varp = p;
6352 }
6353 if (varp == &p_enc)
6354 {
6355 errmsg = mb_init();
6356# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006357 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358# endif
6359 }
6360 }
6361
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006362# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6364 {
6365 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6366 if (STRCMP(p_tenc, "utf-8") != 0)
6367 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6368 }
6369# endif
6370
6371 if (errmsg == NULL)
6372 {
6373# ifdef FEAT_KEYMAP
6374 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6375 * (with another encoding). */
6376 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6377 (void)keymap_init();
6378# endif
6379
6380 /* When 'termencoding' is not empty and 'encoding' changes or when
6381 * 'termencoding' changes, need to setup for keyboard input and
6382 * display output conversion. */
6383 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6384 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006385 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6386 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6387 {
6388 EMSG3(_("E950: Cannot convert between %s and %s"),
6389 p_tenc, p_enc);
6390 errmsg = e_invarg;
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006393
6394# if defined(WIN3264) && defined(FEAT_MBYTE)
6395 /* $HOME may have characters in active code page. */
6396 if (varp == &p_enc)
6397 init_homedir();
6398# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 }
6400 }
6401#endif
6402
6403#if defined(FEAT_POSTSCRIPT)
6404 else if (varp == &p_penc)
6405 {
6406 /* Canonize printencoding if VIM standard one */
6407 p = enc_canonize(p_penc);
6408 if (p != NULL)
6409 {
6410 vim_free(p_penc);
6411 p_penc = p;
6412 }
6413 else
6414 {
6415 /* Ensure lower case and '-' for '_' */
6416 for (s = p_penc; *s != NUL; s++)
6417 {
6418 if (*s == '_')
6419 *s = '-';
6420 else
6421 *s = TOLOWER_ASC(*s);
6422 }
6423 }
6424 }
6425#endif
6426
Bram Moolenaar9372a112005-12-06 19:59:18 +00006427#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 else if (varp == &p_imak)
6429 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006430 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 errmsg = e_invarg;
6432 }
6433#endif
6434
6435#ifdef FEAT_KEYMAP
6436 else if (varp == &curbuf->b_p_keymap)
6437 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006438 if (!valid_filetype(*varp))
6439 errmsg = e_invarg;
6440 else
6441 /* load or unload key mapping tables */
6442 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443
Bram Moolenaarfab06232009-03-04 03:13:35 +00006444 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006446 if (*curbuf->b_p_keymap != NUL)
6447 {
6448 /* Installed a new keymap, switch on using it. */
6449 curbuf->b_p_iminsert = B_IMODE_LMAP;
6450 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6451 curbuf->b_p_imsearch = B_IMODE_LMAP;
6452 }
6453 else
6454 {
6455 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6456 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6457 curbuf->b_p_iminsert = B_IMODE_NONE;
6458 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6459 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6460 }
6461 if ((opt_flags & OPT_LOCAL) == 0)
6462 {
6463 set_iminsert_global();
6464 set_imsearch_global();
6465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
6468 }
6469#endif
6470
6471 /* 'fileformat' */
6472 else if (gvarp == &p_ff)
6473 {
6474 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6475 errmsg = e_modifiable;
6476 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6477 errmsg = e_invarg;
6478 else
6479 {
6480 /* may also change 'textmode' */
6481 if (get_fileformat(curbuf) == EOL_DOS)
6482 curbuf->b_p_tx = TRUE;
6483 else
6484 curbuf->b_p_tx = FALSE;
6485#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006486 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006488 /* update flag in swap file */
6489 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006490 /* Redraw needed when switching to/from "mac": a CR in the text
6491 * will be displayed differently. */
6492 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6493 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494 }
6495 }
6496
6497 /* 'fileformats' */
6498 else if (varp == &p_ffs)
6499 {
6500 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6501 errmsg = e_invarg;
6502 else
6503 {
6504 /* also change 'textauto' */
6505 if (*p_ffs == NUL)
6506 p_ta = FALSE;
6507 else
6508 p_ta = TRUE;
6509 }
6510 }
6511
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006512#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 /* 'cryptkey' */
6514 else if (gvarp == &p_key)
6515 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006516# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517 /* Make sure the ":set" command doesn't show the new value in the
6518 * history. */
6519 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006520# endif
6521 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6522 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006523 ml_set_crypt_key(curbuf, oldval,
6524 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006525 }
6526
6527 else if (gvarp == &p_cm)
6528 {
6529 if (opt_flags & OPT_LOCAL)
6530 p = curbuf->b_p_cm;
6531 else
6532 p = p_cm;
6533 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6534 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006535 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006536 errmsg = e_invarg;
6537 else
6538 {
6539 /* When setting the global value to empty, make it "zip". */
6540 if (*p_cm == NUL)
6541 {
6542 if (new_value_alloced)
6543 free_string_option(p_cm);
6544 p_cm = vim_strsave((char_u *)"zip");
6545 new_value_alloced = TRUE;
6546 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006547 /* When using ":set cm=name" the local value is going to be empty.
6548 * Do that here, otherwise the crypt functions will still use the
6549 * local value. */
6550 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6551 {
6552 free_string_option(curbuf->b_p_cm);
6553 curbuf->b_p_cm = empty_option;
6554 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006555
6556 /* Need to update the swapfile when the effective method changed.
6557 * Set "s" to the effective old value, "p" to the effective new
6558 * method and compare. */
6559 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6560 s = p_cm; /* was previously using the global value */
6561 else
6562 s = oldval;
6563 if (*curbuf->b_p_cm == NUL)
6564 p = p_cm; /* is now using the global value */
6565 else
6566 p = curbuf->b_p_cm;
6567 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006568 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006569
6570 /* If the global value changes need to update the swapfile for all
6571 * buffers using that value. */
6572 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6573 {
6574 buf_T *buf;
6575
Bram Moolenaar29323592016-07-24 22:04:11 +02006576 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006577 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006578 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006579 }
6580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
6582#endif
6583
6584 /* 'matchpairs' */
6585 else if (gvarp == &p_mps)
6586 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006587#ifdef FEAT_MBYTE
6588 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006590 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006592 int x2 = -1;
6593 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006594
6595 if (*p != NUL)
6596 p += mb_ptr2len(p);
6597 if (*p != NUL)
6598 x2 = *p++;
6599 if (*p != NUL)
6600 {
6601 x3 = mb_ptr2char(p);
6602 p += mb_ptr2len(p);
6603 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006604 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006605 {
6606 errmsg = e_invarg;
6607 break;
6608 }
6609 if (*p == NUL)
6610 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006612 }
6613 else
6614#endif
6615 {
6616 /* Check for "x:y,x:y" */
6617 for (p = *varp; *p != NUL; p += 4)
6618 {
6619 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6620 {
6621 errmsg = e_invarg;
6622 break;
6623 }
6624 if (p[3] == NUL)
6625 break;
6626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006627 }
6628 }
6629
6630#ifdef FEAT_COMMENTS
6631 /* 'comments' */
6632 else if (gvarp == &p_com)
6633 {
6634 for (s = *varp; *s; )
6635 {
6636 while (*s && *s != ':')
6637 {
6638 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6639 && !VIM_ISDIGIT(*s) && *s != '-')
6640 {
6641 errmsg = illegal_char(errbuf, *s);
6642 break;
6643 }
6644 ++s;
6645 }
6646 if (*s++ == NUL)
6647 errmsg = (char_u *)N_("E524: Missing colon");
6648 else if (*s == ',' || *s == NUL)
6649 errmsg = (char_u *)N_("E525: Zero length string");
6650 if (errmsg != NULL)
6651 break;
6652 while (*s && *s != ',')
6653 {
6654 if (*s == '\\' && s[1] != NUL)
6655 ++s;
6656 ++s;
6657 }
6658 s = skip_to_option_part(s);
6659 }
6660 }
6661#endif
6662
6663 /* 'listchars' */
6664 else if (varp == &p_lcs)
6665 {
6666 errmsg = set_chars_option(varp);
6667 }
6668
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 /* 'fillchars' */
6670 else if (varp == &p_fcs)
6671 {
6672 errmsg = set_chars_option(varp);
6673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674
6675#ifdef FEAT_CMDWIN
6676 /* 'cedit' */
6677 else if (varp == &p_cedit)
6678 {
6679 errmsg = check_cedit();
6680 }
6681#endif
6682
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006683 /* 'verbosefile' */
6684 else if (varp == &p_vfile)
6685 {
6686 verbose_stop();
6687 if (*p_vfile != NUL && verbose_open() == FAIL)
6688 errmsg = e_invarg;
6689 }
6690
Bram Moolenaar071d4272004-06-13 20:20:40 +00006691#ifdef FEAT_VIMINFO
6692 /* 'viminfo' */
6693 else if (varp == &p_viminfo)
6694 {
6695 for (s = p_viminfo; *s;)
6696 {
6697 /* Check it's a valid character */
6698 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6699 {
6700 errmsg = illegal_char(errbuf, *s);
6701 break;
6702 }
6703 if (*s == 'n') /* name is always last one */
6704 {
6705 break;
6706 }
6707 else if (*s == 'r') /* skip until next ',' */
6708 {
6709 while (*++s && *s != ',')
6710 ;
6711 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006712 else if (*s == '%')
6713 {
6714 /* optional number */
6715 while (vim_isdigit(*++s))
6716 ;
6717 }
6718 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 ++s; /* no extra chars */
6720 else /* must have a number */
6721 {
6722 while (vim_isdigit(*++s))
6723 ;
6724
6725 if (!VIM_ISDIGIT(*(s - 1)))
6726 {
6727 if (errbuf != NULL)
6728 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006729 sprintf((char *)errbuf,
6730 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 transchar_byte(*(s - 1)));
6732 errmsg = errbuf;
6733 }
6734 else
6735 errmsg = (char_u *)"";
6736 break;
6737 }
6738 }
6739 if (*s == ',')
6740 ++s;
6741 else if (*s)
6742 {
6743 if (errbuf != NULL)
6744 errmsg = (char_u *)N_("E527: Missing comma");
6745 else
6746 errmsg = (char_u *)"";
6747 break;
6748 }
6749 }
6750 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6751 errmsg = (char_u *)N_("E528: Must specify a ' value");
6752 }
6753#endif /* FEAT_VIMINFO */
6754
6755 /* terminal options */
6756 else if (istermoption(&options[opt_idx]) && full_screen)
6757 {
6758 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6759 if (varp == &T_CCO)
6760 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006761 int colors = atoi((char *)T_CCO);
6762
6763 /* Only reinitialize colors if t_Co value has really changed to
6764 * avoid expensive reload of colorscheme if t_Co is set to the
6765 * same value multiple times. */
6766 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006768 t_colors = colors;
6769 if (t_colors <= 1)
6770 {
6771 if (new_value_alloced)
6772 vim_free(T_CCO);
6773 T_CCO = empty_option;
6774 }
6775 /* We now have a different color setup, initialize it again. */
6776 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 }
6779 ttest(FALSE);
6780 if (varp == &T_ME)
6781 {
6782 out_str(T_ME);
6783 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006784#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 /* Since t_me has been set, this probably means that the user
6786 * wants to use this as default colors. Need to reset default
6787 * background/foreground colors. */
6788 mch_set_normal_colors();
6789#endif
6790 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006791 if (varp == &T_BE && termcap_active)
6792 {
6793 if (*T_BE == NUL)
6794 /* When clearing t_BE we assume the user no longer wants
6795 * bracketed paste, thus disable it by writing t_BD. */
6796 out_str(T_BD);
6797 else
6798 out_str(T_BE);
6799 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 }
6801
6802#ifdef FEAT_LINEBREAK
6803 /* 'showbreak' */
6804 else if (varp == &p_sbr)
6805 {
6806 for (s = p_sbr; *s; )
6807 {
6808 if (ptr2cells(s) != 1)
6809 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006810 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811 }
6812 }
6813#endif
6814
6815#ifdef FEAT_GUI
6816 /* 'guifont' */
6817 else if (varp == &p_guifont)
6818 {
6819 if (gui.in_use)
6820 {
6821 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006822# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 /*
6824 * Put up a font dialog and let the user select a new value.
6825 * If this is cancelled go back to the old value but don't
6826 * give an error message.
6827 */
6828 if (STRCMP(p, "*") == 0)
6829 {
6830 p = gui_mch_font_dialog(oldval);
6831
6832 if (new_value_alloced)
6833 free_string_option(p_guifont);
6834
6835 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6836 new_value_alloced = TRUE;
6837 }
6838# endif
6839 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6840 {
6841# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6842 if (STRCMP(p_guifont, "*") == 0)
6843 {
6844 /* Dialog was cancelled: Keep the old value without giving
6845 * an error message. */
6846 if (new_value_alloced)
6847 free_string_option(p_guifont);
6848 p_guifont = vim_strsave(oldval);
6849 new_value_alloced = TRUE;
6850 }
6851 else
6852# endif
6853 errmsg = (char_u *)N_("E596: Invalid font(s)");
6854 }
6855 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006856 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857 }
6858# ifdef FEAT_XFONTSET
6859 else if (varp == &p_guifontset)
6860 {
6861 if (STRCMP(p_guifontset, "*") == 0)
6862 errmsg = (char_u *)N_("E597: can't select fontset");
6863 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6864 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006865 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 }
6867# endif
6868# ifdef FEAT_MBYTE
6869 else if (varp == &p_guifontwide)
6870 {
6871 if (STRCMP(p_guifontwide, "*") == 0)
6872 errmsg = (char_u *)N_("E533: can't select wide font");
6873 else if (gui_get_wide_font() == FAIL)
6874 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006875 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876 }
6877# endif
6878#endif
6879
6880#ifdef CURSOR_SHAPE
6881 /* 'guicursor' */
6882 else if (varp == &p_guicursor)
6883 errmsg = parse_shape_opt(SHAPE_CURSOR);
6884#endif
6885
6886#ifdef FEAT_MOUSESHAPE
6887 /* 'mouseshape' */
6888 else if (varp == &p_mouseshape)
6889 {
6890 errmsg = parse_shape_opt(SHAPE_MOUSE);
6891 update_mouseshape(-1);
6892 }
6893#endif
6894
6895#ifdef FEAT_PRINTER
6896 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006897 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006898# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006899 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006900 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006901# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902#endif
6903
6904#ifdef FEAT_LANGMAP
6905 /* 'langmap' */
6906 else if (varp == &p_langmap)
6907 langmap_set();
6908#endif
6909
6910#ifdef FEAT_LINEBREAK
6911 /* 'breakat' */
6912 else if (varp == &p_breakat)
6913 fill_breakat_flags();
6914#endif
6915
6916#ifdef FEAT_TITLE
6917 /* 'titlestring' and 'iconstring' */
6918 else if (varp == &p_titlestring || varp == &p_iconstring)
6919 {
6920# ifdef FEAT_STL_OPT
6921 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6922
6923 /* NULL => statusline syntax */
6924 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6925 stl_syntax |= flagval;
6926 else
6927 stl_syntax &= ~flagval;
6928# endif
6929 did_set_title(varp == &p_iconstring);
6930
6931 }
6932#endif
6933
6934#ifdef FEAT_GUI
6935 /* 'guioptions' */
6936 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006937 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006939 redraw_gui_only = TRUE;
6940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941#endif
6942
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006943#if defined(FEAT_GUI_TABLINE)
6944 /* 'guitablabel' */
6945 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006946 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006947 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006948 redraw_gui_only = TRUE;
6949 }
6950 /* 'guitabtooltip' */
6951 else if (varp == &p_gtt)
6952 {
6953 redraw_gui_only = TRUE;
6954 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006955#endif
6956
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6958 /* 'ttymouse' */
6959 else if (varp == &p_ttym)
6960 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006961 /* Switch the mouse off before changing the escape sequences used for
6962 * that. */
6963 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6965 errmsg = e_invarg;
6966 else
6967 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006968 if (termcap_active)
6969 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 }
6971#endif
6972
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 /* 'selection' */
6974 else if (varp == &p_sel)
6975 {
6976 if (*p_sel == NUL
6977 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6978 errmsg = e_invarg;
6979 }
6980
6981 /* 'selectmode' */
6982 else if (varp == &p_slm)
6983 {
6984 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6985 errmsg = e_invarg;
6986 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987
6988#ifdef FEAT_BROWSE
6989 /* 'browsedir' */
6990 else if (varp == &p_bsdir)
6991 {
6992 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6993 && !mch_isdir(p_bsdir))
6994 errmsg = e_invarg;
6995 }
6996#endif
6997
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998 /* 'keymodel' */
6999 else if (varp == &p_km)
7000 {
7001 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7002 errmsg = e_invarg;
7003 else
7004 {
7005 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7006 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7007 }
7008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009
7010 /* 'mousemodel' */
7011 else if (varp == &p_mousem)
7012 {
7013 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7014 errmsg = e_invarg;
7015#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7016 else if (*p_mousem != *oldval)
7017 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7018 * to create or delete the popup menus. */
7019 gui_motif_update_mousemodel(root_menu);
7020#endif
7021 }
7022
7023 /* 'switchbuf' */
7024 else if (varp == &p_swb)
7025 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007026 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 errmsg = e_invarg;
7028 }
7029
7030 /* 'debug' */
7031 else if (varp == &p_debug)
7032 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007033 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 errmsg = e_invarg;
7035 }
7036
7037 /* 'display' */
7038 else if (varp == &p_dy)
7039 {
7040 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7041 errmsg = e_invarg;
7042 else
7043 (void)init_chartab();
7044
7045 }
7046
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 /* 'eadirection' */
7048 else if (varp == &p_ead)
7049 {
7050 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7051 errmsg = e_invarg;
7052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007053
7054#ifdef FEAT_CLIPBOARD
7055 /* 'clipboard' */
7056 else if (varp == &p_cb)
7057 errmsg = check_clipboard_option();
7058#endif
7059
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007060#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007061 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7062 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007063 else if (varp == &(curwin->w_s->b_p_spl)
7064 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007065 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007066 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007067 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007068 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007069 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007070 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007071 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007072 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007073 /* 'spellsuggest' */
7074 else if (varp == &p_sps)
7075 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007076 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007077 errmsg = e_invarg;
7078 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007079 /* 'mkspellmem' */
7080 else if (varp == &p_msm)
7081 {
7082 if (spell_check_msm() != OK)
7083 errmsg = e_invarg;
7084 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007085#endif
7086
Bram Moolenaar071d4272004-06-13 20:20:40 +00007087 /* When 'bufhidden' is set, check for valid value. */
7088 else if (gvarp == &p_bh)
7089 {
7090 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7091 errmsg = e_invarg;
7092 }
7093
7094 /* When 'buftype' is set, check for valid value. */
7095 else if (gvarp == &p_bt)
7096 {
7097 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7098 errmsg = e_invarg;
7099 else
7100 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 if (curwin->w_status_height)
7102 {
7103 curwin->w_redr_status = TRUE;
7104 redraw_later(VALID);
7105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007107#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007108 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 }
7111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112
7113#ifdef FEAT_STL_OPT
7114 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007115 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 {
7117 int wid;
7118
7119 if (varp == &p_ruf) /* reset ru_wid first */
7120 ru_wid = 0;
7121 s = *varp;
7122 if (varp == &p_ruf && *s == '%')
7123 {
7124 /* set ru_wid if 'ruf' starts with "%99(" */
7125 if (*++s == '-') /* ignore a '-' */
7126 s++;
7127 wid = getdigits(&s);
7128 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7129 ru_wid = wid;
7130 else
7131 errmsg = check_stl_option(p_ruf);
7132 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007133 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007134 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007136 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137 comp_col();
7138 }
7139#endif
7140
7141#ifdef FEAT_INS_EXPAND
7142 /* check if it is a valid value for 'complete' -- Acevedo */
7143 else if (gvarp == &p_cpt)
7144 {
7145 for (s = *varp; *s;)
7146 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007147 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 s++;
7149 if (!*s)
7150 break;
7151 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7152 {
7153 errmsg = illegal_char(errbuf, *s);
7154 break;
7155 }
7156 if (*++s != NUL && *s != ',' && *s != ' ')
7157 {
7158 if (s[-1] == 'k' || s[-1] == 's')
7159 {
7160 /* skip optional filename after 'k' and 's' */
7161 while (*s && *s != ',' && *s != ' ')
7162 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007163 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 ++s;
7165 ++s;
7166 }
7167 }
7168 else
7169 {
7170 if (errbuf != NULL)
7171 {
7172 sprintf((char *)errbuf,
7173 _("E535: Illegal character after <%c>"),
7174 *--s);
7175 errmsg = errbuf;
7176 }
7177 else
7178 errmsg = (char_u *)"";
7179 break;
7180 }
7181 }
7182 }
7183 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007184
7185 /* 'completeopt' */
7186 else if (varp == &p_cot)
7187 {
7188 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7189 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007190 else
7191 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007192 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193#endif /* FEAT_INS_EXPAND */
7194
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007195#ifdef FEAT_SIGNS
7196 /* 'signcolumn' */
7197 else if (varp == &curwin->w_p_scl)
7198 {
7199 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7200 errmsg = e_invarg;
7201 }
7202#endif
7203
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204
7205#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007206 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 else if (varp == &p_toolbar)
7208 {
7209 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7210 &toolbar_flags, TRUE) != OK)
7211 errmsg = e_invarg;
7212 else
7213 {
7214 out_flush();
7215 gui_mch_show_toolbar((toolbar_flags &
7216 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7217 }
7218 }
7219#endif
7220
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007221#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007222 /* 'toolbariconsize': GTK+ 2 only */
7223 else if (varp == &p_tbis)
7224 {
7225 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7226 errmsg = e_invarg;
7227 else
7228 {
7229 out_flush();
7230 gui_mch_show_toolbar((toolbar_flags &
7231 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7232 }
7233 }
7234#endif
7235
7236 /* 'pastetoggle': translate key codes like in a mapping */
7237 else if (varp == &p_pt)
7238 {
7239 if (*p_pt)
7240 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007241 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 if (p != NULL)
7243 {
7244 if (new_value_alloced)
7245 free_string_option(p_pt);
7246 p_pt = p;
7247 new_value_alloced = TRUE;
7248 }
7249 }
7250 }
7251
7252 /* 'backspace' */
7253 else if (varp == &p_bs)
7254 {
7255 if (VIM_ISDIGIT(*p_bs))
7256 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007257 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 errmsg = e_invarg;
7259 }
7260 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7261 errmsg = e_invarg;
7262 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007263 else if (varp == &p_bo)
7264 {
7265 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7266 errmsg = e_invarg;
7267 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007269 /* 'tagcase' */
7270 else if (gvarp == &p_tc)
7271 {
7272 unsigned int *flags;
7273
7274 if (opt_flags & OPT_LOCAL)
7275 {
7276 p = curbuf->b_p_tc;
7277 flags = &curbuf->b_tc_flags;
7278 }
7279 else
7280 {
7281 p = p_tc;
7282 flags = &tc_flags;
7283 }
7284
7285 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7286 /* make the local value empty: use the global value */
7287 *flags = 0;
7288 else if (*p == NUL
7289 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7290 errmsg = e_invarg;
7291 }
7292
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007293#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294 /* 'casemap' */
7295 else if (varp == &p_cmp)
7296 {
7297 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7298 errmsg = e_invarg;
7299 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301
7302#ifdef FEAT_DIFF
7303 /* 'diffopt' */
7304 else if (varp == &p_dip)
7305 {
7306 if (diffopt_changed() == FAIL)
7307 errmsg = e_invarg;
7308 }
7309#endif
7310
7311#ifdef FEAT_FOLDING
7312 /* 'foldmethod' */
7313 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7314 {
7315 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7316 || *curwin->w_p_fdm == NUL)
7317 errmsg = e_invarg;
7318 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007319 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007321 if (foldmethodIsDiff(curwin))
7322 newFoldLevel();
7323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 }
7325# ifdef FEAT_EVAL
7326 /* 'foldexpr' */
7327 else if (varp == &curwin->w_p_fde)
7328 {
7329 if (foldmethodIsExpr(curwin))
7330 foldUpdateAll(curwin);
7331 }
7332# endif
7333 /* 'foldmarker' */
7334 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7335 {
7336 p = vim_strchr(*varp, ',');
7337 if (p == NULL)
7338 errmsg = (char_u *)N_("E536: comma required");
7339 else if (p == *varp || p[1] == NUL)
7340 errmsg = e_invarg;
7341 else if (foldmethodIsMarker(curwin))
7342 foldUpdateAll(curwin);
7343 }
7344 /* 'commentstring' */
7345 else if (gvarp == &p_cms)
7346 {
7347 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7348 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7349 }
7350 /* 'foldopen' */
7351 else if (varp == &p_fdo)
7352 {
7353 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7354 errmsg = e_invarg;
7355 }
7356 /* 'foldclose' */
7357 else if (varp == &p_fcl)
7358 {
7359 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7360 errmsg = e_invarg;
7361 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007362 /* 'foldignore' */
7363 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7364 {
7365 if (foldmethodIsIndent(curwin))
7366 foldUpdateAll(curwin);
7367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368#endif
7369
7370#ifdef FEAT_VIRTUALEDIT
7371 /* 'virtualedit' */
7372 else if (varp == &p_ve)
7373 {
7374 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7375 errmsg = e_invarg;
7376 else if (STRCMP(p_ve, oldval) != 0)
7377 {
7378 /* Recompute cursor position in case the new 've' setting
7379 * changes something. */
7380 validate_virtcol();
7381 coladvance(curwin->w_virtcol);
7382 }
7383 }
7384#endif
7385
7386#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7387 else if (varp == &p_csqf)
7388 {
7389 if (p_csqf != NULL)
7390 {
7391 p = p_csqf;
7392 while (*p != NUL)
7393 {
7394 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7395 || p[1] == NUL
7396 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7397 || (p[2] != NUL && p[2] != ','))
7398 {
7399 errmsg = e_invarg;
7400 break;
7401 }
7402 else if (p[2] == NUL)
7403 break;
7404 else
7405 p += 3;
7406 }
7407 }
7408 }
7409#endif
7410
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007411#ifdef FEAT_CINDENT
7412 /* 'cinoptions' */
7413 else if (gvarp == &p_cino)
7414 {
7415 /* TODO: recognize errors */
7416 parse_cino(curbuf);
7417 }
7418#endif
7419
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007420#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007421 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007422 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007423 {
7424 if (!gui_mch_set_rendering_options(p_rop))
7425 errmsg = e_invarg;
7426 }
7427#endif
7428
Bram Moolenaard0b51382016-11-04 15:23:45 +01007429 else if (gvarp == &p_ft)
7430 {
7431 if (!valid_filetype(*varp))
7432 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007433 else
7434 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007435 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007436
7437#ifdef FEAT_SYN_HL
7438 else if (gvarp == &p_syn)
7439 {
7440 if (!valid_filetype(*varp))
7441 errmsg = e_invarg;
7442 }
7443#endif
7444
Bram Moolenaar825680f2017-07-22 17:04:02 +02007445#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007446 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007447 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007448 {
7449 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7450 errmsg = e_invarg;
7451 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007452 /* 'termsize' */
7453 else if (varp == &curwin->w_p_tms)
7454 {
7455 if (*curwin->w_p_tms != NUL)
7456 {
7457 p = skipdigits(curwin->w_p_tms);
7458 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7459 errmsg = e_invarg;
7460 }
7461 }
7462#endif
7463
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 /* Options that are a list of flags. */
7465 else
7466 {
7467 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007468 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007469 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007470 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007472 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007473 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007474 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007476#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007477 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007478 p = (char_u *)COCU_ALL;
7479#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007480 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 {
7482#ifdef FEAT_MOUSE
7483 p = (char_u *)MOUSE_ALL;
7484#else
7485 if (*p_mouse != NUL)
7486 errmsg = (char_u *)N_("E538: No mouse support");
7487#endif
7488 }
7489#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007490 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 p = (char_u *)GO_ALL;
7492#endif
7493 if (p != NULL)
7494 {
7495 for (s = *varp; *s; ++s)
7496 if (vim_strchr(p, *s) == NULL)
7497 {
7498 errmsg = illegal_char(errbuf, *s);
7499 break;
7500 }
7501 }
7502 }
7503
7504 /*
7505 * If error detected, restore the previous value.
7506 */
7507 if (errmsg != NULL)
7508 {
7509 if (new_value_alloced)
7510 free_string_option(*varp);
7511 *varp = oldval;
7512 /*
7513 * When resetting some values, need to act on it.
7514 */
7515 if (did_chartab)
7516 (void)init_chartab();
7517 if (varp == &p_hl)
7518 (void)highlight_changed();
7519 }
7520 else
7521 {
7522#ifdef FEAT_EVAL
7523 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007524 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525#endif
7526 /*
7527 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007528 * Use "free_oldval", because recursiveness may change the flags under
7529 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007531 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532 free_string_option(oldval);
7533 if (new_value_alloced)
7534 options[opt_idx].flags |= P_ALLOCED;
7535 else
7536 options[opt_idx].flags &= ~P_ALLOCED;
7537
7538 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007539 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 {
7541 /* global option with local value set to use global value; free
7542 * the local value and make it empty */
7543 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7544 free_string_option(*(char_u **)p);
7545 *(char_u **)p = empty_option;
7546 }
7547
7548 /* May set global value for local option. */
7549 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7550 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007551
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007552 /*
7553 * Trigger the autocommand only after setting the flags.
7554 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007555#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007556 /* When 'syntax' is set, load the syntax of that name */
7557 if (varp == &(curbuf->b_p_syn))
7558 {
7559 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7560 curbuf->b_fname, TRUE, curbuf);
7561 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007562#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007563 else if (varp == &(curbuf->b_p_ft))
7564 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007565 /* 'filetype' is set, trigger the FileType autocommand.
7566 * Skip this when called from a modeline and the filetype was
7567 * already set to this value. */
7568 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7569 {
7570 did_filetype = TRUE;
7571 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007572 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007573 /* Just in case the old "curbuf" is now invalid. */
7574 if (varp != &(curbuf->b_p_ft))
7575 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007576 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007577 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007578#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007580 {
7581 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007582 char_u *q = curwin->w_s->b_p_spl;
7583
7584 /* Skip the first name if it is "cjk". */
7585 if (STRNCMP(q, "cjk,", 4) == 0)
7586 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007587
7588 /*
7589 * Source the spell/LANG.vim in 'runtimepath'.
7590 * They could set 'spellcapcheck' depending on the language.
7591 * Use the first name in 'spelllang' up to '_region' or
7592 * '.encoding'.
7593 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007594 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7596 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007597 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007598 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007599 }
7600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 }
7602
7603#ifdef FEAT_MOUSE
7604 if (varp == &p_mouse)
7605 {
7606# ifdef FEAT_MOUSE_TTY
7607 if (*p_mouse == NUL)
7608 mch_setmouse(FALSE); /* switch mouse off */
7609 else
7610# endif
7611 setmouse(); /* in case 'mouse' changed */
7612 }
7613#endif
7614
Bram Moolenaar913077c2012-03-28 19:59:04 +02007615 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007616 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007617 curwin->w_set_curswant = TRUE;
7618
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007619#ifdef FEAT_GUI
7620 /* check redraw when it's not a GUI option or the GUI is active. */
7621 if (!redraw_gui_only || gui.in_use)
7622#endif
7623 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624
7625 return errmsg;
7626}
7627
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007628#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007629/*
7630 * Simple int comparison function for use with qsort()
7631 */
7632 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007633int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007634{
7635 return *(const int *)a - *(const int *)b;
7636}
7637
7638/*
7639 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7640 * Returns error message, NULL if it's OK.
7641 */
7642 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007643check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007644{
7645 char_u *s;
7646 int col;
7647 int count = 0;
7648 int color_cols[256];
7649 int i;
7650 int j = 0;
7651
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007652 if (wp->w_buffer == NULL)
7653 return NULL; /* buffer was closed */
7654
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007655 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007656 {
7657 if (*s == '-' || *s == '+')
7658 {
7659 /* -N and +N: add to 'textwidth' */
7660 col = (*s == '-') ? -1 : 1;
7661 ++s;
7662 if (!VIM_ISDIGIT(*s))
7663 return e_invarg;
7664 col = col * getdigits(&s);
7665 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007666 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007667 col += wp->w_buffer->b_p_tw;
7668 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007669 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007670 }
7671 else if (VIM_ISDIGIT(*s))
7672 col = getdigits(&s);
7673 else
7674 return e_invarg;
7675 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007676skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007677 if (*s == NUL)
7678 break;
7679 if (*s != ',')
7680 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007681 if (*++s == NUL)
7682 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007683 }
7684
7685 vim_free(wp->w_p_cc_cols);
7686 if (count == 0)
7687 wp->w_p_cc_cols = NULL;
7688 else
7689 {
7690 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7691 if (wp->w_p_cc_cols != NULL)
7692 {
7693 /* sort the columns for faster usage on screen redraw inside
7694 * win_line() */
7695 qsort(color_cols, count, sizeof(int), int_cmp);
7696
7697 for (i = 0; i < count; ++i)
7698 /* skip duplicates */
7699 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7700 wp->w_p_cc_cols[j++] = color_cols[i];
7701 wp->w_p_cc_cols[j] = -1; /* end marker */
7702 }
7703 }
7704
7705 return NULL; /* no error */
7706}
7707#endif
7708
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709/*
7710 * Handle setting 'listchars' or 'fillchars'.
7711 * Returns error message, NULL if it's OK.
7712 */
7713 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007714set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715{
7716 int round, i, len, entries;
7717 char_u *p, *s;
7718 int c1, c2 = 0;
7719 struct charstab
7720 {
7721 int *cp;
7722 char *name;
7723 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724 static struct charstab filltab[] =
7725 {
7726 {&fill_stl, "stl"},
7727 {&fill_stlnc, "stlnc"},
7728 {&fill_vert, "vert"},
7729 {&fill_fold, "fold"},
7730 {&fill_diff, "diff"},
7731 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 static struct charstab lcstab[] =
7733 {
7734 {&lcs_eol, "eol"},
7735 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007736 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007738 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 {&lcs_tab2, "tab"},
7740 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007741#ifdef FEAT_CONCEAL
7742 {&lcs_conceal, "conceal"},
7743#else
7744 {NULL, "conceal"},
7745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 };
7747 struct charstab *tab;
7748
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 {
7751 tab = lcstab;
7752 entries = sizeof(lcstab) / sizeof(struct charstab);
7753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 else
7755 {
7756 tab = filltab;
7757 entries = sizeof(filltab) / sizeof(struct charstab);
7758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759
7760 /* first round: check for valid value, second round: assign values */
7761 for (round = 0; round <= 1; ++round)
7762 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007763 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 {
7765 /* After checking that the value is valid: set defaults: space for
7766 * 'fillchars', NUL for 'listchars' */
7767 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007768 if (tab[i].cp != NULL)
7769 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 if (varp == &p_lcs)
7771 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772 else
7773 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 }
7775 p = *varp;
7776 while (*p)
7777 {
7778 for (i = 0; i < entries; ++i)
7779 {
7780 len = (int)STRLEN(tab[i].name);
7781 if (STRNCMP(p, tab[i].name, len) == 0
7782 && p[len] == ':'
7783 && p[len + 1] != NUL)
7784 {
7785 s = p + len + 1;
7786#ifdef FEAT_MBYTE
7787 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007788 if (mb_char2cells(c1) > 1)
7789 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790#else
7791 c1 = *s++;
7792#endif
7793 if (tab[i].cp == &lcs_tab2)
7794 {
7795 if (*s == NUL)
7796 continue;
7797#ifdef FEAT_MBYTE
7798 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007799 if (mb_char2cells(c2) > 1)
7800 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801#else
7802 c2 = *s++;
7803#endif
7804 }
7805 if (*s == ',' || *s == NUL)
7806 {
7807 if (round)
7808 {
7809 if (tab[i].cp == &lcs_tab2)
7810 {
7811 lcs_tab1 = c1;
7812 lcs_tab2 = c2;
7813 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007814 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815 *(tab[i].cp) = c1;
7816
7817 }
7818 p = s;
7819 break;
7820 }
7821 }
7822 }
7823
7824 if (i == entries)
7825 return e_invarg;
7826 if (*p == ',')
7827 ++p;
7828 }
7829 }
7830
7831 return NULL; /* no error */
7832}
7833
7834#ifdef FEAT_STL_OPT
7835/*
7836 * Check validity of options with the 'statusline' format.
7837 * Return error message or NULL.
7838 */
7839 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007840check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841{
7842 int itemcnt = 0;
7843 int groupdepth = 0;
7844 static char_u errbuf[80];
7845
7846 while (*s && itemcnt < STL_MAX_ITEM)
7847 {
7848 /* Check for valid keys after % sequences */
7849 while (*s && *s != '%')
7850 s++;
7851 if (!*s)
7852 break;
7853 s++;
7854 if (*s != '%' && *s != ')')
7855 ++itemcnt;
7856 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7857 {
7858 s++;
7859 continue;
7860 }
7861 if (*s == ')')
7862 {
7863 s++;
7864 if (--groupdepth < 0)
7865 break;
7866 continue;
7867 }
7868 if (*s == '-')
7869 s++;
7870 while (VIM_ISDIGIT(*s))
7871 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007872 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 continue;
7874 if (*s == '.')
7875 {
7876 s++;
7877 while (*s && VIM_ISDIGIT(*s))
7878 s++;
7879 }
7880 if (*s == '(')
7881 {
7882 groupdepth++;
7883 continue;
7884 }
7885 if (vim_strchr(STL_ALL, *s) == NULL)
7886 {
7887 return illegal_char(errbuf, *s);
7888 }
7889 if (*s == '{')
7890 {
7891 s++;
7892 while (*s != '}' && *s)
7893 s++;
7894 if (*s != '}')
7895 return (char_u *)N_("E540: Unclosed expression sequence");
7896 }
7897 }
7898 if (itemcnt >= STL_MAX_ITEM)
7899 return (char_u *)N_("E541: too many items");
7900 if (groupdepth != 0)
7901 return (char_u *)N_("E542: unbalanced groups");
7902 return NULL;
7903}
7904#endif
7905
7906#ifdef FEAT_CLIPBOARD
7907/*
7908 * Extract the items in the 'clipboard' option and set global values.
7909 */
7910 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007911check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007913 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007914 int new_autoselect_star = FALSE;
7915 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007917 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 regprog_T *new_exclude_prog = NULL;
7919 char_u *errmsg = NULL;
7920 char_u *p;
7921
7922 for (p = p_cb; *p != NUL; )
7923 {
7924 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7925 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007926 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 p += 7;
7928 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007929 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007930 && (p[11] == ',' || p[11] == NUL))
7931 {
7932 new_unnamed |= CLIP_UNNAMED_PLUS;
7933 p += 11;
7934 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007936 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007938 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 p += 10;
7940 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007941 else if (STRNCMP(p, "autoselectplus", 14) == 0
7942 && (p[14] == ',' || p[14] == NUL))
7943 {
7944 new_autoselect_plus = TRUE;
7945 p += 14;
7946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007948 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 {
7950 new_autoselectml = TRUE;
7951 p += 12;
7952 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007953 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7954 {
7955 new_html = TRUE;
7956 p += 4;
7957 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7959 {
7960 p += 8;
7961 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7962 if (new_exclude_prog == NULL)
7963 errmsg = e_invarg;
7964 break;
7965 }
7966 else
7967 {
7968 errmsg = e_invarg;
7969 break;
7970 }
7971 if (*p == ',')
7972 ++p;
7973 }
7974 if (errmsg == NULL)
7975 {
7976 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007977 clip_autoselect_star = new_autoselect_star;
7978 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007980 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007981 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007983#ifdef FEAT_GUI_GTK
7984 if (gui.in_use)
7985 {
7986 gui_gtk_set_selection_targets();
7987 gui_gtk_set_dnd_targets();
7988 }
7989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 }
7991 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007992 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993
7994 return errmsg;
7995}
7996#endif
7997
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007998#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007999 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008000did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008001{
8002 char_u *errmsg = NULL;
8003 win_T *wp;
8004 int l;
8005
8006 if (is_spellfile)
8007 {
8008 l = (int)STRLEN(curwin->w_s->b_p_spf);
8009 if (l > 0 && (l < 4
8010 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8011 errmsg = e_invarg;
8012 }
8013
8014 if (errmsg == NULL)
8015 {
8016 FOR_ALL_WINDOWS(wp)
8017 if (wp->w_buffer == curbuf && wp->w_p_spell)
8018 {
8019 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008020 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008021 }
8022 }
8023 return errmsg;
8024}
8025
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008026/*
8027 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8028 * Return error message when failed, NULL when OK.
8029 */
8030 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008031compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008032{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008033 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008034 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008035
Bram Moolenaar860cae12010-06-05 23:22:07 +02008036 if (*synblock->b_p_spc == NUL)
8037 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008038 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008039 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008040 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008041 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008042 if (re != NULL)
8043 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008044 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008045 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008046 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008047 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008048 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008049 return e_invarg;
8050 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008051 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008052 }
8053
Bram Moolenaar473de612013-06-08 18:19:48 +02008054 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008055 return NULL;
8056}
8057#endif
8058
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008059#if defined(FEAT_EVAL) || defined(PROTO)
8060/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008061 * Set the scriptID for an option, taking care of setting the buffer- or
8062 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008063 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008064 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008065set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008066{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008067 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8068 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008069
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008070 /* Remember where the option was set. For local options need to do that
8071 * in the buffer or window structure. */
8072 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008073 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008074 if (both || (opt_flags & OPT_LOCAL))
8075 {
8076 if (indir & PV_BUF)
8077 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8078 else if (indir & PV_WIN)
8079 curwin->w_p_scriptID[indir & PV_MASK] = id;
8080 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008081}
8082#endif
8083
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084/*
8085 * Set the value of a boolean option, and take care of side effects.
8086 * Returns NULL for success, or an error message for an error.
8087 */
8088 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008089set_bool_option(
8090 int opt_idx, /* index in options[] table */
8091 char_u *varp, /* pointer to the option variable */
8092 int value, /* new value */
8093 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094{
8095 int old_value = *(int *)varp;
8096
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 /* Disallow changing some options from secure mode */
8098 if ((secure
8099#ifdef HAVE_SANDBOX
8100 || sandbox != 0
8101#endif
8102 ) && (options[opt_idx].flags & P_SECURE))
8103 return e_secure;
8104
8105 *(int *)varp = value; /* set the new value */
8106#ifdef FEAT_EVAL
8107 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008108 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109#endif
8110
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008111#ifdef FEAT_GUI
8112 need_mouse_correct = TRUE;
8113#endif
8114
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 /* May set global value for local option. */
8116 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8117 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8118
8119 /*
8120 * Handle side effects of changing a bool option.
8121 */
8122
8123 /* 'compatible' */
8124 if ((int *)varp == &p_cp)
8125 {
8126 compatible_set();
8127 }
8128
Bram Moolenaar920694c2016-08-21 17:45:02 +02008129#ifdef FEAT_LANGMAP
8130 if ((int *)varp == &p_lrm)
8131 /* 'langremap' -> !'langnoremap' */
8132 p_lnr = !p_lrm;
8133 else if ((int *)varp == &p_lnr)
8134 /* 'langnoremap' -> !'langremap' */
8135 p_lrm = !p_lnr;
8136#endif
8137
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008138#ifdef FEAT_PERSISTENT_UNDO
8139 /* 'undofile' */
8140 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8141 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008142 /* Only take action when the option was set. When reset we do not
8143 * delete the undo file, the option may be set again without making
8144 * any changes in between. */
8145 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008146 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008147 char_u hash[UNDO_HASH_SIZE];
8148 buf_T *save_curbuf = curbuf;
8149
Bram Moolenaar29323592016-07-24 22:04:11 +02008150 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008151 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008152 /* When 'undofile' is set globally: for every buffer, otherwise
8153 * only for the current buffer: Try to read in the undofile,
8154 * if one exists, the buffer wasn't changed and the buffer was
8155 * loaded */
8156 if ((curbuf == save_curbuf
8157 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8158 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8159 {
8160 u_compute_hash(hash);
8161 u_read_undo(NULL, hash, curbuf->b_fname);
8162 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008163 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008164 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008165 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008166 }
8167#endif
8168
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 else if ((int *)varp == &curbuf->b_p_ro)
8170 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008171 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8173 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008174
8175 /* when 'readonly' is set may give W10 again */
8176 if (curbuf->b_p_ro)
8177 curbuf->b_did_warn = FALSE;
8178
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008180 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181#endif
8182 }
8183
Bram Moolenaar9c449722010-07-20 18:44:27 +02008184#ifdef FEAT_GUI
8185 else if ((int *)varp == &p_mh)
8186 {
8187 if (!p_mh)
8188 gui_mch_mousehide(FALSE);
8189 }
8190#endif
8191
Bram Moolenaara539df02010-08-01 14:35:05 +02008192 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008194 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008195# ifdef FEAT_TERMINAL
8196 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008197 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8198 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008199 {
8200 curbuf->b_p_ma = FALSE;
8201 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8202 }
8203# endif
8204# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008205 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008206# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008207 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008208#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 /* when 'endofline' is changed, redraw the window title */
8210 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008211 {
8212 redraw_titles();
8213 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008214 /* when 'fixeol' is changed, redraw the window title */
8215 else if ((int *)varp == &curbuf->b_p_fixeol)
8216 {
8217 redraw_titles();
8218 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008219# ifdef FEAT_MBYTE
8220 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008221 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008222 {
8223 redraw_titles();
8224 }
8225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226#endif
8227
8228 /* when 'bin' is set also set some other options */
8229 else if ((int *)varp == &curbuf->b_p_bin)
8230 {
8231 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8232#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008233 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234#endif
8235 }
8236
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 /* when 'buflisted' changes, trigger autocommands */
8238 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8239 {
8240 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8241 NULL, NULL, TRUE, curbuf);
8242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243
8244 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8245 else if ((int *)varp == &curbuf->b_p_swf)
8246 {
8247 if (curbuf->b_p_swf && p_uc)
8248 ml_open_file(curbuf); /* create the swap file */
8249 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008250 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8251 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 mf_close_file(curbuf, TRUE); /* remove the swap file */
8253 }
8254
8255 /* when 'terse' is set change 'shortmess' */
8256 else if ((int *)varp == &p_terse)
8257 {
8258 char_u *p;
8259
8260 p = vim_strchr(p_shm, SHM_SEARCH);
8261
8262 /* insert 's' in p_shm */
8263 if (p_terse && p == NULL)
8264 {
8265 STRCPY(IObuff, p_shm);
8266 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008267 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 }
8269 /* remove 's' from p_shm */
8270 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008271 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272 }
8273
8274 /* when 'paste' is set or reset also change other options */
8275 else if ((int *)varp == &p_paste)
8276 {
8277 paste_option_changed();
8278 }
8279
8280 /* when 'insertmode' is set from an autocommand need to do work here */
8281 else if ((int *)varp == &p_im)
8282 {
8283 if (p_im)
8284 {
8285 if ((State & INSERT) == 0)
8286 need_start_insertmode = TRUE;
8287 stop_insert_mode = FALSE;
8288 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008289 /* only reset if it was set previously */
8290 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 {
8292 need_start_insertmode = FALSE;
8293 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008294 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295 clear_cmdline = TRUE; /* remove "(insert)" */
8296 restart_edit = 0;
8297 }
8298 }
8299
8300 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8301 else if ((int *)varp == &p_ic && p_hls)
8302 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008303 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 }
8305
8306#ifdef FEAT_SEARCH_EXTRA
8307 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8308 else if ((int *)varp == &p_hls)
8309 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008310 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008311 }
8312#endif
8313
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8315 * at the end of normal_cmd() */
8316 else if ((int *)varp == &curwin->w_p_scb)
8317 {
8318 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008319 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008321 curwin->w_scbind_pos = curwin->w_topline;
8322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324
Bram Moolenaar4033c552017-09-16 20:54:51 +02008325#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 /* There can be only one window with 'previewwindow' set. */
8327 else if ((int *)varp == &curwin->w_p_pvw)
8328 {
8329 if (curwin->w_p_pvw)
8330 {
8331 win_T *win;
8332
Bram Moolenaar29323592016-07-24 22:04:11 +02008333 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008334 if (win->w_p_pvw && win != curwin)
8335 {
8336 curwin->w_p_pvw = FALSE;
8337 return (char_u *)N_("E590: A preview window already exists");
8338 }
8339 }
8340 }
8341#endif
8342
8343 /* when 'textmode' is set or reset also change 'fileformat' */
8344 else if ((int *)varp == &curbuf->b_p_tx)
8345 {
8346 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8347 }
8348
8349 /* when 'textauto' is set or reset also change 'fileformats' */
8350 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 set_string_option_direct((char_u *)"ffs", -1,
8352 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008353 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354
8355 /*
8356 * When 'lisp' option changes include/exclude '-' in
8357 * keyword characters.
8358 */
8359#ifdef FEAT_LISP
8360 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8361 {
8362 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8363 }
8364#endif
8365
8366#ifdef FEAT_TITLE
8367 /* when 'title' changed, may need to change the title; same for 'icon' */
8368 else if ((int *)varp == &p_title)
8369 {
8370 did_set_title(FALSE);
8371 }
8372
8373 else if ((int *)varp == &p_icon)
8374 {
8375 did_set_title(TRUE);
8376 }
8377#endif
8378
8379 else if ((int *)varp == &curbuf->b_changed)
8380 {
8381 if (!value)
8382 save_file_ff(curbuf); /* Buffer is unchanged */
8383#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008384 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 }
8388
8389#ifdef BACKSLASH_IN_FILENAME
8390 else if ((int *)varp == &p_ssl)
8391 {
8392 if (p_ssl)
8393 {
8394 psepc = '/';
8395 psepcN = '\\';
8396 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397 }
8398 else
8399 {
8400 psepc = '\\';
8401 psepcN = '/';
8402 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 }
8404
8405 /* need to adjust the file name arguments and buffer names. */
8406 buflist_slash_adjust();
8407 alist_slash_adjust();
8408# ifdef FEAT_EVAL
8409 scriptnames_slash_adjust();
8410# endif
8411 }
8412#endif
8413
8414 /* If 'wrap' is set, set w_leftcol to zero. */
8415 else if ((int *)varp == &curwin->w_p_wrap)
8416 {
8417 if (curwin->w_p_wrap)
8418 curwin->w_leftcol = 0;
8419 }
8420
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 else if ((int *)varp == &p_ea)
8422 {
8423 if (p_ea && !old_value)
8424 win_equal(curwin, FALSE, 0);
8425 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426
8427 else if ((int *)varp == &p_wiv)
8428 {
8429 /*
8430 * When 'weirdinvert' changed, set/reset 't_xs'.
8431 * Then set 'weirdinvert' according to value of 't_xs'.
8432 */
8433 if (p_wiv && !old_value)
8434 T_XS = (char_u *)"y";
8435 else if (!p_wiv && old_value)
8436 T_XS = empty_option;
8437 p_wiv = (*T_XS != NUL);
8438 }
8439
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008440#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 else if ((int *)varp == &p_beval)
8442 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008443 if (!balloonEvalForTerm)
8444 {
8445 if (p_beval && !old_value)
8446 gui_mch_enable_beval_area(balloonEval);
8447 else if (!p_beval && old_value)
8448 gui_mch_disable_beval_area(balloonEval);
8449 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008451#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008452#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008453 else if ((int *)varp == &p_bevalterm)
8454 {
8455 mch_bevalterm_changed();
8456 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008459#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 else if ((int *)varp == &p_acd)
8461 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008462 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008463 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 }
8465#endif
8466
8467#ifdef FEAT_DIFF
8468 /* 'diff' */
8469 else if ((int *)varp == &curwin->w_p_diff)
8470 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008471 /* May add or remove the buffer from the list of diff buffers. */
8472 diff_buf_adjust(curwin);
8473# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 if (foldmethodIsDiff(curwin))
8475 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008476# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 }
8478#endif
8479
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008480#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481 /* 'imdisable' */
8482 else if ((int *)varp == &p_imdisable)
8483 {
8484 /* Only de-activate it here, it will be enabled when changing mode. */
8485 if (p_imdisable)
8486 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008487 else if (State & INSERT)
8488 /* When the option is set from an autocommand, it may need to take
8489 * effect right away. */
8490 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 }
8492#endif
8493
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008494#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008495 /* 'spell' */
8496 else if ((int *)varp == &curwin->w_p_spell)
8497 {
8498 if (curwin->w_p_spell)
8499 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008500 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008501 if (errmsg != NULL)
8502 EMSG(_(errmsg));
8503 }
8504 }
8505#endif
8506
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507#ifdef FEAT_FKMAP
8508 else if ((int *)varp == &p_altkeymap)
8509 {
8510 if (old_value != p_altkeymap)
8511 {
8512 if (!p_altkeymap)
8513 {
8514 p_hkmap = p_fkmap;
8515 p_fkmap = 0;
8516 }
8517 else
8518 {
8519 p_fkmap = p_hkmap;
8520 p_hkmap = 0;
8521 }
8522 (void)init_chartab();
8523 }
8524 }
8525
8526 /*
8527 * In case some second language keymapping options have changed, check
8528 * and correct the setting in a consistent way.
8529 */
8530
8531 /*
8532 * If hkmap or fkmap are set, reset Arabic keymapping.
8533 */
8534 if ((p_hkmap || p_fkmap) && p_altkeymap)
8535 {
8536 p_altkeymap = p_fkmap;
8537# ifdef FEAT_ARABIC
8538 curwin->w_p_arab = FALSE;
8539# endif
8540 (void)init_chartab();
8541 }
8542
8543 /*
8544 * If hkmap set, reset Farsi keymapping.
8545 */
8546 if (p_hkmap && p_altkeymap)
8547 {
8548 p_altkeymap = 0;
8549 p_fkmap = 0;
8550# ifdef FEAT_ARABIC
8551 curwin->w_p_arab = FALSE;
8552# endif
8553 (void)init_chartab();
8554 }
8555
8556 /*
8557 * If fkmap set, reset Hebrew keymapping.
8558 */
8559 if (p_fkmap && !p_altkeymap)
8560 {
8561 p_altkeymap = 1;
8562 p_hkmap = 0;
8563# ifdef FEAT_ARABIC
8564 curwin->w_p_arab = FALSE;
8565# endif
8566 (void)init_chartab();
8567 }
8568#endif
8569
8570#ifdef FEAT_ARABIC
8571 if ((int *)varp == &curwin->w_p_arab)
8572 {
8573 if (curwin->w_p_arab)
8574 {
8575 /*
8576 * 'arabic' is set, handle various sub-settings.
8577 */
8578 if (!p_tbidi)
8579 {
8580 /* set rightleft mode */
8581 if (!curwin->w_p_rl)
8582 {
8583 curwin->w_p_rl = TRUE;
8584 changed_window_setting();
8585 }
8586
8587 /* Enable Arabic shaping (major part of what Arabic requires) */
8588 if (!p_arshape)
8589 {
8590 p_arshape = TRUE;
8591 redraw_later_clear();
8592 }
8593 }
8594
8595 /* Arabic requires a utf-8 encoding, inform the user if its not
8596 * set. */
8597 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008598 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008599 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8600
Bram Moolenaar8820b482017-03-16 17:23:31 +01008601 msg_source(HL_ATTR(HLF_W));
8602 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008603#ifdef FEAT_EVAL
8604 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8605#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008606 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607
8608# ifdef FEAT_MBYTE
8609 /* set 'delcombine' */
8610 p_deco = TRUE;
8611# endif
8612
8613# ifdef FEAT_KEYMAP
8614 /* Force-set the necessary keymap for arabic */
8615 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8616 OPT_LOCAL);
8617# endif
8618# ifdef FEAT_FKMAP
8619 p_altkeymap = 0;
8620 p_hkmap = 0;
8621 p_fkmap = 0;
8622 (void)init_chartab();
8623# endif
8624 }
8625 else
8626 {
8627 /*
8628 * 'arabic' is reset, handle various sub-settings.
8629 */
8630 if (!p_tbidi)
8631 {
8632 /* reset rightleft mode */
8633 if (curwin->w_p_rl)
8634 {
8635 curwin->w_p_rl = FALSE;
8636 changed_window_setting();
8637 }
8638
8639 /* 'arabicshape' isn't reset, it is a global option and
8640 * another window may still need it "on". */
8641 }
8642
8643 /* 'delcombine' isn't reset, it is a global option and another
8644 * window may still want it "on". */
8645
8646# ifdef FEAT_KEYMAP
8647 /* Revert to the default keymap */
8648 curbuf->b_p_iminsert = B_IMODE_NONE;
8649 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8650# endif
8651 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008652 }
8653
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008654#endif
8655
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008656#ifdef FEAT_TERMGUICOLORS
8657 /* 'termguicolors' */
8658 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008659 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008660# ifdef FEAT_VTP
8661 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8662 if (!has_vtp_working())
8663 {
8664 p_tgc = 0;
8665 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8666 }
8667 swap_tcap();
8668# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008669# ifdef FEAT_GUI
8670 if (!gui.in_use && !gui.starting)
8671# endif
8672 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008673# ifdef FEAT_VTP
8674 control_console_color_rgb();
8675 /* reset t_Co */
8676 if (STRCMP(T_NAME, "win32") == 0)
8677 set_termname(T_NAME);
8678# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008679 }
8680#endif
8681
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 /*
8683 * End of handling side effects for bool options.
8684 */
8685
Bram Moolenaar53744302015-07-17 17:38:22 +02008686 /* after handling side effects, call autocommand */
8687
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688 options[opt_idx].flags |= P_WAS_SET;
8689
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008690#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008691 if (!starting)
8692 {
8693 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008694 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8695 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8696 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008697 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8698 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8699 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8700 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8701 reset_v_option_vars();
8702 }
8703#endif
8704
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008706 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008707 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008708 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 check_redraw(options[opt_idx].flags);
8710
8711 return NULL;
8712}
8713
8714/*
8715 * Set the value of a number option, and take care of side effects.
8716 * Returns NULL for success, or an error message for an error.
8717 */
8718 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008719set_num_option(
8720 int opt_idx, /* index in options[] table */
8721 char_u *varp, /* pointer to the option variable */
8722 long value, /* new value */
8723 char_u *errbuf, /* buffer for error messages */
8724 size_t errbuflen, /* length of "errbuf" */
8725 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 OPT_MODELINE */
8727{
8728 char_u *errmsg = NULL;
8729 long old_value = *(long *)varp;
8730 long old_Rows = Rows; /* remember old Rows */
8731 long old_Columns = Columns; /* remember old Columns */
8732 long *pp = (long *)varp;
8733
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008734 /* Disallow changing some options from secure mode. */
8735 if ((secure
8736#ifdef HAVE_SANDBOX
8737 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008739 ) && (options[opt_idx].flags & P_SECURE))
8740 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741
8742 *pp = value;
8743#ifdef FEAT_EVAL
8744 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008745 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008747#ifdef FEAT_GUI
8748 need_mouse_correct = TRUE;
8749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750
Bram Moolenaar14f24742012-08-08 18:01:05 +02008751 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 {
8753 errmsg = e_positive;
8754 curbuf->b_p_sw = curbuf->b_p_ts;
8755 }
8756
8757 /*
8758 * Number options that need some action when changed
8759 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008760 if (pp == &p_wh || pp == &p_hh)
8761 {
8762 if (p_wh < 1)
8763 {
8764 errmsg = e_positive;
8765 p_wh = 1;
8766 }
8767 if (p_wmh > p_wh)
8768 {
8769 errmsg = e_winheight;
8770 p_wh = p_wmh;
8771 }
8772 if (p_hh < 0)
8773 {
8774 errmsg = e_positive;
8775 p_hh = 0;
8776 }
8777
8778 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008779 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 {
8781 if (pp == &p_wh && curwin->w_height < p_wh)
8782 win_setheight((int)p_wh);
8783 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8784 win_setheight((int)p_hh);
8785 }
8786 }
8787
8788 /* 'winminheight' */
8789 else if (pp == &p_wmh)
8790 {
8791 if (p_wmh < 0)
8792 {
8793 errmsg = e_positive;
8794 p_wmh = 0;
8795 }
8796 if (p_wmh > p_wh)
8797 {
8798 errmsg = e_winheight;
8799 p_wmh = p_wh;
8800 }
8801 win_setminheight();
8802 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008803 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 {
8805 if (p_wiw < 1)
8806 {
8807 errmsg = e_positive;
8808 p_wiw = 1;
8809 }
8810 if (p_wmw > p_wiw)
8811 {
8812 errmsg = e_winwidth;
8813 p_wiw = p_wmw;
8814 }
8815
8816 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008817 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008818 win_setwidth((int)p_wiw);
8819 }
8820
8821 /* 'winminwidth' */
8822 else if (pp == &p_wmw)
8823 {
8824 if (p_wmw < 0)
8825 {
8826 errmsg = e_positive;
8827 p_wmw = 0;
8828 }
8829 if (p_wmw > p_wiw)
8830 {
8831 errmsg = e_winwidth;
8832 p_wmw = p_wiw;
8833 }
8834 win_setminheight();
8835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 /* (re)set last window status line */
8838 else if (pp == &p_ls)
8839 {
8840 last_status(FALSE);
8841 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008842
8843 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008844 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008845 {
8846 shell_new_rows(); /* recompute window positions and heights */
8847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848
8849#ifdef FEAT_GUI
8850 else if (pp == &p_linespace)
8851 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008852 /* Recompute gui.char_height and resize the Vim window to keep the
8853 * same number of lines. */
8854 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008855 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 }
8857#endif
8858
8859#ifdef FEAT_FOLDING
8860 /* 'foldlevel' */
8861 else if (pp == &curwin->w_p_fdl)
8862 {
8863 if (curwin->w_p_fdl < 0)
8864 curwin->w_p_fdl = 0;
8865 newFoldLevel();
8866 }
8867
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008868 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 else if (pp == &curwin->w_p_fml)
8870 {
8871 foldUpdateAll(curwin);
8872 }
8873
8874 /* 'foldnestmax' */
8875 else if (pp == &curwin->w_p_fdn)
8876 {
8877 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8878 foldUpdateAll(curwin);
8879 }
8880
8881 /* 'foldcolumn' */
8882 else if (pp == &curwin->w_p_fdc)
8883 {
8884 if (curwin->w_p_fdc < 0)
8885 {
8886 errmsg = e_positive;
8887 curwin->w_p_fdc = 0;
8888 }
8889 else if (curwin->w_p_fdc > 12)
8890 {
8891 errmsg = e_invarg;
8892 curwin->w_p_fdc = 12;
8893 }
8894 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008895#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008897#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 /* 'shiftwidth' or 'tabstop' */
8899 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8900 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008901# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 if (foldmethodIsIndent(curwin))
8903 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008904# endif
8905# ifdef FEAT_CINDENT
8906 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8907 * parse 'cinoptions'. */
8908 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8909 parse_cino(curbuf);
8910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008914#ifdef FEAT_MBYTE
8915 /* 'maxcombine' */
8916 else if (pp == &p_mco)
8917 {
8918 if (p_mco > MAX_MCO)
8919 p_mco = MAX_MCO;
8920 else if (p_mco < 0)
8921 p_mco = 0;
8922 screenclear(); /* will re-allocate the screen */
8923 }
8924#endif
8925
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 else if (pp == &curbuf->b_p_iminsert)
8927 {
8928 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8929 {
8930 errmsg = e_invarg;
8931 curbuf->b_p_iminsert = B_IMODE_NONE;
8932 }
8933 p_iminsert = curbuf->b_p_iminsert;
8934 if (termcap_active) /* don't do this in the alternate screen */
8935 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008936#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 /* Show/unshow value of 'keymap' in status lines. */
8938 status_redraw_curbuf();
8939#endif
8940 }
8941
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008942#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8943 /* 'imstyle' */
8944 else if (pp == &p_imst)
8945 {
8946 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8947 errmsg = e_invarg;
8948 }
8949#endif
8950
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008951 else if (pp == &p_window)
8952 {
8953 if (p_window < 1)
8954 p_window = 1;
8955 else if (p_window >= Rows)
8956 p_window = Rows - 1;
8957 }
8958
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959 else if (pp == &curbuf->b_p_imsearch)
8960 {
8961 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8962 {
8963 errmsg = e_invarg;
8964 curbuf->b_p_imsearch = B_IMODE_NONE;
8965 }
8966 p_imsearch = curbuf->b_p_imsearch;
8967 }
8968
8969#ifdef FEAT_TITLE
8970 /* if 'titlelen' has changed, redraw the title */
8971 else if (pp == &p_titlelen)
8972 {
8973 if (p_titlelen < 0)
8974 {
8975 errmsg = e_positive;
8976 p_titlelen = 85;
8977 }
8978 if (starting != NO_SCREEN && old_value != p_titlelen)
8979 need_maketitle = TRUE;
8980 }
8981#endif
8982
8983 /* if p_ch changed value, change the command line height */
8984 else if (pp == &p_ch)
8985 {
8986 if (p_ch < 1)
8987 {
8988 errmsg = e_positive;
8989 p_ch = 1;
8990 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008991 if (p_ch > Rows - min_rows() + 1)
8992 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993
8994 /* Only compute the new window layout when startup has been
8995 * completed. Otherwise the frame sizes may be wrong. */
8996 if (p_ch != old_value && full_screen
8997#ifdef FEAT_GUI
8998 && !gui.starting
8999#endif
9000 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009001 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002 }
9003
9004 /* when 'updatecount' changes from zero to non-zero, open swap files */
9005 else if (pp == &p_uc)
9006 {
9007 if (p_uc < 0)
9008 {
9009 errmsg = e_positive;
9010 p_uc = 100;
9011 }
9012 if (p_uc && !old_value)
9013 ml_open_files();
9014 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009015#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009016 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009017 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009018 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009019 {
9020 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009021 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009022 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009023 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009024 {
9025 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009026 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009027 }
9028 }
9029#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009030#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009031 else if (pp == &p_mzq)
9032 mzvim_reset_timer();
9033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009035#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9036 /* 'pyxversion' */
9037 else if (pp == &p_pyx)
9038 {
9039 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9040 errmsg = e_invarg;
9041 }
9042#endif
9043
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044 /* sync undo before 'undolevels' changes */
9045 else if (pp == &p_ul)
9046 {
9047 /* use the old value, otherwise u_sync() may not work properly */
9048 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009049 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 p_ul = value;
9051 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009052 else if (pp == &curbuf->b_p_ul)
9053 {
9054 /* use the old value, otherwise u_sync() may not work properly */
9055 curbuf->b_p_ul = old_value;
9056 u_sync(TRUE);
9057 curbuf->b_p_ul = value;
9058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009060#ifdef FEAT_LINEBREAK
9061 /* 'numberwidth' must be positive */
9062 else if (pp == &curwin->w_p_nuw)
9063 {
9064 if (curwin->w_p_nuw < 1)
9065 {
9066 errmsg = e_positive;
9067 curwin->w_p_nuw = 1;
9068 }
9069 if (curwin->w_p_nuw > 10)
9070 {
9071 errmsg = e_invarg;
9072 curwin->w_p_nuw = 10;
9073 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009074 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009075 }
9076#endif
9077
Bram Moolenaar1a384422010-07-14 19:53:30 +02009078 else if (pp == &curbuf->b_p_tw)
9079 {
9080 if (curbuf->b_p_tw < 0)
9081 {
9082 errmsg = e_positive;
9083 curbuf->b_p_tw = 0;
9084 }
9085#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009086 {
9087 win_T *wp;
9088 tabpage_T *tp;
9089
9090 FOR_ALL_TAB_WINDOWS(tp, wp)
9091 check_colorcolumn(wp);
9092 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009093#endif
9094 }
9095
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 /*
9097 * Check the bounds for numeric options here
9098 */
9099 if (Rows < min_rows() && full_screen)
9100 {
9101 if (errbuf != NULL)
9102 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009103 vim_snprintf((char *)errbuf, errbuflen,
9104 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 errmsg = errbuf;
9106 }
9107 Rows = min_rows();
9108 }
9109 if (Columns < MIN_COLUMNS && full_screen)
9110 {
9111 if (errbuf != NULL)
9112 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009113 vim_snprintf((char *)errbuf, errbuflen,
9114 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 errmsg = errbuf;
9116 }
9117 Columns = MIN_COLUMNS;
9118 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009119 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 /*
9122 * If the screen (shell) height has been changed, assume it is the
9123 * physical screenheight.
9124 */
9125 if (old_Rows != Rows || old_Columns != Columns)
9126 {
9127 /* Changing the screen size is not allowed while updating the screen. */
9128 if (updating_screen)
9129 *pp = old_value;
9130 else if (full_screen
9131#ifdef FEAT_GUI
9132 && !gui.starting
9133#endif
9134 )
9135 set_shellsize((int)Columns, (int)Rows, TRUE);
9136 else
9137 {
9138 /* Postpone the resizing; check the size and cmdline position for
9139 * messages. */
9140 check_shellsize();
9141 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9142 cmdline_row = Rows - p_ch;
9143 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009144 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009145 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009146 }
9147
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 if (curbuf->b_p_ts <= 0)
9149 {
9150 errmsg = e_positive;
9151 curbuf->b_p_ts = 8;
9152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009153 if (p_tm < 0)
9154 {
9155 errmsg = e_positive;
9156 p_tm = 0;
9157 }
9158 if ((curwin->w_p_scr <= 0
9159 || (curwin->w_p_scr > curwin->w_height
9160 && curwin->w_height > 0))
9161 && full_screen)
9162 {
9163 if (pp == &(curwin->w_p_scr))
9164 {
9165 if (curwin->w_p_scr != 0)
9166 errmsg = e_scroll;
9167 win_comp_scroll(curwin);
9168 }
9169 /* If 'scroll' became invalid because of a side effect silently adjust
9170 * it. */
9171 else if (curwin->w_p_scr <= 0)
9172 curwin->w_p_scr = 1;
9173 else /* curwin->w_p_scr > curwin->w_height */
9174 curwin->w_p_scr = curwin->w_height;
9175 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009176 if (p_hi < 0)
9177 {
9178 errmsg = e_positive;
9179 p_hi = 0;
9180 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009181 else if (p_hi > 10000)
9182 {
9183 errmsg = e_invarg;
9184 p_hi = 10000;
9185 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009186 if (p_re < 0 || p_re > 2)
9187 {
9188 errmsg = e_invarg;
9189 p_re = 0;
9190 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009191 if (p_report < 0)
9192 {
9193 errmsg = e_positive;
9194 p_report = 1;
9195 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009196 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 {
9198 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9199 p_sj = Rows / 2;
9200 else
9201 {
9202 errmsg = e_scroll;
9203 p_sj = 1;
9204 }
9205 }
9206 if (p_so < 0 && full_screen)
9207 {
9208 errmsg = e_scroll;
9209 p_so = 0;
9210 }
9211 if (p_siso < 0 && full_screen)
9212 {
9213 errmsg = e_positive;
9214 p_siso = 0;
9215 }
9216#ifdef FEAT_CMDWIN
9217 if (p_cwh < 1)
9218 {
9219 errmsg = e_positive;
9220 p_cwh = 1;
9221 }
9222#endif
9223 if (p_ut < 0)
9224 {
9225 errmsg = e_positive;
9226 p_ut = 2000;
9227 }
9228 if (p_ss < 0)
9229 {
9230 errmsg = e_positive;
9231 p_ss = 0;
9232 }
9233
9234 /* May set global value for local option. */
9235 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9236 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9237
9238 options[opt_idx].flags |= P_WAS_SET;
9239
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009240#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009241 if (!starting && errmsg == NULL)
9242 {
9243 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009244 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9245 vim_snprintf((char *)buf_new, 10, "%ld", value);
9246 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009247 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9248 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9249 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9250 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9251 reset_v_option_vars();
9252 }
9253#endif
9254
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009256 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009257 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009258 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009259 check_redraw(options[opt_idx].flags);
9260
9261 return errmsg;
9262}
9263
9264/*
9265 * Called after an option changed: check if something needs to be redrawn.
9266 */
9267 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009268check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269{
9270 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009271 int doclear = (flags & P_RCLR) == P_RCLR;
9272 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9275 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009276
9277 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9278 changed_window_setting();
9279 if (flags & P_RBUF)
9280 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009281 if (flags & P_RWINONLY)
9282 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009283 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 redraw_all_later(CLEAR);
9285 else if (all)
9286 redraw_all_later(NOT_VALID);
9287}
9288
9289/*
9290 * Find index for option 'arg'.
9291 * Return -1 if not found.
9292 */
9293 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009294findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295{
9296 int opt_idx;
9297 char *s, *p;
9298 static short quick_tab[27] = {0, 0}; /* quick access table */
9299 int is_term_opt;
9300
9301 /*
9302 * For first call: Initialize the quick-access table.
9303 * It contains the index for the first option that starts with a certain
9304 * letter. There are 26 letters, plus the first "t_" option.
9305 */
9306 if (quick_tab[1] == 0)
9307 {
9308 p = options[0].fullname;
9309 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9310 {
9311 if (s[0] != p[0])
9312 {
9313 if (s[0] == 't' && s[1] == '_')
9314 quick_tab[26] = opt_idx;
9315 else
9316 quick_tab[CharOrdLow(s[0])] = opt_idx;
9317 }
9318 p = s;
9319 }
9320 }
9321
9322 /*
9323 * Check for name starting with an illegal character.
9324 */
9325#ifdef EBCDIC
9326 if (!islower(arg[0]))
9327#else
9328 if (arg[0] < 'a' || arg[0] > 'z')
9329#endif
9330 return -1;
9331
9332 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9333 if (is_term_opt)
9334 opt_idx = quick_tab[26];
9335 else
9336 opt_idx = quick_tab[CharOrdLow(arg[0])];
9337 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9338 {
9339 if (STRCMP(arg, s) == 0) /* match full name */
9340 break;
9341 }
9342 if (s == NULL && !is_term_opt)
9343 {
9344 opt_idx = quick_tab[CharOrdLow(arg[0])];
9345 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9346 {
9347 s = options[opt_idx].shortname;
9348 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9349 break;
9350 s = NULL;
9351 }
9352 }
9353 if (s == NULL)
9354 opt_idx = -1;
9355 return opt_idx;
9356}
9357
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009358#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359/*
9360 * Get the value for an option.
9361 *
9362 * Returns:
9363 * Number or Toggle option: 1, *numval gets value.
9364 * String option: 0, *stringval gets allocated string.
9365 * Hidden Number or Toggle option: -1.
9366 * hidden String option: -2.
9367 * unknown option: -3.
9368 */
9369 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009370get_option_value(
9371 char_u *name,
9372 long *numval,
9373 char_u **stringval, /* NULL when only checking existence */
9374 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375{
9376 int opt_idx;
9377 char_u *varp;
9378
9379 opt_idx = findoption(name);
9380 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009381 {
9382 int key;
9383
9384 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9385 && (key = find_key_option(name)) != 0)
9386 {
9387 char_u key_name[2];
9388 char_u *p;
9389
9390 if (key < 0)
9391 {
9392 key_name[0] = KEY2TERMCAP0(key);
9393 key_name[1] = KEY2TERMCAP1(key);
9394 }
9395 else
9396 {
9397 key_name[0] = KS_KEY;
9398 key_name[1] = (key & 0xff);
9399 }
9400 p = find_termcode(key_name);
9401 if (p != NULL)
9402 {
9403 if (stringval != NULL)
9404 *stringval = vim_strsave(p);
9405 return 0;
9406 }
9407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410
9411 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9412
9413 if (options[opt_idx].flags & P_STRING)
9414 {
9415 if (varp == NULL) /* hidden option */
9416 return -2;
9417 if (stringval != NULL)
9418 {
9419#ifdef FEAT_CRYPT
9420 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009421 if ((char_u **)varp == &curbuf->b_p_key
9422 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 *stringval = vim_strsave((char_u *)"*****");
9424 else
9425#endif
9426 *stringval = vim_strsave(*(char_u **)(varp));
9427 }
9428 return 0;
9429 }
9430
9431 if (varp == NULL) /* hidden option */
9432 return -1;
9433 if (options[opt_idx].flags & P_NUM)
9434 *numval = *(long *)varp;
9435 else
9436 {
9437 /* Special case: 'modified' is b_changed, but we also want to consider
9438 * it set when 'ff' or 'fenc' changed. */
9439 if ((int *)varp == &curbuf->b_changed)
9440 *numval = curbufIsChanged();
9441 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009442 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 }
9444 return 1;
9445}
9446#endif
9447
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009448#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009449/*
9450 * Returns the option attributes and its value. Unlike the above function it
9451 * will return either global value or local value of the option depending on
9452 * what was requested, but it will never return global value if it was
9453 * requested to return local one and vice versa. Neither it will return
9454 * buffer-local value if it was requested to return window-local one.
9455 *
9456 * Pretends that option is absent if it is not present in the requested scope
9457 * (i.e. has no global, window-local or buffer-local value depending on
9458 * opt_type). Uses
9459 *
9460 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009461 * 0 hidden or unknown option, also option that does not have requested
9462 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009463 * see SOPT_* in vim.h for other flags
9464 *
9465 * Possible opt_type values: see SREQ_* in vim.h
9466 */
9467 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009468get_option_value_strict(
9469 char_u *name,
9470 long *numval,
9471 char_u **stringval, /* NULL when only obtaining attributes */
9472 int opt_type,
9473 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009474{
9475 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009476 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009477 struct vimoption *p;
9478 int r = 0;
9479
9480 opt_idx = findoption(name);
9481 if (opt_idx < 0)
9482 return 0;
9483
9484 p = &(options[opt_idx]);
9485
9486 /* Hidden option */
9487 if (p->var == NULL)
9488 return 0;
9489
9490 if (p->flags & P_BOOL)
9491 r |= SOPT_BOOL;
9492 else if (p->flags & P_NUM)
9493 r |= SOPT_NUM;
9494 else if (p->flags & P_STRING)
9495 r |= SOPT_STRING;
9496
9497 if (p->indir == PV_NONE)
9498 {
9499 if (opt_type == SREQ_GLOBAL)
9500 r |= SOPT_GLOBAL;
9501 else
9502 return 0; /* Did not request global-only option */
9503 }
9504 else
9505 {
9506 if (p->indir & PV_BOTH)
9507 r |= SOPT_GLOBAL;
9508 else if (opt_type == SREQ_GLOBAL)
9509 return 0; /* Requested global option */
9510
9511 if (p->indir & PV_WIN)
9512 {
9513 if (opt_type == SREQ_BUF)
9514 return 0; /* Did not request window-local option */
9515 else
9516 r |= SOPT_WIN;
9517 }
9518 else if (p->indir & PV_BUF)
9519 {
9520 if (opt_type == SREQ_WIN)
9521 return 0; /* Did not request buffer-local option */
9522 else
9523 r |= SOPT_BUF;
9524 }
9525 }
9526
9527 if (stringval == NULL)
9528 return r;
9529
9530 if (opt_type == SREQ_GLOBAL)
9531 varp = p->var;
9532 else
9533 {
9534 if (opt_type == SREQ_BUF)
9535 {
9536 /* Special case: 'modified' is b_changed, but we also want to
9537 * consider it set when 'ff' or 'fenc' changed. */
9538 if (p->indir == PV_MOD)
9539 {
9540 *numval = bufIsChanged((buf_T *) from);
9541 varp = NULL;
9542 }
9543#ifdef FEAT_CRYPT
9544 else if (p->indir == PV_KEY)
9545 {
9546 /* never return the value of the crypt key */
9547 *stringval = NULL;
9548 varp = NULL;
9549 }
9550#endif
9551 else
9552 {
9553 aco_save_T aco;
9554 aucmd_prepbuf(&aco, (buf_T *) from);
9555 varp = get_varp(p);
9556 aucmd_restbuf(&aco);
9557 }
9558 }
9559 else if (opt_type == SREQ_WIN)
9560 {
9561 win_T *save_curwin;
9562 save_curwin = curwin;
9563 curwin = (win_T *) from;
9564 curbuf = curwin->w_buffer;
9565 varp = get_varp(p);
9566 curwin = save_curwin;
9567 curbuf = curwin->w_buffer;
9568 }
9569 if (varp == p->var)
9570 return (r | SOPT_UNSET);
9571 }
9572
9573 if (varp != NULL)
9574 {
9575 if (p->flags & P_STRING)
9576 *stringval = vim_strsave(*(char_u **)(varp));
9577 else if (p->flags & P_NUM)
9578 *numval = *(long *) varp;
9579 else
9580 *numval = *(int *)varp;
9581 }
9582
9583 return r;
9584}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009585
9586/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009587 * Iterate over options. First argument is a pointer to a pointer to a
9588 * structure inside options[] array, second is option type like in the above
9589 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009590 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009591 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009592 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009593 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009594 * first argument to NULL.
9595 *
9596 * Returns full option name for current option on each call.
9597 */
9598 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009599option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009600{
9601 struct vimoption *ret = NULL;
9602 do
9603 {
9604 if (*option == NULL)
9605 *option = (void *) options;
9606 else if (((struct vimoption *) (*option))->fullname == NULL)
9607 {
9608 *option = NULL;
9609 return NULL;
9610 }
9611 else
9612 *option = (void *) (((struct vimoption *) (*option)) + 1);
9613
9614 ret = ((struct vimoption *) (*option));
9615
9616 /* Hidden option */
9617 if (ret->var == NULL)
9618 {
9619 ret = NULL;
9620 continue;
9621 }
9622
9623 switch (opt_type)
9624 {
9625 case SREQ_GLOBAL:
9626 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9627 ret = NULL;
9628 break;
9629 case SREQ_BUF:
9630 if (!(ret->indir & PV_BUF))
9631 ret = NULL;
9632 break;
9633 case SREQ_WIN:
9634 if (!(ret->indir & PV_WIN))
9635 ret = NULL;
9636 break;
9637 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009638 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009639 return NULL;
9640 }
9641 }
9642 while (ret == NULL);
9643
9644 return (char_u *)ret->fullname;
9645}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009646#endif
9647
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648/*
9649 * Set the value of option "name".
9650 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009651 *
9652 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009654 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009655set_option_value(
9656 char_u *name,
9657 long number,
9658 char_u *string,
9659 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660{
9661 int opt_idx;
9662 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009663 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664
9665 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009666 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009667 {
9668 int key;
9669
9670 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9671 && (key = find_key_option(name)) != 0)
9672 {
9673 char_u key_name[2];
9674
9675 if (key < 0)
9676 {
9677 key_name[0] = KEY2TERMCAP0(key);
9678 key_name[1] = KEY2TERMCAP1(key);
9679 }
9680 else
9681 {
9682 key_name[0] = KS_KEY;
9683 key_name[1] = (key & 0xff);
9684 }
9685 add_termcode(key_name, string, FALSE);
9686 if (full_screen)
9687 ttest(FALSE);
9688 redraw_all_later(CLEAR);
9689 return NULL;
9690 }
9691
Bram Moolenaar071d4272004-06-13 20:20:40 +00009692 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 else
9695 {
9696 flags = options[opt_idx].flags;
9697#ifdef HAVE_SANDBOX
9698 /* Disallow changing some options in the sandbox */
9699 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009700 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009702 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009705 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009706 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707 else
9708 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009709 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710 if (varp != NULL) /* hidden option is not changed */
9711 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009712 if (number == 0 && string != NULL)
9713 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009714 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009715
9716 /* Either we are given a string or we are setting option
9717 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009718 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009719 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009720 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009721 {
9722 /* There's another character after zeros or the string
9723 * is empty. In both cases, we are trying to set a
9724 * num option using a string. */
9725 EMSG3(_("E521: Number required: &%s = '%s'"),
9726 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009727 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009728
9729 }
9730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009732 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009733 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009735 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009736 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 }
9738 }
9739 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009740 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741}
9742
9743/*
9744 * Get the terminal code for a terminal option.
9745 * Returns NULL when not found.
9746 */
9747 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009748get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749{
9750 int opt_idx;
9751 char_u *varp;
9752
9753 if (tname[0] != 't' || tname[1] != '_' ||
9754 tname[2] == NUL || tname[3] == NUL)
9755 return NULL;
9756 if ((opt_idx = findoption(tname)) >= 0)
9757 {
9758 varp = get_varp(&(options[opt_idx]));
9759 if (varp != NULL)
9760 varp = *(char_u **)(varp);
9761 return varp;
9762 }
9763 return find_termcode(tname + 2);
9764}
9765
9766 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009767get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768{
9769 int i;
9770
9771 i = findoption((char_u *)"hl");
9772 if (i >= 0)
9773 return options[i].def_val[VI_DEFAULT];
9774 return (char_u *)NULL;
9775}
9776
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009777#if defined(FEAT_MBYTE) || defined(PROTO)
9778 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009779get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009780{
9781 int i;
9782
9783 i = findoption((char_u *)"enc");
9784 if (i >= 0)
9785 return options[i].def_val[VI_DEFAULT];
9786 return (char_u *)NULL;
9787}
9788#endif
9789
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790/*
9791 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9792 */
9793 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009794find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795{
9796 int key;
9797 int modifiers;
9798
9799 /*
9800 * Don't use get_special_key_code() for t_xx, we don't want it to call
9801 * add_termcap_entry().
9802 */
9803 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9804 key = TERMCAP2KEY(arg[2], arg[3]);
9805 else
9806 {
9807 --arg; /* put arg at the '<' */
9808 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009809 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 if (modifiers) /* can't handle modifiers here */
9811 key = 0;
9812 }
9813 return key;
9814}
9815
9816/*
9817 * if 'all' == 0: show changed options
9818 * if 'all' == 1: show all normal options
9819 * if 'all' == 2: show all terminal options
9820 */
9821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009822showoptions(
9823 int all,
9824 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009825{
9826 struct vimoption *p;
9827 int col;
9828 int isterm;
9829 char_u *varp;
9830 struct vimoption **items;
9831 int item_count;
9832 int run;
9833 int row, rows;
9834 int cols;
9835 int i;
9836 int len;
9837
9838#define INC 20
9839#define GAP 3
9840
9841 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9842 PARAM_COUNT));
9843 if (items == NULL)
9844 return;
9845
9846 /* Highlight title */
9847 if (all == 2)
9848 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9849 else if (opt_flags & OPT_GLOBAL)
9850 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9851 else if (opt_flags & OPT_LOCAL)
9852 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9853 else
9854 MSG_PUTS_TITLE(_("\n--- Options ---"));
9855
9856 /*
9857 * do the loop two times:
9858 * 1. display the short items
9859 * 2. display the long items (only strings and numbers)
9860 */
9861 for (run = 1; run <= 2 && !got_int; ++run)
9862 {
9863 /*
9864 * collect the items in items[]
9865 */
9866 item_count = 0;
9867 for (p = &options[0]; p->fullname != NULL; p++)
9868 {
9869 varp = NULL;
9870 isterm = istermoption(p);
9871 if (opt_flags != 0)
9872 {
9873 if (p->indir != PV_NONE && !isterm)
9874 varp = get_varp_scope(p, opt_flags);
9875 }
9876 else
9877 varp = get_varp(p);
9878 if (varp != NULL
9879 && ((all == 2 && isterm)
9880 || (all == 1 && !isterm)
9881 || (all == 0 && !optval_default(p, varp))))
9882 {
9883 if (p->flags & P_BOOL)
9884 len = 1; /* a toggle option fits always */
9885 else
9886 {
9887 option_value2string(p, opt_flags);
9888 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9889 }
9890 if ((len <= INC - GAP && run == 1) ||
9891 (len > INC - GAP && run == 2))
9892 items[item_count++] = p;
9893 }
9894 }
9895
9896 /*
9897 * display the items
9898 */
9899 if (run == 1)
9900 {
9901 cols = (Columns + GAP - 3) / INC;
9902 if (cols == 0)
9903 cols = 1;
9904 rows = (item_count + cols - 1) / cols;
9905 }
9906 else /* run == 2 */
9907 rows = item_count;
9908 for (row = 0; row < rows && !got_int; ++row)
9909 {
9910 msg_putchar('\n'); /* go to next line */
9911 if (got_int) /* 'q' typed in more */
9912 break;
9913 col = 0;
9914 for (i = row; i < item_count; i += rows)
9915 {
9916 msg_col = col; /* make columns */
9917 showoneopt(items[i], opt_flags);
9918 col += INC;
9919 }
9920 out_flush();
9921 ui_breakcheck();
9922 }
9923 }
9924 vim_free(items);
9925}
9926
9927/*
9928 * Return TRUE if option "p" has its default value.
9929 */
9930 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009931optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932{
9933 int dvi;
9934
9935 if (varp == NULL)
9936 return TRUE; /* hidden option is always at default */
9937 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9938 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009939 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009941 /* the cast to long is required for Manx C, long_i is
9942 * needed for MSVC */
9943 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944 /* P_STRING */
9945 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9946}
9947
9948/*
9949 * showoneopt: show the value of one option
9950 * must not be called with a hidden option!
9951 */
9952 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953showoneopt(
9954 struct vimoption *p,
9955 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009957 char_u *varp;
9958 int save_silent = silent_mode;
9959
9960 silent_mode = FALSE;
9961 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962
9963 varp = get_varp_scope(p, opt_flags);
9964
9965 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9966 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9967 ? !curbufIsChanged() : !*(int *)varp))
9968 MSG_PUTS("no");
9969 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9970 MSG_PUTS("--");
9971 else
9972 MSG_PUTS(" ");
9973 MSG_PUTS(p->fullname);
9974 if (!(p->flags & P_BOOL))
9975 {
9976 msg_putchar('=');
9977 /* put value string in NameBuff */
9978 option_value2string(p, opt_flags);
9979 msg_outtrans(NameBuff);
9980 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009981
9982 silent_mode = save_silent;
9983 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984}
9985
9986/*
9987 * Write modified options as ":set" commands to a file.
9988 *
9989 * There are three values for "opt_flags":
9990 * OPT_GLOBAL: Write global option values and fresh values of
9991 * buffer-local options (used for start of a session
9992 * file).
9993 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9994 * curwin (used for a vimrc file).
9995 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9996 * and local values for window-local options of
9997 * curwin. Local values are also written when at the
9998 * default value, because a modeline or autocommand
9999 * may have set them when doing ":edit file" and the
10000 * user has set them back at the default or fresh
10001 * value.
10002 * When "local_only" is TRUE, don't write fresh
10003 * values, only local values (for ":mkview").
10004 * (fresh value = value used for a new buffer or window for a local option).
10005 *
10006 * Return FAIL on error, OK otherwise.
10007 */
10008 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010009makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010{
10011 struct vimoption *p;
10012 char_u *varp; /* currently used value */
10013 char_u *varp_fresh; /* local value */
10014 char_u *varp_local = NULL; /* fresh value */
10015 char *cmd;
10016 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010017 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018
10019 /*
10020 * The options that don't have a default (terminal name, columns, lines)
10021 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010022 * Do the loop over "options[]" twice: once for options with the
10023 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010025 for (pri = 1; pri >= 0; --pri)
10026 {
10027 for (p = &options[0]; !istermoption(p); p++)
10028 if (!(p->flags & P_NO_MKRC)
10029 && !istermoption(p)
10030 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031 {
10032 /* skip global option when only doing locals */
10033 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10034 continue;
10035
10036 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10037 * file, they are always buffer-specific. */
10038 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10039 continue;
10040
10041 /* Global values are only written when not at the default value. */
10042 varp = get_varp_scope(p, opt_flags);
10043 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10044 continue;
10045
10046 round = 2;
10047 if (p->indir != PV_NONE)
10048 {
10049 if (p->var == VAR_WIN)
10050 {
10051 /* skip window-local option when only doing globals */
10052 if (!(opt_flags & OPT_LOCAL))
10053 continue;
10054 /* When fresh value of window-local option is not at the
10055 * default, need to write it too. */
10056 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10057 {
10058 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10059 if (!optval_default(p, varp_fresh))
10060 {
10061 round = 1;
10062 varp_local = varp;
10063 varp = varp_fresh;
10064 }
10065 }
10066 }
10067 }
10068
10069 /* Round 1: fresh value for window-local options.
10070 * Round 2: other values */
10071 for ( ; round <= 2; varp = varp_local, ++round)
10072 {
10073 if (round == 1 || (opt_flags & OPT_GLOBAL))
10074 cmd = "set";
10075 else
10076 cmd = "setlocal";
10077
10078 if (p->flags & P_BOOL)
10079 {
10080 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10081 return FAIL;
10082 }
10083 else if (p->flags & P_NUM)
10084 {
10085 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10086 return FAIL;
10087 }
10088 else /* P_STRING */
10089 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010090 int do_endif = FALSE;
10091
Bram Moolenaar071d4272004-06-13 20:20:40 +000010092 /* Don't set 'syntax' and 'filetype' again if the value is
10093 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010094 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010095#if defined(FEAT_SYN_HL)
10096 p->indir == PV_SYN ||
10097#endif
10098 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099 {
10100 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10101 *(char_u **)(varp)) < 0
10102 || put_eol(fd) < 0)
10103 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010104 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105 }
10106 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10107 (p->flags & P_EXPAND) != 0) == FAIL)
10108 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010109 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010110 {
10111 if (put_line(fd, "endif") == FAIL)
10112 return FAIL;
10113 }
10114 }
10115 }
10116 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 return OK;
10119}
10120
10121#if defined(FEAT_FOLDING) || defined(PROTO)
10122/*
10123 * Generate set commands for the local fold options only. Used when
10124 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10125 */
10126 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010127makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128{
10129 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10130# ifdef FEAT_EVAL
10131 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10132 == FAIL
10133# endif
10134 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10135 == FAIL
10136 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10137 == FAIL
10138 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10139 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10140 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10141 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10142 )
10143 return FAIL;
10144
10145 return OK;
10146}
10147#endif
10148
10149 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010150put_setstring(
10151 FILE *fd,
10152 char *cmd,
10153 char *name,
10154 char_u **valuep,
10155 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156{
10157 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010158 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159
10160 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10161 return FAIL;
10162 if (*valuep != NULL)
10163 {
10164 /* Output 'pastetoggle' as key names. For other
10165 * options some characters have to be escaped with
10166 * CTRL-V or backslash */
10167 if (valuep == &p_pt)
10168 {
10169 s = *valuep;
10170 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010171 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 return FAIL;
10173 }
10174 else if (expand)
10175 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010176 buf = alloc(MAXPATHL);
10177 if (buf == NULL)
10178 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10180 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010181 {
10182 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010184 }
10185 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 }
10187 else if (put_escstr(fd, *valuep, 2) == FAIL)
10188 return FAIL;
10189 }
10190 if (put_eol(fd) < 0)
10191 return FAIL;
10192 return OK;
10193}
10194
10195 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010196put_setnum(
10197 FILE *fd,
10198 char *cmd,
10199 char *name,
10200 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201{
10202 long wc;
10203
10204 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10205 return FAIL;
10206 if (wc_use_keyname((char_u *)valuep, &wc))
10207 {
10208 /* print 'wildchar' and 'wildcharm' as a key name */
10209 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10210 return FAIL;
10211 }
10212 else if (fprintf(fd, "%ld", *valuep) < 0)
10213 return FAIL;
10214 if (put_eol(fd) < 0)
10215 return FAIL;
10216 return OK;
10217}
10218
10219 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010220put_setbool(
10221 FILE *fd,
10222 char *cmd,
10223 char *name,
10224 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225{
Bram Moolenaar893de922007-10-02 18:40:57 +000010226 if (value < 0) /* global/local option using global value */
10227 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10229 || put_eol(fd) < 0)
10230 return FAIL;
10231 return OK;
10232}
10233
10234/*
10235 * Clear all the terminal options.
10236 * If the option has been allocated, free the memory.
10237 * Terminal options are never hidden or indirect.
10238 */
10239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010240clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 /*
10243 * Reset a few things before clearing the old options. This may cause
10244 * outputting a few things that the terminal doesn't understand, but the
10245 * screen will be cleared later, so this is OK.
10246 */
10247#ifdef FEAT_MOUSE_TTY
10248 mch_setmouse(FALSE); /* switch mouse off */
10249#endif
10250#ifdef FEAT_TITLE
10251 mch_restore_title(3); /* restore window titles */
10252#endif
10253#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10254 /* When starting the GUI close the display opened for the clipboard.
10255 * After restoring the title, because that will need the display. */
10256 if (gui.starting)
10257 clear_xterm_clip();
10258#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010259 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010261 free_termoptions();
10262}
10263
10264 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010265free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010266{
10267 struct vimoption *p;
10268
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 for (p = &options[0]; p->fullname != NULL; p++)
10270 if (istermoption(p))
10271 {
10272 if (p->flags & P_ALLOCED)
10273 free_string_option(*(char_u **)(p->var));
10274 if (p->flags & P_DEF_ALLOCED)
10275 free_string_option(p->def_val[VI_DEFAULT]);
10276 *(char_u **)(p->var) = empty_option;
10277 p->def_val[VI_DEFAULT] = empty_option;
10278 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10279 }
10280 clear_termcodes();
10281}
10282
10283/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010284 * Free the string for one term option, if it was allocated.
10285 * Set the string to empty_option and clear allocated flag.
10286 * "var" points to the option value.
10287 */
10288 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010289free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010290{
10291 struct vimoption *p;
10292
10293 for (p = &options[0]; p->fullname != NULL; p++)
10294 if (p->var == var)
10295 {
10296 if (p->flags & P_ALLOCED)
10297 free_string_option(*(char_u **)(p->var));
10298 *(char_u **)(p->var) = empty_option;
10299 p->flags &= ~P_ALLOCED;
10300 break;
10301 }
10302}
10303
10304/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305 * Set the terminal option defaults to the current value.
10306 * Used after setting the terminal name.
10307 */
10308 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010309set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310{
10311 struct vimoption *p;
10312
10313 for (p = &options[0]; p->fullname != NULL; p++)
10314 {
10315 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10316 {
10317 if (p->flags & P_DEF_ALLOCED)
10318 {
10319 free_string_option(p->def_val[VI_DEFAULT]);
10320 p->flags &= ~P_DEF_ALLOCED;
10321 }
10322 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10323 if (p->flags & P_ALLOCED)
10324 {
10325 p->flags |= P_DEF_ALLOCED;
10326 p->flags &= ~P_ALLOCED; /* don't free the value now */
10327 }
10328 }
10329 }
10330}
10331
10332/*
10333 * return TRUE if 'p' starts with 't_'
10334 */
10335 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010336istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337{
10338 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10339}
10340
10341/*
10342 * Compute columns for ruler and shown command. 'sc_col' is also used to
10343 * decide what the maximum length of a message on the status line can be.
10344 * If there is a status line for the last window, 'sc_col' is independent
10345 * of 'ru_col'.
10346 */
10347
10348#define COL_RULER 17 /* columns needed by standard ruler */
10349
10350 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010351comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010353#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010354 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355
10356 sc_col = 0;
10357 ru_col = 0;
10358 if (p_ru)
10359 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010360# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010362# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010364# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 /* no last status line, adjust sc_col */
10366 if (!last_has_status)
10367 sc_col = ru_col;
10368 }
10369 if (p_sc)
10370 {
10371 sc_col += SHOWCMD_COLS;
10372 if (!p_ru || last_has_status) /* no need for separating space */
10373 ++sc_col;
10374 }
10375 sc_col = Columns - sc_col;
10376 ru_col = Columns - ru_col;
10377 if (sc_col <= 0) /* screen too narrow, will become a mess */
10378 sc_col = 1;
10379 if (ru_col <= 0)
10380 ru_col = 1;
10381#else
10382 sc_col = Columns;
10383 ru_col = Columns;
10384#endif
10385}
10386
10387/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010388 * Unset local option value, similar to ":set opt<".
10389 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010390 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010391unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010392{
10393 struct vimoption *p;
10394 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010395 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010396
10397 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010398 if (opt_idx < 0)
10399 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 p = &(options[opt_idx]);
10401
10402 switch ((int)p->indir)
10403 {
10404 /* global option with local value: use local value if it's been set */
10405 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010406 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407 break;
10408 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010409 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 break;
10411 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010412 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 break;
10414 case PV_AR:
10415 buf->b_p_ar = -1;
10416 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010417 case PV_BKC:
10418 clear_string_option(&buf->b_p_bkc);
10419 buf->b_bkc_flags = 0;
10420 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010424 case PV_TC:
10425 clear_string_option(&buf->b_p_tc);
10426 buf->b_tc_flags = 0;
10427 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428#ifdef FEAT_FIND_ID
10429 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435#endif
10436#ifdef FEAT_INS_EXPAND
10437 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010438 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439 break;
10440 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010441 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 break;
10443#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010444 case PV_FP:
10445 clear_string_option(&buf->b_p_fp);
10446 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010447#ifdef FEAT_QUICKFIX
10448 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010449 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010450 break;
10451 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010455 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456 break;
10457#endif
10458#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10459 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010460 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010461 break;
10462#endif
10463#if defined(FEAT_CRYPT)
10464 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 break;
10467#endif
10468#ifdef FEAT_STL_OPT
10469 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010473 case PV_UL:
10474 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10475 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010476#ifdef FEAT_LISP
10477 case PV_LW:
10478 clear_string_option(&buf->b_p_lw);
10479 break;
10480#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010481#ifdef FEAT_MBYTE
10482 case PV_MENC:
10483 clear_string_option(&buf->b_p_menc);
10484 break;
10485#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010486 }
10487}
10488
10489/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 * Get pointer to option variable, depending on local or global scope.
10491 */
10492 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010493get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494{
10495 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10496 {
10497 if (p->var == VAR_WIN)
10498 return (char_u *)GLOBAL_WO(get_varp(p));
10499 return p->var;
10500 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010501 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 {
10503 switch ((int)p->indir)
10504 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010505 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010507 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10508 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10509 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010511 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10512 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10513 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010514 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010515 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010516 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010518 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10519 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520#endif
10521#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010522 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10523 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010525#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10526 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10527#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010528#if defined(FEAT_CRYPT)
10529 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10530#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010531#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010532 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010533#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010534 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010535#ifdef FEAT_LISP
10536 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10537#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010538 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010539#ifdef FEAT_MBYTE
10540 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 }
10543 return NULL; /* "cannot happen" */
10544 }
10545 return get_varp(p);
10546}
10547
10548/*
10549 * Get pointer to option variable.
10550 */
10551 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010552get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553{
10554 /* hidden option, always return NULL */
10555 if (p->var == NULL)
10556 return NULL;
10557
10558 switch ((int)p->indir)
10559 {
10560 case PV_NONE: return p->var;
10561
10562 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010565 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010569 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010571 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010573 case PV_TC: return *curbuf->b_p_tc != NUL
10574 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010575 case PV_BKC: return *curbuf->b_p_bkc != NUL
10576 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010580 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10582#endif
10583#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010586 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10588#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010589 case PV_FP: return *curbuf->b_p_fp != NUL
10590 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010592 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010594 case PV_GP: return *curbuf->b_p_gp != NUL
10595 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10596 case PV_MP: return *curbuf->b_p_mp != NUL
10597 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010599#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10600 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10601 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10602#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010603#if defined(FEAT_CRYPT)
10604 case PV_CM: return *curbuf->b_p_cm != NUL
10605 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10606#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010607#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010608 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010609 ? (char_u *)&(curwin->w_p_stl) : p->var;
10610#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010611 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10612 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010613#ifdef FEAT_LISP
10614 case PV_LW: return *curbuf->b_p_lw != NUL
10615 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10616#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010617#ifdef FEAT_MBYTE
10618 case PV_MENC: return *curbuf->b_p_menc != NUL
10619 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621
10622#ifdef FEAT_ARABIC
10623 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10624#endif
10625 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010626#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010627 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10628#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010629#ifdef FEAT_SYN_HL
10630 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10631 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010632 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010633#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634#ifdef FEAT_DIFF
10635 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10636#endif
10637#ifdef FEAT_FOLDING
10638 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10639 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10640 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10641 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10642 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10643 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10644 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10645# ifdef FEAT_EVAL
10646 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10647 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10648# endif
10649 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10650#endif
10651 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010652 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010653#ifdef FEAT_LINEBREAK
10654 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010657 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010658#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10660#endif
10661#ifdef FEAT_RIGHTLEFT
10662 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10663 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10664#endif
10665 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10666 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10667#ifdef FEAT_LINEBREAK
10668 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010669 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10670 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010672 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010673 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010674#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010675 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10676 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10677#endif
10678#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010679 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010680 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682
10683 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10684 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10685#ifdef FEAT_MBYTE
10686 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10687#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10689 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10691 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10692#ifdef FEAT_CINDENT
10693 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10694 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10695 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10696#endif
10697#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10698 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10699#endif
10700#ifdef FEAT_COMMENTS
10701 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10702#endif
10703#ifdef FEAT_FOLDING
10704 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10705#endif
10706#ifdef FEAT_INS_EXPAND
10707 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10708#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010709#ifdef FEAT_COMPL_FUNC
10710 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010711 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010714 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10716#ifdef FEAT_MBYTE
10717 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10718#endif
10719 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010722 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10724 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10725 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10726 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10727#ifdef FEAT_FIND_ID
10728# ifdef FEAT_EVAL
10729 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10730# endif
10731#endif
10732#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10733 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10734 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10735#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010736#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010737 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739#ifdef FEAT_CRYPT
10740 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10741#endif
10742#ifdef FEAT_LISP
10743 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10744#endif
10745 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10746 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10747 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10748 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10749 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010751#ifdef FEAT_TEXTOBJ
10752 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10755#ifdef FEAT_SMARTINDENT
10756 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010758 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10760#ifdef FEAT_SEARCHPATH
10761 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10762#endif
10763 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10764#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010765 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010766 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10767#endif
10768#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010769 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10770 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10771 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#endif
10773 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10774 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10775 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10776 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010777#ifdef FEAT_PERSISTENT_UNDO
10778 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10781#ifdef FEAT_KEYMAP
10782 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10783#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010784#ifdef FEAT_SIGNS
10785 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10786#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010787 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 }
10789 /* always return a valid pointer to avoid a crash! */
10790 return (char_u *)&(curbuf->b_p_wm);
10791}
10792
10793/*
10794 * Get the value of 'equalprg', either the buffer-local one or the global one.
10795 */
10796 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010797get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798{
10799 if (*curbuf->b_p_ep == NUL)
10800 return p_ep;
10801 return curbuf->b_p_ep;
10802}
10803
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804/*
10805 * Copy options from one window to another.
10806 * Used when splitting a window.
10807 */
10808 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010809win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810{
10811 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10812 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10813# ifdef FEAT_RIGHTLEFT
10814# ifdef FEAT_FKMAP
10815 /* Is this right? */
10816 wp_to->w_farsi = wp_from->w_farsi;
10817# endif
10818# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010819#if defined(FEAT_LINEBREAK)
10820 briopt_check(wp_to);
10821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823
10824/*
10825 * Copy the options from one winopt_T to another.
10826 * Doesn't free the old option values in "to", use clear_winopt() for that.
10827 * The 'scroll' option is not copied, because it depends on the window height.
10828 * The 'previewwindow' option is reset, there can be only one preview window.
10829 */
10830 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010831copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832{
10833#ifdef FEAT_ARABIC
10834 to->wo_arab = from->wo_arab;
10835#endif
10836 to->wo_list = from->wo_list;
10837 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010838 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010839#ifdef FEAT_LINEBREAK
10840 to->wo_nuw = from->wo_nuw;
10841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842#ifdef FEAT_RIGHTLEFT
10843 to->wo_rl = from->wo_rl;
10844 to->wo_rlc = vim_strsave(from->wo_rlc);
10845#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010846#ifdef FEAT_STL_OPT
10847 to->wo_stl = vim_strsave(from->wo_stl);
10848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010850#ifdef FEAT_DIFF
10851 to->wo_wrap_save = from->wo_wrap_save;
10852#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#ifdef FEAT_LINEBREAK
10854 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010855 to->wo_bri = from->wo_bri;
10856 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010859 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010860 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010861 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010862#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010863 to->wo_spell = from->wo_spell;
10864#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010865#ifdef FEAT_SYN_HL
10866 to->wo_cuc = from->wo_cuc;
10867 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010868 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870#ifdef FEAT_DIFF
10871 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010872 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010874#ifdef FEAT_CONCEAL
10875 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010876 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010877#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010878#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010879 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010880 to->wo_tms = vim_strsave(from->wo_tms);
10881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882#ifdef FEAT_FOLDING
10883 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010884 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010885 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010886 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 to->wo_fdi = vim_strsave(from->wo_fdi);
10888 to->wo_fml = from->wo_fml;
10889 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010890 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010892 to->wo_fdm_save = from->wo_diff_saved
10893 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894 to->wo_fdn = from->wo_fdn;
10895# ifdef FEAT_EVAL
10896 to->wo_fde = vim_strsave(from->wo_fde);
10897 to->wo_fdt = vim_strsave(from->wo_fdt);
10898# endif
10899 to->wo_fmr = vim_strsave(from->wo_fmr);
10900#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010901#ifdef FEAT_SIGNS
10902 to->wo_scl = vim_strsave(from->wo_scl);
10903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904 check_winopt(to); /* don't want NULL pointers */
10905}
10906
10907/*
10908 * Check string options in a window for a NULL value.
10909 */
10910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010911check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912{
10913 check_winopt(&win->w_onebuf_opt);
10914 check_winopt(&win->w_allbuf_opt);
10915}
10916
10917/*
10918 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10919 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010920 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010921check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922{
10923#ifdef FEAT_FOLDING
10924 check_string_option(&wop->wo_fdi);
10925 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010926 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927# ifdef FEAT_EVAL
10928 check_string_option(&wop->wo_fde);
10929 check_string_option(&wop->wo_fdt);
10930# endif
10931 check_string_option(&wop->wo_fmr);
10932#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010933#ifdef FEAT_SIGNS
10934 check_string_option(&wop->wo_scl);
10935#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936#ifdef FEAT_RIGHTLEFT
10937 check_string_option(&wop->wo_rlc);
10938#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010939#ifdef FEAT_STL_OPT
10940 check_string_option(&wop->wo_stl);
10941#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010942#ifdef FEAT_SYN_HL
10943 check_string_option(&wop->wo_cc);
10944#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010945#ifdef FEAT_CONCEAL
10946 check_string_option(&wop->wo_cocu);
10947#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010948#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010949 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010950 check_string_option(&wop->wo_tms);
10951#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010952#ifdef FEAT_LINEBREAK
10953 check_string_option(&wop->wo_briopt);
10954#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955}
10956
10957/*
10958 * Free the allocated memory inside a winopt_T.
10959 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010961clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962{
10963#ifdef FEAT_FOLDING
10964 clear_string_option(&wop->wo_fdi);
10965 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010966 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967# ifdef FEAT_EVAL
10968 clear_string_option(&wop->wo_fde);
10969 clear_string_option(&wop->wo_fdt);
10970# endif
10971 clear_string_option(&wop->wo_fmr);
10972#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010973#ifdef FEAT_SIGNS
10974 clear_string_option(&wop->wo_scl);
10975#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010976#ifdef FEAT_LINEBREAK
10977 clear_string_option(&wop->wo_briopt);
10978#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979#ifdef FEAT_RIGHTLEFT
10980 clear_string_option(&wop->wo_rlc);
10981#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010982#ifdef FEAT_STL_OPT
10983 clear_string_option(&wop->wo_stl);
10984#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010985#ifdef FEAT_SYN_HL
10986 clear_string_option(&wop->wo_cc);
10987#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010988#ifdef FEAT_CONCEAL
10989 clear_string_option(&wop->wo_cocu);
10990#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010991#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010992 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010993 clear_string_option(&wop->wo_tms);
10994#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010995}
10996
10997/*
10998 * Copy global option values to local options for one buffer.
10999 * Used when creating a new buffer and sometimes when entering a buffer.
11000 * flags:
11001 * BCO_ENTER We will enter the buf buffer.
11002 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11003 * appropriate.
11004 * BCO_NOHELP Don't copy the values to a help buffer.
11005 */
11006 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011007buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008{
11009 int should_copy = TRUE;
11010 char_u *save_p_isk = NULL; /* init for GCC */
11011 int dont_do_help;
11012 int did_isk = FALSE;
11013
11014 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015 * Skip this when the option defaults have not been set yet. Happens when
11016 * main() allocates the first buffer.
11017 */
11018 if (p_cpo != NULL)
11019 {
11020 /*
11021 * Always copy when entering and 'cpo' contains 'S'.
11022 * Don't copy when already initialized.
11023 * Don't copy when 'cpo' contains 's' and not entering.
11024 * 'S' BCO_ENTER initialized 's' should_copy
11025 * yes yes X X TRUE
11026 * yes no yes X FALSE
11027 * no X yes X FALSE
11028 * X no no yes FALSE
11029 * X no no no TRUE
11030 * no yes no X TRUE
11031 */
11032 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11033 && (buf->b_p_initialized
11034 || (!(flags & BCO_ENTER)
11035 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11036 should_copy = FALSE;
11037
11038 if (should_copy || (flags & BCO_ALWAYS))
11039 {
11040 /* Don't copy the options specific to a help buffer when
11041 * BCO_NOHELP is given or the options were initialized already
11042 * (jumping back to a help file with CTRL-T or CTRL-O) */
11043 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11044 || buf->b_p_initialized;
11045 if (dont_do_help) /* don't free b_p_isk */
11046 {
11047 save_p_isk = buf->b_p_isk;
11048 buf->b_p_isk = NULL;
11049 }
11050 /*
11051 * Always free the allocated strings.
11052 * If not already initialized, set 'readonly' and copy 'fileformat'.
11053 */
11054 if (!buf->b_p_initialized)
11055 {
11056 free_buf_options(buf, TRUE);
11057 buf->b_p_ro = FALSE; /* don't copy readonly */
11058 buf->b_p_tx = p_tx;
11059#ifdef FEAT_MBYTE
11060 buf->b_p_fenc = vim_strsave(p_fenc);
11061#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011062 switch (*p_ffs)
11063 {
11064 case 'm':
11065 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11066 case 'd':
11067 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11068 case 'u':
11069 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11070 default:
11071 buf->b_p_ff = vim_strsave(p_ff);
11072 }
11073 if (buf->b_p_ff != NULL)
11074 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011075 buf->b_p_bh = empty_option;
11076 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 }
11078 else
11079 free_buf_options(buf, FALSE);
11080
11081 buf->b_p_ai = p_ai;
11082 buf->b_p_ai_nopaste = p_ai_nopaste;
11083 buf->b_p_sw = p_sw;
11084 buf->b_p_tw = p_tw;
11085 buf->b_p_tw_nopaste = p_tw_nopaste;
11086 buf->b_p_tw_nobin = p_tw_nobin;
11087 buf->b_p_wm = p_wm;
11088 buf->b_p_wm_nopaste = p_wm_nopaste;
11089 buf->b_p_wm_nobin = p_wm_nobin;
11090 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011091#ifdef FEAT_MBYTE
11092 buf->b_p_bomb = p_bomb;
11093#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011094 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 buf->b_p_et = p_et;
11096 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011097 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 buf->b_p_ml = p_ml;
11099 buf->b_p_ml_nobin = p_ml_nobin;
11100 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011101 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102#ifdef FEAT_INS_EXPAND
11103 buf->b_p_cpt = vim_strsave(p_cpt);
11104#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011105#ifdef FEAT_COMPL_FUNC
11106 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011107 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 buf->b_p_sts = p_sts;
11110 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112#ifdef FEAT_COMMENTS
11113 buf->b_p_com = vim_strsave(p_com);
11114#endif
11115#ifdef FEAT_FOLDING
11116 buf->b_p_cms = vim_strsave(p_cms);
11117#endif
11118 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011119 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 buf->b_p_nf = vim_strsave(p_nf);
11121 buf->b_p_mps = vim_strsave(p_mps);
11122#ifdef FEAT_SMARTINDENT
11123 buf->b_p_si = p_si;
11124#endif
11125 buf->b_p_ci = p_ci;
11126#ifdef FEAT_CINDENT
11127 buf->b_p_cin = p_cin;
11128 buf->b_p_cink = vim_strsave(p_cink);
11129 buf->b_p_cino = vim_strsave(p_cino);
11130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131 /* Don't copy 'filetype', it must be detected */
11132 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 buf->b_p_pi = p_pi;
11134#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11135 buf->b_p_cinw = vim_strsave(p_cinw);
11136#endif
11137#ifdef FEAT_LISP
11138 buf->b_p_lisp = p_lisp;
11139#endif
11140#ifdef FEAT_SYN_HL
11141 /* Don't copy 'syntax', it must be set */
11142 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011143 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011144 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011145#endif
11146#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011147 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011148 (void)compile_cap_prog(&buf->b_s);
11149 buf->b_s.b_p_spf = vim_strsave(p_spf);
11150 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151#endif
11152#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11153 buf->b_p_inde = vim_strsave(p_inde);
11154 buf->b_p_indk = vim_strsave(p_indk);
11155#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011156 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011157#if defined(FEAT_EVAL)
11158 buf->b_p_fex = vim_strsave(p_fex);
11159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160#ifdef FEAT_CRYPT
11161 buf->b_p_key = vim_strsave(p_key);
11162#endif
11163#ifdef FEAT_SEARCHPATH
11164 buf->b_p_sua = vim_strsave(p_sua);
11165#endif
11166#ifdef FEAT_KEYMAP
11167 buf->b_p_keymap = vim_strsave(p_keymap);
11168 buf->b_kmap_state |= KEYMAP_INIT;
11169#endif
11170 /* This isn't really an option, but copying the langmap and IME
11171 * state from the current buffer is better than resetting it. */
11172 buf->b_p_iminsert = p_iminsert;
11173 buf->b_p_imsearch = p_imsearch;
11174
11175 /* options that are normally global but also have a local value
11176 * are not copied, start using the global value */
11177 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011178 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011179 buf->b_p_bkc = empty_option;
11180 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181#ifdef FEAT_QUICKFIX
11182 buf->b_p_gp = empty_option;
11183 buf->b_p_mp = empty_option;
11184 buf->b_p_efm = empty_option;
11185#endif
11186 buf->b_p_ep = empty_option;
11187 buf->b_p_kp = empty_option;
11188 buf->b_p_path = empty_option;
11189 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011190 buf->b_p_tc = empty_option;
11191 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192#ifdef FEAT_FIND_ID
11193 buf->b_p_def = empty_option;
11194 buf->b_p_inc = empty_option;
11195# ifdef FEAT_EVAL
11196 buf->b_p_inex = vim_strsave(p_inex);
11197# endif
11198#endif
11199#ifdef FEAT_INS_EXPAND
11200 buf->b_p_dict = empty_option;
11201 buf->b_p_tsr = empty_option;
11202#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011203#ifdef FEAT_TEXTOBJ
11204 buf->b_p_qe = vim_strsave(p_qe);
11205#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011206#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11207 buf->b_p_bexpr = empty_option;
11208#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011209#if defined(FEAT_CRYPT)
11210 buf->b_p_cm = empty_option;
11211#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011212#ifdef FEAT_PERSISTENT_UNDO
11213 buf->b_p_udf = p_udf;
11214#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011215#ifdef FEAT_LISP
11216 buf->b_p_lw = empty_option;
11217#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011218#ifdef FEAT_MBYTE
11219 buf->b_p_menc = empty_option;
11220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011221
11222 /*
11223 * Don't copy the options set by ex_help(), use the saved values,
11224 * when going from a help buffer to a non-help buffer.
11225 * Don't touch these at all when BCO_NOHELP is used and going from
11226 * or to a help buffer.
11227 */
11228 if (dont_do_help)
11229 buf->b_p_isk = save_p_isk;
11230 else
11231 {
11232 buf->b_p_isk = vim_strsave(p_isk);
11233 did_isk = TRUE;
11234 buf->b_p_ts = p_ts;
11235 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 if (buf->b_p_bt[0] == 'h')
11237 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238 buf->b_p_ma = p_ma;
11239 }
11240 }
11241
11242 /*
11243 * When the options should be copied (ignoring BCO_ALWAYS), set the
11244 * flag that indicates that the options have been initialized.
11245 */
11246 if (should_copy)
11247 buf->b_p_initialized = TRUE;
11248 }
11249
11250 check_buf_options(buf); /* make sure we don't have NULLs */
11251 if (did_isk)
11252 (void)buf_init_chartab(buf, FALSE);
11253}
11254
11255/*
11256 * Reset the 'modifiable' option and its default value.
11257 */
11258 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011259reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260{
11261 int opt_idx;
11262
11263 curbuf->b_p_ma = FALSE;
11264 p_ma = FALSE;
11265 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011266 if (opt_idx >= 0)
11267 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268}
11269
11270/*
11271 * Set the global value for 'iminsert' to the local value.
11272 */
11273 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011274set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275{
11276 p_iminsert = curbuf->b_p_iminsert;
11277}
11278
11279/*
11280 * Set the global value for 'imsearch' to the local value.
11281 */
11282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011283set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284{
11285 p_imsearch = curbuf->b_p_imsearch;
11286}
11287
11288#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11289static int expand_option_idx = -1;
11290static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11291static int expand_option_flags = 0;
11292
11293 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011294set_context_in_set_cmd(
11295 expand_T *xp,
11296 char_u *arg,
11297 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298{
11299 int nextchar;
11300 long_u flags = 0; /* init for GCC */
11301 int opt_idx = 0; /* init for GCC */
11302 char_u *p;
11303 char_u *s;
11304 int is_term_option = FALSE;
11305 int key;
11306
11307 expand_option_flags = opt_flags;
11308
11309 xp->xp_context = EXPAND_SETTINGS;
11310 if (*arg == NUL)
11311 {
11312 xp->xp_pattern = arg;
11313 return;
11314 }
11315 p = arg + STRLEN(arg) - 1;
11316 if (*p == ' ' && *(p - 1) != '\\')
11317 {
11318 xp->xp_pattern = p + 1;
11319 return;
11320 }
11321 while (p > arg)
11322 {
11323 s = p;
11324 /* count number of backslashes before ' ' or ',' */
11325 if (*p == ' ' || *p == ',')
11326 {
11327 while (s > arg && *(s - 1) == '\\')
11328 --s;
11329 }
11330 /* break at a space with an even number of backslashes */
11331 if (*p == ' ' && ((p - s) & 1) == 0)
11332 {
11333 ++p;
11334 break;
11335 }
11336 --p;
11337 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011338 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339 {
11340 xp->xp_context = EXPAND_BOOL_SETTINGS;
11341 p += 2;
11342 }
11343 if (STRNCMP(p, "inv", 3) == 0)
11344 {
11345 xp->xp_context = EXPAND_BOOL_SETTINGS;
11346 p += 3;
11347 }
11348 xp->xp_pattern = arg = p;
11349 if (*arg == '<')
11350 {
11351 while (*p != '>')
11352 if (*p++ == NUL) /* expand terminal option name */
11353 return;
11354 key = get_special_key_code(arg + 1);
11355 if (key == 0) /* unknown name */
11356 {
11357 xp->xp_context = EXPAND_NOTHING;
11358 return;
11359 }
11360 nextchar = *++p;
11361 is_term_option = TRUE;
11362 expand_option_name[2] = KEY2TERMCAP0(key);
11363 expand_option_name[3] = KEY2TERMCAP1(key);
11364 }
11365 else
11366 {
11367 if (p[0] == 't' && p[1] == '_')
11368 {
11369 p += 2;
11370 if (*p != NUL)
11371 ++p;
11372 if (*p == NUL)
11373 return; /* expand option name */
11374 nextchar = *++p;
11375 is_term_option = TRUE;
11376 expand_option_name[2] = p[-2];
11377 expand_option_name[3] = p[-1];
11378 }
11379 else
11380 {
11381 /* Allow * wildcard */
11382 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11383 p++;
11384 if (*p == NUL)
11385 return;
11386 nextchar = *p;
11387 *p = NUL;
11388 opt_idx = findoption(arg);
11389 *p = nextchar;
11390 if (opt_idx == -1 || options[opt_idx].var == NULL)
11391 {
11392 xp->xp_context = EXPAND_NOTHING;
11393 return;
11394 }
11395 flags = options[opt_idx].flags;
11396 if (flags & P_BOOL)
11397 {
11398 xp->xp_context = EXPAND_NOTHING;
11399 return;
11400 }
11401 }
11402 }
11403 /* handle "-=" and "+=" */
11404 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11405 {
11406 ++p;
11407 nextchar = '=';
11408 }
11409 if ((nextchar != '=' && nextchar != ':')
11410 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11411 {
11412 xp->xp_context = EXPAND_UNSUCCESSFUL;
11413 return;
11414 }
11415 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11416 {
11417 xp->xp_context = EXPAND_OLD_SETTING;
11418 if (is_term_option)
11419 expand_option_idx = -1;
11420 else
11421 expand_option_idx = opt_idx;
11422 xp->xp_pattern = p + 1;
11423 return;
11424 }
11425 xp->xp_context = EXPAND_NOTHING;
11426 if (is_term_option || (flags & P_NUM))
11427 return;
11428
11429 xp->xp_pattern = p + 1;
11430
11431 if (flags & P_EXPAND)
11432 {
11433 p = options[opt_idx].var;
11434 if (p == (char_u *)&p_bdir
11435 || p == (char_u *)&p_dir
11436 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011437 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011438 || p == (char_u *)&p_rtp
11439#ifdef FEAT_SEARCHPATH
11440 || p == (char_u *)&p_cdpath
11441#endif
11442#ifdef FEAT_SESSION
11443 || p == (char_u *)&p_vdir
11444#endif
11445 )
11446 {
11447 xp->xp_context = EXPAND_DIRECTORIES;
11448 if (p == (char_u *)&p_path
11449#ifdef FEAT_SEARCHPATH
11450 || p == (char_u *)&p_cdpath
11451#endif
11452 )
11453 xp->xp_backslash = XP_BS_THREE;
11454 else
11455 xp->xp_backslash = XP_BS_ONE;
11456 }
11457 else
11458 {
11459 xp->xp_context = EXPAND_FILES;
11460 /* for 'tags' need three backslashes for a space */
11461 if (p == (char_u *)&p_tags)
11462 xp->xp_backslash = XP_BS_THREE;
11463 else
11464 xp->xp_backslash = XP_BS_ONE;
11465 }
11466 }
11467
11468 /* For an option that is a list of file names, find the start of the
11469 * last file name. */
11470 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11471 {
11472 /* count number of backslashes before ' ' or ',' */
11473 if (*p == ' ' || *p == ',')
11474 {
11475 s = p;
11476 while (s > xp->xp_pattern && *(s - 1) == '\\')
11477 --s;
11478 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11479 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11480 {
11481 xp->xp_pattern = p + 1;
11482 break;
11483 }
11484 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011485
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011486#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011487 /* for 'spellsuggest' start at "file:" */
11488 if (options[opt_idx].var == (char_u *)&p_sps
11489 && STRNCMP(p, "file:", 5) == 0)
11490 {
11491 xp->xp_pattern = p + 5;
11492 break;
11493 }
11494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495 }
11496
11497 return;
11498}
11499
11500 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011501ExpandSettings(
11502 expand_T *xp,
11503 regmatch_T *regmatch,
11504 int *num_file,
11505 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506{
11507 int num_normal = 0; /* Nr of matching non-term-code settings */
11508 int num_term = 0; /* Nr of matching terminal code settings */
11509 int opt_idx;
11510 int match;
11511 int count = 0;
11512 char_u *str;
11513 int loop;
11514 int is_term_opt;
11515 char_u name_buf[MAX_KEY_NAME_LEN];
11516 static char *(names[]) = {"all", "termcap"};
11517 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11518
11519 /* do this loop twice:
11520 * loop == 0: count the number of matching options
11521 * loop == 1: copy the matching options into allocated memory
11522 */
11523 for (loop = 0; loop <= 1; ++loop)
11524 {
11525 regmatch->rm_ic = ic;
11526 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11527 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011528 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11529 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011530 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11531 {
11532 if (loop == 0)
11533 num_normal++;
11534 else
11535 (*file)[count++] = vim_strsave((char_u *)names[match]);
11536 }
11537 }
11538 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11539 opt_idx++)
11540 {
11541 if (options[opt_idx].var == NULL)
11542 continue;
11543 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11544 && !(options[opt_idx].flags & P_BOOL))
11545 continue;
11546 is_term_opt = istermoption(&options[opt_idx]);
11547 if (is_term_opt && num_normal > 0)
11548 continue;
11549 match = FALSE;
11550 if (vim_regexec(regmatch, str, (colnr_T)0)
11551 || (options[opt_idx].shortname != NULL
11552 && vim_regexec(regmatch,
11553 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11554 match = TRUE;
11555 else if (is_term_opt)
11556 {
11557 name_buf[0] = '<';
11558 name_buf[1] = 't';
11559 name_buf[2] = '_';
11560 name_buf[3] = str[2];
11561 name_buf[4] = str[3];
11562 name_buf[5] = '>';
11563 name_buf[6] = NUL;
11564 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11565 {
11566 match = TRUE;
11567 str = name_buf;
11568 }
11569 }
11570 if (match)
11571 {
11572 if (loop == 0)
11573 {
11574 if (is_term_opt)
11575 num_term++;
11576 else
11577 num_normal++;
11578 }
11579 else
11580 (*file)[count++] = vim_strsave(str);
11581 }
11582 }
11583 /*
11584 * Check terminal key codes, these are not in the option table
11585 */
11586 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11587 {
11588 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11589 {
11590 if (!isprint(str[0]) || !isprint(str[1]))
11591 continue;
11592
11593 name_buf[0] = 't';
11594 name_buf[1] = '_';
11595 name_buf[2] = str[0];
11596 name_buf[3] = str[1];
11597 name_buf[4] = NUL;
11598
11599 match = FALSE;
11600 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11601 match = TRUE;
11602 else
11603 {
11604 name_buf[0] = '<';
11605 name_buf[1] = 't';
11606 name_buf[2] = '_';
11607 name_buf[3] = str[0];
11608 name_buf[4] = str[1];
11609 name_buf[5] = '>';
11610 name_buf[6] = NUL;
11611
11612 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11613 match = TRUE;
11614 }
11615 if (match)
11616 {
11617 if (loop == 0)
11618 num_term++;
11619 else
11620 (*file)[count++] = vim_strsave(name_buf);
11621 }
11622 }
11623
11624 /*
11625 * Check special key names.
11626 */
11627 regmatch->rm_ic = TRUE; /* ignore case here */
11628 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11629 {
11630 name_buf[0] = '<';
11631 STRCPY(name_buf + 1, str);
11632 STRCAT(name_buf, ">");
11633
11634 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11635 {
11636 if (loop == 0)
11637 num_term++;
11638 else
11639 (*file)[count++] = vim_strsave(name_buf);
11640 }
11641 }
11642 }
11643 if (loop == 0)
11644 {
11645 if (num_normal > 0)
11646 *num_file = num_normal;
11647 else if (num_term > 0)
11648 *num_file = num_term;
11649 else
11650 return OK;
11651 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11652 if (*file == NULL)
11653 {
11654 *file = (char_u **)"";
11655 return FAIL;
11656 }
11657 }
11658 }
11659 return OK;
11660}
11661
11662 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011663ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664{
11665 char_u *var = NULL; /* init for GCC */
11666 char_u *buf;
11667
11668 *num_file = 0;
11669 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11670 if (*file == NULL)
11671 return FAIL;
11672
11673 /*
11674 * For a terminal key code expand_option_idx is < 0.
11675 */
11676 if (expand_option_idx < 0)
11677 {
11678 var = find_termcode(expand_option_name + 2);
11679 if (var == NULL)
11680 expand_option_idx = findoption(expand_option_name);
11681 }
11682
11683 if (expand_option_idx >= 0)
11684 {
11685 /* put string of option value in NameBuff */
11686 option_value2string(&options[expand_option_idx], expand_option_flags);
11687 var = NameBuff;
11688 }
11689 else if (var == NULL)
11690 var = (char_u *)"";
11691
11692 /* A backslash is required before some characters. This is the reverse of
11693 * what happens in do_set(). */
11694 buf = vim_strsave_escaped(var, escape_chars);
11695
11696 if (buf == NULL)
11697 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011698 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011699 return FAIL;
11700 }
11701
11702#ifdef BACKSLASH_IN_FILENAME
11703 /* For MS-Windows et al. we don't double backslashes at the start and
11704 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011705 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706 if (var[0] == '\\' && var[1] == '\\'
11707 && expand_option_idx >= 0
11708 && (options[expand_option_idx].flags & P_EXPAND)
11709 && vim_isfilec(var[2])
11710 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011711 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712#endif
11713
11714 *file[0] = buf;
11715 *num_file = 1;
11716 return OK;
11717}
11718#endif
11719
11720/*
11721 * Get the value for the numeric or string option *opp in a nice format into
11722 * NameBuff[]. Must not be called with a hidden option!
11723 */
11724 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011725option_value2string(
11726 struct vimoption *opp,
11727 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728{
11729 char_u *varp;
11730
11731 varp = get_varp_scope(opp, opt_flags);
11732
11733 if (opp->flags & P_NUM)
11734 {
11735 long wc = 0;
11736
11737 if (wc_use_keyname(varp, &wc))
11738 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11739 else if (wc != 0)
11740 STRCPY(NameBuff, transchar((int)wc));
11741 else
11742 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11743 }
11744 else /* P_STRING */
11745 {
11746 varp = *(char_u **)(varp);
11747 if (varp == NULL) /* just in case */
11748 NameBuff[0] = NUL;
11749#ifdef FEAT_CRYPT
11750 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011751 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752 STRCPY(NameBuff, "*****");
11753#endif
11754 else if (opp->flags & P_EXPAND)
11755 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11756 /* Translate 'pastetoggle' into special key names */
11757 else if ((char_u **)opp->var == &p_pt)
11758 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11759 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011760 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762}
11763
11764/*
11765 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11766 * printed as a keyname.
11767 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11768 */
11769 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011770wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771{
11772 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11773 {
11774 *wcp = *(long *)varp;
11775 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11776 return TRUE;
11777 }
11778 return FALSE;
11779}
11780
Bram Moolenaar01615492015-02-03 13:00:38 +010011781#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011783 * Any character has an equivalent 'langmap' character. This is used for
11784 * keyboards that have a special language mode that sends characters above
11785 * 128 (although other characters can be translated too). The "to" field is a
11786 * Vim command character. This avoids having to switch the keyboard back to
11787 * ASCII mode when leaving Insert mode.
11788 *
11789 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11790 * commands.
11791 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11792 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11793 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011795# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011796/*
11797 * With multi-byte support use growarray for 'langmap' chars >= 256
11798 */
11799typedef struct
11800{
11801 int from;
11802 int to;
11803} langmap_entry_T;
11804
11805static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011806static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807
11808/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011809 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11810 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011812 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011813langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011814{
11815 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011816 int a = 0;
11817 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011818
11819 /* Do a binary search for an existing entry. */
11820 while (a != b)
11821 {
11822 int i = (a + b) / 2;
11823 int d = entries[i].from - from;
11824
11825 if (d == 0)
11826 {
11827 entries[i].to = to;
11828 return;
11829 }
11830 if (d < 0)
11831 a = i + 1;
11832 else
11833 b = i;
11834 }
11835
11836 if (ga_grow(&langmap_mapga, 1) != OK)
11837 return; /* out of memory */
11838
11839 /* insert new entry at position "a" */
11840 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11841 mch_memmove(entries + 1, entries,
11842 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11843 ++langmap_mapga.ga_len;
11844 entries[0].from = from;
11845 entries[0].to = to;
11846}
11847
11848/*
11849 * Apply 'langmap' to multi-byte character "c" and return the result.
11850 */
11851 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011852langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011853{
11854 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11855 int a = 0;
11856 int b = langmap_mapga.ga_len;
11857
11858 while (a != b)
11859 {
11860 int i = (a + b) / 2;
11861 int d = entries[i].from - c;
11862
11863 if (d == 0)
11864 return entries[i].to; /* found matching entry */
11865 if (d < 0)
11866 a = i + 1;
11867 else
11868 b = i;
11869 }
11870 return c; /* no entry found, return "c" unmodified */
11871}
11872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873
11874 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011875langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876{
11877 int i;
11878
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011879 for (i = 0; i < 256; i++)
11880 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11881# ifdef FEAT_MBYTE
11882 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884}
11885
11886/*
11887 * Called when langmap option is set; the language map can be
11888 * changed at any time!
11889 */
11890 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011891langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892{
11893 char_u *p;
11894 char_u *p2;
11895 int from, to;
11896
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011897#ifdef FEAT_MBYTE
11898 ga_clear(&langmap_mapga); /* clear the previous map first */
11899#endif
11900 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901
11902 for (p = p_langmap; p[0] != NUL; )
11903 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011904 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011905 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 {
11907 if (p2[0] == '\\' && p2[1] != NUL)
11908 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909 }
11910 if (p2[0] == ';')
11911 ++p2; /* abcd;ABCD form, p2 points to A */
11912 else
11913 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11914 while (p[0])
11915 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011916 if (p[0] == ',')
11917 {
11918 ++p;
11919 break;
11920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921 if (p[0] == '\\' && p[1] != NUL)
11922 ++p;
11923#ifdef FEAT_MBYTE
11924 from = (*mb_ptr2char)(p);
11925#else
11926 from = p[0];
11927#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011928 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929 if (p2 == NULL)
11930 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011931 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011932 if (p[0] != ',')
11933 {
11934 if (p[0] == '\\')
11935 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011939 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942 }
11943 else
11944 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011945 if (p2[0] != ',')
11946 {
11947 if (p2[0] == '\\')
11948 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011950 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011952 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011953#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 }
11956 if (to == NUL)
11957 {
11958 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11959 transchar(from));
11960 return;
11961 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011962
11963#ifdef FEAT_MBYTE
11964 if (from >= 256)
11965 langmap_set_entry(from, to);
11966 else
11967#endif
11968 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969
11970 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011971 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011972 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011973 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011974 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011975 if (*p == ';')
11976 {
11977 p = p2;
11978 if (p[0] != NUL)
11979 {
11980 if (p[0] != ',')
11981 {
11982 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11983 return;
11984 }
11985 ++p;
11986 }
11987 break;
11988 }
11989 }
11990 }
11991 }
11992}
11993#endif
11994
11995/*
11996 * Return TRUE if format option 'x' is in effect.
11997 * Take care of no formatting when 'paste' is set.
11998 */
11999 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012000has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001{
12002 if (p_paste)
12003 return FALSE;
12004 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12005}
12006
12007/*
12008 * Return TRUE if "x" is present in 'shortmess' option, or
12009 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12010 */
12011 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012012shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012014 return p_shm != NULL &&
12015 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 || (vim_strchr(p_shm, 'a') != NULL
12017 && vim_strchr((char_u *)SHM_A, x) != NULL));
12018}
12019
12020/*
12021 * paste_option_changed() - Called after p_paste was set or reset.
12022 */
12023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012024paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025{
12026 static int old_p_paste = FALSE;
12027 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012028 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029#ifdef FEAT_CMDL_INFO
12030 static int save_ru = 0;
12031#endif
12032#ifdef FEAT_RIGHTLEFT
12033 static int save_ri = 0;
12034 static int save_hkmap = 0;
12035#endif
12036 buf_T *buf;
12037
12038 if (p_paste)
12039 {
12040 /*
12041 * Paste switched from off to on.
12042 * Save the current values, so they can be restored later.
12043 */
12044 if (!old_p_paste)
12045 {
12046 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012047 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048 {
12049 buf->b_p_tw_nopaste = buf->b_p_tw;
12050 buf->b_p_wm_nopaste = buf->b_p_wm;
12051 buf->b_p_sts_nopaste = buf->b_p_sts;
12052 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012053 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054 }
12055
12056 /* save global options */
12057 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012058 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059#ifdef FEAT_CMDL_INFO
12060 save_ru = p_ru;
12061#endif
12062#ifdef FEAT_RIGHTLEFT
12063 save_ri = p_ri;
12064 save_hkmap = p_hkmap;
12065#endif
12066 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012067 p_ai_nopaste = p_ai;
12068 p_et_nopaste = p_et;
12069 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 p_tw_nopaste = p_tw;
12071 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072 }
12073
12074 /*
12075 * Always set the option values, also when 'paste' is set when it is
12076 * already on.
12077 */
12078 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012079 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080 {
12081 buf->b_p_tw = 0; /* textwidth is 0 */
12082 buf->b_p_wm = 0; /* wrapmargin is 0 */
12083 buf->b_p_sts = 0; /* softtabstop is 0 */
12084 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012085 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 }
12087
12088 /* set global options */
12089 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012090 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092 if (p_ru)
12093 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094 p_ru = 0; /* no ruler */
12095#endif
12096#ifdef FEAT_RIGHTLEFT
12097 p_ri = 0; /* no reverse insert */
12098 p_hkmap = 0; /* no Hebrew keyboard */
12099#endif
12100 /* set global values for local buffer options */
12101 p_tw = 0;
12102 p_wm = 0;
12103 p_sts = 0;
12104 p_ai = 0;
12105 }
12106
12107 /*
12108 * Paste switched from on to off: Restore saved values.
12109 */
12110 else if (old_p_paste)
12111 {
12112 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012113 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114 {
12115 buf->b_p_tw = buf->b_p_tw_nopaste;
12116 buf->b_p_wm = buf->b_p_wm_nopaste;
12117 buf->b_p_sts = buf->b_p_sts_nopaste;
12118 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012119 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 }
12121
12122 /* restore global options */
12123 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012124 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 if (p_ru != save_ru)
12127 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 p_ru = save_ru;
12129#endif
12130#ifdef FEAT_RIGHTLEFT
12131 p_ri = save_ri;
12132 p_hkmap = save_hkmap;
12133#endif
12134 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012135 p_ai = p_ai_nopaste;
12136 p_et = p_et_nopaste;
12137 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012138 p_tw = p_tw_nopaste;
12139 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140 }
12141
12142 old_p_paste = p_paste;
12143}
12144
12145/*
12146 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12147 *
12148 * Reset 'compatible' and set the values for options that didn't get set yet
12149 * to the Vim defaults.
12150 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012151 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152 */
12153 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012154vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012156 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012157 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012158 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159
12160 if (!option_was_set((char_u *)"cp"))
12161 {
12162 p_cp = FALSE;
12163 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12164 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12165 set_option_default(opt_idx, OPT_FREE, FALSE);
12166 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012167 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012169
12170 if (fname != NULL)
12171 {
12172 p = vim_getenv(envname, &dofree);
12173 if (p == NULL)
12174 {
12175 /* Set $MYVIMRC to the first vimrc file found. */
12176 p = FullName_save(fname, FALSE);
12177 if (p != NULL)
12178 {
12179 vim_setenv(envname, p);
12180 vim_free(p);
12181 }
12182 }
12183 else if (dofree)
12184 vim_free(p);
12185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186}
12187
12188/*
12189 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12190 */
12191 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012192change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012194 int opt_idx;
12195
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 if (p_cp != on)
12197 {
12198 p_cp = on;
12199 compatible_set();
12200 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012201 opt_idx = findoption((char_u *)"cp");
12202 if (opt_idx >= 0)
12203 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204}
12205
12206/*
12207 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012208 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 */
12210 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012211option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212{
12213 int idx;
12214
12215 idx = findoption(name);
12216 if (idx < 0) /* unknown option */
12217 return FALSE;
12218 if (options[idx].flags & P_WAS_SET)
12219 return TRUE;
12220 return FALSE;
12221}
12222
12223/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012224 * Reset the flag indicating option "name" was set.
12225 */
12226 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012227reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012228{
12229 int idx = findoption(name);
12230
12231 if (idx >= 0)
12232 options[idx].flags &= ~P_WAS_SET;
12233}
12234
12235/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 * compatible_set() - Called when 'compatible' has been set or unset.
12237 *
12238 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12239 * flag) to a Vi compatible value.
12240 * When 'compatible' is unset: Set all options that have a different default
12241 * for Vim (without the P_VI_DEF flag) to that default.
12242 */
12243 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012244compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245{
12246 int opt_idx;
12247
12248 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12249 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12250 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12251 set_option_default(opt_idx, OPT_FREE, p_cp);
12252 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012253 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254}
12255
12256#ifdef FEAT_LINEBREAK
12257
12258# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12259 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012260 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261# endif
12262
12263/*
12264 * fill_breakat_flags() -- called when 'breakat' changes value.
12265 */
12266 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012269 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 int i;
12271
12272 for (i = 0; i < 256; i++)
12273 breakat_flags[i] = FALSE;
12274
12275 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012276 for (p = p_breakat; *p; p++)
12277 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278}
12279
12280# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012281 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282# endif
12283
12284#endif
12285
12286/*
12287 * Check an option that can be a range of string values.
12288 *
12289 * Return OK for correct value, FAIL otherwise.
12290 * Empty is always OK.
12291 */
12292 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012293check_opt_strings(
12294 char_u *val,
12295 char **values,
12296 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297{
12298 return opt_strings_flags(val, values, NULL, list);
12299}
12300
12301/*
12302 * Handle an option that can be a range of string values.
12303 * Set a flag in "*flagp" for each string present.
12304 *
12305 * Return OK for correct value, FAIL otherwise.
12306 * Empty is always OK.
12307 */
12308 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012309opt_strings_flags(
12310 char_u *val, /* new value */
12311 char **values, /* array of valid string values */
12312 unsigned *flagp,
12313 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012314{
12315 int i;
12316 int len;
12317 unsigned new_flags = 0;
12318
12319 while (*val)
12320 {
12321 for (i = 0; ; ++i)
12322 {
12323 if (values[i] == NULL) /* val not found in values[] */
12324 return FAIL;
12325
12326 len = (int)STRLEN(values[i]);
12327 if (STRNCMP(values[i], val, len) == 0
12328 && ((list && val[len] == ',') || val[len] == NUL))
12329 {
12330 val += len + (val[len] == ',');
12331 new_flags |= (1 << i);
12332 break; /* check next item in val list */
12333 }
12334 }
12335 }
12336 if (flagp != NULL)
12337 *flagp = new_flags;
12338
12339 return OK;
12340}
12341
12342/*
12343 * Read the 'wildmode' option, fill wim_flags[].
12344 */
12345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012346check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012347{
12348 char_u new_wim_flags[4];
12349 char_u *p;
12350 int i;
12351 int idx = 0;
12352
12353 for (i = 0; i < 4; ++i)
12354 new_wim_flags[i] = 0;
12355
12356 for (p = p_wim; *p; ++p)
12357 {
12358 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12359 ;
12360 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12361 return FAIL;
12362 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12363 new_wim_flags[idx] |= WIM_LONGEST;
12364 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12365 new_wim_flags[idx] |= WIM_FULL;
12366 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12367 new_wim_flags[idx] |= WIM_LIST;
12368 else
12369 return FAIL;
12370 p += i;
12371 if (*p == NUL)
12372 break;
12373 if (*p == ',')
12374 {
12375 if (idx == 3)
12376 return FAIL;
12377 ++idx;
12378 }
12379 }
12380
12381 /* fill remaining entries with last flag */
12382 while (idx < 3)
12383 {
12384 new_wim_flags[idx + 1] = new_wim_flags[idx];
12385 ++idx;
12386 }
12387
12388 /* only when there are no errors, wim_flags[] is changed */
12389 for (i = 0; i < 4; ++i)
12390 wim_flags[i] = new_wim_flags[i];
12391 return OK;
12392}
12393
12394/*
12395 * Check if backspacing over something is allowed.
12396 */
12397 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012398can_bs(
12399 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400{
12401 switch (*p_bs)
12402 {
12403 case '2': return TRUE;
12404 case '1': return (what != BS_START);
12405 case '0': return FALSE;
12406 }
12407 return vim_strchr(p_bs, what) != NULL;
12408}
12409
12410/*
12411 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12412 * the file must be considered changed when the value is different.
12413 */
12414 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012415save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416{
12417 buf->b_start_ffc = *buf->b_p_ff;
12418 buf->b_start_eol = buf->b_p_eol;
12419#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012420 buf->b_start_bomb = buf->b_p_bomb;
12421
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422 /* Only use free/alloc when necessary, they take time. */
12423 if (buf->b_start_fenc == NULL
12424 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12425 {
12426 vim_free(buf->b_start_fenc);
12427 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12428 }
12429#endif
12430}
12431
12432/*
12433 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12434 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012435 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12436 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012437 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012438 * When "ignore_empty" is true don't consider a new, empty buffer to be
12439 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 */
12441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012442file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012444 /* In a buffer that was never loaded the options are not valid. */
12445 if (buf->b_flags & BF_NEVERLOADED)
12446 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012447 if (ignore_empty
12448 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449 && buf->b_ml.ml_line_count == 1
12450 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12451 return FALSE;
12452 if (buf->b_start_ffc != *buf->b_p_ff)
12453 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012454 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455 return TRUE;
12456#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012457 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12458 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012459 if (buf->b_start_fenc == NULL)
12460 return (*buf->b_p_fenc != NUL);
12461 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12462#else
12463 return FALSE;
12464#endif
12465}
12466
12467/*
12468 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12469 */
12470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
12473 return check_opt_strings(p, p_ff_values, FALSE);
12474}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012475
12476/*
12477 * Return the effective shiftwidth value for current buffer, using the
12478 * 'tabstop' value when 'shiftwidth' is zero.
12479 */
12480 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012481get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012482{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012483 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012484}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012485
12486/*
12487 * Return the effective softtabstop value for the current buffer, using the
12488 * 'tabstop' value when 'softtabstop' is negative.
12489 */
12490 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012491get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012492{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012493 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012494}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012495
12496/*
12497 * Check matchpairs option for "*initc".
12498 * If there is a match set "*initc" to the matching character and "*findc" to
12499 * the opposite character. Set "*backwards" to the direction.
12500 * When "switchit" is TRUE swap the direction.
12501 */
12502 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012503find_mps_values(
12504 int *initc,
12505 int *findc,
12506 int *backwards,
12507 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012508{
12509 char_u *ptr;
12510
12511 ptr = curbuf->b_p_mps;
12512 while (*ptr != NUL)
12513 {
12514#ifdef FEAT_MBYTE
12515 if (has_mbyte)
12516 {
12517 char_u *prev;
12518
12519 if (mb_ptr2char(ptr) == *initc)
12520 {
12521 if (switchit)
12522 {
12523 *findc = *initc;
12524 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12525 *backwards = TRUE;
12526 }
12527 else
12528 {
12529 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12530 *backwards = FALSE;
12531 }
12532 return;
12533 }
12534 prev = ptr;
12535 ptr += mb_ptr2len(ptr) + 1;
12536 if (mb_ptr2char(ptr) == *initc)
12537 {
12538 if (switchit)
12539 {
12540 *findc = *initc;
12541 *initc = mb_ptr2char(prev);
12542 *backwards = FALSE;
12543 }
12544 else
12545 {
12546 *findc = mb_ptr2char(prev);
12547 *backwards = TRUE;
12548 }
12549 return;
12550 }
12551 ptr += mb_ptr2len(ptr);
12552 }
12553 else
12554#endif
12555 {
12556 if (*ptr == *initc)
12557 {
12558 if (switchit)
12559 {
12560 *backwards = TRUE;
12561 *findc = *initc;
12562 *initc = ptr[2];
12563 }
12564 else
12565 {
12566 *backwards = FALSE;
12567 *findc = ptr[2];
12568 }
12569 return;
12570 }
12571 ptr += 2;
12572 if (*ptr == *initc)
12573 {
12574 if (switchit)
12575 {
12576 *backwards = FALSE;
12577 *findc = *initc;
12578 *initc = ptr[-2];
12579 }
12580 else
12581 {
12582 *backwards = TRUE;
12583 *findc = ptr[-2];
12584 }
12585 return;
12586 }
12587 ++ptr;
12588 }
12589 if (*ptr == ',')
12590 ++ptr;
12591 }
12592}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012593
12594#if defined(FEAT_LINEBREAK) || defined(PROTO)
12595/*
12596 * This is called when 'breakindentopt' is changed and when a window is
12597 * initialized.
12598 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012599 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012600briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012601{
12602 char_u *p;
12603 int bri_shift = 0;
12604 long bri_min = 20;
12605 int bri_sbr = FALSE;
12606
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012607 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012608 while (*p != NUL)
12609 {
12610 if (STRNCMP(p, "shift:", 6) == 0
12611 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12612 {
12613 p += 6;
12614 bri_shift = getdigits(&p);
12615 }
12616 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12617 {
12618 p += 4;
12619 bri_min = getdigits(&p);
12620 }
12621 else if (STRNCMP(p, "sbr", 3) == 0)
12622 {
12623 p += 3;
12624 bri_sbr = TRUE;
12625 }
12626 if (*p != ',' && *p != NUL)
12627 return FAIL;
12628 if (*p == ',')
12629 ++p;
12630 }
12631
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012632 wp->w_p_brishift = bri_shift;
12633 wp->w_p_brimin = bri_min;
12634 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012635
12636 return OK;
12637}
12638#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012639
12640/*
12641 * Get the local or global value of 'backupcopy'.
12642 */
12643 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012644get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012645{
12646 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12647}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012648
12649#if defined(FEAT_SIGNS) || defined(PROTO)
12650/*
12651 * Return TRUE when window "wp" has a column to draw signs in.
12652 */
12653 int
12654signcolumn_on(win_T *wp)
12655{
12656 if (*wp->w_p_scl == 'n')
12657 return FALSE;
12658 if (*wp->w_p_scl == 'y')
12659 return TRUE;
12660 return (wp->w_buffer->b_signlist != NULL
12661# ifdef FEAT_NETBEANS_INTG
12662 || wp->w_buffer->b_has_sign_column
12663# endif
12664 );
12665}
12666#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012667
12668#if defined(FEAT_EVAL) || defined(PROTO)
12669/*
12670 * Get window or buffer local options.
12671 */
12672 dict_T *
12673get_winbuf_options(int bufopt)
12674{
12675 dict_T *d;
12676 int opt_idx;
12677
12678 d = dict_alloc();
12679 if (d == NULL)
12680 return NULL;
12681
12682 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12683 {
12684 struct vimoption *opt = &options[opt_idx];
12685
12686 if ((bufopt && (opt->indir & PV_BUF))
12687 || (!bufopt && (opt->indir & PV_WIN)))
12688 {
12689 char_u *varp = get_varp(opt);
12690
12691 if (varp != NULL)
12692 {
12693 if (opt->flags & P_STRING)
12694 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012695 else if (opt->flags & P_NUM)
12696 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012697 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012698 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012699 }
12700 }
12701 }
12702
12703 return d;
12704}
12705#endif