blob: 6fb24c536f461c36da5d60f92734a264a2b47da9 [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
230#ifdef FEAT_SCROLLBIND
231# define PV_SCBIND OPT_WIN(WV_SCBIND)
232#endif
233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235# define PV_SPELL OPT_WIN(WV_SPELL)
236#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SYN_HL
238# define PV_CUC OPT_WIN(WV_CUC)
239# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200240# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#ifdef FEAT_STL_OPT
243# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
244#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100245#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#ifdef FEAT_CURSORBIND
250# define PV_CRBIND OPT_WIN(WV_CRBIND)
251#endif
252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200257# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258# define PV_TMS OPT_WIN(WV_TMS)
259#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200260#ifdef FEAT_SIGNS
261# define PV_SCL OPT_WIN(WV_SCL)
262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000263
264/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265typedef enum
266{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000267 PV_NONE = 0,
268 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269} idopt_T;
270
271/*
272 * Options local to a window have a value local to a buffer and global to all
273 * buffers. Indicate this by setting "var" to VAR_WIN.
274 */
275#define VAR_WIN ((char_u *)-1)
276
277/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000278 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 * Only to be used in option.c!
280 */
281static int p_ai;
282static int p_bin;
283#ifdef FEAT_MBYTE
284static int p_bomb;
285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286static char_u *p_bh;
287static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static int p_bl;
289static int p_ci;
290#ifdef FEAT_CINDENT
291static int p_cin;
292static char_u *p_cink;
293static char_u *p_cino;
294#endif
295#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
296static char_u *p_cinw;
297#endif
298#ifdef FEAT_COMMENTS
299static char_u *p_com;
300#endif
301#ifdef FEAT_FOLDING
302static char_u *p_cms;
303#endif
304#ifdef FEAT_INS_EXPAND
305static char_u *p_cpt;
306#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#ifdef FEAT_COMPL_FUNC
308static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000309static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200312static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_et;
314#ifdef FEAT_MBYTE
315static char_u *p_fenc;
316#endif
317static char_u *p_ff;
318static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000319static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393
394struct vimoption
395{
396 char *fullname; /* full option name */
397 char *shortname; /* permissible abbreviation */
398 long_u flags; /* see below */
399 char_u *var; /* global option: pointer to variable;
400 * window-local option: VAR_WIN;
401 * buffer-local option: global value */
402 idopt_T indir; /* global option: PV_NONE;
403 * local option: indirect option index */
404 char_u *def_val[2]; /* default values for variable (vi and vim) */
405#ifdef FEAT_EVAL
406 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000407# define SCRIPTID_INIT , 0
408#else
409# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#endif
411};
412
413#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
414#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
415
416/*
417 * Flags
418 */
419#define P_BOOL 0x01 /* the option is boolean */
420#define P_NUM 0x02 /* the option is numeric */
421#define P_STRING 0x04 /* the option is a string */
422#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000423 must use free_string_option() when
424 assigning new value. Not set if default is
425 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
427 never be used for local or hidden options! */
428#define P_NODEFAULT 0x40 /* don't set to default value */
429#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
430 use vim_free() when assigning new value */
431#define P_WAS_SET 0x100 /* option has been set/reset */
432#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
433#define P_VI_DEF 0x400 /* Use Vi default for Vim */
434#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
435
436 /* when option changed, what to display: */
437#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100438#define P_RWIN 0x2000 /* redraw current window and recompute text */
439#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440#define P_RALL 0x6000 /* redraw all windows */
441#define P_RCLR 0x7000 /* clear and redraw all */
442
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200443#define P_COMMA 0x8000 /* comma separated list */
444#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
445 * commas */
446#define P_NODUP 0x20000L /* don't allow duplicate strings */
447#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
450#define P_GETTEXT 0x100000L /* expand default value with _() */
451#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
452#define P_NFNAME 0x400000L /* only normal file name chars allowed */
453#define P_INSECURE 0x800000L /* option was set from a modeline */
454#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100455 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200456#define P_NO_ML 0x2000000L /* not allowed in modeline */
457#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200458 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100460#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000462#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
463
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000464/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
465 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100466#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000467# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000468#else
469# define ISP_LATIN1 (char_u *)"@,161-255"
470#endif
471
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200472# 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 +0000473
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100474/* Default python version for pyx* commands */
475#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
476# define DEFAULT_PYTHON_VER 0
477#elif defined(FEAT_PYTHON3)
478# define DEFAULT_PYTHON_VER 3
479#elif defined(FEAT_PYTHON)
480# define DEFAULT_PYTHON_VER 2
481#else
482# define DEFAULT_PYTHON_VER 0
483#endif
484
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485/*
486 * options[] is initialized here.
487 * The order of the options MUST be alphabetic for ":set all" and findoption().
488 * All option names MUST start with a lowercase letter (for findoption()).
489 * Exception: "t_" options are at the end.
490 * The options with a NULL variable are 'hidden': a set command for them is
491 * ignored and they are not printed.
492 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100493static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200495 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496#ifdef FEAT_RIGHTLEFT
497 (char_u *)&p_aleph, PV_NONE,
498#else
499 (char_u *)NULL, PV_NONE,
500#endif
501 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100502#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 (char_u *)128L,
504#else
505 (char_u *)224L,
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200509#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 (char_u *)&p_antialias, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512#else
513 (char_u *)NULL, PV_NONE,
514 {(char_u *)FALSE, (char_u *)FALSE}
515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000516 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200517 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518#ifdef FEAT_ARABIC
519 (char_u *)VAR_WIN, PV_ARAB,
520#else
521 (char_u *)NULL, PV_NONE,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525#ifdef FEAT_ARABIC
526 (char_u *)&p_arshape, PV_NONE,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
532#ifdef FEAT_RIGHTLEFT
533 (char_u *)&p_ari, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
539#ifdef FEAT_FKMAP
540 (char_u *)&p_altkeymap, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
546#if defined(FEAT_MBYTE)
547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
549#else
550 (char_u *)NULL, PV_NONE,
551 {(char_u *)0L, (char_u *)0L}
552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100555#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100557 {(char_u *)FALSE, (char_u *)0L}
558#else
559 (char_u *)NULL, PV_NONE,
560 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoindent", "ai", P_BOOL|P_VI_DEF,
564 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoprint", "ap", P_BOOL|P_VI_DEF,
567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000570 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autowrite", "aw", P_BOOL|P_VI_DEF,
573 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autowriteall","awa", P_BOOL|P_VI_DEF,
576 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
579 (char_u *)&p_bg, PV_NONE,
580 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100581#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 (char_u *)"dark",
583#else
584 (char_u *)"light",
585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200587 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
591 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200593 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200594 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595#ifdef UNIX
596 {(char_u *)"yes", (char_u *)"auto"}
597#else
598 {(char_u *)"auto", (char_u *)"auto"}
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
602 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000605 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 (char_u *)&p_bex, PV_NONE,
607 {
608#ifdef VMS
609 (char_u *)"_",
610#else
611 (char_u *)"~",
612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200614 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615#ifdef FEAT_WILDIGN
616 (char_u *)&p_bsk, PV_NONE,
617 {(char_u *)"", (char_u *)0L}
618#else
619 (char_u *)NULL, PV_NONE,
620 {(char_u *)0L, (char_u *)0L}
621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100624#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100626 {(char_u *)600L, (char_u *)0L}
627#else
628 (char_u *)NULL, PV_NONE,
629 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 SCRIPTID_INIT},
632 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100633#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100634 (char_u *)&p_beval, PV_NONE,
635 {(char_u *)FALSE, (char_u *)0L}
636#else
637 (char_u *)NULL, PV_NONE,
638 {(char_u *)0L, (char_u *)0L}
639#endif
640 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100641 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100642#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100643 (char_u *)&p_bevalterm, PV_NONE,
644 {(char_u *)FALSE, (char_u *)0L}
645#else
646 (char_u *)NULL, PV_NONE,
647 {(char_u *)0L, (char_u *)0L}
648#endif
649 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100650 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
651#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
652 (char_u *)&p_bexpr, PV_BEXPR,
653 {(char_u *)"", (char_u *)0L}
654#else
655 (char_u *)NULL, PV_NONE,
656 {(char_u *)0L, (char_u *)0L}
657#endif
658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 {"beautify", "bf", P_BOOL|P_VI_DEF,
660 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200662 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
663 (char_u *)&p_bo, PV_NONE,
664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
666 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
672#ifdef FEAT_MBYTE
673 (char_u *)&p_bomb, PV_BOMB,
674#else
675 (char_u *)NULL, PV_NONE,
676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
679#ifdef FEAT_LINEBREAK
680 (char_u *)&p_breakat, PV_NONE,
681 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000686 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200687 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
688#ifdef FEAT_LINEBREAK
689 (char_u *)VAR_WIN, PV_BRI,
690 {(char_u *)FALSE, (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
695 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200696 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
697 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200698#ifdef FEAT_LINEBREAK
699 (char_u *)VAR_WIN, PV_BRIOPT,
700 {(char_u *)"", (char_u *)NULL}
701#else
702 (char_u *)NULL, PV_NONE,
703 {(char_u *)"", (char_u *)NULL}
704#endif
705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
707#ifdef FEAT_BROWSE
708 (char_u *)&p_bsdir, PV_NONE,
709 {(char_u *)"last", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 (char_u *)&p_bh, PV_BH,
717 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
720 (char_u *)&p_bl, PV_BL,
721 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_bt, PV_BT,
725 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200727 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000728#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 (char_u *)&p_cmp, PV_NONE,
730 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
737#ifdef FEAT_SEARCHPATH
738 (char_u *)&p_cdpath, PV_NONE,
739 {(char_u *)",,", (char_u *)0L}
740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"cedit", NULL, P_STRING,
746#ifdef FEAT_CMDWIN
747 (char_u *)&p_cedit, PV_NONE,
748 {(char_u *)"", (char_u *)CTRL_F_STR}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
755#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
756 (char_u *)&p_ccv, PV_NONE,
757 {(char_u *)"", (char_u *)0L}
758#else
759 (char_u *)NULL, PV_NONE,
760 {(char_u *)0L, (char_u *)0L}
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
764#ifdef FEAT_CINDENT
765 (char_u *)&p_cin, PV_CIN,
766#else
767 (char_u *)NULL, PV_NONE,
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CINDENT
772 (char_u *)&p_cink, PV_CINK,
773 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
774#else
775 (char_u *)NULL, PV_NONE,
776 {(char_u *)0L, (char_u *)0L}
777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000778 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200779 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#ifdef FEAT_CINDENT
781 (char_u *)&p_cino, PV_CINO,
782#else
783 (char_u *)NULL, PV_NONE,
784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000785 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200786 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
788 (char_u *)&p_cinw, PV_CINW,
789 {(char_u *)"if,else,while,do,for,switch",
790 (char_u *)0L}
791#else
792 (char_u *)NULL, PV_NONE,
793 {(char_u *)0L, (char_u *)0L}
794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000795 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200796 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797#ifdef FEAT_CLIPBOARD
798 (char_u *)&p_cb, PV_NONE,
799# ifdef FEAT_XCLIPBOARD
800 {(char_u *)"autoselect,exclude:cons\\|linux",
801 (char_u *)0L}
802# else
803 {(char_u *)"", (char_u *)0L}
804# endif
805#else
806 (char_u *)NULL, PV_NONE,
807 {(char_u *)"", (char_u *)0L}
808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
811 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000812 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
814#ifdef FEAT_CMDWIN
815 (char_u *)&p_cwh, PV_NONE,
816#else
817 (char_u *)NULL, PV_NONE,
818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000819 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200820 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200821#ifdef FEAT_SYN_HL
822 (char_u *)VAR_WIN, PV_CC,
823#else
824 (char_u *)NULL, PV_NONE,
825#endif
826 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
828 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200830 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
831 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832#ifdef FEAT_COMMENTS
833 (char_u *)&p_com, PV_COM,
834 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
835 (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200841 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842#ifdef FEAT_FOLDING
843 (char_u *)&p_cms, PV_CMS,
844 {(char_u *)"/*%s*/", (char_u *)0L}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)0L, (char_u *)0L}
848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000850 /* P_PRI_MKRC isn't needed here, optval_default()
851 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852 {"compatible", "cp", P_BOOL|P_RALL,
853 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200855 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856#ifdef FEAT_INS_EXPAND
857 (char_u *)&p_cpt, PV_CPT,
858 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200864 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200866 (char_u *)VAR_WIN, PV_COCU,
867 {(char_u *)"", (char_u *)NULL}
868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)NULL, (char_u *)0L}
871#endif
872 SCRIPTID_INIT},
873 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
874#ifdef FEAT_CONCEAL
875 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200876#else
877 (char_u *)NULL, PV_NONE,
878#endif
879 {(char_u *)0L, (char_u *)0L}
880 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000881 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
882#ifdef FEAT_COMPL_FUNC
883 (char_u *)&p_cfu, PV_CFU,
884 {(char_u *)"", (char_u *)0L}
885#else
886 (char_u *)NULL, PV_NONE,
887 {(char_u *)0L, (char_u *)0L}
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200890 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000891#ifdef FEAT_INS_EXPAND
892 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000893 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000894#else
895 (char_u *)NULL, PV_NONE,
896 {(char_u *)0L, (char_u *)0L}
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"confirm", "cf", P_BOOL|P_VI_DEF,
900#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
901 (char_u *)&p_confirm, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
910 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
913 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
915 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200916 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200917#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200918 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200920#else
921 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_cspc, PV_NONE,
928#else
929 (char_u *)NULL, PV_NONE,
930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000932 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
933#ifdef FEAT_CSCOPE
934 (char_u *)&p_csprg, PV_NONE,
935 {(char_u *)"cscope", (char_u *)0L}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)0L, (char_u *)0L}
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200941 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
943 (char_u *)&p_csqf, PV_NONE,
944 {(char_u *)"", (char_u *)0L}
945#else
946 (char_u *)NULL, PV_NONE,
947 {(char_u *)0L, (char_u *)0L}
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200950 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_csre, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_cst, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csto, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
972#ifdef FEAT_CSCOPE
973 (char_u *)&p_csverbose, PV_NONE,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200978 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
979#ifdef FEAT_CURSORBIND
980 (char_u *)VAR_WIN, PV_CRBIND,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
986#ifdef FEAT_SYN_HL
987 (char_u *)VAR_WIN, PV_CUC,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100992 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000993#ifdef FEAT_SYN_HL
994 (char_u *)VAR_WIN, PV_CUL,
995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"debug", NULL, P_STRING|P_VI_DEF,
1000 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001002 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001004 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001005 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006#else
1007 (char_u *)NULL, PV_NONE,
1008 {(char_u *)NULL, (char_u *)0L}
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1012#ifdef FEAT_MBYTE
1013 (char_u *)&p_deco, PV_NONE,
1014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001018 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001020 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021#else
1022 (char_u *)NULL, PV_NONE,
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1026#ifdef FEAT_DIFF
1027 (char_u *)VAR_WIN, PV_DIFF,
1028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001032 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1034 (char_u *)&p_dex, PV_NONE,
1035 {(char_u *)"", (char_u *)0L}
1036#else
1037 (char_u *)NULL, PV_NONE,
1038 {(char_u *)0L, (char_u *)0L}
1039#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001040 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001041 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1042 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043#ifdef FEAT_DIFF
1044 (char_u *)&p_dip, PV_NONE,
1045 {(char_u *)"filler", (char_u *)NULL}
1046#else
1047 (char_u *)NULL, PV_NONE,
1048 {(char_u *)"", (char_u *)NULL}
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1052#ifdef FEAT_DIGRAPHS
1053 (char_u *)&p_dg, PV_NONE,
1054#else
1055 (char_u *)NULL, PV_NONE,
1056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001058 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1059 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001062 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_ead, PV_NONE,
1067 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1070 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001072 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1073#if defined(FEAT_MBYTE)
1074 (char_u *)&p_emoji, PV_NONE,
1075 {(char_u *)TRUE, (char_u *)0L}
1076#else
1077 (char_u *)NULL, PV_NONE,
1078 {(char_u *)0L, (char_u *)0L}
1079#endif
1080 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001081 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082#ifdef FEAT_MBYTE
1083 (char_u *)&p_enc, PV_NONE,
1084 {(char_u *)ENC_DFLT, (char_u *)0L}
1085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)0L, (char_u *)0L}
1088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1091 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1094 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001097 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1100 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1103#ifdef FEAT_QUICKFIX
1104 (char_u *)&p_ef, PV_NONE,
1105 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1106#else
1107 (char_u *)NULL, PV_NONE,
1108 {(char_u *)NULL, (char_u *)0L}
1109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001113 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115#else
1116 (char_u *)NULL, PV_NONE,
1117 {(char_u *)NULL, (char_u *)0L}
1118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"esckeys", "ek", P_BOOL|P_VIM,
1121 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001123 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 (char_u *)&p_ei, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1127 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1130 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1133 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_MBYTE
1135 (char_u *)&p_fenc, PV_FENC,
1136 {(char_u *)"", (char_u *)0L}
1137#else
1138 (char_u *)NULL, PV_NONE,
1139 {(char_u *)0L, (char_u *)0L}
1140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001141 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143#ifdef FEAT_MBYTE
1144 (char_u *)&p_fencs, PV_NONE,
1145 {(char_u *)"ucs-bom", (char_u *)0L}
1146#else
1147 (char_u *)NULL, PV_NONE,
1148 {(char_u *)0L, (char_u *)0L}
1149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1152 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001155 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1158 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001159 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1160 (char_u *)&p_fic, PV_NONE,
1161 {
1162#ifdef CASE_INSENSITIVE_FILENAME
1163 (char_u *)TRUE,
1164#else
1165 (char_u *)FALSE,
1166#endif
1167 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001168 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 (char_u *)&p_ft, PV_FT,
1170 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 (char_u *)&p_fcs, PV_NONE,
1174 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001176 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1177 (char_u *)&p_fixeol, PV_FIXEOL,
1178 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1180#ifdef FEAT_FKMAP
1181 (char_u *)&p_fkmap, PV_NONE,
1182#else
1183 (char_u *)NULL, PV_NONE,
1184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"flash", "fl", P_BOOL|P_VI_DEF,
1187 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001189 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192 {(char_u *)"", (char_u *)0L}
1193#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196#endif
1197 SCRIPTID_INIT},
1198 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1199#ifdef FEAT_FOLDING
1200 (char_u *)VAR_WIN, PV_FDC,
1201 {(char_u *)FALSE, (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205#endif
1206 SCRIPTID_INIT},
1207 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1208#ifdef FEAT_FOLDING
1209 (char_u *)VAR_WIN, PV_FEN,
1210 {(char_u *)TRUE, (char_u *)0L}
1211#else
1212 (char_u *)NULL, PV_NONE,
1213 {(char_u *)NULL, (char_u *)0L}
1214#endif
1215 SCRIPTID_INIT},
1216 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1217#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1218 (char_u *)VAR_WIN, PV_FDE,
1219 {(char_u *)"0", (char_u *)NULL}
1220#else
1221 (char_u *)NULL, PV_NONE,
1222 {(char_u *)NULL, (char_u *)0L}
1223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001224 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001226#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001228 {(char_u *)"#", (char_u *)NULL}
1229#else
1230 (char_u *)NULL, PV_NONE,
1231 {(char_u *)NULL, (char_u *)0L}
1232#endif
1233 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001237 {(char_u *)0L, (char_u *)0L}
1238#else
1239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
1241#endif
1242 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001243 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001244#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001246 {(char_u *)-1L, (char_u *)0L}
1247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)NULL, (char_u *)0L}
1250#endif
1251 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001253 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001254#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)NULL, PV_NONE,
1259 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261 SCRIPTID_INIT},
1262 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1263#ifdef FEAT_FOLDING
1264 (char_u *)VAR_WIN, PV_FDM,
1265 {(char_u *)"manual", (char_u *)NULL}
1266#else
1267 (char_u *)NULL, PV_NONE,
1268 {(char_u *)NULL, (char_u *)0L}
1269#endif
1270 SCRIPTID_INIT},
1271 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1272#ifdef FEAT_FOLDING
1273 (char_u *)VAR_WIN, PV_FML,
1274 {(char_u *)1L, (char_u *)0L}
1275#else
1276 (char_u *)NULL, PV_NONE,
1277 {(char_u *)NULL, (char_u *)0L}
1278#endif
1279 SCRIPTID_INIT},
1280 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1281#ifdef FEAT_FOLDING
1282 (char_u *)VAR_WIN, PV_FDN,
1283 {(char_u *)20L, (char_u *)0L}
1284#else
1285 (char_u *)NULL, PV_NONE,
1286 {(char_u *)NULL, (char_u *)0L}
1287#endif
1288 SCRIPTID_INIT},
1289 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1290#ifdef FEAT_FOLDING
1291 (char_u *)&p_fdo, PV_NONE,
1292 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1293 (char_u *)0L}
1294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
1298 SCRIPTID_INIT},
1299 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1300#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1301 (char_u *)VAR_WIN, PV_FDT,
1302 {(char_u *)"foldtext()", (char_u *)NULL}
1303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
1307 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001308 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001309#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001310 (char_u *)&p_fex, PV_FEX,
1311 {(char_u *)"", (char_u *)0L}
1312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)0L, (char_u *)0L}
1315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1318 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1320 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001321 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1322 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1324 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001326 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001328 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1329#ifdef HAVE_FSYNC
1330 (char_u *)&p_fs, PV_NONE,
1331 {(char_u *)TRUE, (char_u *)0L}
1332#else
1333 (char_u *)NULL, PV_NONE,
1334 {(char_u *)FALSE, (char_u *)0L}
1335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1338 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 {"graphic", "gr", P_BOOL|P_VI_DEF,
1341 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001343 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344#ifdef FEAT_QUICKFIX
1345 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347#else
1348 (char_u *)NULL, PV_NONE,
1349 {(char_u *)NULL, (char_u *)0L}
1350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1353#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001354 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355 {
1356# ifdef WIN3264
1357 /* may be changed to "grep -n" in os_win32.c */
1358 (char_u *)"findstr /n",
1359# else
1360# ifdef UNIX
1361 /* Add an extra file name so that grep will always
1362 * insert a file name in the match line. */
1363 (char_u *)"grep -n $* /dev/null",
1364# else
1365# ifdef VMS
1366 (char_u *)"SEARCH/NUMBERS ",
1367# else
1368 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369# endif
1370# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373#else
1374 (char_u *)NULL, PV_NONE,
1375 {(char_u *)NULL, (char_u *)0L}
1376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001378 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379#ifdef CURSOR_SHAPE
1380 (char_u *)&p_guicursor, PV_NONE,
1381 {
1382# ifdef FEAT_GUI
1383 (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 +01001384# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1386# endif
1387 (char_u *)0L}
1388#else
1389 (char_u *)NULL, PV_NONE,
1390 {(char_u *)NULL, (char_u *)0L}
1391#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001392 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001393 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394#ifdef FEAT_GUI
1395 (char_u *)&p_guifont, PV_NONE,
1396 {(char_u *)"", (char_u *)0L}
1397#else
1398 (char_u *)NULL, PV_NONE,
1399 {(char_u *)NULL, (char_u *)0L}
1400#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001401 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001402 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1404 (char_u *)&p_guifontset, PV_NONE,
1405 {(char_u *)"", (char_u *)0L}
1406#else
1407 (char_u *)NULL, PV_NONE,
1408 {(char_u *)NULL, (char_u *)0L}
1409#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001411 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1413 (char_u *)&p_guifontwide, PV_NONE,
1414 {(char_u *)"", (char_u *)0L}
1415#else
1416 (char_u *)NULL, PV_NONE,
1417 {(char_u *)NULL, (char_u *)0L}
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001421#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 (char_u *)&p_ghr, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001428#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001430# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001431 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001433 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434# endif
1435#else
1436 (char_u *)NULL, PV_NONE,
1437 {(char_u *)NULL, (char_u *)0L}
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"guipty", NULL, P_BOOL|P_VI_DEF,
1441#if defined(FEAT_GUI)
1442 (char_u *)&p_guipty, PV_NONE,
1443#else
1444 (char_u *)NULL, PV_NONE,
1445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001446 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001447 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001448#if defined(FEAT_GUI_TABLINE)
1449 (char_u *)&p_gtl, PV_NONE,
1450 {(char_u *)"", (char_u *)0L}
1451#else
1452 (char_u *)NULL, PV_NONE,
1453 {(char_u *)NULL, (char_u *)0L}
1454#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001455 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001456 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001457#if defined(FEAT_GUI_TABLINE)
1458 (char_u *)&p_gtt, PV_NONE,
1459 {(char_u *)"", (char_u *)0L}
1460#else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1466 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1469 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1471 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001475 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476#ifdef FEAT_MULTI_LANG
1477 (char_u *)&p_hlg, PV_NONE,
1478 {(char_u *)"", (char_u *)0L}
1479#else
1480 (char_u *)NULL, PV_NONE,
1481 {(char_u *)0L, (char_u *)0L}
1482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"hidden", "hid", P_BOOL|P_VI_DEF,
1485 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001487 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"history", "hi", P_NUM|P_VIM,
1492 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001493 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1495#ifdef FEAT_RIGHTLEFT
1496 (char_u *)&p_hkmap, PV_NONE,
1497#else
1498 (char_u *)NULL, PV_NONE,
1499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1502#ifdef FEAT_RIGHTLEFT
1503 (char_u *)&p_hkmapp, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1509 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"icon", NULL, P_BOOL|P_VI_DEF,
1512#ifdef FEAT_TITLE
1513 (char_u *)&p_icon, PV_NONE,
1514#else
1515 (char_u *)NULL, PV_NONE,
1516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"iconstring", NULL, P_STRING|P_VI_DEF,
1519#ifdef FEAT_TITLE
1520 (char_u *)&p_iconstring, PV_NONE,
1521#else
1522 (char_u *)NULL, PV_NONE,
1523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1526 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001528 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001529#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001530 (char_u *)&p_imaf, PV_NONE,
1531 {(char_u *)"", (char_u *)NULL}
1532# else
1533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)NULL, (char_u *)0L}
1535# endif
1536 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001538#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 (char_u *)&p_imak, PV_NONE,
1540#else
1541 (char_u *)NULL, PV_NONE,
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001545#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 (char_u *)&p_imcmdline, PV_NONE,
1547#else
1548 (char_u *)NULL, PV_NONE,
1549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001552#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 (char_u *)&p_imdisable, PV_NONE,
1554#else
1555 (char_u *)NULL, PV_NONE,
1556#endif
1557#ifdef __sgi
1558 {(char_u *)TRUE, (char_u *)0L}
1559#else
1560 {(char_u *)FALSE, (char_u *)0L}
1561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"iminsert", "imi", P_NUM|P_VI_DEF,
1564 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"imsearch", "ims", P_NUM|P_VI_DEF,
1568 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001569 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001571 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001572#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001573 (char_u *)&p_imsf, PV_NONE,
1574 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001575#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001576 (char_u *)NULL, PV_NONE,
1577 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001578#endif
1579 SCRIPTID_INIT},
1580 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1581#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1582 (char_u *)&p_imst, PV_NONE,
1583 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1584#else
1585 (char_u *)NULL, PV_NONE,
1586 {(char_u *)0L, (char_u *)0L}
1587#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001588 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1590#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001591 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1593#else
1594 (char_u *)NULL, PV_NONE,
1595 {(char_u *)0L, (char_u *)0L}
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1599#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1600 (char_u *)&p_inex, PV_INEX,
1601 {(char_u *)"", (char_u *)0L}
1602#else
1603 (char_u *)NULL, PV_NONE,
1604 {(char_u *)0L, (char_u *)0L}
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1608 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1611#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1612 (char_u *)&p_inde, PV_INDE,
1613 {(char_u *)"", (char_u *)0L}
1614#else
1615 (char_u *)NULL, PV_NONE,
1616 {(char_u *)0L, (char_u *)0L}
1617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001618 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001619 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1621 (char_u *)&p_indk, PV_INDK,
1622 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1623#else
1624 (char_u *)NULL, PV_NONE,
1625 {(char_u *)0L, (char_u *)0L}
1626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {"infercase", "inf", P_BOOL|P_VI_DEF,
1629 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1632 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1635 (char_u *)&p_isf, PV_NONE,
1636 {
1637#ifdef BACKSLASH_IN_FILENAME
1638 /* Excluded are: & and ^ are special in cmd.exe
1639 * ( and ) are used in text separating fnames */
1640 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1641#else
1642# ifdef AMIGA
1643 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1644# else
1645# ifdef VMS
1646 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1647# else /* UNIX et al. */
1648# ifdef EBCDIC
1649 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1650# else
1651 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1652# endif
1653# endif
1654# endif
1655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001656 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1658 (char_u *)&p_isi, PV_NONE,
1659 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001660#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 (char_u *)"@,48-57,_,128-167,224-235",
1662#else
1663# ifdef EBCDIC
1664 /* TODO: EBCDIC Check this! @ == isalpha()*/
1665 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1666 "112-120,128,140-142,156,158,172,"
1667 "174,186,191,203-207,219-225,235-239,"
1668 "251-254",
1669# else
1670 (char_u *)"@,48-57,_,192-255",
1671# endif
1672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001673 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1675 (char_u *)&p_isk, PV_ISK,
1676 {
1677#ifdef EBCDIC
1678 (char_u *)"@,240-249,_",
1679 /* TODO: EBCDIC Check this! @ == isalpha()*/
1680 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1681 "112-120,128,140-142,156,158,172,"
1682 "174,186,191,203-207,219-225,235-239,"
1683 "251-254",
1684#else
1685 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001686# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 (char_u *)"@,48-57,_,128-167,224-235"
1688# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001689 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690# endif
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1694 (char_u *)&p_isp, PV_NONE,
1695 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001696#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 (char_u *)"@,~-255",
1698#else
1699# ifdef EBCDIC
1700 /* all chars above 63 are printable */
1701 (char_u *)"63-255",
1702# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001703 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704# endif
1705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001706 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001707 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1708 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1711#ifdef FEAT_CRYPT
1712 (char_u *)&p_key, PV_KEY,
1713 {(char_u *)"", (char_u *)0L}
1714#else
1715 (char_u *)NULL, PV_NONE,
1716 {(char_u *)0L, (char_u *)0L}
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001719 {"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 +00001720#ifdef FEAT_KEYMAP
1721 (char_u *)&p_keymap, PV_KMAP,
1722 {(char_u *)"", (char_u *)0L}
1723#else
1724 (char_u *)NULL, PV_NONE,
1725 {(char_u *)"", (char_u *)0L}
1726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001728 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001732 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001734#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)":help",
1736#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001737# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001739# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001740# ifdef USEMAN_S
1741 (char_u *)"man -s",
1742# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001744# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745# endif
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001748 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749#ifdef FEAT_LANGMAP
1750 (char_u *)&p_langmap, PV_NONE,
1751 {(char_u *)"", /* unmatched } */
1752#else
1753 (char_u *)NULL, PV_NONE,
1754 {(char_u *)NULL,
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001757 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1759 (char_u *)&p_lm, PV_NONE,
1760#else
1761 (char_u *)NULL, PV_NONE,
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001764 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1765#ifdef FEAT_LANGMAP
1766 (char_u *)&p_lnr, PV_NONE,
1767#else
1768 (char_u *)NULL, PV_NONE,
1769#endif
1770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001771 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1772#ifdef FEAT_LANGMAP
1773 (char_u *)&p_lrm, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1782 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1785#ifdef FEAT_LINEBREAK
1786 (char_u *)VAR_WIN, PV_LBR,
1787#else
1788 (char_u *)NULL, PV_NONE,
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1792 (char_u *)&Rows, PV_NONE,
1793 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001794#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 (char_u *)25L,
1796#else
1797 (char_u *)24L,
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1801#ifdef FEAT_GUI
1802 (char_u *)&p_linespace, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
1806#ifdef FEAT_GUI_W32
1807 {(char_u *)1L, (char_u *)0L}
1808#else
1809 {(char_u *)0L, (char_u *)0L}
1810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001811 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"lisp", NULL, P_BOOL|P_VI_DEF,
1813#ifdef FEAT_LISP
1814 (char_u *)&p_lisp, PV_LISP,
1815#else
1816 (char_u *)NULL, PV_NONE,
1817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001818 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001819 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001821 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1823#else
1824 (char_u *)NULL, PV_NONE,
1825 {(char_u *)"", (char_u *)0L}
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1829 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001831 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1835 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001836 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001837 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001838#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001839 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001840 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001841#else
1842 (char_u *)NULL, PV_NONE,
1843 {(char_u *)"", (char_u *)0L}
1844#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001845 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001846 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001847#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001848 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001849 {(char_u *)TRUE, (char_u *)0L}
1850#else
1851 (char_u *)NULL, PV_NONE,
1852 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001853#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"magic", NULL, P_BOOL|P_VI_DEF,
1856 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001858 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859#ifdef FEAT_QUICKFIX
1860 (char_u *)&p_mef, PV_NONE,
1861 {(char_u *)"", (char_u *)0L}
1862#else
1863 (char_u *)NULL, PV_NONE,
1864 {(char_u *)NULL, (char_u *)0L}
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001867 {"makeencoding","menc", P_STRING|P_VI_DEF,
1868#ifdef FEAT_MBYTE
1869 (char_u *)&p_menc, PV_MENC,
1870 {(char_u *)"", (char_u *)0L}
1871#else
1872 (char_u *)NULL, PV_NONE,
1873 {(char_u *)0L, (char_u *)0L}
1874#endif
1875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1877#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001878 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879# ifdef VMS
1880 {(char_u *)"MMS", (char_u *)0L}
1881# else
1882 {(char_u *)"make", (char_u *)0L}
1883# endif
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)NULL, (char_u *)0L}
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001889 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1892 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"matchtime", "mat", P_NUM|P_VI_DEF,
1894 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001896 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001897#ifdef FEAT_MBYTE
1898 (char_u *)&p_mco, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1904#ifdef FEAT_EVAL
1905 (char_u *)&p_mfd, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1911 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"maxmem", "mm", P_NUM|P_VI_DEF,
1914 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1916 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001917 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1921 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1923 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"menuitems", "mis", P_NUM|P_VI_DEF,
1925#ifdef FEAT_MENU
1926 (char_u *)&p_mis, PV_NONE,
1927#else
1928 (char_u *)NULL, PV_NONE,
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"mesg", NULL, P_BOOL|P_VI_DEF,
1932 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001934 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001935#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001936 (char_u *)&p_msm, PV_NONE,
1937 {(char_u *)"460000,2000,500", (char_u *)0L}
1938#else
1939 (char_u *)NULL, PV_NONE,
1940 {(char_u *)0L, (char_u *)0L}
1941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001942 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"modeline", "ml", P_BOOL|P_VIM,
1944 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946 {"modelines", "mls", P_NUM|P_VI_DEF,
1947 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001949 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1950 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1953 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 {"more", NULL, P_BOOL|P_VIM,
1956 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1959 (char_u *)&p_mouse, PV_NONE,
1960 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001961#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 (char_u *)"a",
1963#else
1964 (char_u *)"",
1965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1968#ifdef FEAT_GUI
1969 (char_u *)&p_mousef, PV_NONE,
1970#else
1971 (char_u *)NULL, PV_NONE,
1972#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1975#ifdef FEAT_GUI
1976 (char_u *)&p_mh, PV_NONE,
1977#else
1978 (char_u *)NULL, PV_NONE,
1979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1982 (char_u *)&p_mousem, PV_NONE,
1983 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001984#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 (char_u *)"popup",
1986#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001987# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 (char_u *)"popup_setpos",
1989# else
1990 (char_u *)"extend",
1991# endif
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001994 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995#ifdef FEAT_MOUSESHAPE
1996 (char_u *)&p_mouseshape, PV_NONE,
1997 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1998#else
1999 (char_u *)NULL, PV_NONE,
2000 {(char_u *)NULL, (char_u *)0L}
2001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2004 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002006 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2007#if defined(DYNAMIC_MZSCHEME)
2008 (char_u *)&p_mzschemedll, PV_NONE,
2009 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2010#else
2011 (char_u *)NULL, PV_NONE,
2012 {(char_u *)"", (char_u *)0L}
2013#endif
2014 SCRIPTID_INIT},
2015 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2016#if defined(DYNAMIC_MZSCHEME)
2017 (char_u *)&p_mzschemegcdll, PV_NONE,
2018 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2019#else
2020 (char_u *)NULL, PV_NONE,
2021 {(char_u *)"", (char_u *)0L}
2022#endif
2023 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002024 {"mzquantum", "mzq", P_NUM,
2025#ifdef FEAT_MZSCHEME
2026 (char_u *)&p_mzq, PV_NONE,
2027#else
2028 (char_u *)NULL, PV_NONE,
2029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002030 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 {"novice", NULL, P_BOOL|P_VI_DEF,
2032 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002034 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002036 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2039 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002040 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002041 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2042#ifdef FEAT_LINEBREAK
2043 (char_u *)VAR_WIN, PV_NUW,
2044#else
2045 (char_u *)NULL, PV_NONE,
2046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002048 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002049#ifdef FEAT_COMPL_FUNC
2050 (char_u *)&p_ofu, PV_OFU,
2051 {(char_u *)"", (char_u *)0L}
2052#else
2053 (char_u *)NULL, PV_NONE,
2054 {(char_u *)0L, (char_u *)0L}
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 {"open", NULL, P_BOOL|P_VI_DEF,
2058 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002060 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002061#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002062 (char_u *)&p_odev, PV_NONE,
2063#else
2064 (char_u *)NULL, PV_NONE,
2065#endif
2066 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002068 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2069 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"optimize", "opt", P_BOOL|P_VI_DEF,
2072 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002076 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002077 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2078 |P_SECURE,
2079 (char_u *)&p_pp, PV_NONE,
2080 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 {"paragraphs", "para", P_STRING|P_VI_DEF,
2083 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002084 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002086 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2090 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2093#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2094 (char_u *)&p_pex, PV_NONE,
2095 {(char_u *)"", (char_u *)0L}
2096#else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)0L, (char_u *)0L}
2099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002101 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002105 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002107#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 (char_u *)".,,",
2109#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002113 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002114#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002115 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002116 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002120#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2123 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002125 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002126#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 (char_u *)&p_pvh, PV_NONE,
2128#else
2129 (char_u *)NULL, PV_NONE,
2130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002133#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 (char_u *)VAR_WIN, PV_PVW,
2135#else
2136 (char_u *)NULL, PV_NONE,
2137#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002139 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140#ifdef FEAT_PRINTER
2141 (char_u *)&p_pdev, PV_NONE,
2142 {(char_u *)"", (char_u *)0L}
2143#else
2144 (char_u *)NULL, PV_NONE,
2145 {(char_u *)NULL, (char_u *)0L}
2146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"printencoding", "penc", P_STRING|P_VI_DEF,
2149#ifdef FEAT_POSTSCRIPT
2150 (char_u *)&p_penc, PV_NONE,
2151 {(char_u *)"", (char_u *)0L}
2152#else
2153 (char_u *)NULL, PV_NONE,
2154 {(char_u *)NULL, (char_u *)0L}
2155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002156 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002157 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158#ifdef FEAT_POSTSCRIPT
2159 (char_u *)&p_pexpr, PV_NONE,
2160 {(char_u *)"", (char_u *)0L}
2161#else
2162 (char_u *)NULL, PV_NONE,
2163 {(char_u *)NULL, (char_u *)0L}
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"printfont", "pfn", P_STRING|P_VI_DEF,
2167#ifdef FEAT_PRINTER
2168 (char_u *)&p_pfn, PV_NONE,
2169 {
2170# ifdef MSWIN
2171 (char_u *)"Courier_New:h10",
2172# else
2173 (char_u *)"courier",
2174# endif
2175 (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)NULL, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2182#ifdef FEAT_PRINTER
2183 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002184 /* untranslated to avoid problems when 'encoding'
2185 * is changed */
2186 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187#else
2188 (char_u *)NULL, PV_NONE,
2189 {(char_u *)NULL, (char_u *)0L}
2190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002191 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002192 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2193#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2194 (char_u *)&p_pmcs, PV_NONE,
2195 {(char_u *)"", (char_u *)0L}
2196#else
2197 (char_u *)NULL, PV_NONE,
2198 {(char_u *)NULL, (char_u *)0L}
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002201 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2202#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2203 (char_u *)&p_pmfn, PV_NONE,
2204 {(char_u *)"", (char_u *)0L}
2205#else
2206 (char_u *)NULL, PV_NONE,
2207 {(char_u *)NULL, (char_u *)0L}
2208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002210 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211#ifdef FEAT_PRINTER
2212 (char_u *)&p_popt, PV_NONE,
2213 {(char_u *)"", (char_u *)0L}
2214#else
2215 (char_u *)NULL, PV_NONE,
2216 {(char_u *)NULL, (char_u *)0L}
2217#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002220 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002222 {"pumheight", "ph", P_NUM|P_VI_DEF,
2223#ifdef FEAT_INS_EXPAND
2224 (char_u *)&p_ph, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002229 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2230#ifdef FEAT_INS_EXPAND
2231 (char_u *)&p_pw, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002235 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002236 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002237#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002238 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002239 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002240#else
2241 (char_u *)NULL, PV_NONE,
2242 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002243#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002244 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002245 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2246#if defined(FEAT_PYTHON3)
2247 (char_u *)&p_py3home, PV_NONE,
2248 {(char_u *)"", (char_u *)0L}
2249#else
2250 (char_u *)NULL, PV_NONE,
2251 {(char_u *)NULL, (char_u *)0L}
2252#endif
2253 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002254 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002255#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002256 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002257 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258#else
2259 (char_u *)NULL, PV_NONE,
2260 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002261#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002262 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002263 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2264#if defined(FEAT_PYTHON)
2265 (char_u *)&p_pyhome, PV_NONE,
2266 {(char_u *)"", (char_u *)0L}
2267#else
2268 (char_u *)NULL, PV_NONE,
2269 {(char_u *)NULL, (char_u *)0L}
2270#endif
2271 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002272 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2273#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2274 (char_u *)&p_pyx, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
2278 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2279 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002280 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2281#ifdef FEAT_TEXTOBJ
2282 (char_u *)&p_qe, PV_QE,
2283 {(char_u *)"\\", (char_u *)0L}
2284#else
2285 (char_u *)NULL, PV_NONE,
2286 {(char_u *)NULL, (char_u *)0L}
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2290 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002291 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"redraw", NULL, P_BOOL|P_VI_DEF,
2293 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002295 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2296#ifdef FEAT_RELTIME
2297 (char_u *)&p_rdt, PV_NONE,
2298#else
2299 (char_u *)NULL, PV_NONE,
2300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002302 {"regexpengine", "re", P_NUM|P_VI_DEF,
2303 (char_u *)&p_re, PV_NONE,
2304 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002305 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2306 (char_u *)VAR_WIN, PV_RNU,
2307 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"remap", NULL, P_BOOL|P_VI_DEF,
2309 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002311 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002312#ifdef FEAT_RENDER_OPTIONS
2313 (char_u *)&p_rop, PV_NONE,
2314 {(char_u *)"", (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)NULL, (char_u *)0L}
2318#endif
2319 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"report", NULL, P_NUM|P_VI_DEF,
2321 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2324#ifdef WIN3264
2325 (char_u *)&p_rs, PV_NONE,
2326#else
2327 (char_u *)NULL, PV_NONE,
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2331#ifdef FEAT_RIGHTLEFT
2332 (char_u *)&p_ri, PV_NONE,
2333#else
2334 (char_u *)NULL, PV_NONE,
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2338#ifdef FEAT_RIGHTLEFT
2339 (char_u *)VAR_WIN, PV_RL,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2345#ifdef FEAT_RIGHTLEFT
2346 (char_u *)VAR_WIN, PV_RLC,
2347 {(char_u *)"search", (char_u *)NULL}
2348#else
2349 (char_u *)NULL, PV_NONE,
2350 {(char_u *)NULL, (char_u *)0L}
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002353 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002354#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002355 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002356 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002357#else
2358 (char_u *)NULL, PV_NONE,
2359 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002360#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2363#ifdef FEAT_CMDL_INFO
2364 (char_u *)&p_ru, PV_NONE,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2370#ifdef FEAT_STL_OPT
2371 (char_u *)&p_ruf, PV_NONE,
2372#else
2373 (char_u *)NULL, PV_NONE,
2374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002376 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2377 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002379 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2380 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2382 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002383 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2385#ifdef FEAT_SCROLLBIND
2386 (char_u *)VAR_WIN, PV_SCBIND,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2392 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2395 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002397 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398#ifdef FEAT_SCROLLBIND
2399 (char_u *)&p_sbo, PV_NONE,
2400 {(char_u *)"ver,jump", (char_u *)0L}
2401#else
2402 (char_u *)NULL, PV_NONE,
2403 {(char_u *)0L, (char_u *)0L}
2404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002405 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 {"sections", "sect", P_STRING|P_VI_DEF,
2407 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2409 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2411 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)"inclusive", (char_u *)0L}
2416 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002417 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002420 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421#ifdef FEAT_SESSION
2422 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002423 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)0L}
2425#else
2426 (char_u *)NULL, PV_NONE,
2427 {(char_u *)0L, (char_u *)0L}
2428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_sh, PV_NONE,
2432 {
2433#ifdef VMS
2434 (char_u *)"-",
2435#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002436# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002438# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440# endif
2441#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2444 (char_u *)&p_shcf, PV_NONE,
2445 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002446#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 (char_u *)"/c",
2448#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2453#ifdef FEAT_QUICKFIX
2454 (char_u *)&p_sp, PV_NONE,
2455 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002456#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458#else
2459 (char_u *)">",
2460#endif
2461 (char_u *)0L}
2462#else
2463 (char_u *)NULL, PV_NONE,
2464 {(char_u *)0L, (char_u *)0L}
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2468 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2471 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2474#ifdef BACKSLASH_IN_FILENAME
2475 (char_u *)&p_ssl, PV_NONE,
2476#else
2477 (char_u *)NULL, PV_NONE,
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002480 {"shelltemp", "stmp", P_BOOL,
2481 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"shelltype", "st", P_NUM|P_VI_DEF,
2484#ifdef AMIGA
2485 (char_u *)&p_st, PV_NONE,
2486#else
2487 (char_u *)NULL, PV_NONE,
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2491 (char_u *)&p_sxq, PV_NONE,
2492 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002493#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 (char_u *)"\"",
2495#else
2496 (char_u *)"",
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002499 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2500 (char_u *)&p_sxe, PV_NONE,
2501 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002502#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002503 (char_u *)"\"&|<>()@^",
2504#else
2505 (char_u *)"",
2506#endif
2507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2509 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2512 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002513 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2515 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 {(char_u *)"", (char_u *)"filnxtToO"}
2517 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2522#ifdef FEAT_LINEBREAK
2523 (char_u *)&p_sbr, PV_NONE,
2524#else
2525 (char_u *)NULL, PV_NONE,
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"showcmd", "sc", P_BOOL|P_VIM,
2529#ifdef FEAT_CMDL_INFO
2530 (char_u *)&p_sc, PV_NONE,
2531#else
2532 (char_u *)NULL, PV_NONE,
2533#endif
2534 {(char_u *)FALSE,
2535#ifdef UNIX
2536 (char_u *)FALSE
2537#else
2538 (char_u *)TRUE
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2542 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2545 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"showmode", "smd", P_BOOL|P_VIM,
2548 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002550 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002551 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2554 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2557 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002559 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2560#ifdef FEAT_SIGNS
2561 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002562 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002563#else
2564 (char_u *)NULL, PV_NONE,
2565 {(char_u *)NULL, (char_u *)0L}
2566#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002567 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2569 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2572 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2575#ifdef FEAT_SMARTINDENT
2576 (char_u *)&p_si, PV_SI,
2577#else
2578 (char_u *)NULL, PV_NONE,
2579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2582 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2585 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2588 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002591#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002592 (char_u *)VAR_WIN, PV_SPELL,
2593#else
2594 (char_u *)NULL, PV_NONE,
2595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002597 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002598#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002599 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002600 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002601#else
2602 (char_u *)NULL, PV_NONE,
2603 {(char_u *)0L, (char_u *)0L}
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002606 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2607 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002608#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002609 (char_u *)&p_spf, PV_SPF,
2610 {(char_u *)"", (char_u *)0L}
2611#else
2612 (char_u *)NULL, PV_NONE,
2613 {(char_u *)0L, (char_u *)0L}
2614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002616 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2617 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002618#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002619 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002620 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002621#else
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}
2624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002626 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002627#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002628 (char_u *)&p_sps, PV_NONE,
2629 {(char_u *)"best", (char_u *)0L}
2630#else
2631 (char_u *)NULL, PV_NONE,
2632 {(char_u *)0L, (char_u *)0L}
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2642 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2645#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002646 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647#else
2648 (char_u *)NULL, PV_NONE,
2649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002651 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 (char_u *)&p_su, PV_NONE,
2653 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002655 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002656#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 (char_u *)&p_sua, PV_SUA,
2658 {(char_u *)"", (char_u *)0L}
2659#else
2660 (char_u *)NULL, PV_NONE,
2661 {(char_u *)0L, (char_u *)0L}
2662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2665 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"swapsync", "sws", P_STRING|P_VI_DEF,
2668 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002670 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002673 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2674#ifdef FEAT_SYN_HL
2675 (char_u *)&p_smc, PV_SMC,
2676 {(char_u *)3000L, (char_u *)0L}
2677#else
2678 (char_u *)NULL, PV_NONE,
2679 {(char_u *)0L, (char_u *)0L}
2680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002682 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#ifdef FEAT_SYN_HL
2684 (char_u *)&p_syn, PV_SYN,
2685 {(char_u *)"", (char_u *)0L}
2686#else
2687 (char_u *)NULL, PV_NONE,
2688 {(char_u *)0L, (char_u *)0L}
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002691 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2692#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002693 (char_u *)&p_tal, PV_NONE,
2694#else
2695 (char_u *)NULL, PV_NONE,
2696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002698 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002699 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2702 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2705 (char_u *)&p_tbs, PV_NONE,
2706#ifdef VMS /* binary searching doesn't appear to work on VMS */
2707 {(char_u *)0L, (char_u *)0L}
2708#else
2709 {(char_u *)TRUE, (char_u *)0L}
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002712 {"tagcase", "tc", P_STRING|P_VIM,
2713 (char_u *)&p_tc, PV_TC,
2714 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"taglength", "tl", P_NUM|P_VI_DEF,
2716 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"tagrelative", "tr", P_BOOL|P_VIM,
2719 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002721 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002722 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {
2724#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2725 (char_u *)"./tags,./TAGS,tags,TAGS",
2726#else
2727 (char_u *)"./tags,tags",
2728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2731 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002733 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002734#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002735 (char_u *)&p_tcldll, PV_NONE,
2736 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002737#else
2738 (char_u *)NULL, PV_NONE,
2739 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002740#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2743 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2746#ifdef FEAT_ARABIC
2747 (char_u *)&p_tbidi, PV_NONE,
2748#else
2749 (char_u *)NULL, PV_NONE,
2750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2753#ifdef FEAT_MBYTE
2754 (char_u *)&p_tenc, PV_NONE,
2755 {(char_u *)"", (char_u *)0L}
2756#else
2757 (char_u *)NULL, PV_NONE,
2758 {(char_u *)0L, (char_u *)0L}
2759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002761 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2762#ifdef FEAT_TERMGUICOLORS
2763 (char_u *)&p_tgc, PV_NONE,
2764 {(char_u *)FALSE, (char_u *)FALSE}
2765#else
2766 (char_u*)NULL, PV_NONE,
2767 {(char_u *)FALSE, (char_u *)FALSE}
2768#endif
2769 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002770 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2771#ifdef FEAT_TERMINAL
2772 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002773 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002774#else
2775 (char_u *)NULL, PV_NONE,
2776 {(char_u *)NULL, (char_u *)0L}
2777#endif
2778 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002779 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2780#ifdef FEAT_TERMINAL
2781 (char_u *)VAR_WIN, PV_TMS,
2782 {(char_u *)"", (char_u *)NULL}
2783#else
2784 (char_u *)NULL, PV_NONE,
2785 {(char_u *)NULL, (char_u *)0L}
2786#endif
2787 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"terse", NULL, P_BOOL|P_VI_DEF,
2789 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"textauto", "ta", P_BOOL|P_VIM,
2792 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2796 (char_u *)&p_tx, PV_TX,
2797 {
2798#ifdef USE_CRNL
2799 (char_u *)TRUE,
2800#else
2801 (char_u *)FALSE,
2802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002804 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002807 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002809 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810#else
2811 (char_u *)NULL, PV_NONE,
2812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2815 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"timeout", "to", P_BOOL|P_VI_DEF,
2818 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2821 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"title", NULL, P_BOOL|P_VI_DEF,
2824#ifdef FEAT_TITLE
2825 (char_u *)&p_title, PV_NONE,
2826#else
2827 (char_u *)NULL, PV_NONE,
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"titlelen", NULL, P_NUM|P_VI_DEF,
2831#ifdef FEAT_TITLE
2832 (char_u *)&p_titlelen, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002837 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838#ifdef FEAT_TITLE
2839 (char_u *)&p_titleold, PV_NONE,
2840 {(char_u *)N_("Thanks for flying Vim"),
2841 (char_u *)0L}
2842#else
2843 (char_u *)NULL, PV_NONE,
2844 {(char_u *)0L, (char_u *)0L}
2845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"titlestring", NULL, P_STRING|P_VI_DEF,
2848#ifdef FEAT_TITLE
2849 (char_u *)&p_titlestring, PV_NONE,
2850#else
2851 (char_u *)NULL, PV_NONE,
2852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002854 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002855#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858#else
2859 (char_u *)NULL, PV_NONE,
2860 {(char_u *)0L, (char_u *)0L}
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002864#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002866 {(char_u *)"small", (char_u *)0L}
2867#else
2868 (char_u *)NULL, PV_NONE,
2869 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2873 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002874 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2876 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2879 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2882 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2885#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2886 (char_u *)&p_ttym, PV_NONE,
2887#else
2888 (char_u *)NULL, PV_NONE,
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2892 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2895 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002897 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2898 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002899#ifdef FEAT_PERSISTENT_UNDO
2900 (char_u *)&p_udir, PV_NONE,
2901 {(char_u *)".", (char_u *)0L}
2902#else
2903 (char_u *)NULL, PV_NONE,
2904 {(char_u *)0L, (char_u *)0L}
2905#endif
2906 SCRIPTID_INIT},
2907 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2908#ifdef FEAT_PERSISTENT_UNDO
2909 (char_u *)&p_udf, PV_UDF,
2910#else
2911 (char_u *)NULL, PV_NONE,
2912#endif
2913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002915 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002917#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 (char_u *)1000L,
2919#else
2920 (char_u *)100L,
2921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002923 {"undoreload", "ur", P_NUM|P_VI_DEF,
2924 (char_u *)&p_ur, PV_NONE,
2925 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"updatecount", "uc", P_NUM|P_VI_DEF,
2927 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"updatetime", "ut", P_NUM|P_VI_DEF,
2930 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"verbose", "vbs", P_NUM|P_VI_DEF,
2933 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002935 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2936 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2939#ifdef FEAT_SESSION
2940 (char_u *)&p_vdir, PV_NONE,
2941 {(char_u *)DFLT_VDIR, (char_u *)0L}
2942#else
2943 (char_u *)NULL, PV_NONE,
2944 {(char_u *)0L, (char_u *)0L}
2945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002946 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002947 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948#ifdef FEAT_SESSION
2949 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002950 {(char_u *)"folds,options,cursor,curdir",
2951 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952#else
2953 (char_u *)NULL, PV_NONE,
2954 {(char_u *)0L, (char_u *)0L}
2955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002956 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002957 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958#ifdef FEAT_VIMINFO
2959 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002960#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002961 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962#else
2963# ifdef AMIGA
2964 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002965 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002967 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968# endif
2969#endif
2970#else
2971 (char_u *)NULL, PV_NONE,
2972 {(char_u *)0L, (char_u *)0L}
2973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002974 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002975 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2976#ifdef FEAT_VIMINFO
2977 (char_u *)&p_viminfofile, PV_NONE,
2978 {(char_u *)"", (char_u *)0L}
2979#else
2980 (char_u *)NULL, PV_NONE,
2981 {(char_u *)0L, (char_u *)0L}
2982#endif
2983 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002984 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2985 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986#ifdef FEAT_VIRTUALEDIT
2987 (char_u *)&p_ve, PV_NONE,
2988 {(char_u *)"", (char_u *)""}
2989#else
2990 (char_u *)NULL, PV_NONE,
2991 {(char_u *)0L, (char_u *)0L}
2992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2995 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"w300", NULL, P_NUM|P_VI_DEF,
2998 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 {"w1200", NULL, P_NUM|P_VI_DEF,
3001 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"w9600", NULL, P_NUM|P_VI_DEF,
3004 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 {"warn", NULL, P_BOOL|P_VI_DEF,
3007 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003008 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3010 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003012 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003014 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"wildchar", "wc", P_NUM|P_VIM,
3016 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3018 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003019 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003022 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023#ifdef FEAT_WILDIGN
3024 (char_u *)&p_wig, PV_NONE,
3025#else
3026 (char_u *)NULL, PV_NONE,
3027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003029 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3030 (char_u *)&p_wic, PV_NONE,
3031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3033#ifdef FEAT_WILDMENU
3034 (char_u *)&p_wmnu, PV_NONE,
3035#else
3036 (char_u *)NULL, PV_NONE,
3037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003039 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003042 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3043#ifdef FEAT_CMDL_COMPL
3044 (char_u *)&p_wop, PV_NONE,
3045 {(char_u *)"", (char_u *)0L}
3046#else
3047 (char_u *)NULL, PV_NONE,
3048 {(char_u *)NULL, (char_u *)0L}
3049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3052#ifdef FEAT_WAK
3053 (char_u *)&p_wak, PV_NONE,
3054 {(char_u *)"menu", (char_u *)0L}
3055#else
3056 (char_u *)NULL, PV_NONE,
3057 {(char_u *)NULL, (char_u *)0L}
3058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003061 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003062 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003068 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003069 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003070 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003071 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003074 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003077 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003078 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003079#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003080 (char_u *)&p_winptydll, PV_NONE, {
3081# ifdef _WIN64
3082 (char_u *)"winpty64.dll",
3083# else
3084 (char_u *)"winpty32.dll",
3085# endif
3086 (char_u *)0L}
3087#else
3088 (char_u *)NULL, PV_NONE,
3089 {(char_u *)0L, (char_u *)0L}
3090#endif
3091 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3096 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3099 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3102 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 {"write", NULL, P_BOOL|P_VI_DEF,
3105 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"writeany", "wa", P_BOOL|P_VI_DEF,
3108 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3111 (char_u *)&p_wb, PV_NONE,
3112 {
3113#ifdef FEAT_WRITEBACKUP
3114 (char_u *)TRUE,
3115#else
3116 (char_u *)FALSE,
3117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 {"writedelay", "wd", P_NUM|P_VI_DEF,
3120 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003121 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122
3123/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003124#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003126 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127
3128 p_term("t_AB", T_CAB)
3129 p_term("t_AF", T_CAF)
3130 p_term("t_AL", T_CAL)
3131 p_term("t_al", T_AL)
3132 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_BE", T_BE)
3134 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_cd", T_CD)
3136 p_term("t_ce", T_CE)
3137 p_term("t_cl", T_CL)
3138 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003139 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 p_term("t_Co", T_CCO)
3141 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003142 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 p_term("t_da", T_DA)
3146 p_term("t_db", T_DB)
3147 p_term("t_DL", T_CDL)
3148 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003149 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003150 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_IE", T_CIE)
3154 p_term("t_IS", T_CIS)
3155 p_term("t_ke", T_KE)
3156 p_term("t_ks", T_KS)
3157 p_term("t_le", T_LE)
3158 p_term("t_mb", T_MB)
3159 p_term("t_md", T_MD)
3160 p_term("t_me", T_ME)
3161 p_term("t_mr", T_MR)
3162 p_term("t_ms", T_MS)
3163 p_term("t_nd", T_ND)
3164 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003165 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003167 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003169 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_RV", T_CRV)
3171 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003172 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003174 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003178 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003180 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_te", T_TE)
3182 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003183 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003184 p_term("t_ts", T_TS)
3185 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 p_term("t_ue", T_UE)
3187 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003188 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_vb", T_VB)
3190 p_term("t_ve", T_VE)
3191 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003192 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_vs", T_VS)
3194 p_term("t_WP", T_CWP)
3195 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003196 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 p_term("t_xs", T_XS)
3198 p_term("t_ZH", T_CZH)
3199 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003200 p_term("t_8f", T_8F)
3201 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202
3203/* terminal key codes are not in here */
3204
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003205 /* end marker */
3206 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207};
3208
3209#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3210
3211#ifdef FEAT_MBYTE
3212static char *(p_ambw_values[]) = {"single", "double", NULL};
3213#endif
3214static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003215static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003217#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003218static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003219#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003220#ifdef FEAT_CMDL_COMPL
3221static char *(p_wop_values[]) = {"tagfile", NULL};
3222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223#ifdef FEAT_WAK
3224static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3225#endif
3226static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3228static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#ifdef FEAT_BROWSE
3231static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3232#endif
3233#ifdef FEAT_SCROLLBIND
3234static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3235#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003236static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003238static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003239static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3241#ifdef FEAT_FOLDING
3242static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 NULL};
3247static char *(p_fcl_values[]) = {"all", NULL};
3248#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003249#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003250static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003251#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003252#ifdef FEAT_SIGNS
3253static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void set_option_default(int, int opt_flags, int compatible);
3257static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003258static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static char_u *term_bg_default(void);
3260static void did_set_option(int opt_idx, int opt_flags, int new_value);
3261static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264#endif
3265#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static char_u *option_expand(int opt_idx, char_u *val);
3269static void didset_options(void);
3270static void didset_options2(void);
3271static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003272#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003274#else
3275# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3276#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void set_string_option_global(int opt_idx, char_u **varp);
3278static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3279static 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);
3280static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003281#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003287#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static char_u *did_set_spell_option(int is_spellfile);
3289static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003290#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003291#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003293#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3295static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3296static void check_redraw(long_u flags);
3297static int findoption(char_u *);
3298static int find_key_option(char_u *);
3299static void showoptions(int all, int opt_flags);
3300static int optval_default(struct vimoption *, char_u *varp);
3301static void showoneopt(struct vimoption *, int opt_flags);
3302static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3303static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3304static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3305static int istermoption(struct vimoption *);
3306static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3307static char_u *get_varp(struct vimoption *);
3308static void option_value2string(struct vimoption *, int opt_flags);
3309static void check_winopt(winopt_T *wop);
3310static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static void langmap_init(void);
3313static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static void paste_option_changed(void);
3316static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003320static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3321static int check_opt_strings(char_u *val, char **values, int);
3322static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003323#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
3327/*
3328 * Initialize the options, first part.
3329 *
3330 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003331 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 */
3333 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003334set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335{
3336 char_u *p;
3337 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003338 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339
3340#ifdef FEAT_LANGMAP
3341 langmap_init();
3342#endif
3343
3344 /* Be Vi compatible by default */
3345 p_cp = TRUE;
3346
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003347 /* Use POSIX compatibility when $VIM_POSIX is set. */
3348 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003349 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003350 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003351 set_string_default("shm", (char_u *)"A");
3352 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003353
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 /*
3355 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003358 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003359#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003360 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003362 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363# endif
3364#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003365 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003366 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367
3368#ifdef FEAT_WILDIGN
3369 /*
3370 * Set the default for 'backupskip' to include environment variables for
3371 * temp files.
3372 */
3373 {
3374# ifdef UNIX
3375 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3376# else
3377 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3378# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003379 int len;
3380 garray_T ga;
3381 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382
3383 ga_init2(&ga, 1, 100);
3384 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3385 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003386 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387# ifdef UNIX
3388 if (*names[n] == NUL)
3389 p = (char_u *)"/tmp";
3390 else
3391# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003392 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 if (p != NULL && *p != NUL)
3394 {
3395 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003396 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 if (ga_grow(&ga, len) == OK)
3398 {
3399 if (ga.ga_len > 0)
3400 STRCAT(ga.ga_data, ",");
3401 STRCAT(ga.ga_data, p);
3402 add_pathsep(ga.ga_data);
3403 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 ga.ga_len += len;
3405 }
3406 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003407 if (mustfree)
3408 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 }
3410 if (ga.ga_data != NULL)
3411 {
3412 set_string_default("bsk", ga.ga_data);
3413 vim_free(ga.ga_data);
3414 }
3415 }
3416#endif
3417
3418 /*
3419 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3420 */
3421 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003422 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3425 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3426#endif
3427 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003429 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003430 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431#else
3432# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003433 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003434 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003436 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437# endif
3438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003440 opt_idx = findoption((char_u *)"maxmem");
3441 if (opt_idx >= 0)
3442 {
3443#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003444 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3445 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446#endif
3447 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3448 }
3449 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 }
3451
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452#ifdef FEAT_SEARCHPATH
3453 {
3454 char_u *cdpath;
3455 char_u *buf;
3456 int i;
3457 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003458 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459
3460 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003461 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 if (cdpath != NULL)
3463 {
3464 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3465 if (buf != NULL)
3466 {
3467 buf[0] = ','; /* start with ",", current dir first */
3468 j = 1;
3469 for (i = 0; cdpath[i] != NUL; ++i)
3470 {
3471 if (vim_ispathlistsep(cdpath[i]))
3472 buf[j++] = ',';
3473 else
3474 {
3475 if (cdpath[i] == ' ' || cdpath[i] == ',')
3476 buf[j++] = '\\';
3477 buf[j++] = cdpath[i];
3478 }
3479 }
3480 buf[j] = NUL;
3481 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003482 if (opt_idx >= 0)
3483 {
3484 options[opt_idx].def_val[VI_DEFAULT] = buf;
3485 options[opt_idx].flags |= P_DEF_ALLOCED;
3486 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003487 else
3488 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003490 if (mustfree)
3491 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 }
3493 }
3494#endif
3495
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003496#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 /* Set print encoding on platforms that don't default to latin1 */
3498 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003499# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 (char_u *)"cp1252"
3501# else
3502# ifdef VMS
3503 (char_u *)"dec-mcs"
3504# else
3505# ifdef EBCDIC
3506 (char_u *)"ebcdic-uk"
3507# else
3508# ifdef MAC
3509 (char_u *)"mac-roman"
3510# else /* HPUX */
3511 (char_u *)"hp-roman8"
3512# endif
3513# endif
3514# endif
3515# endif
3516 );
3517#endif
3518
3519#ifdef FEAT_POSTSCRIPT
3520 /* 'printexpr' must be allocated to be able to evaluate it. */
3521 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003522# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003523 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524# else
3525# ifdef VMS
3526 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3527
3528# else
3529 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3530# endif
3531# endif
3532 );
3533#endif
3534
3535 /*
3536 * Set all the options (except the terminal options) to their default
3537 * value. Also set the global value for local options.
3538 */
3539 set_options_default(0);
3540
Bram Moolenaar07268702018-03-01 21:57:32 +01003541#ifdef CLEAN_RUNTIMEPATH
3542 if (clean_arg)
3543 {
3544 opt_idx = findoption((char_u *)"runtimepath");
3545 if (opt_idx >= 0)
3546 {
3547 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3548 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3549 }
3550 opt_idx = findoption((char_u *)"packpath");
3551 if (opt_idx >= 0)
3552 {
3553 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3554 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3555 }
3556 }
3557#endif
3558
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559#ifdef FEAT_GUI
3560 if (found_reverse_arg)
3561 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3562#endif
3563
3564 curbuf->b_p_initialized = TRUE;
3565 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003566 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003567 check_buf_options(curbuf);
3568 check_win_options(curwin);
3569 check_options();
3570
3571 /* Must be before option_expand(), because that one needs vim_isIDc() */
3572 didset_options();
3573
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003574#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003575 /* Use the current chartab for the generic chartab. This is not in
3576 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003577 init_spell_chartab();
3578#endif
3579
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580 /*
3581 * Expand environment variables and things like "~" for the defaults.
3582 * If option_expand() returns non-NULL the variable is expanded. This can
3583 * only happen for non-indirect options.
3584 * Also set the default to the expanded value, so ":set" does not list
3585 * them.
3586 * Don't set the P_ALLOCED flag, because we don't want to free the
3587 * default.
3588 */
3589 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3590 {
3591 if ((options[opt_idx].flags & P_GETTEXT)
3592 && options[opt_idx].var != NULL)
3593 p = (char_u *)_(*(char **)options[opt_idx].var);
3594 else
3595 p = option_expand(opt_idx, NULL);
3596 if (p != NULL && (p = vim_strsave(p)) != NULL)
3597 {
3598 *(char_u **)options[opt_idx].var = p;
3599 /* VIMEXP
3600 * Defaults for all expanded options are currently the same for Vi
3601 * and Vim. When this changes, add some code here! Also need to
3602 * split P_DEF_ALLOCED in two.
3603 */
3604 if (options[opt_idx].flags & P_DEF_ALLOCED)
3605 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3606 options[opt_idx].def_val[VI_DEFAULT] = p;
3607 options[opt_idx].flags |= P_DEF_ALLOCED;
3608 }
3609 }
3610
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 save_file_ff(curbuf); /* Buffer is unchanged */
3612
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613#if defined(FEAT_ARABIC)
3614 /* Detect use of mlterm.
3615 * Mlterm is a terminal emulator akin to xterm that has some special
3616 * abilities (bidi namely).
3617 * NOTE: mlterm's author is being asked to 'set' a variable
3618 * instead of an environment variable due to inheritance.
3619 */
3620 if (mch_getenv((char_u *)"MLTERM") != NULL)
3621 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3622#endif
3623
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003624 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625
3626#ifdef FEAT_MBYTE
3627# if defined(WIN3264) && defined(FEAT_GETTEXT)
3628 /*
3629 * If $LANG isn't set, try to get a good value for it. This makes the
3630 * right language be used automatically. Don't do this for English.
3631 */
3632 if (mch_getenv((char_u *)"LANG") == NULL)
3633 {
3634 char buf[20];
3635
3636 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3637 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3638 * only the first two. */
3639 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3640 (LPTSTR)buf, 20);
3641 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3642 {
3643 /* There are a few exceptions (probably more) */
3644 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3645 STRCPY(buf, "zh_TW");
3646 else if (STRNICMP(buf, "chs", 3) == 0
3647 || STRNICMP(buf, "zhc", 3) == 0)
3648 STRCPY(buf, "zh_CN");
3649 else if (STRNICMP(buf, "jp", 2) == 0)
3650 STRCPY(buf, "ja");
3651 else
3652 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003653 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 }
3655 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003656# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003657# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003658 /* Moved to os_mac_conv.c to avoid dependency problems. */
3659 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003660# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661# endif
3662
3663 /* enc_locale() will try to find the encoding of the current locale. */
3664 p = enc_locale();
3665 if (p != NULL)
3666 {
3667 char_u *save_enc;
3668
3669 /* Try setting 'encoding' and check if the value is valid.
3670 * If not, go back to the default "latin1". */
3671 save_enc = p_enc;
3672 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003673 if (STRCMP(p_enc, "gb18030") == 0)
3674 {
3675 /* We don't support "gb18030", but "cp936" is a good substitute
3676 * for practical purposes, thus use that. It's not an alias to
3677 * still support conversion between gb18030 and utf-8. */
3678 p_enc = vim_strsave((char_u *)"cp936");
3679 vim_free(p);
3680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 if (mb_init() == NULL)
3682 {
3683 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003684 if (opt_idx >= 0)
3685 {
3686 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3687 options[opt_idx].flags |= P_DEF_ALLOCED;
3688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689
Bram Moolenaard0573012017-10-28 21:11:06 +02003690#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003691 if (STRCMP(p_enc, "latin1") == 0
3692# ifdef FEAT_MBYTE
3693 || enc_utf8
3694# endif
3695 )
3696 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003697 /* Adjust the default for 'isprint' and 'iskeyword' to match
3698 * latin1. Also set the defaults for when 'nocompatible' is
3699 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003700 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003701 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003702 set_string_option_direct((char_u *)"isk", -1,
3703 ISK_LATIN1, OPT_FREE, SID_NONE);
3704 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003705 if (opt_idx >= 0)
3706 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003707 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003708 if (opt_idx >= 0)
3709 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003710 (void)init_chartab();
3711 }
3712#endif
3713
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714# if defined(WIN3264) && !defined(FEAT_GUI)
3715 /* Win32 console: When GetACP() returns a different value from
3716 * GetConsoleCP() set 'termencoding'. */
3717 if (GetACP() != GetConsoleCP())
3718 {
3719 char buf[50];
3720
3721 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3722 p_tenc = vim_strsave((char_u *)buf);
3723 if (p_tenc != NULL)
3724 {
3725 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003726 if (opt_idx >= 0)
3727 {
3728 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3729 options[opt_idx].flags |= P_DEF_ALLOCED;
3730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 convert_setup(&input_conv, p_tenc, p_enc);
3732 convert_setup(&output_conv, p_enc, p_tenc);
3733 }
3734 else
3735 p_tenc = empty_option;
3736 }
3737# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003738# if defined(WIN3264) && defined(FEAT_MBYTE)
3739 /* $HOME may have characters in active code page. */
3740 init_homedir();
3741# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 }
3743 else
3744 {
3745 vim_free(p_enc);
3746 p_enc = save_enc;
3747 }
3748 }
3749#endif
3750
3751#ifdef FEAT_MULTI_LANG
3752 /* Set the default for 'helplang'. */
3753 set_helplang_default(get_mess_lang());
3754#endif
3755}
3756
3757/*
3758 * Set an option to its default value.
3759 * This does not take care of side effects!
3760 */
3761 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003762set_option_default(
3763 int opt_idx,
3764 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3765 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766{
3767 char_u *varp; /* pointer to variable for current option */
3768 int dvi; /* index in def_val[] */
3769 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003770 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3772
3773 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3774 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003775 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 {
3777 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3778 if (flags & P_STRING)
3779 {
3780 /* Use set_string_option_direct() for local options to handle
3781 * freeing and allocating the value. */
3782 if (options[opt_idx].indir != PV_NONE)
3783 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003784 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 else
3786 {
3787 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3788 free_string_option(*(char_u **)(varp));
3789 *(char_u **)varp = options[opt_idx].def_val[dvi];
3790 options[opt_idx].flags &= ~P_ALLOCED;
3791 }
3792 }
3793 else if (flags & P_NUM)
3794 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003795 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 win_comp_scroll(curwin);
3797 else
3798 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003799 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 /* May also set global value for local option. */
3801 if (both)
3802 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3803 *(long *)varp;
3804 }
3805 }
3806 else /* P_BOOL */
3807 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003808 /* the cast to long is required for Manx C, long_i is needed for
3809 * MSVC */
3810 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003811#ifdef UNIX
3812 /* 'modeline' defaults to off for root */
3813 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3814 *(int *)varp = FALSE;
3815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 /* May also set global value for local option. */
3817 if (both)
3818 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3819 *(int *)varp;
3820 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003821
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003822 /* The default value is not insecure. */
3823 flagsp = insecure_flag(opt_idx, opt_flags);
3824 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 }
3826
3827#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003828 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829#endif
3830}
3831
3832/*
3833 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003834 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 */
3836 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003837set_options_default(
3838 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839{
3840 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003842 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843
3844 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003845 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003846#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003847 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003848 || (TRUE
3849# if defined(FEAT_MBYTE)
3850 && options[i].var != (char_u *)&p_enc
3851# endif
3852# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003853 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003854 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003855# endif
3856 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003857#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003858 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 set_option_default(i, opt_flags, p_cp);
3860
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003862 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003864#ifdef FEAT_CINDENT
3865 parse_cino(curbuf);
3866#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867}
3868
3869/*
3870 * Set the Vi-default value of a string option.
3871 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003872 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003874 static void
3875set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876{
3877 char_u *p;
3878 int opt_idx;
3879
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003880 if (escape && vim_strchr(val, ' ') != NULL)
3881 p = vim_strsave_escaped(val, (char_u *)" ");
3882 else
3883 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 if (p != NULL) /* we don't want a NULL */
3885 {
3886 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003887 if (opt_idx >= 0)
3888 {
3889 if (options[opt_idx].flags & P_DEF_ALLOCED)
3890 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3891 options[opt_idx].def_val[VI_DEFAULT] = p;
3892 options[opt_idx].flags |= P_DEF_ALLOCED;
3893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 }
3895}
3896
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003897 void
3898set_string_default(char *name, char_u *val)
3899{
3900 set_string_default_esc(name, val, FALSE);
3901}
3902
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903/*
3904 * Set the Vi-default value of a number option.
3905 * Used for 'lines' and 'columns'.
3906 */
3907 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003908set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003910 int opt_idx;
3911
3912 opt_idx = findoption((char_u *)name);
3913 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003914 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915}
3916
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003917#if defined(EXITFREE) || defined(PROTO)
3918/*
3919 * Free all options.
3920 */
3921 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003922free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003923{
3924 int i;
3925
3926 for (i = 0; !istermoption(&options[i]); i++)
3927 {
3928 if (options[i].indir == PV_NONE)
3929 {
3930 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003931 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003932 free_string_option(*(char_u **)options[i].var);
3933 if (options[i].flags & P_DEF_ALLOCED)
3934 free_string_option(options[i].def_val[VI_DEFAULT]);
3935 }
3936 else if (options[i].var != VAR_WIN
3937 && (options[i].flags & P_STRING))
3938 /* buffer-local option: free global value */
3939 free_string_option(*(char_u **)options[i].var);
3940 }
3941}
3942#endif
3943
3944
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945/*
3946 * Initialize the options, part two: After getting Rows and Columns and
3947 * setting 'term'.
3948 */
3949 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003950set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003952 int idx;
3953
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003955 * 'scroll' defaults to half the window height. The stored default is zero,
3956 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003958 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003959 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003960 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 comp_col();
3962
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003963 /*
3964 * 'window' is only for backwards compatibility with Vi.
3965 * Default is Rows - 1.
3966 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003967 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003968 p_window = Rows - 1;
3969 set_number_default("window", Rows - 1);
3970
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003972#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003973 /*
3974 * If 'background' wasn't set by the user, try guessing the value,
3975 * depending on the terminal name. Only need to check for terminals
3976 * with a dark background, that can handle color.
3977 */
3978 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003979 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3980 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003982 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003983 /* don't mark it as set, when starting the GUI it may be
3984 * changed again */
3985 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 }
3987#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003988
3989#ifdef CURSOR_SHAPE
3990 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3991#endif
3992#ifdef FEAT_MOUSESHAPE
3993 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3994#endif
3995#ifdef FEAT_PRINTER
3996 (void)parse_printoptions(); /* parse 'printoptions' default value */
3997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998}
3999
4000/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004001 * Return "dark" or "light" depending on the kind of terminal.
4002 * This is just guessing! Recognized are:
4003 * "linux" Linux console
4004 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004005 * "cygwin.*" Cygwin shell
4006 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004007 * We also check the COLORFGBG environment variable, which is set by
4008 * rxvt and derivatives. This variable contains either two or three
4009 * values separated by semicolons; we want the last value in either
4010 * case. If this value is 0-6 or 8, our background is dark.
4011 */
4012 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004013term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004014{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004015#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004016 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004017 return (char_u *)"dark";
4018#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004019 char_u *p;
4020
Bram Moolenaarf740b292006-02-16 22:11:02 +00004021 if (STRCMP(T_NAME, "linux") == 0
4022 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004023 || STRNCMP(T_NAME, "cygwin", 6) == 0
4024 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004025 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4026 && (p = vim_strrchr(p, ';')) != NULL
4027 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4028 && p[2] == NUL))
4029 return (char_u *)"dark";
4030 return (char_u *)"light";
4031#endif
4032}
4033
4034/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 * Initialize the options, part three: After reading the .vimrc
4036 */
4037 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004038set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041/*
4042 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4043 * This is done after other initializations, where 'shell' might have been
4044 * set, but only if they have not been set before.
4045 */
4046 char_u *p;
4047 int idx_srr;
4048 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004049# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 int idx_sp;
4051 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053
4054 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004055 if (idx_srr < 0)
4056 do_srr = FALSE;
4057 else
4058 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004061 if (idx_sp < 0)
4062 do_sp = FALSE;
4063 else
4064 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004066 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 if (p != NULL)
4068 {
4069 /*
4070 * Default for p_sp is "| tee", for p_srr is ">".
4071 * For known shells it is changed here to include stderr.
4072 */
4073 if ( fnamecmp(p, "csh") == 0
4074 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "csh.exe") == 0
4077 || fnamecmp(p, "tcsh.exe") == 0
4078# endif
4079 )
4080 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 if (do_sp)
4083 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4090 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (do_srr)
4093 {
4094 p_srr = (char_u *)">&";
4095 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4096 }
4097 }
4098 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 if ( fnamecmp(p, "sh") == 0
4101 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004102 || fnamecmp(p, "mksh") == 0
4103 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004105 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004107 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 || fnamecmp(p, "cmd") == 0
4110 || fnamecmp(p, "sh.exe") == 0
4111 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004112 || fnamecmp(p, "mksh.exe") == 0
4113 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004115 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 || fnamecmp(p, "bash.exe") == 0
4117 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004121# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 if (do_sp)
4123 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4130 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004131# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 if (do_srr)
4133 {
4134 p_srr = (char_u *)">%s 2>&1";
4135 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4136 }
4137 }
4138 vim_free(p);
4139 }
4140#endif
4141
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004142#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004144 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4145 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 * This is done after other initializations, where 'shell' might have been
4147 * set, but only if they have not been set before. Default for p_shcf is
4148 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004149 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004151 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 {
4153 int idx3;
4154
4155 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004156 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158 p_shcf = (char_u *)"-c";
4159 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4160 }
4161
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 /* Somehow Win32 requires the quotes around the redirection too */
4163 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004164 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 {
4166 p_sxq = (char_u *)"\"";
4167 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004170 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4171 {
4172 int idx3;
4173
4174 /*
4175 * cmd.exe on Windows will strip the first and last double quote given
4176 * on the command line, e.g. most of the time things like:
4177 * cmd /c "my path/to/echo" "my args to echo"
4178 * become:
4179 * my path/to/echo" "my args to echo
4180 * when executed.
4181 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004182 * To avoid this, set shellxquote to surround the command in
4183 * parenthesis. This appears to make most commands work, without
4184 * breaking commands that worked previously, such as
4185 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004186 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004187 idx3 = findoption((char_u *)"sxq");
4188 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4189 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004190 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004191 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4192 }
4193
Bram Moolenaara64ba222012-02-12 23:23:31 +01004194 idx3 = findoption((char_u *)"shcf");
4195 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4196 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004197 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004198 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4199 }
4200 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201#endif
4202
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004203 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004204 {
4205 int idx_ffs = findoption((char_u *)"ffs");
4206
4207 /* Apply the first entry of 'fileformats' to the initial buffer. */
4208 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4209 set_fileformat(default_fileformat(), OPT_LOCAL);
4210 }
4211
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212#ifdef FEAT_TITLE
4213 set_title_defaults();
4214#endif
4215}
4216
4217#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4218/*
4219 * When 'helplang' is still at its default value, set it to "lang".
4220 * Only the first two characters of "lang" are used.
4221 */
4222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004223set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224{
4225 int idx;
4226
4227 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4228 return;
4229 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004230 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 {
4232 if (options[idx].flags & P_ALLOCED)
4233 free_string_option(p_hlg);
4234 p_hlg = vim_strsave(lang);
4235 if (p_hlg == NULL)
4236 p_hlg = empty_option;
4237 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004238 {
4239 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4240 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4241 {
4242 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4243 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4244 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004246 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 options[idx].flags |= P_ALLOCED;
4248 }
4249}
4250#endif
4251
4252#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004253static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254
4255 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004256gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257{
4258 if (gui_get_lightness(gui.back_pixel) < 127)
4259 return (char_u *)"dark";
4260 return (char_u *)"light";
4261}
4262
4263/*
4264 * Option initializations that can only be done after opening the GUI window.
4265 */
4266 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004267init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268{
4269 /* Set the 'background' option according to the lightness of the
4270 * background color, unless the user has set it already. */
4271 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4272 {
4273 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4274 highlight_changed();
4275 }
4276}
4277#endif
4278
4279#ifdef FEAT_TITLE
4280/*
4281 * 'title' and 'icon' only default to true if they have not been set or reset
4282 * in .vimrc and we can read the old value.
4283 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4284 * they can be reset. This reduces startup time when using X on a remote
4285 * machine.
4286 */
4287 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004288set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004289{
4290 int idx1;
4291 long val;
4292
4293 /*
4294 * If GUI is (going to be) used, we can always set the window title and
4295 * icon name. Saves a bit of time, because the X11 display server does
4296 * not need to be contacted.
4297 */
4298 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004299 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004300 {
4301#ifdef FEAT_GUI
4302 if (gui.starting || gui.in_use)
4303 val = TRUE;
4304 else
4305#endif
4306 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004307 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308 p_title = val;
4309 }
4310 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004311 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004312 {
4313#ifdef FEAT_GUI
4314 if (gui.starting || gui.in_use)
4315 val = TRUE;
4316 else
4317#endif
4318 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004319 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 p_icon = val;
4321 }
4322}
4323#endif
4324
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004325#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004326 static void
4327trigger_optionsset_string(
4328 int opt_idx,
4329 int opt_flags,
4330 char_u *oldval,
4331 char_u *newval)
4332{
4333 if (oldval != NULL && newval != NULL)
4334 {
4335 char_u buf_type[7];
4336
4337 sprintf((char *)buf_type, "%s",
4338 (opt_flags & OPT_LOCAL) ? "local" : "global");
4339 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4340 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4341 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4342 apply_autocmds(EVENT_OPTIONSET,
4343 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4344 reset_v_option_vars();
4345 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004346}
4347#endif
4348
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349/*
4350 * Parse 'arg' for option settings.
4351 *
4352 * 'arg' may be IObuff, but only when no errors can be present and option
4353 * does not need to be expanded with option_expand().
4354 * "opt_flags":
4355 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004356 * OPT_GLOBAL for ":setglobal"
4357 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004359 * OPT_WINONLY to only set window-local options
4360 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004361 *
4362 * returns FAIL if an error is detected, OK otherwise
4363 */
4364 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004365do_set(
4366 char_u *arg, /* option string (may be written to!) */
4367 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368{
4369 int opt_idx;
4370 char_u *errmsg;
4371 char_u errbuf[80];
4372 char_u *startarg;
4373 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4374 int nextchar; /* next non-white char after option name */
4375 int afterchar; /* character just after option name */
4376 int len;
4377 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004378 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 int key;
4380 long_u flags; /* flags for current option */
4381 char_u *varp = NULL; /* pointer to variable for current option */
4382 int did_show = FALSE; /* already showed one value */
4383 int adding; /* "opt+=arg" */
4384 int prepending; /* "opt^=arg" */
4385 int removing; /* "opt-=arg" */
4386 int cp_val = 0;
4387 char_u key_name[2];
4388
4389 if (*arg == NUL)
4390 {
4391 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004392 did_show = TRUE;
4393 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 }
4395
4396 while (*arg != NUL) /* loop to process all options */
4397 {
4398 errmsg = NULL;
4399 startarg = arg; /* remember for error message */
4400
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004401 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4402 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 {
4404 /*
4405 * ":set all" show all options.
4406 * ":set all&" set all options to their default value.
4407 */
4408 arg += 3;
4409 if (*arg == '&')
4410 {
4411 ++arg;
4412 /* Only for :set command set global value of local options. */
4413 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004414 didset_options();
4415 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004416 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 }
4418 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004421 did_show = TRUE;
4422 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004424 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 {
4426 showoptions(2, opt_flags);
4427 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004428 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 arg += 7;
4430 }
4431 else
4432 {
4433 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004434 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004435 {
4436 prefix = 0;
4437 arg += 2;
4438 }
4439 else if (STRNCMP(arg, "inv", 3) == 0)
4440 {
4441 prefix = 2;
4442 arg += 3;
4443 }
4444
4445 /* find end of name */
4446 key = 0;
4447 if (*arg == '<')
4448 {
4449 nextchar = 0;
4450 opt_idx = -1;
4451 /* look out for <t_>;> */
4452 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4453 len = 5;
4454 else
4455 {
4456 len = 1;
4457 while (arg[len] != NUL && arg[len] != '>')
4458 ++len;
4459 }
4460 if (arg[len] != '>')
4461 {
4462 errmsg = e_invarg;
4463 goto skip;
4464 }
4465 arg[len] = NUL; /* put NUL after name */
4466 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4467 opt_idx = findoption(arg + 1);
4468 arg[len++] = '>'; /* restore '>' */
4469 if (opt_idx == -1)
4470 key = find_key_option(arg + 1);
4471 }
4472 else
4473 {
4474 len = 0;
4475 /*
4476 * The two characters after "t_" may not be alphanumeric.
4477 */
4478 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4479 len = 4;
4480 else
4481 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4482 ++len;
4483 nextchar = arg[len];
4484 arg[len] = NUL; /* put NUL after name */
4485 opt_idx = findoption(arg);
4486 arg[len] = nextchar; /* restore nextchar */
4487 if (opt_idx == -1)
4488 key = find_key_option(arg);
4489 }
4490
4491 /* remember character after option name */
4492 afterchar = arg[len];
4493
4494 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004495 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 ++len;
4497
4498 adding = FALSE;
4499 prepending = FALSE;
4500 removing = FALSE;
4501 if (arg[len] != NUL && arg[len + 1] == '=')
4502 {
4503 if (arg[len] == '+')
4504 {
4505 adding = TRUE; /* "+=" */
4506 ++len;
4507 }
4508 else if (arg[len] == '^')
4509 {
4510 prepending = TRUE; /* "^=" */
4511 ++len;
4512 }
4513 else if (arg[len] == '-')
4514 {
4515 removing = TRUE; /* "-=" */
4516 ++len;
4517 }
4518 }
4519 nextchar = arg[len];
4520
4521 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4522 {
4523 errmsg = (char_u *)N_("E518: Unknown option");
4524 goto skip;
4525 }
4526
4527 if (opt_idx >= 0)
4528 {
4529 if (options[opt_idx].var == NULL) /* hidden option: skip */
4530 {
4531 /* Only give an error message when requesting the value of
4532 * a hidden option, ignore setting it. */
4533 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4534 && (!(options[opt_idx].flags & P_BOOL)
4535 || nextchar == '?'))
4536 errmsg = (char_u *)N_("E519: Option not supported");
4537 goto skip;
4538 }
4539
4540 flags = options[opt_idx].flags;
4541 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4542 }
4543 else
4544 {
4545 flags = P_STRING;
4546 if (key < 0)
4547 {
4548 key_name[0] = KEY2TERMCAP0(key);
4549 key_name[1] = KEY2TERMCAP1(key);
4550 }
4551 else
4552 {
4553 key_name[0] = KS_KEY;
4554 key_name[1] = (key & 0xff);
4555 }
4556 }
4557
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004558 /* Skip all options that are not window-local (used when showing
4559 * an already loaded buffer in a window). */
4560 if ((opt_flags & OPT_WINONLY)
4561 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4562 goto skip;
4563
Bram Moolenaara3227e22006-03-08 21:32:40 +00004564 /* Skip all options that are window-local (used for :vimgrep). */
4565 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4566 && options[opt_idx].var == VAR_WIN)
4567 goto skip;
4568
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004569 /* Disallow changing some options from modelines. */
4570 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004572 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004573 {
4574 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4575 goto skip;
4576 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004577#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004578 /* In diff mode some options are overruled. This avoids that
4579 * 'foldmethod' becomes "marker" instead of "diff" and that
4580 * "wrap" gets set. */
4581 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004582 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004583 && (
4584#ifdef FEAT_FOLDING
4585 options[opt_idx].indir == PV_FDM ||
4586#endif
4587 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004588 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004589#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 }
4591
4592#ifdef HAVE_SANDBOX
4593 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004594 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 {
4596 errmsg = (char_u *)_(e_sandbox);
4597 goto skip;
4598 }
4599#endif
4600
4601 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4602 {
4603 arg += len;
4604 cp_val = p_cp;
4605 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4606 {
4607 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4608 {
4609 cp_val = FALSE;
4610 arg += 3;
4611 }
4612 else /* "opt&vi": set to Vi default */
4613 {
4614 cp_val = TRUE;
4615 arg += 2;
4616 }
4617 }
4618 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004619 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 {
4621 errmsg = e_trailing;
4622 goto skip;
4623 }
4624 }
4625
4626 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004627 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4628 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 */
4630 if (nextchar == '?'
4631 || (prefix == 1
4632 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4633 && !(flags & P_BOOL)))
4634 {
4635 /*
4636 * print value
4637 */
4638 if (did_show)
4639 msg_putchar('\n'); /* cursor below last one */
4640 else
4641 {
4642 gotocmdline(TRUE); /* cursor at status line */
4643 did_show = TRUE; /* remember that we did a line */
4644 }
4645 if (opt_idx >= 0)
4646 {
4647 showoneopt(&options[opt_idx], opt_flags);
4648#ifdef FEAT_EVAL
4649 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004650 {
4651 /* Mention where the option was last set. */
4652 if (varp == options[opt_idx].var)
4653 last_set_msg(options[opt_idx].scriptID);
4654 else if ((int)options[opt_idx].indir & PV_WIN)
4655 last_set_msg(curwin->w_p_scriptID[
4656 (int)options[opt_idx].indir & PV_MASK]);
4657 else if ((int)options[opt_idx].indir & PV_BUF)
4658 last_set_msg(curbuf->b_p_scriptID[
4659 (int)options[opt_idx].indir & PV_MASK]);
4660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661#endif
4662 }
4663 else
4664 {
4665 char_u *p;
4666
4667 p = find_termcode(key_name);
4668 if (p == NULL)
4669 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004670 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 goto skip;
4672 }
4673 else
4674 (void)show_one_termcode(key_name, p, TRUE);
4675 }
4676 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004677 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 errmsg = e_trailing;
4679 }
4680 else
4681 {
4682 if (flags & P_BOOL) /* boolean */
4683 {
4684 if (nextchar == '=' || nextchar == ':')
4685 {
4686 errmsg = e_invarg;
4687 goto skip;
4688 }
4689
4690 /*
4691 * ":set opt!": invert
4692 * ":set opt&": reset to default value
4693 * ":set opt<": reset to global value
4694 */
4695 if (nextchar == '!')
4696 value = *(int *)(varp) ^ 1;
4697 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004698 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 ((flags & P_VI_DEF) || cp_val)
4700 ? VI_DEFAULT : VIM_DEFAULT];
4701 else if (nextchar == '<')
4702 {
4703 /* For 'autoread' -1 means to use global value. */
4704 if ((int *)varp == &curbuf->b_p_ar
4705 && opt_flags == OPT_LOCAL)
4706 value = -1;
4707 else
4708 value = *(int *)get_varp_scope(&(options[opt_idx]),
4709 OPT_GLOBAL);
4710 }
4711 else
4712 {
4713 /*
4714 * ":set invopt": invert
4715 * ":set opt" or ":set noopt": set or reset
4716 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004717 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004718 {
4719 errmsg = e_trailing;
4720 goto skip;
4721 }
4722 if (prefix == 2) /* inv */
4723 value = *(int *)(varp) ^ 1;
4724 else
4725 value = prefix;
4726 }
4727
4728 errmsg = set_bool_option(opt_idx, varp, (int)value,
4729 opt_flags);
4730 }
4731 else /* numeric or string */
4732 {
4733 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4734 || prefix != 1)
4735 {
4736 errmsg = e_invarg;
4737 goto skip;
4738 }
4739
4740 if (flags & P_NUM) /* numeric */
4741 {
4742 /*
4743 * Different ways to set a number option:
4744 * & set to default value
4745 * < set to global value
4746 * <xx> accept special key codes for 'wildchar'
4747 * c accept any non-digit for 'wildchar'
4748 * [-]0-9 set number
4749 * other error
4750 */
4751 ++arg;
4752 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004753 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 ((flags & P_VI_DEF) || cp_val)
4755 ? VI_DEFAULT : VIM_DEFAULT];
4756 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004757 {
4758 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4759 * use the global value. */
4760 if ((long *)varp == &curbuf->b_p_ul
4761 && opt_flags == OPT_LOCAL)
4762 value = NO_LOCAL_UNDOLEVEL;
4763 else
4764 value = *(long *)get_varp_scope(
4765 &(options[opt_idx]), OPT_GLOBAL);
4766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 else if (((long *)varp == &p_wc
4768 || (long *)varp == &p_wcm)
4769 && (*arg == '<'
4770 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004771 || (*arg != NUL
4772 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 && !VIM_ISDIGIT(*arg))))
4774 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004775 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 if (value == 0 && (long *)varp != &p_wcm)
4777 {
4778 errmsg = e_invarg;
4779 goto skip;
4780 }
4781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004782 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4783 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004784 /* Allow negative (for 'undolevels'), octal and
4785 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004786 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4787 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004788 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 {
4790 errmsg = e_invarg;
4791 goto skip;
4792 }
4793 }
4794 else
4795 {
4796 errmsg = (char_u *)N_("E521: Number required after =");
4797 goto skip;
4798 }
4799
4800 if (adding)
4801 value = *(long *)varp + value;
4802 if (prepending)
4803 value = *(long *)varp * value;
4804 if (removing)
4805 value = *(long *)varp - value;
4806 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004807 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004808 }
4809 else if (opt_idx >= 0) /* string */
4810 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004811 char_u *save_arg = NULL;
4812 char_u *s = NULL;
4813 char_u *oldval = NULL; /* previous value if *varp */
4814 char_u *newval;
4815 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004816#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004817 char_u *saved_origval = NULL;
4818 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004819#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004820 unsigned newlen;
4821 int comma;
4822 int bs;
4823 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004824 was allocated */
4825
4826 /* When using ":set opt=val" for a global option
4827 * with a local value the local value will be
4828 * reset, use the global value here. */
4829 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004830 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 varp = options[opt_idx].var;
4832
4833 /* The old value is kept until we are sure that the
4834 * new value is valid. */
4835 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004836
4837 /* When setting the local value of a global
4838 * option, the old value may be the global value. */
4839 if (((int)options[opt_idx].indir & PV_BOTH)
4840 && (opt_flags & OPT_LOCAL))
4841 origval = *(char_u **)get_varp(
4842 &options[opt_idx]);
4843 else
4844 origval = oldval;
4845
Bram Moolenaar071d4272004-06-13 20:20:40 +00004846 if (nextchar == '&') /* set to default val */
4847 {
4848 newval = options[opt_idx].def_val[
4849 ((flags & P_VI_DEF) || cp_val)
4850 ? VI_DEFAULT : VIM_DEFAULT];
4851 if ((char_u **)varp == &p_bg)
4852 {
4853 /* guess the value of 'background' */
4854#ifdef FEAT_GUI
4855 if (gui.in_use)
4856 newval = gui_bg_default();
4857 else
4858#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004859 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 }
4861
4862 /* expand environment variables and ~ (since the
4863 * default value was already expanded, only
4864 * required when an environment variable was set
4865 * later */
4866 if (newval == NULL)
4867 newval = empty_option;
4868 else
4869 {
4870 s = option_expand(opt_idx, newval);
4871 if (s == NULL)
4872 s = newval;
4873 newval = vim_strsave(s);
4874 }
4875 new_value_alloced = TRUE;
4876 }
4877 else if (nextchar == '<') /* set to global val */
4878 {
4879 newval = vim_strsave(*(char_u **)get_varp_scope(
4880 &(options[opt_idx]), OPT_GLOBAL));
4881 new_value_alloced = TRUE;
4882 }
4883 else
4884 {
4885 ++arg; /* jump to after the '=' or ':' */
4886
4887 /*
4888 * Set 'keywordprg' to ":help" if an empty
4889 * value was passed to :set by the user.
4890 * Misuse errbuf[] for the resulting string.
4891 */
4892 if (varp == (char_u *)&p_kp
4893 && (*arg == NUL || *arg == ' '))
4894 {
4895 STRCPY(errbuf, ":help");
4896 save_arg = arg;
4897 arg = errbuf;
4898 }
4899 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004900 * Convert 'backspace' number to string, for
4901 * adding, prepending and removing string.
4902 */
4903 else if (varp == (char_u *)&p_bs
4904 && VIM_ISDIGIT(**(char_u **)varp))
4905 {
4906 i = getdigits((char_u **)varp);
4907 switch (i)
4908 {
4909 case 0:
4910 *(char_u **)varp = empty_option;
4911 break;
4912 case 1:
4913 *(char_u **)varp = vim_strsave(
4914 (char_u *)"indent,eol");
4915 break;
4916 case 2:
4917 *(char_u **)varp = vim_strsave(
4918 (char_u *)"indent,eol,start");
4919 break;
4920 }
4921 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004922 if (origval == oldval)
4923 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004924 oldval = *(char_u **)varp;
4925 }
4926 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 * Convert 'whichwrap' number to string, for
4928 * backwards compatibility with Vim 3.0.
4929 * Misuse errbuf[] for the resulting string.
4930 */
4931 else if (varp == (char_u *)&p_ww
4932 && VIM_ISDIGIT(*arg))
4933 {
4934 *errbuf = NUL;
4935 i = getdigits(&arg);
4936 if (i & 1)
4937 STRCAT(errbuf, "b,");
4938 if (i & 2)
4939 STRCAT(errbuf, "s,");
4940 if (i & 4)
4941 STRCAT(errbuf, "h,l,");
4942 if (i & 8)
4943 STRCAT(errbuf, "<,>,");
4944 if (i & 16)
4945 STRCAT(errbuf, "[,],");
4946 if (*errbuf != NUL) /* remove trailing , */
4947 errbuf[STRLEN(errbuf) - 1] = NUL;
4948 save_arg = arg;
4949 arg = errbuf;
4950 }
4951 /*
4952 * Remove '>' before 'dir' and 'bdir', for
4953 * backwards compatibility with version 3.0
4954 */
4955 else if ( *arg == '>'
4956 && (varp == (char_u *)&p_dir
4957 || varp == (char_u *)&p_bdir))
4958 {
4959 ++arg;
4960 }
4961
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 /*
4963 * Copy the new string into allocated memory.
4964 * Can't use set_string_option_direct(), because
4965 * we need to remove the backslashes.
4966 */
4967 /* get a bit too much */
4968 newlen = (unsigned)STRLEN(arg) + 1;
4969 if (adding || prepending || removing)
4970 newlen += (unsigned)STRLEN(origval) + 1;
4971 newval = alloc(newlen);
4972 if (newval == NULL) /* out of mem, don't change */
4973 break;
4974 s = newval;
4975
4976 /*
4977 * Copy the string, skip over escaped chars.
4978 * For MS-DOS and WIN32 backslashes before normal
4979 * file name characters are not removed, and keep
4980 * backslash at start, for "\\machine\path", but
4981 * do remove it for "\\\\machine\\path".
4982 * The reverse is found in ExpandOldSetting().
4983 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004984 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 {
4986 if (*arg == '\\' && arg[1] != NUL
4987#ifdef BACKSLASH_IN_FILENAME
4988 && !((flags & P_EXPAND)
4989 && vim_isfilec(arg[1])
4990 && (arg[1] != '\\'
4991 || (s == newval
4992 && arg[2] != '\\')))
4993#endif
4994 )
4995 ++arg; /* remove backslash */
4996#ifdef FEAT_MBYTE
4997 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004998 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004999 {
5000 /* copy multibyte char */
5001 mch_memmove(s, arg, (size_t)i);
5002 arg += i;
5003 s += i;
5004 }
5005 else
5006#endif
5007 *s++ = *arg++;
5008 }
5009 *s = NUL;
5010
5011 /*
5012 * Expand environment variables and ~.
5013 * Don't do it when adding without inserting a
5014 * comma.
5015 */
5016 if (!(adding || prepending || removing)
5017 || (flags & P_COMMA))
5018 {
5019 s = option_expand(opt_idx, newval);
5020 if (s != NULL)
5021 {
5022 vim_free(newval);
5023 newlen = (unsigned)STRLEN(s) + 1;
5024 if (adding || prepending || removing)
5025 newlen += (unsigned)STRLEN(origval) + 1;
5026 newval = alloc(newlen);
5027 if (newval == NULL)
5028 break;
5029 STRCPY(newval, s);
5030 }
5031 }
5032
5033 /* locate newval[] in origval[] when removing it
5034 * and when adding to avoid duplicates */
5035 i = 0; /* init for GCC */
5036 if (removing || (flags & P_NODUP))
5037 {
5038 i = (int)STRLEN(newval);
5039 bs = 0;
5040 for (s = origval; *s; ++s)
5041 {
5042 if ((!(flags & P_COMMA)
5043 || s == origval
5044 || (s[-1] == ',' && !(bs & 1)))
5045 && STRNCMP(s, newval, i) == 0
5046 && (!(flags & P_COMMA)
5047 || s[i] == ','
5048 || s[i] == NUL))
5049 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005050 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005051 * even number of backslashes or a single
5052 * backslash preceded by a comma before it
5053 * is recognized as a separator */
5054 if ((s > origval + 1
5055 && s[-1] == '\\'
5056 && s[-2] != ',')
5057 || (s == origval + 1
5058 && s[-1] == '\\'))
5059
Bram Moolenaar071d4272004-06-13 20:20:40 +00005060 ++bs;
5061 else
5062 bs = 0;
5063 }
5064
5065 /* do not add if already there */
5066 if ((adding || prepending) && *s)
5067 {
5068 prepending = FALSE;
5069 adding = FALSE;
5070 STRCPY(newval, origval);
5071 }
5072 }
5073
5074 /* concatenate the two strings; add a ',' if
5075 * needed */
5076 if (adding || prepending)
5077 {
5078 comma = ((flags & P_COMMA) && *origval != NUL
5079 && *newval != NUL);
5080 if (adding)
5081 {
5082 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005083 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005084 if (comma && i > 1
5085 && (flags & P_ONECOMMA) == P_ONECOMMA
5086 && origval[i - 1] == ','
5087 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005088 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 mch_memmove(newval + i + comma, newval,
5090 STRLEN(newval) + 1);
5091 mch_memmove(newval, origval, (size_t)i);
5092 }
5093 else
5094 {
5095 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005096 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005097 }
5098 if (comma)
5099 newval[i] = ',';
5100 }
5101
5102 /* Remove newval[] from origval[]. (Note: "i" has
5103 * been set above and is used here). */
5104 if (removing)
5105 {
5106 STRCPY(newval, origval);
5107 if (*s)
5108 {
5109 /* may need to remove a comma */
5110 if (flags & P_COMMA)
5111 {
5112 if (s == origval)
5113 {
5114 /* include comma after string */
5115 if (s[i] == ',')
5116 ++i;
5117 }
5118 else
5119 {
5120 /* include comma before string */
5121 --s;
5122 ++i;
5123 }
5124 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005125 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126 }
5127 }
5128
5129 if (flags & P_FLAGLIST)
5130 {
5131 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005132 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005133 {
5134 /* if options have P_FLAGLIST and
5135 * P_ONECOMMA such as 'whichwrap' */
5136 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005138 if (*s != ',' && *(s + 1) == ','
5139 && vim_strchr(s + 2, *s) != NULL)
5140 {
5141 /* Remove the duplicated value and
5142 * the next comma. */
5143 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005144 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005147 else
5148 {
5149 if ((!(flags & P_COMMA) || *s != ',')
5150 && vim_strchr(s + 1, *s) != NULL)
5151 {
5152 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005153 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005154 }
5155 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005156 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005158 }
5159
5160 if (save_arg != NULL) /* number for 'whichwrap' */
5161 arg = save_arg;
5162 new_value_alloced = TRUE;
5163 }
5164
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005165 /*
5166 * Set the new value.
5167 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 *(char_u **)(varp) = newval;
5169
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005170#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005171 if (!starting
5172# ifdef FEAT_CRYPT
5173 && options[opt_idx].indir != PV_KEY
5174# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005175 && origval != NULL && newval != NULL)
5176 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005177 /* origval may be freed by
5178 * did_set_string_option(), make a copy. */
5179 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005180 /* newval (and varp) may become invalid if the
5181 * buffer is closed by autocommands. */
5182 saved_newval = vim_strsave(newval);
5183 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005184#endif
5185
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005187 * ":set" on local options. Note: when setting 'syntax'
5188 * or 'filetype' autocommands may be triggered that can
5189 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5191 new_value_alloced, oldval, errbuf, opt_flags);
5192
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005193#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005194 if (errmsg == NULL)
5195 trigger_optionsset_string(opt_idx, opt_flags,
5196 saved_origval, saved_newval);
5197 vim_free(saved_origval);
5198 vim_free(saved_newval);
5199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 /* If error detected, print the error message. */
5201 if (errmsg != NULL)
5202 goto skip;
5203 }
5204 else /* key code option */
5205 {
5206 char_u *p;
5207
5208 if (nextchar == '&')
5209 {
5210 if (add_termcap_entry(key_name, TRUE) == FAIL)
5211 errmsg = (char_u *)N_("E522: Not found in termcap");
5212 }
5213 else
5214 {
5215 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005216 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005217 if (*p == '\\' && p[1] != NUL)
5218 ++p;
5219 nextchar = *p;
5220 *p = NUL;
5221 add_termcode(key_name, arg, FALSE);
5222 *p = nextchar;
5223 }
5224 if (full_screen)
5225 ttest(FALSE);
5226 redraw_all_later(CLEAR);
5227 }
5228 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005229
Bram Moolenaar071d4272004-06-13 20:20:40 +00005230 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005231 did_set_option(opt_idx, opt_flags,
5232 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 }
5234
5235skip:
5236 /*
5237 * Advance to next argument.
5238 * - skip until a blank found, taking care of backslashes
5239 * - skip blanks
5240 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5241 */
5242 for (i = 0; i < 2 ; ++i)
5243 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005244 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 if (*arg++ == '\\' && *arg != NUL)
5246 ++arg;
5247 arg = skipwhite(arg);
5248 if (*arg != '=')
5249 break;
5250 }
5251 }
5252
5253 if (errmsg != NULL)
5254 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005255 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005256 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005257 if (i + (arg - startarg) < IOSIZE)
5258 {
5259 /* append the argument with the error */
5260 STRCAT(IObuff, ": ");
5261 mch_memmove(IObuff + i, startarg, (arg - startarg));
5262 IObuff[i + (arg - startarg)] = NUL;
5263 }
5264 /* make sure all characters are printable */
5265 trans_characters(IObuff, IOSIZE);
5266
5267 ++no_wait_return; /* wait_return done later */
5268 emsg(IObuff); /* show error highlighted */
5269 --no_wait_return;
5270
5271 return FAIL;
5272 }
5273
5274 arg = skipwhite(arg);
5275 }
5276
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005277theend:
5278 if (silent_mode && did_show)
5279 {
5280 /* After displaying option values in silent mode. */
5281 silent_mode = FALSE;
5282 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5283 msg_putchar('\n');
5284 cursor_on(); /* msg_start() switches it off */
5285 out_flush();
5286 silent_mode = TRUE;
5287 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5288 }
5289
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 return OK;
5291}
5292
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005293/*
5294 * Call this when an option has been given a new value through a user command.
5295 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5296 */
5297 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005298did_set_option(
5299 int opt_idx,
5300 int opt_flags, /* possibly with OPT_MODELINE */
5301 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005302{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005303 long_u *p;
5304
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005305 options[opt_idx].flags |= P_WAS_SET;
5306
5307 /* When an option is set in the sandbox, from a modeline or in secure mode
5308 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005309 * flag. */
5310 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005311 if (secure
5312#ifdef HAVE_SANDBOX
5313 || sandbox != 0
5314#endif
5315 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005316 *p = *p | P_INSECURE;
5317 else if (new_value)
5318 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005319}
5320
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005322illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323{
5324 if (errbuf == NULL)
5325 return (char_u *)"";
5326 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005327 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 return errbuf;
5329}
5330
5331/*
5332 * Convert a key name or string into a key value.
5333 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005334 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005336 int
5337string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338{
5339 if (*arg == '<')
5340 return find_key_option(arg + 1);
5341 if (*arg == '^')
5342 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005343 if (multi_byte)
5344 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 return *arg;
5346}
5347
5348#ifdef FEAT_CMDWIN
5349/*
5350 * Check value of 'cedit' and set cedit_key.
5351 * Returns NULL if value is OK, error message otherwise.
5352 */
5353 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005354check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355{
5356 int n;
5357
5358 if (*p_cedit == NUL)
5359 cedit_key = -1;
5360 else
5361 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005362 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363 if (vim_isprintc(n))
5364 return e_invarg;
5365 cedit_key = n;
5366 }
5367 return NULL;
5368}
5369#endif
5370
5371#ifdef FEAT_TITLE
5372/*
5373 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5374 * maketitle() to create and display it.
5375 * When switching the title or icon off, call mch_restore_title() to get
5376 * the old value back.
5377 */
5378 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005379did_set_title(
5380 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381{
5382 if (starting != NO_SCREEN
5383#ifdef FEAT_GUI
5384 && !gui.starting
5385#endif
5386 )
5387 {
5388 maketitle();
5389 if (icon)
5390 {
5391 if (!p_icon)
5392 mch_restore_title(2);
5393 }
5394 else
5395 {
5396 if (!p_title)
5397 mch_restore_title(1);
5398 }
5399 }
5400}
5401#endif
5402
5403/*
5404 * set_options_bin - called when 'bin' changes value.
5405 */
5406 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005407set_options_bin(
5408 int oldval,
5409 int newval,
5410 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411{
5412 /*
5413 * The option values that are changed when 'bin' changes are
5414 * copied when 'bin is set and restored when 'bin' is reset.
5415 */
5416 if (newval)
5417 {
5418 if (!oldval) /* switched on */
5419 {
5420 if (!(opt_flags & OPT_GLOBAL))
5421 {
5422 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5423 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5424 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5425 curbuf->b_p_et_nobin = curbuf->b_p_et;
5426 }
5427 if (!(opt_flags & OPT_LOCAL))
5428 {
5429 p_tw_nobin = p_tw;
5430 p_wm_nobin = p_wm;
5431 p_ml_nobin = p_ml;
5432 p_et_nobin = p_et;
5433 }
5434 }
5435
5436 if (!(opt_flags & OPT_GLOBAL))
5437 {
5438 curbuf->b_p_tw = 0; /* no automatic line wrap */
5439 curbuf->b_p_wm = 0; /* no automatic line wrap */
5440 curbuf->b_p_ml = 0; /* no modelines */
5441 curbuf->b_p_et = 0; /* no expandtab */
5442 }
5443 if (!(opt_flags & OPT_LOCAL))
5444 {
5445 p_tw = 0;
5446 p_wm = 0;
5447 p_ml = FALSE;
5448 p_et = FALSE;
5449 p_bin = TRUE; /* needed when called for the "-b" argument */
5450 }
5451 }
5452 else if (oldval) /* switched off */
5453 {
5454 if (!(opt_flags & OPT_GLOBAL))
5455 {
5456 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5457 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5458 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5459 curbuf->b_p_et = curbuf->b_p_et_nobin;
5460 }
5461 if (!(opt_flags & OPT_LOCAL))
5462 {
5463 p_tw = p_tw_nobin;
5464 p_wm = p_wm_nobin;
5465 p_ml = p_ml_nobin;
5466 p_et = p_et_nobin;
5467 }
5468 }
5469}
5470
5471#ifdef FEAT_VIMINFO
5472/*
5473 * Find the parameter represented by the given character (eg ', :, ", or /),
5474 * and return its associated value in the 'viminfo' string.
5475 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005476 * If the parameter is not specified in the string or there is no following
5477 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 */
5479 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482 char_u *p;
5483
5484 p = find_viminfo_parameter(type);
5485 if (p != NULL && VIM_ISDIGIT(*p))
5486 return atoi((char *)p);
5487 return -1;
5488}
5489
5490/*
5491 * Find the parameter represented by the given character (eg ''', ':', '"', or
5492 * '/') in the 'viminfo' option and return a pointer to the string after it.
5493 * Return NULL if the parameter is not specified in the string.
5494 */
5495 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005496find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005497{
5498 char_u *p;
5499
5500 for (p = p_viminfo; *p; ++p)
5501 {
5502 if (*p == type)
5503 return p + 1;
5504 if (*p == 'n') /* 'n' is always the last one */
5505 break;
5506 p = vim_strchr(p, ','); /* skip until next ',' */
5507 if (p == NULL) /* hit the end without finding parameter */
5508 break;
5509 }
5510 return NULL;
5511}
5512#endif
5513
5514/*
5515 * Expand environment variables for some string options.
5516 * These string options cannot be indirect!
5517 * If "val" is NULL expand the current value of the option.
5518 * Return pointer to NameBuff, or NULL when not expanded.
5519 */
5520 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005521option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522{
5523 /* if option doesn't need expansion nothing to do */
5524 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5525 return NULL;
5526
5527 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5528 * expand_env() would truncate the string. */
5529 if (val != NULL && STRLEN(val) > MAXPATHL)
5530 return NULL;
5531
5532 if (val == NULL)
5533 val = *(char_u **)options[opt_idx].var;
5534
5535 /*
5536 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5537 * Escape spaces when expanding 'tags', they are used to separate file
5538 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005539 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 */
5541 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005542 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005543#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005544 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5545#endif
5546 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5548 return NULL;
5549
5550 return NameBuff;
5551}
5552
5553/*
5554 * After setting various option values: recompute variables that depend on
5555 * option values.
5556 */
5557 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 /* initialize the table for 'iskeyword' et.al. */
5561 (void)init_chartab();
5562
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005563#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005567 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568#ifdef FEAT_SESSION
5569 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5570 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5571#endif
5572#ifdef FEAT_FOLDING
5573 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5574#endif
5575 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005576 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577#ifdef FEAT_VIRTUALEDIT
5578 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5579#endif
5580#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5581 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5582#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005583#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005584 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005585 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005586 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005587 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5590 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5591#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005592#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5594#endif
5595#ifdef FEAT_CMDWIN
5596 /* set cedit_key */
5597 (void)check_cedit();
5598#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005599#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005600 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005601#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005602#ifdef FEAT_LINEBREAK
5603 /* initialize the table for 'breakat'. */
5604 fill_breakat_flags();
5605#endif
5606
5607}
5608
5609/*
5610 * More side effects of setting options.
5611 */
5612 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005613didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005614{
5615 /* Initialize the highlight_attr[] table. */
5616 (void)highlight_changed();
5617
5618 /* Parse default for 'wildmode' */
5619 check_opt_wim();
5620
5621 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005622 /* Parse default for 'fillchars'. */
5623 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005624
5625#ifdef FEAT_CLIPBOARD
5626 /* Parse default for 'clipboard' */
5627 (void)check_clipboard_option();
5628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629}
5630
5631/*
5632 * Check for string options that are NULL (normally only termcap options).
5633 */
5634 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005635check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636{
5637 int opt_idx;
5638
5639 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5640 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5641 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5642}
5643
5644/*
5645 * Check string options in a buffer for NULL value.
5646 */
5647 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005648check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650 check_string_option(&buf->b_p_bh);
5651 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652#ifdef FEAT_MBYTE
5653 check_string_option(&buf->b_p_fenc);
5654#endif
5655 check_string_option(&buf->b_p_ff);
5656#ifdef FEAT_FIND_ID
5657 check_string_option(&buf->b_p_def);
5658 check_string_option(&buf->b_p_inc);
5659# ifdef FEAT_EVAL
5660 check_string_option(&buf->b_p_inex);
5661# endif
5662#endif
5663#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5664 check_string_option(&buf->b_p_inde);
5665 check_string_option(&buf->b_p_indk);
5666#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005667#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5668 check_string_option(&buf->b_p_bexpr);
5669#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005670#if defined(FEAT_CRYPT)
5671 check_string_option(&buf->b_p_cm);
5672#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005673 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005674#if defined(FEAT_EVAL)
5675 check_string_option(&buf->b_p_fex);
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#ifdef FEAT_CRYPT
5678 check_string_option(&buf->b_p_key);
5679#endif
5680 check_string_option(&buf->b_p_kp);
5681 check_string_option(&buf->b_p_mps);
5682 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005683 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 check_string_option(&buf->b_p_isk);
5685#ifdef FEAT_COMMENTS
5686 check_string_option(&buf->b_p_com);
5687#endif
5688#ifdef FEAT_FOLDING
5689 check_string_option(&buf->b_p_cms);
5690#endif
5691 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005692#ifdef FEAT_TEXTOBJ
5693 check_string_option(&buf->b_p_qe);
5694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#ifdef FEAT_SYN_HL
5696 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005697 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005698#endif
5699#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005700 check_string_option(&buf->b_s.b_p_spc);
5701 check_string_option(&buf->b_s.b_p_spf);
5702 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703#endif
5704#ifdef FEAT_SEARCHPATH
5705 check_string_option(&buf->b_p_sua);
5706#endif
5707#ifdef FEAT_CINDENT
5708 check_string_option(&buf->b_p_cink);
5709 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005710 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5714 check_string_option(&buf->b_p_cinw);
5715#endif
5716#ifdef FEAT_INS_EXPAND
5717 check_string_option(&buf->b_p_cpt);
5718#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005719#ifdef FEAT_COMPL_FUNC
5720 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005721 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723#ifdef FEAT_KEYMAP
5724 check_string_option(&buf->b_p_keymap);
5725#endif
5726#ifdef FEAT_QUICKFIX
5727 check_string_option(&buf->b_p_gp);
5728 check_string_option(&buf->b_p_mp);
5729 check_string_option(&buf->b_p_efm);
5730#endif
5731 check_string_option(&buf->b_p_ep);
5732 check_string_option(&buf->b_p_path);
5733 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005734 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735#ifdef FEAT_INS_EXPAND
5736 check_string_option(&buf->b_p_dict);
5737 check_string_option(&buf->b_p_tsr);
5738#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005739#ifdef FEAT_LISP
5740 check_string_option(&buf->b_p_lw);
5741#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005742 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005743#ifdef FEAT_MBYTE
5744 check_string_option(&buf->b_p_menc);
5745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746}
5747
5748/*
5749 * Free the string allocated for an option.
5750 * Checks for the string being empty_option. This may happen if we're out of
5751 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5752 * check_options().
5753 * Does NOT check for P_ALLOCED flag!
5754 */
5755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (p != empty_option)
5759 vim_free(p);
5760}
5761
5762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 if (*pp != empty_option)
5766 vim_free(*pp);
5767 *pp = empty_option;
5768}
5769
5770 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005771check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772{
5773 if (*pp == NULL)
5774 *pp = empty_option;
5775}
5776
5777/*
5778 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5779 */
5780 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782{
5783 int opt_idx;
5784
5785 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5786 if (options[opt_idx].var == (char_u *)p)
5787 {
5788 options[opt_idx].flags |= P_ALLOCED;
5789 return;
5790 }
5791 return; /* cannot happen: didn't find it! */
5792}
5793
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794#if defined(FEAT_EVAL) || defined(PROTO)
5795/*
5796 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5797 * Return FALSE when it wasn't.
5798 * Return -1 for an unknown option.
5799 */
5800 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005801was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005802{
5803 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805
5806 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005807 {
5808 flagp = insecure_flag(idx, opt_flags);
5809 return (*flagp & P_INSECURE) != 0;
5810 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005811 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005812 return -1;
5813}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005814
5815/*
5816 * Get a pointer to the flags used for the P_INSECURE flag of option
5817 * "opt_idx". For some local options a local flags field is used.
5818 */
5819 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005820insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821{
5822 if (opt_flags & OPT_LOCAL)
5823 switch ((int)options[opt_idx].indir)
5824 {
5825#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005826 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827#endif
5828#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005829# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005830 case PV_FDE: return &curwin->w_p_fde_flags;
5831 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005832# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005833# ifdef FEAT_BEVAL
5834 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5835# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005836# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005837 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005838# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005839 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005841 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005842# endif
5843#endif
5844 }
5845
5846 /* Nothing special, return global flags field. */
5847 return &options[opt_idx].flags;
5848}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005849#endif
5850
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005851#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005852static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005853
5854/*
5855 * Redraw the window title and/or tab page text later.
5856 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005857static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005858{
5859 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005860 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005861}
5862#endif
5863
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864/*
5865 * Set a string option to a new value (without checking the effect).
5866 * The string is copied into allocated memory.
5867 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005868 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005869 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 */
5871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005872set_string_option_direct(
5873 char_u *name,
5874 int opt_idx,
5875 char_u *val,
5876 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5877 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878{
5879 char_u *s;
5880 char_u **varp;
5881 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 idx = findoption(name);
5887 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 {
5889 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005890 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 }
5894
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 return;
5897
5898 s = vim_strsave(val);
5899 if (s != NULL)
5900 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 free_string_option(*varp);
5905 *varp = s;
5906
5907 /* For buffer/window local option may also set the global value. */
5908 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912
5913 /* When setting both values of a global option with a local value,
5914 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 {
5917 free_string_option(*varp);
5918 *varp = empty_option;
5919 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920# ifdef FEAT_EVAL
5921 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005923 set_sid == 0 ? current_SID : set_sid);
5924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925 }
5926}
5927
5928/*
5929 * Set global value for string option when it's a local option.
5930 */
5931 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005932set_string_option_global(
5933 int opt_idx, /* option index */
5934 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935{
5936 char_u **p, *s;
5937
5938 /* the global value is always allocated */
5939 if (options[opt_idx].var == VAR_WIN)
5940 p = (char_u **)GLOBAL_WO(varp);
5941 else
5942 p = (char_u **)options[opt_idx].var;
5943 if (options[opt_idx].indir != PV_NONE
5944 && p != varp
5945 && (s = vim_strsave(*varp)) != NULL)
5946 {
5947 free_string_option(*p);
5948 *p = s;
5949 }
5950}
5951
5952/*
5953 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005954 *
5955 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005957 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005958set_string_option(
5959 int opt_idx,
5960 char_u *value,
5961 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962{
5963 char_u *s;
5964 char_u **varp;
5965 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005966#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005967 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005968 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005969#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005970 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971
5972 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005973 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974
5975 s = vim_strsave(value);
5976 if (s != NULL)
5977 {
5978 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5979 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005980 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981 ? OPT_GLOBAL : OPT_LOCAL)
5982 : opt_flags);
5983 oldval = *varp;
5984 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005985
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005986#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005987 if (!starting
5988# ifdef FEAT_CRYPT
5989 && options[opt_idx].indir != PV_KEY
5990# endif
5991 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005992 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005993 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005994 saved_newval = vim_strsave(s);
5995 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005996#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005997 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5998 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005999 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006000
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006001#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006002 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006003 if (r == NULL)
6004 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006005 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006006 vim_free(saved_oldval);
6007 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006010 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011}
6012
6013/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006014 * Return TRUE if "val" is a valid 'filetype' name.
6015 * Also used for 'syntax' and 'keymap'.
6016 */
6017 static int
6018valid_filetype(char_u *val)
6019{
6020 char_u *s;
6021
6022 for (s = val; *s != NUL; ++s)
6023 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6024 return FALSE;
6025 return TRUE;
6026}
6027
6028/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029 * Handle string options that need some action to perform when changed.
6030 * Returns NULL for success, or an error message for an error.
6031 */
6032 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006033did_set_string_option(
6034 int opt_idx, /* index in options[] table */
6035 char_u **varp, /* pointer to the option variable */
6036 int new_value_alloced, /* new value was allocated */
6037 char_u *oldval, /* previous value of the option */
6038 char_u *errbuf, /* buffer for errors, or NULL */
6039 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040{
6041 char_u *errmsg = NULL;
6042 char_u *s, *p;
6043 int did_chartab = FALSE;
6044 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006045 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006046#ifdef FEAT_GUI
6047 /* set when changing an option that only requires a redraw in the GUI */
6048 int redraw_gui_only = FALSE;
6049#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006050 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051
6052 /* Get the global option to compare with, otherwise we would have to check
6053 * two values for all local options. */
6054 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6055
6056 /* Disallow changing some options from secure mode */
6057 if ((secure
6058#ifdef HAVE_SANDBOX
6059 || sandbox != 0
6060#endif
6061 ) && (options[opt_idx].flags & P_SECURE))
6062 {
6063 errmsg = e_secure;
6064 }
6065
Bram Moolenaar7554da42016-11-25 22:04:13 +01006066 /* Check for a "normal" directory or file name in some options. Disallow a
6067 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006068 * are often illegal in a file name. Be more permissive if "secure" is off.
6069 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006070 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006071 && vim_strpbrk(*varp, (char_u *)(secure
6072 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006073 || ((options[opt_idx].flags & P_NDNAME)
6074 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006075 {
6076 errmsg = e_invarg;
6077 }
6078
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 /* 'term' */
6080 else if (varp == &T_NAME)
6081 {
6082 if (T_NAME[0] == NUL)
6083 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6084#ifdef FEAT_GUI
6085 if (gui.in_use)
6086 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6087 else if (term_is_gui(T_NAME))
6088 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6089#endif
6090 else if (set_termname(T_NAME) == FAIL)
6091 errmsg = (char_u *)N_("E522: Not found in termcap");
6092 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006093 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 /* Screen colors may have changed. */
6095 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006096
6097 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6098 * P_ALLOCED flag on 'term'. */
6099 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006100 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 }
6103
6104 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006105 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006107 char_u *bkc = p_bkc;
6108 unsigned int *flags = &bkc_flags;
6109
6110 if (opt_flags & OPT_LOCAL)
6111 {
6112 bkc = curbuf->b_p_bkc;
6113 flags = &curbuf->b_bkc_flags;
6114 }
6115
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006116 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6117 /* make the local value empty: use the global value */
6118 *flags = 0;
6119 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006121 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6122 errmsg = e_invarg;
6123 if ((((int)*flags & BKC_AUTO) != 0)
6124 + (((int)*flags & BKC_YES) != 0)
6125 + (((int)*flags & BKC_NO) != 0) != 1)
6126 {
6127 /* Must have exactly one of "auto", "yes" and "no". */
6128 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6129 errmsg = e_invarg;
6130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 }
6132 }
6133
6134 /* 'backupext' and 'patchmode' */
6135 else if (varp == &p_bex || varp == &p_pm)
6136 {
6137 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6138 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6139 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6140 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006141#ifdef FEAT_LINEBREAK
6142 /* 'breakindentopt' */
6143 else if (varp == &curwin->w_p_briopt)
6144 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006145 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006146 errmsg = e_invarg;
6147 }
6148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149
6150 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006151 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006153 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 */
6155 else if ( varp == &p_isi
6156 || varp == &(curbuf->b_p_isk)
6157 || varp == &p_isp
6158 || varp == &p_isf)
6159 {
6160 if (init_chartab() == FAIL)
6161 {
6162 did_chartab = TRUE; /* need to restore it below */
6163 errmsg = e_invarg; /* error in value */
6164 }
6165 }
6166
6167 /* 'helpfile' */
6168 else if (varp == &p_hf)
6169 {
6170 /* May compute new values for $VIM and $VIMRUNTIME */
6171 if (didset_vim)
6172 {
6173 vim_setenv((char_u *)"VIM", (char_u *)"");
6174 didset_vim = FALSE;
6175 }
6176 if (didset_vimruntime)
6177 {
6178 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6179 didset_vimruntime = FALSE;
6180 }
6181 }
6182
Bram Moolenaar1a384422010-07-14 19:53:30 +02006183#ifdef FEAT_SYN_HL
6184 /* 'colorcolumn' */
6185 else if (varp == &curwin->w_p_cc)
6186 errmsg = check_colorcolumn(curwin);
6187#endif
6188
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189#ifdef FEAT_MULTI_LANG
6190 /* 'helplang' */
6191 else if (varp == &p_hlg)
6192 {
6193 /* Check for "", "ab", "ab,cd", etc. */
6194 for (s = p_hlg; *s != NUL; s += 3)
6195 {
6196 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6197 {
6198 errmsg = e_invarg;
6199 break;
6200 }
6201 if (s[2] == NUL)
6202 break;
6203 }
6204 }
6205#endif
6206
6207 /* 'highlight' */
6208 else if (varp == &p_hl)
6209 {
6210 if (highlight_changed() == FAIL)
6211 errmsg = e_invarg; /* invalid flags */
6212 }
6213
6214 /* 'nrformats' */
6215 else if (gvarp == &p_nf)
6216 {
6217 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6218 errmsg = e_invarg;
6219 }
6220
6221#ifdef FEAT_SESSION
6222 /* 'sessionoptions' */
6223 else if (varp == &p_ssop)
6224 {
6225 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6226 errmsg = e_invarg;
6227 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6228 {
6229 /* Don't allow both "sesdir" and "curdir". */
6230 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6231 errmsg = e_invarg;
6232 }
6233 }
6234 /* 'viewoptions' */
6235 else if (varp == &p_vop)
6236 {
6237 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6238 errmsg = e_invarg;
6239 }
6240#endif
6241
6242 /* 'scrollopt' */
6243#ifdef FEAT_SCROLLBIND
6244 else if (varp == &p_sbo)
6245 {
6246 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6247 errmsg = e_invarg;
6248 }
6249#endif
6250
6251 /* 'ambiwidth' */
6252#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006253 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 {
6255 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6256 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006257 else if (set_chars_option(&p_lcs) != NULL)
6258 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006259 else if (set_chars_option(&p_fcs) != NULL)
6260 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261 }
6262#endif
6263
6264 /* 'background' */
6265 else if (varp == &p_bg)
6266 {
6267 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6268 {
6269#ifdef FEAT_EVAL
6270 int dark = (*p_bg == 'd');
6271#endif
6272
6273 init_highlight(FALSE, FALSE);
6274
6275#ifdef FEAT_EVAL
6276 if (dark != (*p_bg == 'd')
6277 && get_var_value((char_u *)"g:colors_name") != NULL)
6278 {
6279 /* The color scheme must have set 'background' back to another
6280 * value, that's not what we want here. Disable the color
6281 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006282 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 free_string_option(p_bg);
6284 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6285 check_string_option(&p_bg);
6286 init_highlight(FALSE, FALSE);
6287 }
6288#endif
6289 }
6290 else
6291 errmsg = e_invarg;
6292 }
6293
6294 /* 'wildmode' */
6295 else if (varp == &p_wim)
6296 {
6297 if (check_opt_wim() == FAIL)
6298 errmsg = e_invarg;
6299 }
6300
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006301#ifdef FEAT_CMDL_COMPL
6302 /* 'wildoptions' */
6303 else if (varp == &p_wop)
6304 {
6305 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6306 errmsg = e_invarg;
6307 }
6308#endif
6309
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310#ifdef FEAT_WAK
6311 /* 'winaltkeys' */
6312 else if (varp == &p_wak)
6313 {
6314 if (*p_wak == NUL
6315 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6316 errmsg = e_invarg;
6317# ifdef FEAT_MENU
6318# ifdef FEAT_GUI_MOTIF
6319 else if (gui.in_use)
6320 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6321# else
6322# ifdef FEAT_GUI_GTK
6323 else if (gui.in_use)
6324 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6325# endif
6326# endif
6327# endif
6328 }
6329#endif
6330
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 /* 'eventignore' */
6332 else if (varp == &p_ei)
6333 {
6334 if (check_ei() == FAIL)
6335 errmsg = e_invarg;
6336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337
6338#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006339 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6340 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6341 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 {
6343 if (gvarp == &p_fenc)
6344 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006345 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 errmsg = e_modifiable;
6347 else if (vim_strchr(*varp, ',') != NULL)
6348 /* No comma allowed in 'fileencoding'; catches confusing it
6349 * with 'fileencodings'. */
6350 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006352 {
6353# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006355 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006357 /* Add 'fileencoding' to the swap file. */
6358 ml_setflags(curbuf);
6359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 }
6361 if (errmsg == NULL)
6362 {
6363 /* canonize the value, so that STRCMP() can be used on it */
6364 p = enc_canonize(*varp);
6365 if (p != NULL)
6366 {
6367 vim_free(*varp);
6368 *varp = p;
6369 }
6370 if (varp == &p_enc)
6371 {
6372 errmsg = mb_init();
6373# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006374 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375# endif
6376 }
6377 }
6378
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006379# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6381 {
6382 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6383 if (STRCMP(p_tenc, "utf-8") != 0)
6384 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6385 }
6386# endif
6387
6388 if (errmsg == NULL)
6389 {
6390# ifdef FEAT_KEYMAP
6391 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6392 * (with another encoding). */
6393 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6394 (void)keymap_init();
6395# endif
6396
6397 /* When 'termencoding' is not empty and 'encoding' changes or when
6398 * 'termencoding' changes, need to setup for keyboard input and
6399 * display output conversion. */
6400 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6401 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006402 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6403 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6404 {
6405 EMSG3(_("E950: Cannot convert between %s and %s"),
6406 p_tenc, p_enc);
6407 errmsg = e_invarg;
6408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006410
6411# if defined(WIN3264) && defined(FEAT_MBYTE)
6412 /* $HOME may have characters in active code page. */
6413 if (varp == &p_enc)
6414 init_homedir();
6415# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 }
6417 }
6418#endif
6419
6420#if defined(FEAT_POSTSCRIPT)
6421 else if (varp == &p_penc)
6422 {
6423 /* Canonize printencoding if VIM standard one */
6424 p = enc_canonize(p_penc);
6425 if (p != NULL)
6426 {
6427 vim_free(p_penc);
6428 p_penc = p;
6429 }
6430 else
6431 {
6432 /* Ensure lower case and '-' for '_' */
6433 for (s = p_penc; *s != NUL; s++)
6434 {
6435 if (*s == '_')
6436 *s = '-';
6437 else
6438 *s = TOLOWER_ASC(*s);
6439 }
6440 }
6441 }
6442#endif
6443
Bram Moolenaar9372a112005-12-06 19:59:18 +00006444#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 else if (varp == &p_imak)
6446 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006447 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 errmsg = e_invarg;
6449 }
6450#endif
6451
6452#ifdef FEAT_KEYMAP
6453 else if (varp == &curbuf->b_p_keymap)
6454 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006455 if (!valid_filetype(*varp))
6456 errmsg = e_invarg;
6457 else
6458 /* load or unload key mapping tables */
6459 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460
Bram Moolenaarfab06232009-03-04 03:13:35 +00006461 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006462 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006463 if (*curbuf->b_p_keymap != NUL)
6464 {
6465 /* Installed a new keymap, switch on using it. */
6466 curbuf->b_p_iminsert = B_IMODE_LMAP;
6467 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6468 curbuf->b_p_imsearch = B_IMODE_LMAP;
6469 }
6470 else
6471 {
6472 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6473 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6474 curbuf->b_p_iminsert = B_IMODE_NONE;
6475 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6476 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6477 }
6478 if ((opt_flags & OPT_LOCAL) == 0)
6479 {
6480 set_iminsert_global();
6481 set_imsearch_global();
6482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 }
6485 }
6486#endif
6487
6488 /* 'fileformat' */
6489 else if (gvarp == &p_ff)
6490 {
6491 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6492 errmsg = e_modifiable;
6493 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6494 errmsg = e_invarg;
6495 else
6496 {
6497 /* may also change 'textmode' */
6498 if (get_fileformat(curbuf) == EOL_DOS)
6499 curbuf->b_p_tx = TRUE;
6500 else
6501 curbuf->b_p_tx = FALSE;
6502#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006503 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006505 /* update flag in swap file */
6506 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006507 /* Redraw needed when switching to/from "mac": a CR in the text
6508 * will be displayed differently. */
6509 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6510 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006511 }
6512 }
6513
6514 /* 'fileformats' */
6515 else if (varp == &p_ffs)
6516 {
6517 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6518 errmsg = e_invarg;
6519 else
6520 {
6521 /* also change 'textauto' */
6522 if (*p_ffs == NUL)
6523 p_ta = FALSE;
6524 else
6525 p_ta = TRUE;
6526 }
6527 }
6528
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006529#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 /* 'cryptkey' */
6531 else if (gvarp == &p_key)
6532 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006533# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 /* Make sure the ":set" command doesn't show the new value in the
6535 * history. */
6536 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006537# endif
6538 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6539 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006540 ml_set_crypt_key(curbuf, oldval,
6541 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006542 }
6543
6544 else if (gvarp == &p_cm)
6545 {
6546 if (opt_flags & OPT_LOCAL)
6547 p = curbuf->b_p_cm;
6548 else
6549 p = p_cm;
6550 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6551 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006552 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006553 errmsg = e_invarg;
6554 else
6555 {
6556 /* When setting the global value to empty, make it "zip". */
6557 if (*p_cm == NUL)
6558 {
6559 if (new_value_alloced)
6560 free_string_option(p_cm);
6561 p_cm = vim_strsave((char_u *)"zip");
6562 new_value_alloced = TRUE;
6563 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006564 /* When using ":set cm=name" the local value is going to be empty.
6565 * Do that here, otherwise the crypt functions will still use the
6566 * local value. */
6567 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6568 {
6569 free_string_option(curbuf->b_p_cm);
6570 curbuf->b_p_cm = empty_option;
6571 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006572
6573 /* Need to update the swapfile when the effective method changed.
6574 * Set "s" to the effective old value, "p" to the effective new
6575 * method and compare. */
6576 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6577 s = p_cm; /* was previously using the global value */
6578 else
6579 s = oldval;
6580 if (*curbuf->b_p_cm == NUL)
6581 p = p_cm; /* is now using the global value */
6582 else
6583 p = curbuf->b_p_cm;
6584 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006585 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006586
6587 /* If the global value changes need to update the swapfile for all
6588 * buffers using that value. */
6589 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6590 {
6591 buf_T *buf;
6592
Bram Moolenaar29323592016-07-24 22:04:11 +02006593 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006594 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006595 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006596 }
6597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 }
6599#endif
6600
6601 /* 'matchpairs' */
6602 else if (gvarp == &p_mps)
6603 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006604#ifdef FEAT_MBYTE
6605 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006607 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006609 int x2 = -1;
6610 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006611
6612 if (*p != NUL)
6613 p += mb_ptr2len(p);
6614 if (*p != NUL)
6615 x2 = *p++;
6616 if (*p != NUL)
6617 {
6618 x3 = mb_ptr2char(p);
6619 p += mb_ptr2len(p);
6620 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006621 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006622 {
6623 errmsg = e_invarg;
6624 break;
6625 }
6626 if (*p == NUL)
6627 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006629 }
6630 else
6631#endif
6632 {
6633 /* Check for "x:y,x:y" */
6634 for (p = *varp; *p != NUL; p += 4)
6635 {
6636 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6637 {
6638 errmsg = e_invarg;
6639 break;
6640 }
6641 if (p[3] == NUL)
6642 break;
6643 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 }
6645 }
6646
6647#ifdef FEAT_COMMENTS
6648 /* 'comments' */
6649 else if (gvarp == &p_com)
6650 {
6651 for (s = *varp; *s; )
6652 {
6653 while (*s && *s != ':')
6654 {
6655 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6656 && !VIM_ISDIGIT(*s) && *s != '-')
6657 {
6658 errmsg = illegal_char(errbuf, *s);
6659 break;
6660 }
6661 ++s;
6662 }
6663 if (*s++ == NUL)
6664 errmsg = (char_u *)N_("E524: Missing colon");
6665 else if (*s == ',' || *s == NUL)
6666 errmsg = (char_u *)N_("E525: Zero length string");
6667 if (errmsg != NULL)
6668 break;
6669 while (*s && *s != ',')
6670 {
6671 if (*s == '\\' && s[1] != NUL)
6672 ++s;
6673 ++s;
6674 }
6675 s = skip_to_option_part(s);
6676 }
6677 }
6678#endif
6679
6680 /* 'listchars' */
6681 else if (varp == &p_lcs)
6682 {
6683 errmsg = set_chars_option(varp);
6684 }
6685
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686 /* 'fillchars' */
6687 else if (varp == &p_fcs)
6688 {
6689 errmsg = set_chars_option(varp);
6690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006691
6692#ifdef FEAT_CMDWIN
6693 /* 'cedit' */
6694 else if (varp == &p_cedit)
6695 {
6696 errmsg = check_cedit();
6697 }
6698#endif
6699
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006700 /* 'verbosefile' */
6701 else if (varp == &p_vfile)
6702 {
6703 verbose_stop();
6704 if (*p_vfile != NUL && verbose_open() == FAIL)
6705 errmsg = e_invarg;
6706 }
6707
Bram Moolenaar071d4272004-06-13 20:20:40 +00006708#ifdef FEAT_VIMINFO
6709 /* 'viminfo' */
6710 else if (varp == &p_viminfo)
6711 {
6712 for (s = p_viminfo; *s;)
6713 {
6714 /* Check it's a valid character */
6715 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6716 {
6717 errmsg = illegal_char(errbuf, *s);
6718 break;
6719 }
6720 if (*s == 'n') /* name is always last one */
6721 {
6722 break;
6723 }
6724 else if (*s == 'r') /* skip until next ',' */
6725 {
6726 while (*++s && *s != ',')
6727 ;
6728 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006729 else if (*s == '%')
6730 {
6731 /* optional number */
6732 while (vim_isdigit(*++s))
6733 ;
6734 }
6735 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 ++s; /* no extra chars */
6737 else /* must have a number */
6738 {
6739 while (vim_isdigit(*++s))
6740 ;
6741
6742 if (!VIM_ISDIGIT(*(s - 1)))
6743 {
6744 if (errbuf != NULL)
6745 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006746 sprintf((char *)errbuf,
6747 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 transchar_byte(*(s - 1)));
6749 errmsg = errbuf;
6750 }
6751 else
6752 errmsg = (char_u *)"";
6753 break;
6754 }
6755 }
6756 if (*s == ',')
6757 ++s;
6758 else if (*s)
6759 {
6760 if (errbuf != NULL)
6761 errmsg = (char_u *)N_("E527: Missing comma");
6762 else
6763 errmsg = (char_u *)"";
6764 break;
6765 }
6766 }
6767 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6768 errmsg = (char_u *)N_("E528: Must specify a ' value");
6769 }
6770#endif /* FEAT_VIMINFO */
6771
6772 /* terminal options */
6773 else if (istermoption(&options[opt_idx]) && full_screen)
6774 {
6775 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6776 if (varp == &T_CCO)
6777 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006778 int colors = atoi((char *)T_CCO);
6779
6780 /* Only reinitialize colors if t_Co value has really changed to
6781 * avoid expensive reload of colorscheme if t_Co is set to the
6782 * same value multiple times. */
6783 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006784 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006785 t_colors = colors;
6786 if (t_colors <= 1)
6787 {
6788 if (new_value_alloced)
6789 vim_free(T_CCO);
6790 T_CCO = empty_option;
6791 }
6792 /* We now have a different color setup, initialize it again. */
6793 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 }
6796 ttest(FALSE);
6797 if (varp == &T_ME)
6798 {
6799 out_str(T_ME);
6800 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006801#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006802 /* Since t_me has been set, this probably means that the user
6803 * wants to use this as default colors. Need to reset default
6804 * background/foreground colors. */
6805 mch_set_normal_colors();
6806#endif
6807 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006808 if (varp == &T_BE && termcap_active)
6809 {
6810 if (*T_BE == NUL)
6811 /* When clearing t_BE we assume the user no longer wants
6812 * bracketed paste, thus disable it by writing t_BD. */
6813 out_str(T_BD);
6814 else
6815 out_str(T_BE);
6816 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 }
6818
6819#ifdef FEAT_LINEBREAK
6820 /* 'showbreak' */
6821 else if (varp == &p_sbr)
6822 {
6823 for (s = p_sbr; *s; )
6824 {
6825 if (ptr2cells(s) != 1)
6826 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006827 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 }
6829 }
6830#endif
6831
6832#ifdef FEAT_GUI
6833 /* 'guifont' */
6834 else if (varp == &p_guifont)
6835 {
6836 if (gui.in_use)
6837 {
6838 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006839# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 /*
6841 * Put up a font dialog and let the user select a new value.
6842 * If this is cancelled go back to the old value but don't
6843 * give an error message.
6844 */
6845 if (STRCMP(p, "*") == 0)
6846 {
6847 p = gui_mch_font_dialog(oldval);
6848
6849 if (new_value_alloced)
6850 free_string_option(p_guifont);
6851
6852 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6853 new_value_alloced = TRUE;
6854 }
6855# endif
6856 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6857 {
6858# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6859 if (STRCMP(p_guifont, "*") == 0)
6860 {
6861 /* Dialog was cancelled: Keep the old value without giving
6862 * an error message. */
6863 if (new_value_alloced)
6864 free_string_option(p_guifont);
6865 p_guifont = vim_strsave(oldval);
6866 new_value_alloced = TRUE;
6867 }
6868 else
6869# endif
6870 errmsg = (char_u *)N_("E596: Invalid font(s)");
6871 }
6872 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006873 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874 }
6875# ifdef FEAT_XFONTSET
6876 else if (varp == &p_guifontset)
6877 {
6878 if (STRCMP(p_guifontset, "*") == 0)
6879 errmsg = (char_u *)N_("E597: can't select fontset");
6880 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6881 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006882 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 }
6884# endif
6885# ifdef FEAT_MBYTE
6886 else if (varp == &p_guifontwide)
6887 {
6888 if (STRCMP(p_guifontwide, "*") == 0)
6889 errmsg = (char_u *)N_("E533: can't select wide font");
6890 else if (gui_get_wide_font() == FAIL)
6891 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006892 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 }
6894# endif
6895#endif
6896
6897#ifdef CURSOR_SHAPE
6898 /* 'guicursor' */
6899 else if (varp == &p_guicursor)
6900 errmsg = parse_shape_opt(SHAPE_CURSOR);
6901#endif
6902
6903#ifdef FEAT_MOUSESHAPE
6904 /* 'mouseshape' */
6905 else if (varp == &p_mouseshape)
6906 {
6907 errmsg = parse_shape_opt(SHAPE_MOUSE);
6908 update_mouseshape(-1);
6909 }
6910#endif
6911
6912#ifdef FEAT_PRINTER
6913 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006914 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006915# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006916 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006917 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919#endif
6920
6921#ifdef FEAT_LANGMAP
6922 /* 'langmap' */
6923 else if (varp == &p_langmap)
6924 langmap_set();
6925#endif
6926
6927#ifdef FEAT_LINEBREAK
6928 /* 'breakat' */
6929 else if (varp == &p_breakat)
6930 fill_breakat_flags();
6931#endif
6932
6933#ifdef FEAT_TITLE
6934 /* 'titlestring' and 'iconstring' */
6935 else if (varp == &p_titlestring || varp == &p_iconstring)
6936 {
6937# ifdef FEAT_STL_OPT
6938 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6939
6940 /* NULL => statusline syntax */
6941 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6942 stl_syntax |= flagval;
6943 else
6944 stl_syntax &= ~flagval;
6945# endif
6946 did_set_title(varp == &p_iconstring);
6947
6948 }
6949#endif
6950
6951#ifdef FEAT_GUI
6952 /* 'guioptions' */
6953 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006956 redraw_gui_only = TRUE;
6957 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006958#endif
6959
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006960#if defined(FEAT_GUI_TABLINE)
6961 /* 'guitablabel' */
6962 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006963 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006964 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006965 redraw_gui_only = TRUE;
6966 }
6967 /* 'guitabtooltip' */
6968 else if (varp == &p_gtt)
6969 {
6970 redraw_gui_only = TRUE;
6971 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006972#endif
6973
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6975 /* 'ttymouse' */
6976 else if (varp == &p_ttym)
6977 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006978 /* Switch the mouse off before changing the escape sequences used for
6979 * that. */
6980 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6982 errmsg = e_invarg;
6983 else
6984 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006985 if (termcap_active)
6986 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987 }
6988#endif
6989
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990 /* 'selection' */
6991 else if (varp == &p_sel)
6992 {
6993 if (*p_sel == NUL
6994 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6995 errmsg = e_invarg;
6996 }
6997
6998 /* 'selectmode' */
6999 else if (varp == &p_slm)
7000 {
7001 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7002 errmsg = e_invarg;
7003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004
7005#ifdef FEAT_BROWSE
7006 /* 'browsedir' */
7007 else if (varp == &p_bsdir)
7008 {
7009 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7010 && !mch_isdir(p_bsdir))
7011 errmsg = e_invarg;
7012 }
7013#endif
7014
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 /* 'keymodel' */
7016 else if (varp == &p_km)
7017 {
7018 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7019 errmsg = e_invarg;
7020 else
7021 {
7022 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7023 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7024 }
7025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026
7027 /* 'mousemodel' */
7028 else if (varp == &p_mousem)
7029 {
7030 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7031 errmsg = e_invarg;
7032#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7033 else if (*p_mousem != *oldval)
7034 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7035 * to create or delete the popup menus. */
7036 gui_motif_update_mousemodel(root_menu);
7037#endif
7038 }
7039
7040 /* 'switchbuf' */
7041 else if (varp == &p_swb)
7042 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007043 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 errmsg = e_invarg;
7045 }
7046
7047 /* 'debug' */
7048 else if (varp == &p_debug)
7049 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007050 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 errmsg = e_invarg;
7052 }
7053
7054 /* 'display' */
7055 else if (varp == &p_dy)
7056 {
7057 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7058 errmsg = e_invarg;
7059 else
7060 (void)init_chartab();
7061
7062 }
7063
Bram Moolenaar071d4272004-06-13 20:20:40 +00007064 /* 'eadirection' */
7065 else if (varp == &p_ead)
7066 {
7067 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7068 errmsg = e_invarg;
7069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070
7071#ifdef FEAT_CLIPBOARD
7072 /* 'clipboard' */
7073 else if (varp == &p_cb)
7074 errmsg = check_clipboard_option();
7075#endif
7076
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007077#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007078 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7079 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007080 else if (varp == &(curwin->w_s->b_p_spl)
7081 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007082 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007083 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007084 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007085 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007086 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007087 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007088 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007089 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007090 /* 'spellsuggest' */
7091 else if (varp == &p_sps)
7092 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007093 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007094 errmsg = e_invarg;
7095 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007096 /* 'mkspellmem' */
7097 else if (varp == &p_msm)
7098 {
7099 if (spell_check_msm() != OK)
7100 errmsg = e_invarg;
7101 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007102#endif
7103
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104 /* When 'bufhidden' is set, check for valid value. */
7105 else if (gvarp == &p_bh)
7106 {
7107 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7108 errmsg = e_invarg;
7109 }
7110
7111 /* When 'buftype' is set, check for valid value. */
7112 else if (gvarp == &p_bt)
7113 {
7114 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7115 errmsg = e_invarg;
7116 else
7117 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118 if (curwin->w_status_height)
7119 {
7120 curwin->w_redr_status = TRUE;
7121 redraw_later(VALID);
7122 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007123 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007124#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007125 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 }
7128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129
7130#ifdef FEAT_STL_OPT
7131 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007132 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 {
7134 int wid;
7135
7136 if (varp == &p_ruf) /* reset ru_wid first */
7137 ru_wid = 0;
7138 s = *varp;
7139 if (varp == &p_ruf && *s == '%')
7140 {
7141 /* set ru_wid if 'ruf' starts with "%99(" */
7142 if (*++s == '-') /* ignore a '-' */
7143 s++;
7144 wid = getdigits(&s);
7145 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7146 ru_wid = wid;
7147 else
7148 errmsg = check_stl_option(p_ruf);
7149 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007150 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007151 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007153 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 comp_col();
7155 }
7156#endif
7157
7158#ifdef FEAT_INS_EXPAND
7159 /* check if it is a valid value for 'complete' -- Acevedo */
7160 else if (gvarp == &p_cpt)
7161 {
7162 for (s = *varp; *s;)
7163 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007164 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 s++;
7166 if (!*s)
7167 break;
7168 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7169 {
7170 errmsg = illegal_char(errbuf, *s);
7171 break;
7172 }
7173 if (*++s != NUL && *s != ',' && *s != ' ')
7174 {
7175 if (s[-1] == 'k' || s[-1] == 's')
7176 {
7177 /* skip optional filename after 'k' and 's' */
7178 while (*s && *s != ',' && *s != ' ')
7179 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007180 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 ++s;
7182 ++s;
7183 }
7184 }
7185 else
7186 {
7187 if (errbuf != NULL)
7188 {
7189 sprintf((char *)errbuf,
7190 _("E535: Illegal character after <%c>"),
7191 *--s);
7192 errmsg = errbuf;
7193 }
7194 else
7195 errmsg = (char_u *)"";
7196 break;
7197 }
7198 }
7199 }
7200 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007201
7202 /* 'completeopt' */
7203 else if (varp == &p_cot)
7204 {
7205 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7206 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007207 else
7208 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210#endif /* FEAT_INS_EXPAND */
7211
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007212#ifdef FEAT_SIGNS
7213 /* 'signcolumn' */
7214 else if (varp == &curwin->w_p_scl)
7215 {
7216 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7217 errmsg = e_invarg;
7218 }
7219#endif
7220
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221
7222#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007223 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 else if (varp == &p_toolbar)
7225 {
7226 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7227 &toolbar_flags, TRUE) != OK)
7228 errmsg = e_invarg;
7229 else
7230 {
7231 out_flush();
7232 gui_mch_show_toolbar((toolbar_flags &
7233 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7234 }
7235 }
7236#endif
7237
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007238#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 /* 'toolbariconsize': GTK+ 2 only */
7240 else if (varp == &p_tbis)
7241 {
7242 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7243 errmsg = e_invarg;
7244 else
7245 {
7246 out_flush();
7247 gui_mch_show_toolbar((toolbar_flags &
7248 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7249 }
7250 }
7251#endif
7252
7253 /* 'pastetoggle': translate key codes like in a mapping */
7254 else if (varp == &p_pt)
7255 {
7256 if (*p_pt)
7257 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007258 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259 if (p != NULL)
7260 {
7261 if (new_value_alloced)
7262 free_string_option(p_pt);
7263 p_pt = p;
7264 new_value_alloced = TRUE;
7265 }
7266 }
7267 }
7268
7269 /* 'backspace' */
7270 else if (varp == &p_bs)
7271 {
7272 if (VIM_ISDIGIT(*p_bs))
7273 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007274 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 errmsg = e_invarg;
7276 }
7277 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7278 errmsg = e_invarg;
7279 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007280 else if (varp == &p_bo)
7281 {
7282 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7283 errmsg = e_invarg;
7284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007286 /* 'tagcase' */
7287 else if (gvarp == &p_tc)
7288 {
7289 unsigned int *flags;
7290
7291 if (opt_flags & OPT_LOCAL)
7292 {
7293 p = curbuf->b_p_tc;
7294 flags = &curbuf->b_tc_flags;
7295 }
7296 else
7297 {
7298 p = p_tc;
7299 flags = &tc_flags;
7300 }
7301
7302 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7303 /* make the local value empty: use the global value */
7304 *flags = 0;
7305 else if (*p == NUL
7306 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7307 errmsg = e_invarg;
7308 }
7309
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007310#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 /* 'casemap' */
7312 else if (varp == &p_cmp)
7313 {
7314 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318
7319#ifdef FEAT_DIFF
7320 /* 'diffopt' */
7321 else if (varp == &p_dip)
7322 {
7323 if (diffopt_changed() == FAIL)
7324 errmsg = e_invarg;
7325 }
7326#endif
7327
7328#ifdef FEAT_FOLDING
7329 /* 'foldmethod' */
7330 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7331 {
7332 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7333 || *curwin->w_p_fdm == NUL)
7334 errmsg = e_invarg;
7335 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007336 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007338 if (foldmethodIsDiff(curwin))
7339 newFoldLevel();
7340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341 }
7342# ifdef FEAT_EVAL
7343 /* 'foldexpr' */
7344 else if (varp == &curwin->w_p_fde)
7345 {
7346 if (foldmethodIsExpr(curwin))
7347 foldUpdateAll(curwin);
7348 }
7349# endif
7350 /* 'foldmarker' */
7351 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7352 {
7353 p = vim_strchr(*varp, ',');
7354 if (p == NULL)
7355 errmsg = (char_u *)N_("E536: comma required");
7356 else if (p == *varp || p[1] == NUL)
7357 errmsg = e_invarg;
7358 else if (foldmethodIsMarker(curwin))
7359 foldUpdateAll(curwin);
7360 }
7361 /* 'commentstring' */
7362 else if (gvarp == &p_cms)
7363 {
7364 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7365 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7366 }
7367 /* 'foldopen' */
7368 else if (varp == &p_fdo)
7369 {
7370 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7371 errmsg = e_invarg;
7372 }
7373 /* 'foldclose' */
7374 else if (varp == &p_fcl)
7375 {
7376 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7377 errmsg = e_invarg;
7378 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007379 /* 'foldignore' */
7380 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7381 {
7382 if (foldmethodIsIndent(curwin))
7383 foldUpdateAll(curwin);
7384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385#endif
7386
7387#ifdef FEAT_VIRTUALEDIT
7388 /* 'virtualedit' */
7389 else if (varp == &p_ve)
7390 {
7391 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7392 errmsg = e_invarg;
7393 else if (STRCMP(p_ve, oldval) != 0)
7394 {
7395 /* Recompute cursor position in case the new 've' setting
7396 * changes something. */
7397 validate_virtcol();
7398 coladvance(curwin->w_virtcol);
7399 }
7400 }
7401#endif
7402
7403#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7404 else if (varp == &p_csqf)
7405 {
7406 if (p_csqf != NULL)
7407 {
7408 p = p_csqf;
7409 while (*p != NUL)
7410 {
7411 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7412 || p[1] == NUL
7413 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7414 || (p[2] != NUL && p[2] != ','))
7415 {
7416 errmsg = e_invarg;
7417 break;
7418 }
7419 else if (p[2] == NUL)
7420 break;
7421 else
7422 p += 3;
7423 }
7424 }
7425 }
7426#endif
7427
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007428#ifdef FEAT_CINDENT
7429 /* 'cinoptions' */
7430 else if (gvarp == &p_cino)
7431 {
7432 /* TODO: recognize errors */
7433 parse_cino(curbuf);
7434 }
7435#endif
7436
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007437#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007438 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007439 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007440 {
7441 if (!gui_mch_set_rendering_options(p_rop))
7442 errmsg = e_invarg;
7443 }
7444#endif
7445
Bram Moolenaard0b51382016-11-04 15:23:45 +01007446 else if (gvarp == &p_ft)
7447 {
7448 if (!valid_filetype(*varp))
7449 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007450 else
7451 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007452 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007453
7454#ifdef FEAT_SYN_HL
7455 else if (gvarp == &p_syn)
7456 {
7457 if (!valid_filetype(*varp))
7458 errmsg = e_invarg;
7459 }
7460#endif
7461
Bram Moolenaar825680f2017-07-22 17:04:02 +02007462#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007463 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007464 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007465 {
7466 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7467 errmsg = e_invarg;
7468 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007469 /* 'termsize' */
7470 else if (varp == &curwin->w_p_tms)
7471 {
7472 if (*curwin->w_p_tms != NUL)
7473 {
7474 p = skipdigits(curwin->w_p_tms);
7475 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7476 errmsg = e_invarg;
7477 }
7478 }
7479#endif
7480
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 /* Options that are a list of flags. */
7482 else
7483 {
7484 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007485 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007487 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007489 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007491 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007493#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007494 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007495 p = (char_u *)COCU_ALL;
7496#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007497 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 {
7499#ifdef FEAT_MOUSE
7500 p = (char_u *)MOUSE_ALL;
7501#else
7502 if (*p_mouse != NUL)
7503 errmsg = (char_u *)N_("E538: No mouse support");
7504#endif
7505 }
7506#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007507 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 p = (char_u *)GO_ALL;
7509#endif
7510 if (p != NULL)
7511 {
7512 for (s = *varp; *s; ++s)
7513 if (vim_strchr(p, *s) == NULL)
7514 {
7515 errmsg = illegal_char(errbuf, *s);
7516 break;
7517 }
7518 }
7519 }
7520
7521 /*
7522 * If error detected, restore the previous value.
7523 */
7524 if (errmsg != NULL)
7525 {
7526 if (new_value_alloced)
7527 free_string_option(*varp);
7528 *varp = oldval;
7529 /*
7530 * When resetting some values, need to act on it.
7531 */
7532 if (did_chartab)
7533 (void)init_chartab();
7534 if (varp == &p_hl)
7535 (void)highlight_changed();
7536 }
7537 else
7538 {
7539#ifdef FEAT_EVAL
7540 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007541 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542#endif
7543 /*
7544 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007545 * Use "free_oldval", because recursiveness may change the flags under
7546 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007548 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 free_string_option(oldval);
7550 if (new_value_alloced)
7551 options[opt_idx].flags |= P_ALLOCED;
7552 else
7553 options[opt_idx].flags &= ~P_ALLOCED;
7554
7555 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007556 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 {
7558 /* global option with local value set to use global value; free
7559 * the local value and make it empty */
7560 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7561 free_string_option(*(char_u **)p);
7562 *(char_u **)p = empty_option;
7563 }
7564
7565 /* May set global value for local option. */
7566 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7567 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007568
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007569 /*
7570 * Trigger the autocommand only after setting the flags.
7571 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007572#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007573 /* When 'syntax' is set, load the syntax of that name */
7574 if (varp == &(curbuf->b_p_syn))
7575 {
7576 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7577 curbuf->b_fname, TRUE, curbuf);
7578 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007579#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007580 else if (varp == &(curbuf->b_p_ft))
7581 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007582 /* 'filetype' is set, trigger the FileType autocommand.
7583 * Skip this when called from a modeline and the filetype was
7584 * already set to this value. */
7585 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7586 {
7587 did_filetype = TRUE;
7588 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007589 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007590 /* Just in case the old "curbuf" is now invalid. */
7591 if (varp != &(curbuf->b_p_ft))
7592 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007593 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007594 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007595#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007596 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007597 {
7598 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007599 char_u *q = curwin->w_s->b_p_spl;
7600
7601 /* Skip the first name if it is "cjk". */
7602 if (STRNCMP(q, "cjk,", 4) == 0)
7603 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007604
7605 /*
7606 * Source the spell/LANG.vim in 'runtimepath'.
7607 * They could set 'spellcapcheck' depending on the language.
7608 * Use the first name in 'spelllang' up to '_region' or
7609 * '.encoding'.
7610 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007611 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007612 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7613 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007614 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007615 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007616 }
7617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007618 }
7619
7620#ifdef FEAT_MOUSE
7621 if (varp == &p_mouse)
7622 {
7623# ifdef FEAT_MOUSE_TTY
7624 if (*p_mouse == NUL)
7625 mch_setmouse(FALSE); /* switch mouse off */
7626 else
7627# endif
7628 setmouse(); /* in case 'mouse' changed */
7629 }
7630#endif
7631
Bram Moolenaar913077c2012-03-28 19:59:04 +02007632 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007633 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007634 curwin->w_set_curswant = TRUE;
7635
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007636#ifdef FEAT_GUI
7637 /* check redraw when it's not a GUI option or the GUI is active. */
7638 if (!redraw_gui_only || gui.in_use)
7639#endif
7640 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007641
7642 return errmsg;
7643}
7644
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007645#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007646/*
7647 * Simple int comparison function for use with qsort()
7648 */
7649 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007650int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007651{
7652 return *(const int *)a - *(const int *)b;
7653}
7654
7655/*
7656 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7657 * Returns error message, NULL if it's OK.
7658 */
7659 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007660check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007661{
7662 char_u *s;
7663 int col;
7664 int count = 0;
7665 int color_cols[256];
7666 int i;
7667 int j = 0;
7668
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007669 if (wp->w_buffer == NULL)
7670 return NULL; /* buffer was closed */
7671
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007672 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007673 {
7674 if (*s == '-' || *s == '+')
7675 {
7676 /* -N and +N: add to 'textwidth' */
7677 col = (*s == '-') ? -1 : 1;
7678 ++s;
7679 if (!VIM_ISDIGIT(*s))
7680 return e_invarg;
7681 col = col * getdigits(&s);
7682 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007683 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007684 col += wp->w_buffer->b_p_tw;
7685 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007686 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007687 }
7688 else if (VIM_ISDIGIT(*s))
7689 col = getdigits(&s);
7690 else
7691 return e_invarg;
7692 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007693skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007694 if (*s == NUL)
7695 break;
7696 if (*s != ',')
7697 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007698 if (*++s == NUL)
7699 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007700 }
7701
7702 vim_free(wp->w_p_cc_cols);
7703 if (count == 0)
7704 wp->w_p_cc_cols = NULL;
7705 else
7706 {
7707 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7708 if (wp->w_p_cc_cols != NULL)
7709 {
7710 /* sort the columns for faster usage on screen redraw inside
7711 * win_line() */
7712 qsort(color_cols, count, sizeof(int), int_cmp);
7713
7714 for (i = 0; i < count; ++i)
7715 /* skip duplicates */
7716 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7717 wp->w_p_cc_cols[j++] = color_cols[i];
7718 wp->w_p_cc_cols[j] = -1; /* end marker */
7719 }
7720 }
7721
7722 return NULL; /* no error */
7723}
7724#endif
7725
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726/*
7727 * Handle setting 'listchars' or 'fillchars'.
7728 * Returns error message, NULL if it's OK.
7729 */
7730 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007731set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732{
7733 int round, i, len, entries;
7734 char_u *p, *s;
7735 int c1, c2 = 0;
7736 struct charstab
7737 {
7738 int *cp;
7739 char *name;
7740 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 static struct charstab filltab[] =
7742 {
7743 {&fill_stl, "stl"},
7744 {&fill_stlnc, "stlnc"},
7745 {&fill_vert, "vert"},
7746 {&fill_fold, "fold"},
7747 {&fill_diff, "diff"},
7748 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 static struct charstab lcstab[] =
7750 {
7751 {&lcs_eol, "eol"},
7752 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007753 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007755 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 {&lcs_tab2, "tab"},
7757 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758#ifdef FEAT_CONCEAL
7759 {&lcs_conceal, "conceal"},
7760#else
7761 {NULL, "conceal"},
7762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 };
7764 struct charstab *tab;
7765
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 {
7768 tab = lcstab;
7769 entries = sizeof(lcstab) / sizeof(struct charstab);
7770 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771 else
7772 {
7773 tab = filltab;
7774 entries = sizeof(filltab) / sizeof(struct charstab);
7775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776
7777 /* first round: check for valid value, second round: assign values */
7778 for (round = 0; round <= 1; ++round)
7779 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007780 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 {
7782 /* After checking that the value is valid: set defaults: space for
7783 * 'fillchars', NUL for 'listchars' */
7784 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007785 if (tab[i].cp != NULL)
7786 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 if (varp == &p_lcs)
7788 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 else
7790 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 }
7792 p = *varp;
7793 while (*p)
7794 {
7795 for (i = 0; i < entries; ++i)
7796 {
7797 len = (int)STRLEN(tab[i].name);
7798 if (STRNCMP(p, tab[i].name, len) == 0
7799 && p[len] == ':'
7800 && p[len + 1] != NUL)
7801 {
7802 s = p + len + 1;
7803#ifdef FEAT_MBYTE
7804 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007805 if (mb_char2cells(c1) > 1)
7806 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807#else
7808 c1 = *s++;
7809#endif
7810 if (tab[i].cp == &lcs_tab2)
7811 {
7812 if (*s == NUL)
7813 continue;
7814#ifdef FEAT_MBYTE
7815 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007816 if (mb_char2cells(c2) > 1)
7817 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818#else
7819 c2 = *s++;
7820#endif
7821 }
7822 if (*s == ',' || *s == NUL)
7823 {
7824 if (round)
7825 {
7826 if (tab[i].cp == &lcs_tab2)
7827 {
7828 lcs_tab1 = c1;
7829 lcs_tab2 = c2;
7830 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007831 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832 *(tab[i].cp) = c1;
7833
7834 }
7835 p = s;
7836 break;
7837 }
7838 }
7839 }
7840
7841 if (i == entries)
7842 return e_invarg;
7843 if (*p == ',')
7844 ++p;
7845 }
7846 }
7847
7848 return NULL; /* no error */
7849}
7850
7851#ifdef FEAT_STL_OPT
7852/*
7853 * Check validity of options with the 'statusline' format.
7854 * Return error message or NULL.
7855 */
7856 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007857check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007858{
7859 int itemcnt = 0;
7860 int groupdepth = 0;
7861 static char_u errbuf[80];
7862
7863 while (*s && itemcnt < STL_MAX_ITEM)
7864 {
7865 /* Check for valid keys after % sequences */
7866 while (*s && *s != '%')
7867 s++;
7868 if (!*s)
7869 break;
7870 s++;
7871 if (*s != '%' && *s != ')')
7872 ++itemcnt;
7873 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7874 {
7875 s++;
7876 continue;
7877 }
7878 if (*s == ')')
7879 {
7880 s++;
7881 if (--groupdepth < 0)
7882 break;
7883 continue;
7884 }
7885 if (*s == '-')
7886 s++;
7887 while (VIM_ISDIGIT(*s))
7888 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007889 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 continue;
7891 if (*s == '.')
7892 {
7893 s++;
7894 while (*s && VIM_ISDIGIT(*s))
7895 s++;
7896 }
7897 if (*s == '(')
7898 {
7899 groupdepth++;
7900 continue;
7901 }
7902 if (vim_strchr(STL_ALL, *s) == NULL)
7903 {
7904 return illegal_char(errbuf, *s);
7905 }
7906 if (*s == '{')
7907 {
7908 s++;
7909 while (*s != '}' && *s)
7910 s++;
7911 if (*s != '}')
7912 return (char_u *)N_("E540: Unclosed expression sequence");
7913 }
7914 }
7915 if (itemcnt >= STL_MAX_ITEM)
7916 return (char_u *)N_("E541: too many items");
7917 if (groupdepth != 0)
7918 return (char_u *)N_("E542: unbalanced groups");
7919 return NULL;
7920}
7921#endif
7922
7923#ifdef FEAT_CLIPBOARD
7924/*
7925 * Extract the items in the 'clipboard' option and set global values.
7926 */
7927 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007928check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007930 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007931 int new_autoselect_star = FALSE;
7932 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007934 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 regprog_T *new_exclude_prog = NULL;
7936 char_u *errmsg = NULL;
7937 char_u *p;
7938
7939 for (p = p_cb; *p != NUL; )
7940 {
7941 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7942 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007943 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 p += 7;
7945 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007946 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007947 && (p[11] == ',' || p[11] == NUL))
7948 {
7949 new_unnamed |= CLIP_UNNAMED_PLUS;
7950 p += 11;
7951 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007953 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007955 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 p += 10;
7957 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007958 else if (STRNCMP(p, "autoselectplus", 14) == 0
7959 && (p[14] == ',' || p[14] == NUL))
7960 {
7961 new_autoselect_plus = TRUE;
7962 p += 14;
7963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007965 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 {
7967 new_autoselectml = TRUE;
7968 p += 12;
7969 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007970 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7971 {
7972 new_html = TRUE;
7973 p += 4;
7974 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7976 {
7977 p += 8;
7978 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7979 if (new_exclude_prog == NULL)
7980 errmsg = e_invarg;
7981 break;
7982 }
7983 else
7984 {
7985 errmsg = e_invarg;
7986 break;
7987 }
7988 if (*p == ',')
7989 ++p;
7990 }
7991 if (errmsg == NULL)
7992 {
7993 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007994 clip_autoselect_star = new_autoselect_star;
7995 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007997 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007998 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008000#ifdef FEAT_GUI_GTK
8001 if (gui.in_use)
8002 {
8003 gui_gtk_set_selection_targets();
8004 gui_gtk_set_dnd_targets();
8005 }
8006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 }
8008 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008009 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010
8011 return errmsg;
8012}
8013#endif
8014
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008015#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008016 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008017did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008018{
8019 char_u *errmsg = NULL;
8020 win_T *wp;
8021 int l;
8022
8023 if (is_spellfile)
8024 {
8025 l = (int)STRLEN(curwin->w_s->b_p_spf);
8026 if (l > 0 && (l < 4
8027 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8028 errmsg = e_invarg;
8029 }
8030
8031 if (errmsg == NULL)
8032 {
8033 FOR_ALL_WINDOWS(wp)
8034 if (wp->w_buffer == curbuf && wp->w_p_spell)
8035 {
8036 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008037 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008038 }
8039 }
8040 return errmsg;
8041}
8042
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008043/*
8044 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8045 * Return error message when failed, NULL when OK.
8046 */
8047 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008048compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008049{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008050 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008051 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008052
Bram Moolenaar860cae12010-06-05 23:22:07 +02008053 if (*synblock->b_p_spc == NUL)
8054 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008055 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008056 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008057 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008058 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008059 if (re != NULL)
8060 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008061 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008062 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008063 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008064 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008065 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008066 return e_invarg;
8067 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008068 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008069 }
8070
Bram Moolenaar473de612013-06-08 18:19:48 +02008071 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008072 return NULL;
8073}
8074#endif
8075
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008076#if defined(FEAT_EVAL) || defined(PROTO)
8077/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008078 * Set the scriptID for an option, taking care of setting the buffer- or
8079 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008080 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008081 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008082set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008083{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008084 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8085 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008086
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008087 /* Remember where the option was set. For local options need to do that
8088 * in the buffer or window structure. */
8089 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008090 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008091 if (both || (opt_flags & OPT_LOCAL))
8092 {
8093 if (indir & PV_BUF)
8094 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8095 else if (indir & PV_WIN)
8096 curwin->w_p_scriptID[indir & PV_MASK] = id;
8097 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008098}
8099#endif
8100
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101/*
8102 * Set the value of a boolean option, and take care of side effects.
8103 * Returns NULL for success, or an error message for an error.
8104 */
8105 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008106set_bool_option(
8107 int opt_idx, /* index in options[] table */
8108 char_u *varp, /* pointer to the option variable */
8109 int value, /* new value */
8110 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111{
8112 int old_value = *(int *)varp;
8113
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 /* Disallow changing some options from secure mode */
8115 if ((secure
8116#ifdef HAVE_SANDBOX
8117 || sandbox != 0
8118#endif
8119 ) && (options[opt_idx].flags & P_SECURE))
8120 return e_secure;
8121
8122 *(int *)varp = value; /* set the new value */
8123#ifdef FEAT_EVAL
8124 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008125 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126#endif
8127
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008128#ifdef FEAT_GUI
8129 need_mouse_correct = TRUE;
8130#endif
8131
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 /* May set global value for local option. */
8133 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8134 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8135
8136 /*
8137 * Handle side effects of changing a bool option.
8138 */
8139
8140 /* 'compatible' */
8141 if ((int *)varp == &p_cp)
8142 {
8143 compatible_set();
8144 }
8145
Bram Moolenaar920694c2016-08-21 17:45:02 +02008146#ifdef FEAT_LANGMAP
8147 if ((int *)varp == &p_lrm)
8148 /* 'langremap' -> !'langnoremap' */
8149 p_lnr = !p_lrm;
8150 else if ((int *)varp == &p_lnr)
8151 /* 'langnoremap' -> !'langremap' */
8152 p_lrm = !p_lnr;
8153#endif
8154
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008155#ifdef FEAT_PERSISTENT_UNDO
8156 /* 'undofile' */
8157 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8158 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008159 /* Only take action when the option was set. When reset we do not
8160 * delete the undo file, the option may be set again without making
8161 * any changes in between. */
8162 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008163 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008164 char_u hash[UNDO_HASH_SIZE];
8165 buf_T *save_curbuf = curbuf;
8166
Bram Moolenaar29323592016-07-24 22:04:11 +02008167 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008168 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008169 /* When 'undofile' is set globally: for every buffer, otherwise
8170 * only for the current buffer: Try to read in the undofile,
8171 * if one exists, the buffer wasn't changed and the buffer was
8172 * loaded */
8173 if ((curbuf == save_curbuf
8174 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8175 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8176 {
8177 u_compute_hash(hash);
8178 u_read_undo(NULL, hash, curbuf->b_fname);
8179 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008180 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008181 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008182 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008183 }
8184#endif
8185
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 else if ((int *)varp == &curbuf->b_p_ro)
8187 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008188 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8190 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008191
8192 /* when 'readonly' is set may give W10 again */
8193 if (curbuf->b_p_ro)
8194 curbuf->b_did_warn = FALSE;
8195
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008197 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198#endif
8199 }
8200
Bram Moolenaar9c449722010-07-20 18:44:27 +02008201#ifdef FEAT_GUI
8202 else if ((int *)varp == &p_mh)
8203 {
8204 if (!p_mh)
8205 gui_mch_mousehide(FALSE);
8206 }
8207#endif
8208
Bram Moolenaara539df02010-08-01 14:35:05 +02008209 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008211 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008212# ifdef FEAT_TERMINAL
8213 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008214 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008215 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008216 {
8217 curbuf->b_p_ma = FALSE;
8218 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8219 }
8220# endif
8221# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008222 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008223# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008224 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008225#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226 /* when 'endofline' is changed, redraw the window title */
8227 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008228 {
8229 redraw_titles();
8230 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008231 /* when 'fixeol' is changed, redraw the window title */
8232 else if ((int *)varp == &curbuf->b_p_fixeol)
8233 {
8234 redraw_titles();
8235 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008236# ifdef FEAT_MBYTE
8237 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008238 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008239 {
8240 redraw_titles();
8241 }
8242# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243#endif
8244
8245 /* when 'bin' is set also set some other options */
8246 else if ((int *)varp == &curbuf->b_p_bin)
8247 {
8248 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8249#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008250 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251#endif
8252 }
8253
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 /* when 'buflisted' changes, trigger autocommands */
8255 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8256 {
8257 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8258 NULL, NULL, TRUE, curbuf);
8259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260
8261 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8262 else if ((int *)varp == &curbuf->b_p_swf)
8263 {
8264 if (curbuf->b_p_swf && p_uc)
8265 ml_open_file(curbuf); /* create the swap file */
8266 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008267 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8268 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269 mf_close_file(curbuf, TRUE); /* remove the swap file */
8270 }
8271
8272 /* when 'terse' is set change 'shortmess' */
8273 else if ((int *)varp == &p_terse)
8274 {
8275 char_u *p;
8276
8277 p = vim_strchr(p_shm, SHM_SEARCH);
8278
8279 /* insert 's' in p_shm */
8280 if (p_terse && p == NULL)
8281 {
8282 STRCPY(IObuff, p_shm);
8283 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008284 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 }
8286 /* remove 's' from p_shm */
8287 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008288 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 }
8290
8291 /* when 'paste' is set or reset also change other options */
8292 else if ((int *)varp == &p_paste)
8293 {
8294 paste_option_changed();
8295 }
8296
8297 /* when 'insertmode' is set from an autocommand need to do work here */
8298 else if ((int *)varp == &p_im)
8299 {
8300 if (p_im)
8301 {
8302 if ((State & INSERT) == 0)
8303 need_start_insertmode = TRUE;
8304 stop_insert_mode = FALSE;
8305 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008306 /* only reset if it was set previously */
8307 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008308 {
8309 need_start_insertmode = FALSE;
8310 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008311 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 clear_cmdline = TRUE; /* remove "(insert)" */
8313 restart_edit = 0;
8314 }
8315 }
8316
8317 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8318 else if ((int *)varp == &p_ic && p_hls)
8319 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008320 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321 }
8322
8323#ifdef FEAT_SEARCH_EXTRA
8324 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8325 else if ((int *)varp == &p_hls)
8326 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008327 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 }
8329#endif
8330
8331#ifdef FEAT_SCROLLBIND
8332 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8333 * at the end of normal_cmd() */
8334 else if ((int *)varp == &curwin->w_p_scb)
8335 {
8336 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008337 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008339 curwin->w_scbind_pos = curwin->w_topline;
8340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 }
8342#endif
8343
Bram Moolenaar4033c552017-09-16 20:54:51 +02008344#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 /* There can be only one window with 'previewwindow' set. */
8346 else if ((int *)varp == &curwin->w_p_pvw)
8347 {
8348 if (curwin->w_p_pvw)
8349 {
8350 win_T *win;
8351
Bram Moolenaar29323592016-07-24 22:04:11 +02008352 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 if (win->w_p_pvw && win != curwin)
8354 {
8355 curwin->w_p_pvw = FALSE;
8356 return (char_u *)N_("E590: A preview window already exists");
8357 }
8358 }
8359 }
8360#endif
8361
8362 /* when 'textmode' is set or reset also change 'fileformat' */
8363 else if ((int *)varp == &curbuf->b_p_tx)
8364 {
8365 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8366 }
8367
8368 /* when 'textauto' is set or reset also change 'fileformats' */
8369 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 set_string_option_direct((char_u *)"ffs", -1,
8371 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008372 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373
8374 /*
8375 * When 'lisp' option changes include/exclude '-' in
8376 * keyword characters.
8377 */
8378#ifdef FEAT_LISP
8379 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8380 {
8381 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8382 }
8383#endif
8384
8385#ifdef FEAT_TITLE
8386 /* when 'title' changed, may need to change the title; same for 'icon' */
8387 else if ((int *)varp == &p_title)
8388 {
8389 did_set_title(FALSE);
8390 }
8391
8392 else if ((int *)varp == &p_icon)
8393 {
8394 did_set_title(TRUE);
8395 }
8396#endif
8397
8398 else if ((int *)varp == &curbuf->b_changed)
8399 {
8400 if (!value)
8401 save_file_ff(curbuf); /* Buffer is unchanged */
8402#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008403 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 }
8407
8408#ifdef BACKSLASH_IN_FILENAME
8409 else if ((int *)varp == &p_ssl)
8410 {
8411 if (p_ssl)
8412 {
8413 psepc = '/';
8414 psepcN = '\\';
8415 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 }
8417 else
8418 {
8419 psepc = '\\';
8420 psepcN = '/';
8421 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422 }
8423
8424 /* need to adjust the file name arguments and buffer names. */
8425 buflist_slash_adjust();
8426 alist_slash_adjust();
8427# ifdef FEAT_EVAL
8428 scriptnames_slash_adjust();
8429# endif
8430 }
8431#endif
8432
8433 /* If 'wrap' is set, set w_leftcol to zero. */
8434 else if ((int *)varp == &curwin->w_p_wrap)
8435 {
8436 if (curwin->w_p_wrap)
8437 curwin->w_leftcol = 0;
8438 }
8439
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 else if ((int *)varp == &p_ea)
8441 {
8442 if (p_ea && !old_value)
8443 win_equal(curwin, FALSE, 0);
8444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008445
8446 else if ((int *)varp == &p_wiv)
8447 {
8448 /*
8449 * When 'weirdinvert' changed, set/reset 't_xs'.
8450 * Then set 'weirdinvert' according to value of 't_xs'.
8451 */
8452 if (p_wiv && !old_value)
8453 T_XS = (char_u *)"y";
8454 else if (!p_wiv && old_value)
8455 T_XS = empty_option;
8456 p_wiv = (*T_XS != NUL);
8457 }
8458
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008459#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 else if ((int *)varp == &p_beval)
8461 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008462 if (!balloonEvalForTerm)
8463 {
8464 if (p_beval && !old_value)
8465 gui_mch_enable_beval_area(balloonEval);
8466 else if (!p_beval && old_value)
8467 gui_mch_disable_beval_area(balloonEval);
8468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008470#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008471#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008472 else if ((int *)varp == &p_bevalterm)
8473 {
8474 mch_bevalterm_changed();
8475 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008478#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 else if ((int *)varp == &p_acd)
8480 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008481 /* Change directories when the 'acd' option is set now. */
8482 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 }
8484#endif
8485
8486#ifdef FEAT_DIFF
8487 /* 'diff' */
8488 else if ((int *)varp == &curwin->w_p_diff)
8489 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008490 /* May add or remove the buffer from the list of diff buffers. */
8491 diff_buf_adjust(curwin);
8492# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 if (foldmethodIsDiff(curwin))
8494 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008495# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 }
8497#endif
8498
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008499#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 /* 'imdisable' */
8501 else if ((int *)varp == &p_imdisable)
8502 {
8503 /* Only de-activate it here, it will be enabled when changing mode. */
8504 if (p_imdisable)
8505 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008506 else if (State & INSERT)
8507 /* When the option is set from an autocommand, it may need to take
8508 * effect right away. */
8509 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511#endif
8512
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008513#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008514 /* 'spell' */
8515 else if ((int *)varp == &curwin->w_p_spell)
8516 {
8517 if (curwin->w_p_spell)
8518 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008519 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008520 if (errmsg != NULL)
8521 EMSG(_(errmsg));
8522 }
8523 }
8524#endif
8525
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526#ifdef FEAT_FKMAP
8527 else if ((int *)varp == &p_altkeymap)
8528 {
8529 if (old_value != p_altkeymap)
8530 {
8531 if (!p_altkeymap)
8532 {
8533 p_hkmap = p_fkmap;
8534 p_fkmap = 0;
8535 }
8536 else
8537 {
8538 p_fkmap = p_hkmap;
8539 p_hkmap = 0;
8540 }
8541 (void)init_chartab();
8542 }
8543 }
8544
8545 /*
8546 * In case some second language keymapping options have changed, check
8547 * and correct the setting in a consistent way.
8548 */
8549
8550 /*
8551 * If hkmap or fkmap are set, reset Arabic keymapping.
8552 */
8553 if ((p_hkmap || p_fkmap) && p_altkeymap)
8554 {
8555 p_altkeymap = p_fkmap;
8556# ifdef FEAT_ARABIC
8557 curwin->w_p_arab = FALSE;
8558# endif
8559 (void)init_chartab();
8560 }
8561
8562 /*
8563 * If hkmap set, reset Farsi keymapping.
8564 */
8565 if (p_hkmap && p_altkeymap)
8566 {
8567 p_altkeymap = 0;
8568 p_fkmap = 0;
8569# ifdef FEAT_ARABIC
8570 curwin->w_p_arab = FALSE;
8571# endif
8572 (void)init_chartab();
8573 }
8574
8575 /*
8576 * If fkmap set, reset Hebrew keymapping.
8577 */
8578 if (p_fkmap && !p_altkeymap)
8579 {
8580 p_altkeymap = 1;
8581 p_hkmap = 0;
8582# ifdef FEAT_ARABIC
8583 curwin->w_p_arab = FALSE;
8584# endif
8585 (void)init_chartab();
8586 }
8587#endif
8588
8589#ifdef FEAT_ARABIC
8590 if ((int *)varp == &curwin->w_p_arab)
8591 {
8592 if (curwin->w_p_arab)
8593 {
8594 /*
8595 * 'arabic' is set, handle various sub-settings.
8596 */
8597 if (!p_tbidi)
8598 {
8599 /* set rightleft mode */
8600 if (!curwin->w_p_rl)
8601 {
8602 curwin->w_p_rl = TRUE;
8603 changed_window_setting();
8604 }
8605
8606 /* Enable Arabic shaping (major part of what Arabic requires) */
8607 if (!p_arshape)
8608 {
8609 p_arshape = TRUE;
8610 redraw_later_clear();
8611 }
8612 }
8613
8614 /* Arabic requires a utf-8 encoding, inform the user if its not
8615 * set. */
8616 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008617 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008618 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8619
Bram Moolenaar8820b482017-03-16 17:23:31 +01008620 msg_source(HL_ATTR(HLF_W));
8621 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008622#ifdef FEAT_EVAL
8623 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8624#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626
8627# ifdef FEAT_MBYTE
8628 /* set 'delcombine' */
8629 p_deco = TRUE;
8630# endif
8631
8632# ifdef FEAT_KEYMAP
8633 /* Force-set the necessary keymap for arabic */
8634 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8635 OPT_LOCAL);
8636# endif
8637# ifdef FEAT_FKMAP
8638 p_altkeymap = 0;
8639 p_hkmap = 0;
8640 p_fkmap = 0;
8641 (void)init_chartab();
8642# endif
8643 }
8644 else
8645 {
8646 /*
8647 * 'arabic' is reset, handle various sub-settings.
8648 */
8649 if (!p_tbidi)
8650 {
8651 /* reset rightleft mode */
8652 if (curwin->w_p_rl)
8653 {
8654 curwin->w_p_rl = FALSE;
8655 changed_window_setting();
8656 }
8657
8658 /* 'arabicshape' isn't reset, it is a global option and
8659 * another window may still need it "on". */
8660 }
8661
8662 /* 'delcombine' isn't reset, it is a global option and another
8663 * window may still want it "on". */
8664
8665# ifdef FEAT_KEYMAP
8666 /* Revert to the default keymap */
8667 curbuf->b_p_iminsert = B_IMODE_NONE;
8668 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8669# endif
8670 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008671 }
8672
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008673#endif
8674
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008675#ifdef FEAT_TERMGUICOLORS
8676 /* 'termguicolors' */
8677 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008678 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008679# ifdef FEAT_VTP
8680 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8681 if (!has_vtp_working())
8682 {
8683 p_tgc = 0;
8684 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8685 }
8686 swap_tcap();
8687# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008688# ifdef FEAT_GUI
8689 if (!gui.in_use && !gui.starting)
8690# endif
8691 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008692# ifdef FEAT_VTP
8693 control_console_color_rgb();
8694 /* reset t_Co */
8695 if (STRCMP(T_NAME, "win32") == 0)
8696 set_termname(T_NAME);
8697# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008698 }
8699#endif
8700
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701 /*
8702 * End of handling side effects for bool options.
8703 */
8704
Bram Moolenaar53744302015-07-17 17:38:22 +02008705 /* after handling side effects, call autocommand */
8706
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707 options[opt_idx].flags |= P_WAS_SET;
8708
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008709#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008710 if (!starting)
8711 {
8712 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008713 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8714 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8715 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008716 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8717 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8718 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8719 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8720 reset_v_option_vars();
8721 }
8722#endif
8723
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008725 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008726 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008727 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728 check_redraw(options[opt_idx].flags);
8729
8730 return NULL;
8731}
8732
8733/*
8734 * Set the value of a number option, and take care of side effects.
8735 * Returns NULL for success, or an error message for an error.
8736 */
8737 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008738set_num_option(
8739 int opt_idx, /* index in options[] table */
8740 char_u *varp, /* pointer to the option variable */
8741 long value, /* new value */
8742 char_u *errbuf, /* buffer for error messages */
8743 size_t errbuflen, /* length of "errbuf" */
8744 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 OPT_MODELINE */
8746{
8747 char_u *errmsg = NULL;
8748 long old_value = *(long *)varp;
8749 long old_Rows = Rows; /* remember old Rows */
8750 long old_Columns = Columns; /* remember old Columns */
8751 long *pp = (long *)varp;
8752
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008753 /* Disallow changing some options from secure mode. */
8754 if ((secure
8755#ifdef HAVE_SANDBOX
8756 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008758 ) && (options[opt_idx].flags & P_SECURE))
8759 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008760
8761 *pp = value;
8762#ifdef FEAT_EVAL
8763 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008764 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008766#ifdef FEAT_GUI
8767 need_mouse_correct = TRUE;
8768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769
Bram Moolenaar14f24742012-08-08 18:01:05 +02008770 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 {
8772 errmsg = e_positive;
8773 curbuf->b_p_sw = curbuf->b_p_ts;
8774 }
8775
8776 /*
8777 * Number options that need some action when changed
8778 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779 if (pp == &p_wh || pp == &p_hh)
8780 {
8781 if (p_wh < 1)
8782 {
8783 errmsg = e_positive;
8784 p_wh = 1;
8785 }
8786 if (p_wmh > p_wh)
8787 {
8788 errmsg = e_winheight;
8789 p_wh = p_wmh;
8790 }
8791 if (p_hh < 0)
8792 {
8793 errmsg = e_positive;
8794 p_hh = 0;
8795 }
8796
8797 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008798 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008799 {
8800 if (pp == &p_wh && curwin->w_height < p_wh)
8801 win_setheight((int)p_wh);
8802 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8803 win_setheight((int)p_hh);
8804 }
8805 }
8806
8807 /* 'winminheight' */
8808 else if (pp == &p_wmh)
8809 {
8810 if (p_wmh < 0)
8811 {
8812 errmsg = e_positive;
8813 p_wmh = 0;
8814 }
8815 if (p_wmh > p_wh)
8816 {
8817 errmsg = e_winheight;
8818 p_wmh = p_wh;
8819 }
8820 win_setminheight();
8821 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008822 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 {
8824 if (p_wiw < 1)
8825 {
8826 errmsg = e_positive;
8827 p_wiw = 1;
8828 }
8829 if (p_wmw > p_wiw)
8830 {
8831 errmsg = e_winwidth;
8832 p_wiw = p_wmw;
8833 }
8834
8835 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008836 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 win_setwidth((int)p_wiw);
8838 }
8839
8840 /* 'winminwidth' */
8841 else if (pp == &p_wmw)
8842 {
8843 if (p_wmw < 0)
8844 {
8845 errmsg = e_positive;
8846 p_wmw = 0;
8847 }
8848 if (p_wmw > p_wiw)
8849 {
8850 errmsg = e_winwidth;
8851 p_wmw = p_wiw;
8852 }
8853 win_setminheight();
8854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 /* (re)set last window status line */
8857 else if (pp == &p_ls)
8858 {
8859 last_status(FALSE);
8860 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008861
8862 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008863 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008864 {
8865 shell_new_rows(); /* recompute window positions and heights */
8866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867
8868#ifdef FEAT_GUI
8869 else if (pp == &p_linespace)
8870 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008871 /* Recompute gui.char_height and resize the Vim window to keep the
8872 * same number of lines. */
8873 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008874 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 }
8876#endif
8877
8878#ifdef FEAT_FOLDING
8879 /* 'foldlevel' */
8880 else if (pp == &curwin->w_p_fdl)
8881 {
8882 if (curwin->w_p_fdl < 0)
8883 curwin->w_p_fdl = 0;
8884 newFoldLevel();
8885 }
8886
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008887 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 else if (pp == &curwin->w_p_fml)
8889 {
8890 foldUpdateAll(curwin);
8891 }
8892
8893 /* 'foldnestmax' */
8894 else if (pp == &curwin->w_p_fdn)
8895 {
8896 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8897 foldUpdateAll(curwin);
8898 }
8899
8900 /* 'foldcolumn' */
8901 else if (pp == &curwin->w_p_fdc)
8902 {
8903 if (curwin->w_p_fdc < 0)
8904 {
8905 errmsg = e_positive;
8906 curwin->w_p_fdc = 0;
8907 }
8908 else if (curwin->w_p_fdc > 12)
8909 {
8910 errmsg = e_invarg;
8911 curwin->w_p_fdc = 12;
8912 }
8913 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008914#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008916#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917 /* 'shiftwidth' or 'tabstop' */
8918 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8919 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008920# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 if (foldmethodIsIndent(curwin))
8922 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008923# endif
8924# ifdef FEAT_CINDENT
8925 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8926 * parse 'cinoptions'. */
8927 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8928 parse_cino(curbuf);
8929# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008933#ifdef FEAT_MBYTE
8934 /* 'maxcombine' */
8935 else if (pp == &p_mco)
8936 {
8937 if (p_mco > MAX_MCO)
8938 p_mco = MAX_MCO;
8939 else if (p_mco < 0)
8940 p_mco = 0;
8941 screenclear(); /* will re-allocate the screen */
8942 }
8943#endif
8944
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 else if (pp == &curbuf->b_p_iminsert)
8946 {
8947 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8948 {
8949 errmsg = e_invarg;
8950 curbuf->b_p_iminsert = B_IMODE_NONE;
8951 }
8952 p_iminsert = curbuf->b_p_iminsert;
8953 if (termcap_active) /* don't do this in the alternate screen */
8954 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008955#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 /* Show/unshow value of 'keymap' in status lines. */
8957 status_redraw_curbuf();
8958#endif
8959 }
8960
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008961#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8962 /* 'imstyle' */
8963 else if (pp == &p_imst)
8964 {
8965 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8966 errmsg = e_invarg;
8967 }
8968#endif
8969
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008970 else if (pp == &p_window)
8971 {
8972 if (p_window < 1)
8973 p_window = 1;
8974 else if (p_window >= Rows)
8975 p_window = Rows - 1;
8976 }
8977
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 else if (pp == &curbuf->b_p_imsearch)
8979 {
8980 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8981 {
8982 errmsg = e_invarg;
8983 curbuf->b_p_imsearch = B_IMODE_NONE;
8984 }
8985 p_imsearch = curbuf->b_p_imsearch;
8986 }
8987
8988#ifdef FEAT_TITLE
8989 /* if 'titlelen' has changed, redraw the title */
8990 else if (pp == &p_titlelen)
8991 {
8992 if (p_titlelen < 0)
8993 {
8994 errmsg = e_positive;
8995 p_titlelen = 85;
8996 }
8997 if (starting != NO_SCREEN && old_value != p_titlelen)
8998 need_maketitle = TRUE;
8999 }
9000#endif
9001
9002 /* if p_ch changed value, change the command line height */
9003 else if (pp == &p_ch)
9004 {
9005 if (p_ch < 1)
9006 {
9007 errmsg = e_positive;
9008 p_ch = 1;
9009 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009010 if (p_ch > Rows - min_rows() + 1)
9011 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009012
9013 /* Only compute the new window layout when startup has been
9014 * completed. Otherwise the frame sizes may be wrong. */
9015 if (p_ch != old_value && full_screen
9016#ifdef FEAT_GUI
9017 && !gui.starting
9018#endif
9019 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009020 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021 }
9022
9023 /* when 'updatecount' changes from zero to non-zero, open swap files */
9024 else if (pp == &p_uc)
9025 {
9026 if (p_uc < 0)
9027 {
9028 errmsg = e_positive;
9029 p_uc = 100;
9030 }
9031 if (p_uc && !old_value)
9032 ml_open_files();
9033 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009034#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009035 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009036 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009037 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009038 {
9039 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009040 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009041 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009042 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009043 {
9044 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009045 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009046 }
9047 }
9048#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009049#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009050 else if (pp == &p_mzq)
9051 mzvim_reset_timer();
9052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009054#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9055 /* 'pyxversion' */
9056 else if (pp == &p_pyx)
9057 {
9058 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9059 errmsg = e_invarg;
9060 }
9061#endif
9062
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 /* sync undo before 'undolevels' changes */
9064 else if (pp == &p_ul)
9065 {
9066 /* use the old value, otherwise u_sync() may not work properly */
9067 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009068 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 p_ul = value;
9070 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009071 else if (pp == &curbuf->b_p_ul)
9072 {
9073 /* use the old value, otherwise u_sync() may not work properly */
9074 curbuf->b_p_ul = old_value;
9075 u_sync(TRUE);
9076 curbuf->b_p_ul = value;
9077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009079#ifdef FEAT_LINEBREAK
9080 /* 'numberwidth' must be positive */
9081 else if (pp == &curwin->w_p_nuw)
9082 {
9083 if (curwin->w_p_nuw < 1)
9084 {
9085 errmsg = e_positive;
9086 curwin->w_p_nuw = 1;
9087 }
9088 if (curwin->w_p_nuw > 10)
9089 {
9090 errmsg = e_invarg;
9091 curwin->w_p_nuw = 10;
9092 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009093 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009094 }
9095#endif
9096
Bram Moolenaar1a384422010-07-14 19:53:30 +02009097 else if (pp == &curbuf->b_p_tw)
9098 {
9099 if (curbuf->b_p_tw < 0)
9100 {
9101 errmsg = e_positive;
9102 curbuf->b_p_tw = 0;
9103 }
9104#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009105 {
9106 win_T *wp;
9107 tabpage_T *tp;
9108
9109 FOR_ALL_TAB_WINDOWS(tp, wp)
9110 check_colorcolumn(wp);
9111 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009112#endif
9113 }
9114
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 /*
9116 * Check the bounds for numeric options here
9117 */
9118 if (Rows < min_rows() && full_screen)
9119 {
9120 if (errbuf != NULL)
9121 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009122 vim_snprintf((char *)errbuf, errbuflen,
9123 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 errmsg = errbuf;
9125 }
9126 Rows = min_rows();
9127 }
9128 if (Columns < MIN_COLUMNS && full_screen)
9129 {
9130 if (errbuf != NULL)
9131 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009132 vim_snprintf((char *)errbuf, errbuflen,
9133 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 errmsg = errbuf;
9135 }
9136 Columns = MIN_COLUMNS;
9137 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009138 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140 /*
9141 * If the screen (shell) height has been changed, assume it is the
9142 * physical screenheight.
9143 */
9144 if (old_Rows != Rows || old_Columns != Columns)
9145 {
9146 /* Changing the screen size is not allowed while updating the screen. */
9147 if (updating_screen)
9148 *pp = old_value;
9149 else if (full_screen
9150#ifdef FEAT_GUI
9151 && !gui.starting
9152#endif
9153 )
9154 set_shellsize((int)Columns, (int)Rows, TRUE);
9155 else
9156 {
9157 /* Postpone the resizing; check the size and cmdline position for
9158 * messages. */
9159 check_shellsize();
9160 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9161 cmdline_row = Rows - p_ch;
9162 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009163 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009164 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 }
9166
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 if (curbuf->b_p_ts <= 0)
9168 {
9169 errmsg = e_positive;
9170 curbuf->b_p_ts = 8;
9171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 if (p_tm < 0)
9173 {
9174 errmsg = e_positive;
9175 p_tm = 0;
9176 }
9177 if ((curwin->w_p_scr <= 0
9178 || (curwin->w_p_scr > curwin->w_height
9179 && curwin->w_height > 0))
9180 && full_screen)
9181 {
9182 if (pp == &(curwin->w_p_scr))
9183 {
9184 if (curwin->w_p_scr != 0)
9185 errmsg = e_scroll;
9186 win_comp_scroll(curwin);
9187 }
9188 /* If 'scroll' became invalid because of a side effect silently adjust
9189 * it. */
9190 else if (curwin->w_p_scr <= 0)
9191 curwin->w_p_scr = 1;
9192 else /* curwin->w_p_scr > curwin->w_height */
9193 curwin->w_p_scr = curwin->w_height;
9194 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009195 if (p_hi < 0)
9196 {
9197 errmsg = e_positive;
9198 p_hi = 0;
9199 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009200 else if (p_hi > 10000)
9201 {
9202 errmsg = e_invarg;
9203 p_hi = 10000;
9204 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009205 if (p_re < 0 || p_re > 2)
9206 {
9207 errmsg = e_invarg;
9208 p_re = 0;
9209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210 if (p_report < 0)
9211 {
9212 errmsg = e_positive;
9213 p_report = 1;
9214 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009215 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216 {
9217 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9218 p_sj = Rows / 2;
9219 else
9220 {
9221 errmsg = e_scroll;
9222 p_sj = 1;
9223 }
9224 }
9225 if (p_so < 0 && full_screen)
9226 {
9227 errmsg = e_scroll;
9228 p_so = 0;
9229 }
9230 if (p_siso < 0 && full_screen)
9231 {
9232 errmsg = e_positive;
9233 p_siso = 0;
9234 }
9235#ifdef FEAT_CMDWIN
9236 if (p_cwh < 1)
9237 {
9238 errmsg = e_positive;
9239 p_cwh = 1;
9240 }
9241#endif
9242 if (p_ut < 0)
9243 {
9244 errmsg = e_positive;
9245 p_ut = 2000;
9246 }
9247 if (p_ss < 0)
9248 {
9249 errmsg = e_positive;
9250 p_ss = 0;
9251 }
9252
9253 /* May set global value for local option. */
9254 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9255 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9256
9257 options[opt_idx].flags |= P_WAS_SET;
9258
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009259#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009260 if (!starting && errmsg == NULL)
9261 {
9262 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009263 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9264 vim_snprintf((char *)buf_new, 10, "%ld", value);
9265 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009266 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9267 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9268 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9269 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9270 reset_v_option_vars();
9271 }
9272#endif
9273
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009275 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009276 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009277 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278 check_redraw(options[opt_idx].flags);
9279
9280 return errmsg;
9281}
9282
9283/*
9284 * Called after an option changed: check if something needs to be redrawn.
9285 */
9286 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009287check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288{
9289 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009290 int doclear = (flags & P_RCLR) == P_RCLR;
9291 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9294 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295
9296 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9297 changed_window_setting();
9298 if (flags & P_RBUF)
9299 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009300 if (flags & P_RWINONLY)
9301 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009302 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303 redraw_all_later(CLEAR);
9304 else if (all)
9305 redraw_all_later(NOT_VALID);
9306}
9307
9308/*
9309 * Find index for option 'arg'.
9310 * Return -1 if not found.
9311 */
9312 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009313findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009314{
9315 int opt_idx;
9316 char *s, *p;
9317 static short quick_tab[27] = {0, 0}; /* quick access table */
9318 int is_term_opt;
9319
9320 /*
9321 * For first call: Initialize the quick-access table.
9322 * It contains the index for the first option that starts with a certain
9323 * letter. There are 26 letters, plus the first "t_" option.
9324 */
9325 if (quick_tab[1] == 0)
9326 {
9327 p = options[0].fullname;
9328 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9329 {
9330 if (s[0] != p[0])
9331 {
9332 if (s[0] == 't' && s[1] == '_')
9333 quick_tab[26] = opt_idx;
9334 else
9335 quick_tab[CharOrdLow(s[0])] = opt_idx;
9336 }
9337 p = s;
9338 }
9339 }
9340
9341 /*
9342 * Check for name starting with an illegal character.
9343 */
9344#ifdef EBCDIC
9345 if (!islower(arg[0]))
9346#else
9347 if (arg[0] < 'a' || arg[0] > 'z')
9348#endif
9349 return -1;
9350
9351 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9352 if (is_term_opt)
9353 opt_idx = quick_tab[26];
9354 else
9355 opt_idx = quick_tab[CharOrdLow(arg[0])];
9356 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9357 {
9358 if (STRCMP(arg, s) == 0) /* match full name */
9359 break;
9360 }
9361 if (s == NULL && !is_term_opt)
9362 {
9363 opt_idx = quick_tab[CharOrdLow(arg[0])];
9364 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9365 {
9366 s = options[opt_idx].shortname;
9367 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9368 break;
9369 s = NULL;
9370 }
9371 }
9372 if (s == NULL)
9373 opt_idx = -1;
9374 return opt_idx;
9375}
9376
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009377#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378/*
9379 * Get the value for an option.
9380 *
9381 * Returns:
9382 * Number or Toggle option: 1, *numval gets value.
9383 * String option: 0, *stringval gets allocated string.
9384 * Hidden Number or Toggle option: -1.
9385 * hidden String option: -2.
9386 * unknown option: -3.
9387 */
9388 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009389get_option_value(
9390 char_u *name,
9391 long *numval,
9392 char_u **stringval, /* NULL when only checking existence */
9393 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009394{
9395 int opt_idx;
9396 char_u *varp;
9397
9398 opt_idx = findoption(name);
9399 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009400 {
9401 int key;
9402
9403 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9404 && (key = find_key_option(name)) != 0)
9405 {
9406 char_u key_name[2];
9407 char_u *p;
9408
9409 if (key < 0)
9410 {
9411 key_name[0] = KEY2TERMCAP0(key);
9412 key_name[1] = KEY2TERMCAP1(key);
9413 }
9414 else
9415 {
9416 key_name[0] = KS_KEY;
9417 key_name[1] = (key & 0xff);
9418 }
9419 p = find_termcode(key_name);
9420 if (p != NULL)
9421 {
9422 if (stringval != NULL)
9423 *stringval = vim_strsave(p);
9424 return 0;
9425 }
9426 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429
9430 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9431
9432 if (options[opt_idx].flags & P_STRING)
9433 {
9434 if (varp == NULL) /* hidden option */
9435 return -2;
9436 if (stringval != NULL)
9437 {
9438#ifdef FEAT_CRYPT
9439 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009440 if ((char_u **)varp == &curbuf->b_p_key
9441 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009442 *stringval = vim_strsave((char_u *)"*****");
9443 else
9444#endif
9445 *stringval = vim_strsave(*(char_u **)(varp));
9446 }
9447 return 0;
9448 }
9449
9450 if (varp == NULL) /* hidden option */
9451 return -1;
9452 if (options[opt_idx].flags & P_NUM)
9453 *numval = *(long *)varp;
9454 else
9455 {
9456 /* Special case: 'modified' is b_changed, but we also want to consider
9457 * it set when 'ff' or 'fenc' changed. */
9458 if ((int *)varp == &curbuf->b_changed)
9459 *numval = curbufIsChanged();
9460 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009461 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462 }
9463 return 1;
9464}
9465#endif
9466
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009467#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009468/*
9469 * Returns the option attributes and its value. Unlike the above function it
9470 * will return either global value or local value of the option depending on
9471 * what was requested, but it will never return global value if it was
9472 * requested to return local one and vice versa. Neither it will return
9473 * buffer-local value if it was requested to return window-local one.
9474 *
9475 * Pretends that option is absent if it is not present in the requested scope
9476 * (i.e. has no global, window-local or buffer-local value depending on
9477 * opt_type). Uses
9478 *
9479 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009480 * 0 hidden or unknown option, also option that does not have requested
9481 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009482 * see SOPT_* in vim.h for other flags
9483 *
9484 * Possible opt_type values: see SREQ_* in vim.h
9485 */
9486 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009487get_option_value_strict(
9488 char_u *name,
9489 long *numval,
9490 char_u **stringval, /* NULL when only obtaining attributes */
9491 int opt_type,
9492 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009493{
9494 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009495 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009496 struct vimoption *p;
9497 int r = 0;
9498
9499 opt_idx = findoption(name);
9500 if (opt_idx < 0)
9501 return 0;
9502
9503 p = &(options[opt_idx]);
9504
9505 /* Hidden option */
9506 if (p->var == NULL)
9507 return 0;
9508
9509 if (p->flags & P_BOOL)
9510 r |= SOPT_BOOL;
9511 else if (p->flags & P_NUM)
9512 r |= SOPT_NUM;
9513 else if (p->flags & P_STRING)
9514 r |= SOPT_STRING;
9515
9516 if (p->indir == PV_NONE)
9517 {
9518 if (opt_type == SREQ_GLOBAL)
9519 r |= SOPT_GLOBAL;
9520 else
9521 return 0; /* Did not request global-only option */
9522 }
9523 else
9524 {
9525 if (p->indir & PV_BOTH)
9526 r |= SOPT_GLOBAL;
9527 else if (opt_type == SREQ_GLOBAL)
9528 return 0; /* Requested global option */
9529
9530 if (p->indir & PV_WIN)
9531 {
9532 if (opt_type == SREQ_BUF)
9533 return 0; /* Did not request window-local option */
9534 else
9535 r |= SOPT_WIN;
9536 }
9537 else if (p->indir & PV_BUF)
9538 {
9539 if (opt_type == SREQ_WIN)
9540 return 0; /* Did not request buffer-local option */
9541 else
9542 r |= SOPT_BUF;
9543 }
9544 }
9545
9546 if (stringval == NULL)
9547 return r;
9548
9549 if (opt_type == SREQ_GLOBAL)
9550 varp = p->var;
9551 else
9552 {
9553 if (opt_type == SREQ_BUF)
9554 {
9555 /* Special case: 'modified' is b_changed, but we also want to
9556 * consider it set when 'ff' or 'fenc' changed. */
9557 if (p->indir == PV_MOD)
9558 {
9559 *numval = bufIsChanged((buf_T *) from);
9560 varp = NULL;
9561 }
9562#ifdef FEAT_CRYPT
9563 else if (p->indir == PV_KEY)
9564 {
9565 /* never return the value of the crypt key */
9566 *stringval = NULL;
9567 varp = NULL;
9568 }
9569#endif
9570 else
9571 {
9572 aco_save_T aco;
9573 aucmd_prepbuf(&aco, (buf_T *) from);
9574 varp = get_varp(p);
9575 aucmd_restbuf(&aco);
9576 }
9577 }
9578 else if (opt_type == SREQ_WIN)
9579 {
9580 win_T *save_curwin;
9581 save_curwin = curwin;
9582 curwin = (win_T *) from;
9583 curbuf = curwin->w_buffer;
9584 varp = get_varp(p);
9585 curwin = save_curwin;
9586 curbuf = curwin->w_buffer;
9587 }
9588 if (varp == p->var)
9589 return (r | SOPT_UNSET);
9590 }
9591
9592 if (varp != NULL)
9593 {
9594 if (p->flags & P_STRING)
9595 *stringval = vim_strsave(*(char_u **)(varp));
9596 else if (p->flags & P_NUM)
9597 *numval = *(long *) varp;
9598 else
9599 *numval = *(int *)varp;
9600 }
9601
9602 return r;
9603}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009604
9605/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009606 * Iterate over options. First argument is a pointer to a pointer to a
9607 * structure inside options[] array, second is option type like in the above
9608 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009609 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009610 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009611 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009612 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009613 * first argument to NULL.
9614 *
9615 * Returns full option name for current option on each call.
9616 */
9617 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009618option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009619{
9620 struct vimoption *ret = NULL;
9621 do
9622 {
9623 if (*option == NULL)
9624 *option = (void *) options;
9625 else if (((struct vimoption *) (*option))->fullname == NULL)
9626 {
9627 *option = NULL;
9628 return NULL;
9629 }
9630 else
9631 *option = (void *) (((struct vimoption *) (*option)) + 1);
9632
9633 ret = ((struct vimoption *) (*option));
9634
9635 /* Hidden option */
9636 if (ret->var == NULL)
9637 {
9638 ret = NULL;
9639 continue;
9640 }
9641
9642 switch (opt_type)
9643 {
9644 case SREQ_GLOBAL:
9645 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9646 ret = NULL;
9647 break;
9648 case SREQ_BUF:
9649 if (!(ret->indir & PV_BUF))
9650 ret = NULL;
9651 break;
9652 case SREQ_WIN:
9653 if (!(ret->indir & PV_WIN))
9654 ret = NULL;
9655 break;
9656 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009657 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009658 return NULL;
9659 }
9660 }
9661 while (ret == NULL);
9662
9663 return (char_u *)ret->fullname;
9664}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009665#endif
9666
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667/*
9668 * Set the value of option "name".
9669 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009670 *
9671 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009673 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009674set_option_value(
9675 char_u *name,
9676 long number,
9677 char_u *string,
9678 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009679{
9680 int opt_idx;
9681 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009682 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009683
9684 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009685 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009686 {
9687 int key;
9688
9689 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9690 && (key = find_key_option(name)) != 0)
9691 {
9692 char_u key_name[2];
9693
9694 if (key < 0)
9695 {
9696 key_name[0] = KEY2TERMCAP0(key);
9697 key_name[1] = KEY2TERMCAP1(key);
9698 }
9699 else
9700 {
9701 key_name[0] = KS_KEY;
9702 key_name[1] = (key & 0xff);
9703 }
9704 add_termcode(key_name, string, FALSE);
9705 if (full_screen)
9706 ttest(FALSE);
9707 redraw_all_later(CLEAR);
9708 return NULL;
9709 }
9710
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 else
9714 {
9715 flags = options[opt_idx].flags;
9716#ifdef HAVE_SANDBOX
9717 /* Disallow changing some options in the sandbox */
9718 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009719 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009721 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009724 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009725 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 else
9727 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009728 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729 if (varp != NULL) /* hidden option is not changed */
9730 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009731 if (number == 0 && string != NULL)
9732 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009733 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009734
9735 /* Either we are given a string or we are setting option
9736 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009737 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009738 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009739 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009740 {
9741 /* There's another character after zeros or the string
9742 * is empty. In both cases, we are trying to set a
9743 * num option using a string. */
9744 EMSG3(_("E521: Number required: &%s = '%s'"),
9745 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009746 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009747
9748 }
9749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009751 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009752 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009754 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009755 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 }
9757 }
9758 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009759 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760}
9761
9762/*
9763 * Get the terminal code for a terminal option.
9764 * Returns NULL when not found.
9765 */
9766 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009767get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768{
9769 int opt_idx;
9770 char_u *varp;
9771
9772 if (tname[0] != 't' || tname[1] != '_' ||
9773 tname[2] == NUL || tname[3] == NUL)
9774 return NULL;
9775 if ((opt_idx = findoption(tname)) >= 0)
9776 {
9777 varp = get_varp(&(options[opt_idx]));
9778 if (varp != NULL)
9779 varp = *(char_u **)(varp);
9780 return varp;
9781 }
9782 return find_termcode(tname + 2);
9783}
9784
9785 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009786get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787{
9788 int i;
9789
9790 i = findoption((char_u *)"hl");
9791 if (i >= 0)
9792 return options[i].def_val[VI_DEFAULT];
9793 return (char_u *)NULL;
9794}
9795
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009796#if defined(FEAT_MBYTE) || defined(PROTO)
9797 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009798get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009799{
9800 int i;
9801
9802 i = findoption((char_u *)"enc");
9803 if (i >= 0)
9804 return options[i].def_val[VI_DEFAULT];
9805 return (char_u *)NULL;
9806}
9807#endif
9808
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809/*
9810 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9811 */
9812 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009813find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814{
9815 int key;
9816 int modifiers;
9817
9818 /*
9819 * Don't use get_special_key_code() for t_xx, we don't want it to call
9820 * add_termcap_entry().
9821 */
9822 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9823 key = TERMCAP2KEY(arg[2], arg[3]);
9824 else
9825 {
9826 --arg; /* put arg at the '<' */
9827 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009828 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009829 if (modifiers) /* can't handle modifiers here */
9830 key = 0;
9831 }
9832 return key;
9833}
9834
9835/*
9836 * if 'all' == 0: show changed options
9837 * if 'all' == 1: show all normal options
9838 * if 'all' == 2: show all terminal options
9839 */
9840 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009841showoptions(
9842 int all,
9843 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844{
9845 struct vimoption *p;
9846 int col;
9847 int isterm;
9848 char_u *varp;
9849 struct vimoption **items;
9850 int item_count;
9851 int run;
9852 int row, rows;
9853 int cols;
9854 int i;
9855 int len;
9856
9857#define INC 20
9858#define GAP 3
9859
9860 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9861 PARAM_COUNT));
9862 if (items == NULL)
9863 return;
9864
9865 /* Highlight title */
9866 if (all == 2)
9867 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9868 else if (opt_flags & OPT_GLOBAL)
9869 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9870 else if (opt_flags & OPT_LOCAL)
9871 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9872 else
9873 MSG_PUTS_TITLE(_("\n--- Options ---"));
9874
9875 /*
9876 * do the loop two times:
9877 * 1. display the short items
9878 * 2. display the long items (only strings and numbers)
9879 */
9880 for (run = 1; run <= 2 && !got_int; ++run)
9881 {
9882 /*
9883 * collect the items in items[]
9884 */
9885 item_count = 0;
9886 for (p = &options[0]; p->fullname != NULL; p++)
9887 {
9888 varp = NULL;
9889 isterm = istermoption(p);
9890 if (opt_flags != 0)
9891 {
9892 if (p->indir != PV_NONE && !isterm)
9893 varp = get_varp_scope(p, opt_flags);
9894 }
9895 else
9896 varp = get_varp(p);
9897 if (varp != NULL
9898 && ((all == 2 && isterm)
9899 || (all == 1 && !isterm)
9900 || (all == 0 && !optval_default(p, varp))))
9901 {
9902 if (p->flags & P_BOOL)
9903 len = 1; /* a toggle option fits always */
9904 else
9905 {
9906 option_value2string(p, opt_flags);
9907 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9908 }
9909 if ((len <= INC - GAP && run == 1) ||
9910 (len > INC - GAP && run == 2))
9911 items[item_count++] = p;
9912 }
9913 }
9914
9915 /*
9916 * display the items
9917 */
9918 if (run == 1)
9919 {
9920 cols = (Columns + GAP - 3) / INC;
9921 if (cols == 0)
9922 cols = 1;
9923 rows = (item_count + cols - 1) / cols;
9924 }
9925 else /* run == 2 */
9926 rows = item_count;
9927 for (row = 0; row < rows && !got_int; ++row)
9928 {
9929 msg_putchar('\n'); /* go to next line */
9930 if (got_int) /* 'q' typed in more */
9931 break;
9932 col = 0;
9933 for (i = row; i < item_count; i += rows)
9934 {
9935 msg_col = col; /* make columns */
9936 showoneopt(items[i], opt_flags);
9937 col += INC;
9938 }
9939 out_flush();
9940 ui_breakcheck();
9941 }
9942 }
9943 vim_free(items);
9944}
9945
9946/*
9947 * Return TRUE if option "p" has its default value.
9948 */
9949 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009950optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951{
9952 int dvi;
9953
9954 if (varp == NULL)
9955 return TRUE; /* hidden option is always at default */
9956 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9957 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009958 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009960 /* the cast to long is required for Manx C, long_i is
9961 * needed for MSVC */
9962 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963 /* P_STRING */
9964 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9965}
9966
9967/*
9968 * showoneopt: show the value of one option
9969 * must not be called with a hidden option!
9970 */
9971 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009972showoneopt(
9973 struct vimoption *p,
9974 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009976 char_u *varp;
9977 int save_silent = silent_mode;
9978
9979 silent_mode = FALSE;
9980 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981
9982 varp = get_varp_scope(p, opt_flags);
9983
9984 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9985 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9986 ? !curbufIsChanged() : !*(int *)varp))
9987 MSG_PUTS("no");
9988 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9989 MSG_PUTS("--");
9990 else
9991 MSG_PUTS(" ");
9992 MSG_PUTS(p->fullname);
9993 if (!(p->flags & P_BOOL))
9994 {
9995 msg_putchar('=');
9996 /* put value string in NameBuff */
9997 option_value2string(p, opt_flags);
9998 msg_outtrans(NameBuff);
9999 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010000
10001 silent_mode = save_silent;
10002 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003}
10004
10005/*
10006 * Write modified options as ":set" commands to a file.
10007 *
10008 * There are three values for "opt_flags":
10009 * OPT_GLOBAL: Write global option values and fresh values of
10010 * buffer-local options (used for start of a session
10011 * file).
10012 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10013 * curwin (used for a vimrc file).
10014 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10015 * and local values for window-local options of
10016 * curwin. Local values are also written when at the
10017 * default value, because a modeline or autocommand
10018 * may have set them when doing ":edit file" and the
10019 * user has set them back at the default or fresh
10020 * value.
10021 * When "local_only" is TRUE, don't write fresh
10022 * values, only local values (for ":mkview").
10023 * (fresh value = value used for a new buffer or window for a local option).
10024 *
10025 * Return FAIL on error, OK otherwise.
10026 */
10027 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010028makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029{
10030 struct vimoption *p;
10031 char_u *varp; /* currently used value */
10032 char_u *varp_fresh; /* local value */
10033 char_u *varp_local = NULL; /* fresh value */
10034 char *cmd;
10035 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010036 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010037
10038 /*
10039 * The options that don't have a default (terminal name, columns, lines)
10040 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010041 * Do the loop over "options[]" twice: once for options with the
10042 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010044 for (pri = 1; pri >= 0; --pri)
10045 {
10046 for (p = &options[0]; !istermoption(p); p++)
10047 if (!(p->flags & P_NO_MKRC)
10048 && !istermoption(p)
10049 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010050 {
10051 /* skip global option when only doing locals */
10052 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10053 continue;
10054
10055 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10056 * file, they are always buffer-specific. */
10057 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10058 continue;
10059
10060 /* Global values are only written when not at the default value. */
10061 varp = get_varp_scope(p, opt_flags);
10062 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10063 continue;
10064
10065 round = 2;
10066 if (p->indir != PV_NONE)
10067 {
10068 if (p->var == VAR_WIN)
10069 {
10070 /* skip window-local option when only doing globals */
10071 if (!(opt_flags & OPT_LOCAL))
10072 continue;
10073 /* When fresh value of window-local option is not at the
10074 * default, need to write it too. */
10075 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10076 {
10077 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10078 if (!optval_default(p, varp_fresh))
10079 {
10080 round = 1;
10081 varp_local = varp;
10082 varp = varp_fresh;
10083 }
10084 }
10085 }
10086 }
10087
10088 /* Round 1: fresh value for window-local options.
10089 * Round 2: other values */
10090 for ( ; round <= 2; varp = varp_local, ++round)
10091 {
10092 if (round == 1 || (opt_flags & OPT_GLOBAL))
10093 cmd = "set";
10094 else
10095 cmd = "setlocal";
10096
10097 if (p->flags & P_BOOL)
10098 {
10099 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10100 return FAIL;
10101 }
10102 else if (p->flags & P_NUM)
10103 {
10104 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10105 return FAIL;
10106 }
10107 else /* P_STRING */
10108 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010109 int do_endif = FALSE;
10110
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111 /* Don't set 'syntax' and 'filetype' again if the value is
10112 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010113 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010114#if defined(FEAT_SYN_HL)
10115 p->indir == PV_SYN ||
10116#endif
10117 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 {
10119 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10120 *(char_u **)(varp)) < 0
10121 || put_eol(fd) < 0)
10122 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010123 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124 }
10125 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10126 (p->flags & P_EXPAND) != 0) == FAIL)
10127 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129 {
10130 if (put_line(fd, "endif") == FAIL)
10131 return FAIL;
10132 }
10133 }
10134 }
10135 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 return OK;
10138}
10139
10140#if defined(FEAT_FOLDING) || defined(PROTO)
10141/*
10142 * Generate set commands for the local fold options only. Used when
10143 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10144 */
10145 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010146makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147{
10148 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10149# ifdef FEAT_EVAL
10150 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10151 == FAIL
10152# endif
10153 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10154 == FAIL
10155 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10156 == FAIL
10157 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10158 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10159 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10160 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10161 )
10162 return FAIL;
10163
10164 return OK;
10165}
10166#endif
10167
10168 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010169put_setstring(
10170 FILE *fd,
10171 char *cmd,
10172 char *name,
10173 char_u **valuep,
10174 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175{
10176 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010177 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178
10179 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10180 return FAIL;
10181 if (*valuep != NULL)
10182 {
10183 /* Output 'pastetoggle' as key names. For other
10184 * options some characters have to be escaped with
10185 * CTRL-V or backslash */
10186 if (valuep == &p_pt)
10187 {
10188 s = *valuep;
10189 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010190 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 return FAIL;
10192 }
10193 else if (expand)
10194 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010195 buf = alloc(MAXPATHL);
10196 if (buf == NULL)
10197 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10199 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010200 {
10201 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010203 }
10204 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 }
10206 else if (put_escstr(fd, *valuep, 2) == FAIL)
10207 return FAIL;
10208 }
10209 if (put_eol(fd) < 0)
10210 return FAIL;
10211 return OK;
10212}
10213
10214 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010215put_setnum(
10216 FILE *fd,
10217 char *cmd,
10218 char *name,
10219 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220{
10221 long wc;
10222
10223 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10224 return FAIL;
10225 if (wc_use_keyname((char_u *)valuep, &wc))
10226 {
10227 /* print 'wildchar' and 'wildcharm' as a key name */
10228 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10229 return FAIL;
10230 }
10231 else if (fprintf(fd, "%ld", *valuep) < 0)
10232 return FAIL;
10233 if (put_eol(fd) < 0)
10234 return FAIL;
10235 return OK;
10236}
10237
10238 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010239put_setbool(
10240 FILE *fd,
10241 char *cmd,
10242 char *name,
10243 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244{
Bram Moolenaar893de922007-10-02 18:40:57 +000010245 if (value < 0) /* global/local option using global value */
10246 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10248 || put_eol(fd) < 0)
10249 return FAIL;
10250 return OK;
10251}
10252
10253/*
10254 * Clear all the terminal options.
10255 * If the option has been allocated, free the memory.
10256 * Terminal options are never hidden or indirect.
10257 */
10258 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010259clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 /*
10262 * Reset a few things before clearing the old options. This may cause
10263 * outputting a few things that the terminal doesn't understand, but the
10264 * screen will be cleared later, so this is OK.
10265 */
10266#ifdef FEAT_MOUSE_TTY
10267 mch_setmouse(FALSE); /* switch mouse off */
10268#endif
10269#ifdef FEAT_TITLE
10270 mch_restore_title(3); /* restore window titles */
10271#endif
10272#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10273 /* When starting the GUI close the display opened for the clipboard.
10274 * After restoring the title, because that will need the display. */
10275 if (gui.starting)
10276 clear_xterm_clip();
10277#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010278 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010280 free_termoptions();
10281}
10282
10283 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010284free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010285{
10286 struct vimoption *p;
10287
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288 for (p = &options[0]; p->fullname != NULL; p++)
10289 if (istermoption(p))
10290 {
10291 if (p->flags & P_ALLOCED)
10292 free_string_option(*(char_u **)(p->var));
10293 if (p->flags & P_DEF_ALLOCED)
10294 free_string_option(p->def_val[VI_DEFAULT]);
10295 *(char_u **)(p->var) = empty_option;
10296 p->def_val[VI_DEFAULT] = empty_option;
10297 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10298 }
10299 clear_termcodes();
10300}
10301
10302/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010303 * Free the string for one term option, if it was allocated.
10304 * Set the string to empty_option and clear allocated flag.
10305 * "var" points to the option value.
10306 */
10307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010308free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010309{
10310 struct vimoption *p;
10311
10312 for (p = &options[0]; p->fullname != NULL; p++)
10313 if (p->var == var)
10314 {
10315 if (p->flags & P_ALLOCED)
10316 free_string_option(*(char_u **)(p->var));
10317 *(char_u **)(p->var) = empty_option;
10318 p->flags &= ~P_ALLOCED;
10319 break;
10320 }
10321}
10322
10323/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 * Set the terminal option defaults to the current value.
10325 * Used after setting the terminal name.
10326 */
10327 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010328set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329{
10330 struct vimoption *p;
10331
10332 for (p = &options[0]; p->fullname != NULL; p++)
10333 {
10334 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10335 {
10336 if (p->flags & P_DEF_ALLOCED)
10337 {
10338 free_string_option(p->def_val[VI_DEFAULT]);
10339 p->flags &= ~P_DEF_ALLOCED;
10340 }
10341 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10342 if (p->flags & P_ALLOCED)
10343 {
10344 p->flags |= P_DEF_ALLOCED;
10345 p->flags &= ~P_ALLOCED; /* don't free the value now */
10346 }
10347 }
10348 }
10349}
10350
10351/*
10352 * return TRUE if 'p' starts with 't_'
10353 */
10354 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010355istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356{
10357 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10358}
10359
10360/*
10361 * Compute columns for ruler and shown command. 'sc_col' is also used to
10362 * decide what the maximum length of a message on the status line can be.
10363 * If there is a status line for the last window, 'sc_col' is independent
10364 * of 'ru_col'.
10365 */
10366
10367#define COL_RULER 17 /* columns needed by standard ruler */
10368
10369 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010370comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010372#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010373 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010374
10375 sc_col = 0;
10376 ru_col = 0;
10377 if (p_ru)
10378 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010379# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010381# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 /* no last status line, adjust sc_col */
10385 if (!last_has_status)
10386 sc_col = ru_col;
10387 }
10388 if (p_sc)
10389 {
10390 sc_col += SHOWCMD_COLS;
10391 if (!p_ru || last_has_status) /* no need for separating space */
10392 ++sc_col;
10393 }
10394 sc_col = Columns - sc_col;
10395 ru_col = Columns - ru_col;
10396 if (sc_col <= 0) /* screen too narrow, will become a mess */
10397 sc_col = 1;
10398 if (ru_col <= 0)
10399 ru_col = 1;
10400#else
10401 sc_col = Columns;
10402 ru_col = Columns;
10403#endif
10404}
10405
10406/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407 * Unset local option value, similar to ":set opt<".
10408 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010410unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010411{
10412 struct vimoption *p;
10413 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010414 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010415
10416 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010417 if (opt_idx < 0)
10418 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 p = &(options[opt_idx]);
10420
10421 switch ((int)p->indir)
10422 {
10423 /* global option with local value: use local value if it's been set */
10424 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010428 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010429 break;
10430 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010431 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010432 break;
10433 case PV_AR:
10434 buf->b_p_ar = -1;
10435 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010436 case PV_BKC:
10437 clear_string_option(&buf->b_p_bkc);
10438 buf->b_bkc_flags = 0;
10439 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010440 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010441 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010443 case PV_TC:
10444 clear_string_option(&buf->b_p_tc);
10445 buf->b_tc_flags = 0;
10446 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010447#ifdef FEAT_FIND_ID
10448 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010449 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010450 break;
10451 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454#endif
10455#ifdef FEAT_INS_EXPAND
10456 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010457 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010458 break;
10459 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010460 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010461 break;
10462#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010463 case PV_FP:
10464 clear_string_option(&buf->b_p_fp);
10465 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466#ifdef FEAT_QUICKFIX
10467 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010468 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010469 break;
10470 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010471 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010472 break;
10473 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010474 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010475 break;
10476#endif
10477#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10478 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010479 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010480 break;
10481#endif
10482#if defined(FEAT_CRYPT)
10483 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
10486#endif
10487#ifdef FEAT_STL_OPT
10488 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010489 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010490 break;
10491#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010492 case PV_UL:
10493 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10494 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010495#ifdef FEAT_LISP
10496 case PV_LW:
10497 clear_string_option(&buf->b_p_lw);
10498 break;
10499#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010500#ifdef FEAT_MBYTE
10501 case PV_MENC:
10502 clear_string_option(&buf->b_p_menc);
10503 break;
10504#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010505 }
10506}
10507
10508/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509 * Get pointer to option variable, depending on local or global scope.
10510 */
10511 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010512get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513{
10514 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10515 {
10516 if (p->var == VAR_WIN)
10517 return (char_u *)GLOBAL_WO(get_varp(p));
10518 return p->var;
10519 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010520 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 {
10522 switch ((int)p->indir)
10523 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010524 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010526 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10527 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10528 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010530 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10531 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10532 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010533 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010534 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010535 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10538 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539#endif
10540#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10542 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010544#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10545 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10546#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010547#if defined(FEAT_CRYPT)
10548 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10549#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010550#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010551 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010552#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010553 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010554#ifdef FEAT_LISP
10555 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10556#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010557 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010558#ifdef FEAT_MBYTE
10559 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10560#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 }
10562 return NULL; /* "cannot happen" */
10563 }
10564 return get_varp(p);
10565}
10566
10567/*
10568 * Get pointer to option variable.
10569 */
10570 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010571get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572{
10573 /* hidden option, always return NULL */
10574 if (p->var == NULL)
10575 return NULL;
10576
10577 switch ((int)p->indir)
10578 {
10579 case PV_NONE: return p->var;
10580
10581 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010582 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010586 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010588 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010590 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010592 case PV_TC: return *curbuf->b_p_tc != NUL
10593 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010594 case PV_BKC: return *curbuf->b_p_bkc != NUL
10595 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010597 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010599 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10601#endif
10602#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010603 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010605 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10607#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010608 case PV_FP: return *curbuf->b_p_fp != NUL
10609 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010611 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010613 case PV_GP: return *curbuf->b_p_gp != NUL
10614 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10615 case PV_MP: return *curbuf->b_p_mp != NUL
10616 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010618#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10619 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10620 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10621#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010622#if defined(FEAT_CRYPT)
10623 case PV_CM: return *curbuf->b_p_cm != NUL
10624 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10625#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010626#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010627 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010628 ? (char_u *)&(curwin->w_p_stl) : p->var;
10629#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010630 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10631 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010632#ifdef FEAT_LISP
10633 case PV_LW: return *curbuf->b_p_lw != NUL
10634 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10635#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010636#ifdef FEAT_MBYTE
10637 case PV_MENC: return *curbuf->b_p_menc != NUL
10638 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640
10641#ifdef FEAT_ARABIC
10642 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10643#endif
10644 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010645#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010646 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10647#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010648#ifdef FEAT_SYN_HL
10649 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10650 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010651 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653#ifdef FEAT_DIFF
10654 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10655#endif
10656#ifdef FEAT_FOLDING
10657 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10658 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10659 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10660 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10661 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10662 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10663 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10664# ifdef FEAT_EVAL
10665 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10666 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10667# endif
10668 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10669#endif
10670 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010671 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010672#ifdef FEAT_LINEBREAK
10673 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010676 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010677#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10679#endif
10680#ifdef FEAT_RIGHTLEFT
10681 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10682 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10683#endif
10684 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10685 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10686#ifdef FEAT_LINEBREAK
10687 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010688 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10689 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690#endif
10691#ifdef FEAT_SCROLLBIND
10692 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10693#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010694#ifdef FEAT_CURSORBIND
10695 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10696#endif
10697#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010698 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10699 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10700#endif
10701#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010702 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010703 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705
10706 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10707 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10708#ifdef FEAT_MBYTE
10709 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10712 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10714 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10715#ifdef FEAT_CINDENT
10716 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10717 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10718 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10719#endif
10720#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10721 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10722#endif
10723#ifdef FEAT_COMMENTS
10724 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10725#endif
10726#ifdef FEAT_FOLDING
10727 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10728#endif
10729#ifdef FEAT_INS_EXPAND
10730 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10731#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010732#ifdef FEAT_COMPL_FUNC
10733 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010734 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010737 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10739#ifdef FEAT_MBYTE
10740 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10741#endif
10742 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010745 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10747 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10748 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10749 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10750#ifdef FEAT_FIND_ID
10751# ifdef FEAT_EVAL
10752 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10753# endif
10754#endif
10755#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10756 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10757 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10758#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010759#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010760 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762#ifdef FEAT_CRYPT
10763 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10764#endif
10765#ifdef FEAT_LISP
10766 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10767#endif
10768 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10769 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10770 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10771 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10772 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010774#ifdef FEAT_TEXTOBJ
10775 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10778#ifdef FEAT_SMARTINDENT
10779 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10783#ifdef FEAT_SEARCHPATH
10784 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10785#endif
10786 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10787#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010788 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010789 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10790#endif
10791#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010792 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10793 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10794 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795#endif
10796 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10797 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10798 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10799 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010800#ifdef FEAT_PERSISTENT_UNDO
10801 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10804#ifdef FEAT_KEYMAP
10805 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10806#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010807#ifdef FEAT_SIGNS
10808 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10809#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010810 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 }
10812 /* always return a valid pointer to avoid a crash! */
10813 return (char_u *)&(curbuf->b_p_wm);
10814}
10815
10816/*
10817 * Get the value of 'equalprg', either the buffer-local one or the global one.
10818 */
10819 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010820get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821{
10822 if (*curbuf->b_p_ep == NUL)
10823 return p_ep;
10824 return curbuf->b_p_ep;
10825}
10826
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827/*
10828 * Copy options from one window to another.
10829 * Used when splitting a window.
10830 */
10831 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010832win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833{
10834 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10835 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10836# ifdef FEAT_RIGHTLEFT
10837# ifdef FEAT_FKMAP
10838 /* Is this right? */
10839 wp_to->w_farsi = wp_from->w_farsi;
10840# endif
10841# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010842#if defined(FEAT_LINEBREAK)
10843 briopt_check(wp_to);
10844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846
10847/*
10848 * Copy the options from one winopt_T to another.
10849 * Doesn't free the old option values in "to", use clear_winopt() for that.
10850 * The 'scroll' option is not copied, because it depends on the window height.
10851 * The 'previewwindow' option is reset, there can be only one preview window.
10852 */
10853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010854copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855{
10856#ifdef FEAT_ARABIC
10857 to->wo_arab = from->wo_arab;
10858#endif
10859 to->wo_list = from->wo_list;
10860 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010861 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010862#ifdef FEAT_LINEBREAK
10863 to->wo_nuw = from->wo_nuw;
10864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865#ifdef FEAT_RIGHTLEFT
10866 to->wo_rl = from->wo_rl;
10867 to->wo_rlc = vim_strsave(from->wo_rlc);
10868#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010869#ifdef FEAT_STL_OPT
10870 to->wo_stl = vim_strsave(from->wo_stl);
10871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010873#ifdef FEAT_DIFF
10874 to->wo_wrap_save = from->wo_wrap_save;
10875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876#ifdef FEAT_LINEBREAK
10877 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010878 to->wo_bri = from->wo_bri;
10879 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880#endif
10881#ifdef FEAT_SCROLLBIND
10882 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010883 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010885#ifdef FEAT_CURSORBIND
10886 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010887 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010888#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010889#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010890 to->wo_spell = from->wo_spell;
10891#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010892#ifdef FEAT_SYN_HL
10893 to->wo_cuc = from->wo_cuc;
10894 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010895 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010896#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010897#ifdef FEAT_DIFF
10898 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010899 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010901#ifdef FEAT_CONCEAL
10902 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010903 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010904#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010905#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010906 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010907 to->wo_tms = vim_strsave(from->wo_tms);
10908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909#ifdef FEAT_FOLDING
10910 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010911 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010913 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 to->wo_fdi = vim_strsave(from->wo_fdi);
10915 to->wo_fml = from->wo_fml;
10916 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010917 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010919 to->wo_fdm_save = from->wo_diff_saved
10920 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 to->wo_fdn = from->wo_fdn;
10922# ifdef FEAT_EVAL
10923 to->wo_fde = vim_strsave(from->wo_fde);
10924 to->wo_fdt = vim_strsave(from->wo_fdt);
10925# endif
10926 to->wo_fmr = vim_strsave(from->wo_fmr);
10927#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010928#ifdef FEAT_SIGNS
10929 to->wo_scl = vim_strsave(from->wo_scl);
10930#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931 check_winopt(to); /* don't want NULL pointers */
10932}
10933
10934/*
10935 * Check string options in a window for a NULL value.
10936 */
10937 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010938check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939{
10940 check_winopt(&win->w_onebuf_opt);
10941 check_winopt(&win->w_allbuf_opt);
10942}
10943
10944/*
10945 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10946 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010947 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010948check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949{
10950#ifdef FEAT_FOLDING
10951 check_string_option(&wop->wo_fdi);
10952 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010953 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954# ifdef FEAT_EVAL
10955 check_string_option(&wop->wo_fde);
10956 check_string_option(&wop->wo_fdt);
10957# endif
10958 check_string_option(&wop->wo_fmr);
10959#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010960#ifdef FEAT_SIGNS
10961 check_string_option(&wop->wo_scl);
10962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963#ifdef FEAT_RIGHTLEFT
10964 check_string_option(&wop->wo_rlc);
10965#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010966#ifdef FEAT_STL_OPT
10967 check_string_option(&wop->wo_stl);
10968#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010969#ifdef FEAT_SYN_HL
10970 check_string_option(&wop->wo_cc);
10971#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010972#ifdef FEAT_CONCEAL
10973 check_string_option(&wop->wo_cocu);
10974#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010975#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010976 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010977 check_string_option(&wop->wo_tms);
10978#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010979#ifdef FEAT_LINEBREAK
10980 check_string_option(&wop->wo_briopt);
10981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982}
10983
10984/*
10985 * Free the allocated memory inside a winopt_T.
10986 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010988clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989{
10990#ifdef FEAT_FOLDING
10991 clear_string_option(&wop->wo_fdi);
10992 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010993 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994# ifdef FEAT_EVAL
10995 clear_string_option(&wop->wo_fde);
10996 clear_string_option(&wop->wo_fdt);
10997# endif
10998 clear_string_option(&wop->wo_fmr);
10999#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011000#ifdef FEAT_SIGNS
11001 clear_string_option(&wop->wo_scl);
11002#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011003#ifdef FEAT_LINEBREAK
11004 clear_string_option(&wop->wo_briopt);
11005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006#ifdef FEAT_RIGHTLEFT
11007 clear_string_option(&wop->wo_rlc);
11008#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011009#ifdef FEAT_STL_OPT
11010 clear_string_option(&wop->wo_stl);
11011#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011012#ifdef FEAT_SYN_HL
11013 clear_string_option(&wop->wo_cc);
11014#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011015#ifdef FEAT_CONCEAL
11016 clear_string_option(&wop->wo_cocu);
11017#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011018#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011019 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011020 clear_string_option(&wop->wo_tms);
11021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022}
11023
11024/*
11025 * Copy global option values to local options for one buffer.
11026 * Used when creating a new buffer and sometimes when entering a buffer.
11027 * flags:
11028 * BCO_ENTER We will enter the buf buffer.
11029 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11030 * appropriate.
11031 * BCO_NOHELP Don't copy the values to a help buffer.
11032 */
11033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011034buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035{
11036 int should_copy = TRUE;
11037 char_u *save_p_isk = NULL; /* init for GCC */
11038 int dont_do_help;
11039 int did_isk = FALSE;
11040
11041 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042 * Skip this when the option defaults have not been set yet. Happens when
11043 * main() allocates the first buffer.
11044 */
11045 if (p_cpo != NULL)
11046 {
11047 /*
11048 * Always copy when entering and 'cpo' contains 'S'.
11049 * Don't copy when already initialized.
11050 * Don't copy when 'cpo' contains 's' and not entering.
11051 * 'S' BCO_ENTER initialized 's' should_copy
11052 * yes yes X X TRUE
11053 * yes no yes X FALSE
11054 * no X yes X FALSE
11055 * X no no yes FALSE
11056 * X no no no TRUE
11057 * no yes no X TRUE
11058 */
11059 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11060 && (buf->b_p_initialized
11061 || (!(flags & BCO_ENTER)
11062 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11063 should_copy = FALSE;
11064
11065 if (should_copy || (flags & BCO_ALWAYS))
11066 {
11067 /* Don't copy the options specific to a help buffer when
11068 * BCO_NOHELP is given or the options were initialized already
11069 * (jumping back to a help file with CTRL-T or CTRL-O) */
11070 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11071 || buf->b_p_initialized;
11072 if (dont_do_help) /* don't free b_p_isk */
11073 {
11074 save_p_isk = buf->b_p_isk;
11075 buf->b_p_isk = NULL;
11076 }
11077 /*
11078 * Always free the allocated strings.
11079 * If not already initialized, set 'readonly' and copy 'fileformat'.
11080 */
11081 if (!buf->b_p_initialized)
11082 {
11083 free_buf_options(buf, TRUE);
11084 buf->b_p_ro = FALSE; /* don't copy readonly */
11085 buf->b_p_tx = p_tx;
11086#ifdef FEAT_MBYTE
11087 buf->b_p_fenc = vim_strsave(p_fenc);
11088#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011089 switch (*p_ffs)
11090 {
11091 case 'm':
11092 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11093 case 'd':
11094 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11095 case 'u':
11096 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11097 default:
11098 buf->b_p_ff = vim_strsave(p_ff);
11099 }
11100 if (buf->b_p_ff != NULL)
11101 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102 buf->b_p_bh = empty_option;
11103 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 }
11105 else
11106 free_buf_options(buf, FALSE);
11107
11108 buf->b_p_ai = p_ai;
11109 buf->b_p_ai_nopaste = p_ai_nopaste;
11110 buf->b_p_sw = p_sw;
11111 buf->b_p_tw = p_tw;
11112 buf->b_p_tw_nopaste = p_tw_nopaste;
11113 buf->b_p_tw_nobin = p_tw_nobin;
11114 buf->b_p_wm = p_wm;
11115 buf->b_p_wm_nopaste = p_wm_nopaste;
11116 buf->b_p_wm_nobin = p_wm_nobin;
11117 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011118#ifdef FEAT_MBYTE
11119 buf->b_p_bomb = p_bomb;
11120#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011121 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 buf->b_p_et = p_et;
11123 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011124 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125 buf->b_p_ml = p_ml;
11126 buf->b_p_ml_nobin = p_ml_nobin;
11127 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011128 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129#ifdef FEAT_INS_EXPAND
11130 buf->b_p_cpt = vim_strsave(p_cpt);
11131#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011132#ifdef FEAT_COMPL_FUNC
11133 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011134 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136 buf->b_p_sts = p_sts;
11137 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139#ifdef FEAT_COMMENTS
11140 buf->b_p_com = vim_strsave(p_com);
11141#endif
11142#ifdef FEAT_FOLDING
11143 buf->b_p_cms = vim_strsave(p_cms);
11144#endif
11145 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011146 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 buf->b_p_nf = vim_strsave(p_nf);
11148 buf->b_p_mps = vim_strsave(p_mps);
11149#ifdef FEAT_SMARTINDENT
11150 buf->b_p_si = p_si;
11151#endif
11152 buf->b_p_ci = p_ci;
11153#ifdef FEAT_CINDENT
11154 buf->b_p_cin = p_cin;
11155 buf->b_p_cink = vim_strsave(p_cink);
11156 buf->b_p_cino = vim_strsave(p_cino);
11157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158 /* Don't copy 'filetype', it must be detected */
11159 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 buf->b_p_pi = p_pi;
11161#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11162 buf->b_p_cinw = vim_strsave(p_cinw);
11163#endif
11164#ifdef FEAT_LISP
11165 buf->b_p_lisp = p_lisp;
11166#endif
11167#ifdef FEAT_SYN_HL
11168 /* Don't copy 'syntax', it must be set */
11169 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011170 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011171 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011172#endif
11173#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011174 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011175 (void)compile_cap_prog(&buf->b_s);
11176 buf->b_s.b_p_spf = vim_strsave(p_spf);
11177 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011178#endif
11179#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11180 buf->b_p_inde = vim_strsave(p_inde);
11181 buf->b_p_indk = vim_strsave(p_indk);
11182#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011183 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011184#if defined(FEAT_EVAL)
11185 buf->b_p_fex = vim_strsave(p_fex);
11186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187#ifdef FEAT_CRYPT
11188 buf->b_p_key = vim_strsave(p_key);
11189#endif
11190#ifdef FEAT_SEARCHPATH
11191 buf->b_p_sua = vim_strsave(p_sua);
11192#endif
11193#ifdef FEAT_KEYMAP
11194 buf->b_p_keymap = vim_strsave(p_keymap);
11195 buf->b_kmap_state |= KEYMAP_INIT;
11196#endif
11197 /* This isn't really an option, but copying the langmap and IME
11198 * state from the current buffer is better than resetting it. */
11199 buf->b_p_iminsert = p_iminsert;
11200 buf->b_p_imsearch = p_imsearch;
11201
11202 /* options that are normally global but also have a local value
11203 * are not copied, start using the global value */
11204 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011205 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011206 buf->b_p_bkc = empty_option;
11207 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208#ifdef FEAT_QUICKFIX
11209 buf->b_p_gp = empty_option;
11210 buf->b_p_mp = empty_option;
11211 buf->b_p_efm = empty_option;
11212#endif
11213 buf->b_p_ep = empty_option;
11214 buf->b_p_kp = empty_option;
11215 buf->b_p_path = empty_option;
11216 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011217 buf->b_p_tc = empty_option;
11218 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219#ifdef FEAT_FIND_ID
11220 buf->b_p_def = empty_option;
11221 buf->b_p_inc = empty_option;
11222# ifdef FEAT_EVAL
11223 buf->b_p_inex = vim_strsave(p_inex);
11224# endif
11225#endif
11226#ifdef FEAT_INS_EXPAND
11227 buf->b_p_dict = empty_option;
11228 buf->b_p_tsr = empty_option;
11229#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011230#ifdef FEAT_TEXTOBJ
11231 buf->b_p_qe = vim_strsave(p_qe);
11232#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011233#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11234 buf->b_p_bexpr = empty_option;
11235#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011236#if defined(FEAT_CRYPT)
11237 buf->b_p_cm = empty_option;
11238#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011239#ifdef FEAT_PERSISTENT_UNDO
11240 buf->b_p_udf = p_udf;
11241#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011242#ifdef FEAT_LISP
11243 buf->b_p_lw = empty_option;
11244#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011245#ifdef FEAT_MBYTE
11246 buf->b_p_menc = empty_option;
11247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248
11249 /*
11250 * Don't copy the options set by ex_help(), use the saved values,
11251 * when going from a help buffer to a non-help buffer.
11252 * Don't touch these at all when BCO_NOHELP is used and going from
11253 * or to a help buffer.
11254 */
11255 if (dont_do_help)
11256 buf->b_p_isk = save_p_isk;
11257 else
11258 {
11259 buf->b_p_isk = vim_strsave(p_isk);
11260 did_isk = TRUE;
11261 buf->b_p_ts = p_ts;
11262 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263 if (buf->b_p_bt[0] == 'h')
11264 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 buf->b_p_ma = p_ma;
11266 }
11267 }
11268
11269 /*
11270 * When the options should be copied (ignoring BCO_ALWAYS), set the
11271 * flag that indicates that the options have been initialized.
11272 */
11273 if (should_copy)
11274 buf->b_p_initialized = TRUE;
11275 }
11276
11277 check_buf_options(buf); /* make sure we don't have NULLs */
11278 if (did_isk)
11279 (void)buf_init_chartab(buf, FALSE);
11280}
11281
11282/*
11283 * Reset the 'modifiable' option and its default value.
11284 */
11285 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011286reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287{
11288 int opt_idx;
11289
11290 curbuf->b_p_ma = FALSE;
11291 p_ma = FALSE;
11292 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011293 if (opt_idx >= 0)
11294 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295}
11296
11297/*
11298 * Set the global value for 'iminsert' to the local value.
11299 */
11300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011301set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302{
11303 p_iminsert = curbuf->b_p_iminsert;
11304}
11305
11306/*
11307 * Set the global value for 'imsearch' to the local value.
11308 */
11309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011310set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311{
11312 p_imsearch = curbuf->b_p_imsearch;
11313}
11314
11315#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11316static int expand_option_idx = -1;
11317static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11318static int expand_option_flags = 0;
11319
11320 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011321set_context_in_set_cmd(
11322 expand_T *xp,
11323 char_u *arg,
11324 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325{
11326 int nextchar;
11327 long_u flags = 0; /* init for GCC */
11328 int opt_idx = 0; /* init for GCC */
11329 char_u *p;
11330 char_u *s;
11331 int is_term_option = FALSE;
11332 int key;
11333
11334 expand_option_flags = opt_flags;
11335
11336 xp->xp_context = EXPAND_SETTINGS;
11337 if (*arg == NUL)
11338 {
11339 xp->xp_pattern = arg;
11340 return;
11341 }
11342 p = arg + STRLEN(arg) - 1;
11343 if (*p == ' ' && *(p - 1) != '\\')
11344 {
11345 xp->xp_pattern = p + 1;
11346 return;
11347 }
11348 while (p > arg)
11349 {
11350 s = p;
11351 /* count number of backslashes before ' ' or ',' */
11352 if (*p == ' ' || *p == ',')
11353 {
11354 while (s > arg && *(s - 1) == '\\')
11355 --s;
11356 }
11357 /* break at a space with an even number of backslashes */
11358 if (*p == ' ' && ((p - s) & 1) == 0)
11359 {
11360 ++p;
11361 break;
11362 }
11363 --p;
11364 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011365 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 {
11367 xp->xp_context = EXPAND_BOOL_SETTINGS;
11368 p += 2;
11369 }
11370 if (STRNCMP(p, "inv", 3) == 0)
11371 {
11372 xp->xp_context = EXPAND_BOOL_SETTINGS;
11373 p += 3;
11374 }
11375 xp->xp_pattern = arg = p;
11376 if (*arg == '<')
11377 {
11378 while (*p != '>')
11379 if (*p++ == NUL) /* expand terminal option name */
11380 return;
11381 key = get_special_key_code(arg + 1);
11382 if (key == 0) /* unknown name */
11383 {
11384 xp->xp_context = EXPAND_NOTHING;
11385 return;
11386 }
11387 nextchar = *++p;
11388 is_term_option = TRUE;
11389 expand_option_name[2] = KEY2TERMCAP0(key);
11390 expand_option_name[3] = KEY2TERMCAP1(key);
11391 }
11392 else
11393 {
11394 if (p[0] == 't' && p[1] == '_')
11395 {
11396 p += 2;
11397 if (*p != NUL)
11398 ++p;
11399 if (*p == NUL)
11400 return; /* expand option name */
11401 nextchar = *++p;
11402 is_term_option = TRUE;
11403 expand_option_name[2] = p[-2];
11404 expand_option_name[3] = p[-1];
11405 }
11406 else
11407 {
11408 /* Allow * wildcard */
11409 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11410 p++;
11411 if (*p == NUL)
11412 return;
11413 nextchar = *p;
11414 *p = NUL;
11415 opt_idx = findoption(arg);
11416 *p = nextchar;
11417 if (opt_idx == -1 || options[opt_idx].var == NULL)
11418 {
11419 xp->xp_context = EXPAND_NOTHING;
11420 return;
11421 }
11422 flags = options[opt_idx].flags;
11423 if (flags & P_BOOL)
11424 {
11425 xp->xp_context = EXPAND_NOTHING;
11426 return;
11427 }
11428 }
11429 }
11430 /* handle "-=" and "+=" */
11431 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11432 {
11433 ++p;
11434 nextchar = '=';
11435 }
11436 if ((nextchar != '=' && nextchar != ':')
11437 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11438 {
11439 xp->xp_context = EXPAND_UNSUCCESSFUL;
11440 return;
11441 }
11442 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11443 {
11444 xp->xp_context = EXPAND_OLD_SETTING;
11445 if (is_term_option)
11446 expand_option_idx = -1;
11447 else
11448 expand_option_idx = opt_idx;
11449 xp->xp_pattern = p + 1;
11450 return;
11451 }
11452 xp->xp_context = EXPAND_NOTHING;
11453 if (is_term_option || (flags & P_NUM))
11454 return;
11455
11456 xp->xp_pattern = p + 1;
11457
11458 if (flags & P_EXPAND)
11459 {
11460 p = options[opt_idx].var;
11461 if (p == (char_u *)&p_bdir
11462 || p == (char_u *)&p_dir
11463 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011464 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011465 || p == (char_u *)&p_rtp
11466#ifdef FEAT_SEARCHPATH
11467 || p == (char_u *)&p_cdpath
11468#endif
11469#ifdef FEAT_SESSION
11470 || p == (char_u *)&p_vdir
11471#endif
11472 )
11473 {
11474 xp->xp_context = EXPAND_DIRECTORIES;
11475 if (p == (char_u *)&p_path
11476#ifdef FEAT_SEARCHPATH
11477 || p == (char_u *)&p_cdpath
11478#endif
11479 )
11480 xp->xp_backslash = XP_BS_THREE;
11481 else
11482 xp->xp_backslash = XP_BS_ONE;
11483 }
11484 else
11485 {
11486 xp->xp_context = EXPAND_FILES;
11487 /* for 'tags' need three backslashes for a space */
11488 if (p == (char_u *)&p_tags)
11489 xp->xp_backslash = XP_BS_THREE;
11490 else
11491 xp->xp_backslash = XP_BS_ONE;
11492 }
11493 }
11494
11495 /* For an option that is a list of file names, find the start of the
11496 * last file name. */
11497 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11498 {
11499 /* count number of backslashes before ' ' or ',' */
11500 if (*p == ' ' || *p == ',')
11501 {
11502 s = p;
11503 while (s > xp->xp_pattern && *(s - 1) == '\\')
11504 --s;
11505 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11506 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11507 {
11508 xp->xp_pattern = p + 1;
11509 break;
11510 }
11511 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011512
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011513#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011514 /* for 'spellsuggest' start at "file:" */
11515 if (options[opt_idx].var == (char_u *)&p_sps
11516 && STRNCMP(p, "file:", 5) == 0)
11517 {
11518 xp->xp_pattern = p + 5;
11519 break;
11520 }
11521#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522 }
11523
11524 return;
11525}
11526
11527 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011528ExpandSettings(
11529 expand_T *xp,
11530 regmatch_T *regmatch,
11531 int *num_file,
11532 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533{
11534 int num_normal = 0; /* Nr of matching non-term-code settings */
11535 int num_term = 0; /* Nr of matching terminal code settings */
11536 int opt_idx;
11537 int match;
11538 int count = 0;
11539 char_u *str;
11540 int loop;
11541 int is_term_opt;
11542 char_u name_buf[MAX_KEY_NAME_LEN];
11543 static char *(names[]) = {"all", "termcap"};
11544 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11545
11546 /* do this loop twice:
11547 * loop == 0: count the number of matching options
11548 * loop == 1: copy the matching options into allocated memory
11549 */
11550 for (loop = 0; loop <= 1; ++loop)
11551 {
11552 regmatch->rm_ic = ic;
11553 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11554 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011555 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11556 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11558 {
11559 if (loop == 0)
11560 num_normal++;
11561 else
11562 (*file)[count++] = vim_strsave((char_u *)names[match]);
11563 }
11564 }
11565 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11566 opt_idx++)
11567 {
11568 if (options[opt_idx].var == NULL)
11569 continue;
11570 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11571 && !(options[opt_idx].flags & P_BOOL))
11572 continue;
11573 is_term_opt = istermoption(&options[opt_idx]);
11574 if (is_term_opt && num_normal > 0)
11575 continue;
11576 match = FALSE;
11577 if (vim_regexec(regmatch, str, (colnr_T)0)
11578 || (options[opt_idx].shortname != NULL
11579 && vim_regexec(regmatch,
11580 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11581 match = TRUE;
11582 else if (is_term_opt)
11583 {
11584 name_buf[0] = '<';
11585 name_buf[1] = 't';
11586 name_buf[2] = '_';
11587 name_buf[3] = str[2];
11588 name_buf[4] = str[3];
11589 name_buf[5] = '>';
11590 name_buf[6] = NUL;
11591 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11592 {
11593 match = TRUE;
11594 str = name_buf;
11595 }
11596 }
11597 if (match)
11598 {
11599 if (loop == 0)
11600 {
11601 if (is_term_opt)
11602 num_term++;
11603 else
11604 num_normal++;
11605 }
11606 else
11607 (*file)[count++] = vim_strsave(str);
11608 }
11609 }
11610 /*
11611 * Check terminal key codes, these are not in the option table
11612 */
11613 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11614 {
11615 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11616 {
11617 if (!isprint(str[0]) || !isprint(str[1]))
11618 continue;
11619
11620 name_buf[0] = 't';
11621 name_buf[1] = '_';
11622 name_buf[2] = str[0];
11623 name_buf[3] = str[1];
11624 name_buf[4] = NUL;
11625
11626 match = FALSE;
11627 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11628 match = TRUE;
11629 else
11630 {
11631 name_buf[0] = '<';
11632 name_buf[1] = 't';
11633 name_buf[2] = '_';
11634 name_buf[3] = str[0];
11635 name_buf[4] = str[1];
11636 name_buf[5] = '>';
11637 name_buf[6] = NUL;
11638
11639 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11640 match = TRUE;
11641 }
11642 if (match)
11643 {
11644 if (loop == 0)
11645 num_term++;
11646 else
11647 (*file)[count++] = vim_strsave(name_buf);
11648 }
11649 }
11650
11651 /*
11652 * Check special key names.
11653 */
11654 regmatch->rm_ic = TRUE; /* ignore case here */
11655 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11656 {
11657 name_buf[0] = '<';
11658 STRCPY(name_buf + 1, str);
11659 STRCAT(name_buf, ">");
11660
11661 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11662 {
11663 if (loop == 0)
11664 num_term++;
11665 else
11666 (*file)[count++] = vim_strsave(name_buf);
11667 }
11668 }
11669 }
11670 if (loop == 0)
11671 {
11672 if (num_normal > 0)
11673 *num_file = num_normal;
11674 else if (num_term > 0)
11675 *num_file = num_term;
11676 else
11677 return OK;
11678 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11679 if (*file == NULL)
11680 {
11681 *file = (char_u **)"";
11682 return FAIL;
11683 }
11684 }
11685 }
11686 return OK;
11687}
11688
11689 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011690ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691{
11692 char_u *var = NULL; /* init for GCC */
11693 char_u *buf;
11694
11695 *num_file = 0;
11696 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11697 if (*file == NULL)
11698 return FAIL;
11699
11700 /*
11701 * For a terminal key code expand_option_idx is < 0.
11702 */
11703 if (expand_option_idx < 0)
11704 {
11705 var = find_termcode(expand_option_name + 2);
11706 if (var == NULL)
11707 expand_option_idx = findoption(expand_option_name);
11708 }
11709
11710 if (expand_option_idx >= 0)
11711 {
11712 /* put string of option value in NameBuff */
11713 option_value2string(&options[expand_option_idx], expand_option_flags);
11714 var = NameBuff;
11715 }
11716 else if (var == NULL)
11717 var = (char_u *)"";
11718
11719 /* A backslash is required before some characters. This is the reverse of
11720 * what happens in do_set(). */
11721 buf = vim_strsave_escaped(var, escape_chars);
11722
11723 if (buf == NULL)
11724 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011725 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011726 return FAIL;
11727 }
11728
11729#ifdef BACKSLASH_IN_FILENAME
11730 /* For MS-Windows et al. we don't double backslashes at the start and
11731 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011732 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 if (var[0] == '\\' && var[1] == '\\'
11734 && expand_option_idx >= 0
11735 && (options[expand_option_idx].flags & P_EXPAND)
11736 && vim_isfilec(var[2])
11737 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011738 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011739#endif
11740
11741 *file[0] = buf;
11742 *num_file = 1;
11743 return OK;
11744}
11745#endif
11746
11747/*
11748 * Get the value for the numeric or string option *opp in a nice format into
11749 * NameBuff[]. Must not be called with a hidden option!
11750 */
11751 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011752option_value2string(
11753 struct vimoption *opp,
11754 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755{
11756 char_u *varp;
11757
11758 varp = get_varp_scope(opp, opt_flags);
11759
11760 if (opp->flags & P_NUM)
11761 {
11762 long wc = 0;
11763
11764 if (wc_use_keyname(varp, &wc))
11765 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11766 else if (wc != 0)
11767 STRCPY(NameBuff, transchar((int)wc));
11768 else
11769 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11770 }
11771 else /* P_STRING */
11772 {
11773 varp = *(char_u **)(varp);
11774 if (varp == NULL) /* just in case */
11775 NameBuff[0] = NUL;
11776#ifdef FEAT_CRYPT
11777 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011778 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 STRCPY(NameBuff, "*****");
11780#endif
11781 else if (opp->flags & P_EXPAND)
11782 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11783 /* Translate 'pastetoggle' into special key names */
11784 else if ((char_u **)opp->var == &p_pt)
11785 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11786 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011787 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788 }
11789}
11790
11791/*
11792 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11793 * printed as a keyname.
11794 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11795 */
11796 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011797wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798{
11799 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11800 {
11801 *wcp = *(long *)varp;
11802 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11803 return TRUE;
11804 }
11805 return FALSE;
11806}
11807
Bram Moolenaar01615492015-02-03 13:00:38 +010011808#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011810 * Any character has an equivalent 'langmap' character. This is used for
11811 * keyboards that have a special language mode that sends characters above
11812 * 128 (although other characters can be translated too). The "to" field is a
11813 * Vim command character. This avoids having to switch the keyboard back to
11814 * ASCII mode when leaving Insert mode.
11815 *
11816 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11817 * commands.
11818 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11819 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11820 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011822# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011823/*
11824 * With multi-byte support use growarray for 'langmap' chars >= 256
11825 */
11826typedef struct
11827{
11828 int from;
11829 int to;
11830} langmap_entry_T;
11831
11832static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011833static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834
11835/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011836 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11837 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011839 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011840langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011841{
11842 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011843 int a = 0;
11844 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011845
11846 /* Do a binary search for an existing entry. */
11847 while (a != b)
11848 {
11849 int i = (a + b) / 2;
11850 int d = entries[i].from - from;
11851
11852 if (d == 0)
11853 {
11854 entries[i].to = to;
11855 return;
11856 }
11857 if (d < 0)
11858 a = i + 1;
11859 else
11860 b = i;
11861 }
11862
11863 if (ga_grow(&langmap_mapga, 1) != OK)
11864 return; /* out of memory */
11865
11866 /* insert new entry at position "a" */
11867 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11868 mch_memmove(entries + 1, entries,
11869 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11870 ++langmap_mapga.ga_len;
11871 entries[0].from = from;
11872 entries[0].to = to;
11873}
11874
11875/*
11876 * Apply 'langmap' to multi-byte character "c" and return the result.
11877 */
11878 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011879langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011880{
11881 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11882 int a = 0;
11883 int b = langmap_mapga.ga_len;
11884
11885 while (a != b)
11886 {
11887 int i = (a + b) / 2;
11888 int d = entries[i].from - c;
11889
11890 if (d == 0)
11891 return entries[i].to; /* found matching entry */
11892 if (d < 0)
11893 a = i + 1;
11894 else
11895 b = i;
11896 }
11897 return c; /* no entry found, return "c" unmodified */
11898}
11899# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900
11901 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011902langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903{
11904 int i;
11905
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011906 for (i = 0; i < 256; i++)
11907 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11908# ifdef FEAT_MBYTE
11909 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911}
11912
11913/*
11914 * Called when langmap option is set; the language map can be
11915 * changed at any time!
11916 */
11917 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011918langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919{
11920 char_u *p;
11921 char_u *p2;
11922 int from, to;
11923
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011924#ifdef FEAT_MBYTE
11925 ga_clear(&langmap_mapga); /* clear the previous map first */
11926#endif
11927 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928
11929 for (p = p_langmap; p[0] != NUL; )
11930 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011931 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011932 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933 {
11934 if (p2[0] == '\\' && p2[1] != NUL)
11935 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936 }
11937 if (p2[0] == ';')
11938 ++p2; /* abcd;ABCD form, p2 points to A */
11939 else
11940 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11941 while (p[0])
11942 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011943 if (p[0] == ',')
11944 {
11945 ++p;
11946 break;
11947 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948 if (p[0] == '\\' && p[1] != NUL)
11949 ++p;
11950#ifdef FEAT_MBYTE
11951 from = (*mb_ptr2char)(p);
11952#else
11953 from = p[0];
11954#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011955 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956 if (p2 == NULL)
11957 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011958 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011959 if (p[0] != ',')
11960 {
11961 if (p[0] == '\\')
11962 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011964 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011966 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011967#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969 }
11970 else
11971 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011972 if (p2[0] != ',')
11973 {
11974 if (p2[0] == '\\')
11975 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011977 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011979 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011981 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011982 }
11983 if (to == NUL)
11984 {
11985 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11986 transchar(from));
11987 return;
11988 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011989
11990#ifdef FEAT_MBYTE
11991 if (from >= 256)
11992 langmap_set_entry(from, to);
11993 else
11994#endif
11995 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996
11997 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011998 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011999 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012000 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012001 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002 if (*p == ';')
12003 {
12004 p = p2;
12005 if (p[0] != NUL)
12006 {
12007 if (p[0] != ',')
12008 {
12009 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12010 return;
12011 }
12012 ++p;
12013 }
12014 break;
12015 }
12016 }
12017 }
12018 }
12019}
12020#endif
12021
12022/*
12023 * Return TRUE if format option 'x' is in effect.
12024 * Take care of no formatting when 'paste' is set.
12025 */
12026 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012027has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028{
12029 if (p_paste)
12030 return FALSE;
12031 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12032}
12033
12034/*
12035 * Return TRUE if "x" is present in 'shortmess' option, or
12036 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12037 */
12038 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012039shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012041 return p_shm != NULL &&
12042 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043 || (vim_strchr(p_shm, 'a') != NULL
12044 && vim_strchr((char_u *)SHM_A, x) != NULL));
12045}
12046
12047/*
12048 * paste_option_changed() - Called after p_paste was set or reset.
12049 */
12050 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012051paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052{
12053 static int old_p_paste = FALSE;
12054 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012055 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056#ifdef FEAT_CMDL_INFO
12057 static int save_ru = 0;
12058#endif
12059#ifdef FEAT_RIGHTLEFT
12060 static int save_ri = 0;
12061 static int save_hkmap = 0;
12062#endif
12063 buf_T *buf;
12064
12065 if (p_paste)
12066 {
12067 /*
12068 * Paste switched from off to on.
12069 * Save the current values, so they can be restored later.
12070 */
12071 if (!old_p_paste)
12072 {
12073 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012074 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075 {
12076 buf->b_p_tw_nopaste = buf->b_p_tw;
12077 buf->b_p_wm_nopaste = buf->b_p_wm;
12078 buf->b_p_sts_nopaste = buf->b_p_sts;
12079 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012080 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081 }
12082
12083 /* save global options */
12084 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012085 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086#ifdef FEAT_CMDL_INFO
12087 save_ru = p_ru;
12088#endif
12089#ifdef FEAT_RIGHTLEFT
12090 save_ri = p_ri;
12091 save_hkmap = p_hkmap;
12092#endif
12093 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012094 p_ai_nopaste = p_ai;
12095 p_et_nopaste = p_et;
12096 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 p_tw_nopaste = p_tw;
12098 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099 }
12100
12101 /*
12102 * Always set the option values, also when 'paste' is set when it is
12103 * already on.
12104 */
12105 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012106 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107 {
12108 buf->b_p_tw = 0; /* textwidth is 0 */
12109 buf->b_p_wm = 0; /* wrapmargin is 0 */
12110 buf->b_p_sts = 0; /* softtabstop is 0 */
12111 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012112 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012113 }
12114
12115 /* set global options */
12116 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012117 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 if (p_ru)
12120 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 p_ru = 0; /* no ruler */
12122#endif
12123#ifdef FEAT_RIGHTLEFT
12124 p_ri = 0; /* no reverse insert */
12125 p_hkmap = 0; /* no Hebrew keyboard */
12126#endif
12127 /* set global values for local buffer options */
12128 p_tw = 0;
12129 p_wm = 0;
12130 p_sts = 0;
12131 p_ai = 0;
12132 }
12133
12134 /*
12135 * Paste switched from on to off: Restore saved values.
12136 */
12137 else if (old_p_paste)
12138 {
12139 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012140 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141 {
12142 buf->b_p_tw = buf->b_p_tw_nopaste;
12143 buf->b_p_wm = buf->b_p_wm_nopaste;
12144 buf->b_p_sts = buf->b_p_sts_nopaste;
12145 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012146 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 }
12148
12149 /* restore global options */
12150 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012151 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012153 if (p_ru != save_ru)
12154 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155 p_ru = save_ru;
12156#endif
12157#ifdef FEAT_RIGHTLEFT
12158 p_ri = save_ri;
12159 p_hkmap = save_hkmap;
12160#endif
12161 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012162 p_ai = p_ai_nopaste;
12163 p_et = p_et_nopaste;
12164 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 p_tw = p_tw_nopaste;
12166 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 }
12168
12169 old_p_paste = p_paste;
12170}
12171
12172/*
12173 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12174 *
12175 * Reset 'compatible' and set the values for options that didn't get set yet
12176 * to the Vim defaults.
12177 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012178 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012179 */
12180 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012181vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012182{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012183 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012184 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012185 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186
12187 if (!option_was_set((char_u *)"cp"))
12188 {
12189 p_cp = FALSE;
12190 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12191 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12192 set_option_default(opt_idx, OPT_FREE, FALSE);
12193 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012194 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012196
12197 if (fname != NULL)
12198 {
12199 p = vim_getenv(envname, &dofree);
12200 if (p == NULL)
12201 {
12202 /* Set $MYVIMRC to the first vimrc file found. */
12203 p = FullName_save(fname, FALSE);
12204 if (p != NULL)
12205 {
12206 vim_setenv(envname, p);
12207 vim_free(p);
12208 }
12209 }
12210 else if (dofree)
12211 vim_free(p);
12212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213}
12214
12215/*
12216 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12217 */
12218 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012219change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012221 int opt_idx;
12222
Bram Moolenaar071d4272004-06-13 20:20:40 +000012223 if (p_cp != on)
12224 {
12225 p_cp = on;
12226 compatible_set();
12227 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012228 opt_idx = findoption((char_u *)"cp");
12229 if (opt_idx >= 0)
12230 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231}
12232
12233/*
12234 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012235 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 */
12237 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012238option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239{
12240 int idx;
12241
12242 idx = findoption(name);
12243 if (idx < 0) /* unknown option */
12244 return FALSE;
12245 if (options[idx].flags & P_WAS_SET)
12246 return TRUE;
12247 return FALSE;
12248}
12249
12250/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012251 * Reset the flag indicating option "name" was set.
12252 */
12253 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012254reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012255{
12256 int idx = findoption(name);
12257
12258 if (idx >= 0)
12259 options[idx].flags &= ~P_WAS_SET;
12260}
12261
12262/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263 * compatible_set() - Called when 'compatible' has been set or unset.
12264 *
12265 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12266 * flag) to a Vi compatible value.
12267 * When 'compatible' is unset: Set all options that have a different default
12268 * for Vim (without the P_VI_DEF flag) to that default.
12269 */
12270 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012271compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012272{
12273 int opt_idx;
12274
12275 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12276 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12277 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12278 set_option_default(opt_idx, OPT_FREE, p_cp);
12279 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012280 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281}
12282
12283#ifdef FEAT_LINEBREAK
12284
12285# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12286 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012287 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288# endif
12289
12290/*
12291 * fill_breakat_flags() -- called when 'breakat' changes value.
12292 */
12293 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012294fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012296 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297 int i;
12298
12299 for (i = 0; i < 256; i++)
12300 breakat_flags[i] = FALSE;
12301
12302 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012303 for (p = p_breakat; *p; p++)
12304 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305}
12306
12307# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012308 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309# endif
12310
12311#endif
12312
12313/*
12314 * Check an option that can be a range of string values.
12315 *
12316 * Return OK for correct value, FAIL otherwise.
12317 * Empty is always OK.
12318 */
12319 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012320check_opt_strings(
12321 char_u *val,
12322 char **values,
12323 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324{
12325 return opt_strings_flags(val, values, NULL, list);
12326}
12327
12328/*
12329 * Handle an option that can be a range of string values.
12330 * Set a flag in "*flagp" for each string present.
12331 *
12332 * Return OK for correct value, FAIL otherwise.
12333 * Empty is always OK.
12334 */
12335 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012336opt_strings_flags(
12337 char_u *val, /* new value */
12338 char **values, /* array of valid string values */
12339 unsigned *flagp,
12340 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012341{
12342 int i;
12343 int len;
12344 unsigned new_flags = 0;
12345
12346 while (*val)
12347 {
12348 for (i = 0; ; ++i)
12349 {
12350 if (values[i] == NULL) /* val not found in values[] */
12351 return FAIL;
12352
12353 len = (int)STRLEN(values[i]);
12354 if (STRNCMP(values[i], val, len) == 0
12355 && ((list && val[len] == ',') || val[len] == NUL))
12356 {
12357 val += len + (val[len] == ',');
12358 new_flags |= (1 << i);
12359 break; /* check next item in val list */
12360 }
12361 }
12362 }
12363 if (flagp != NULL)
12364 *flagp = new_flags;
12365
12366 return OK;
12367}
12368
12369/*
12370 * Read the 'wildmode' option, fill wim_flags[].
12371 */
12372 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012373check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012374{
12375 char_u new_wim_flags[4];
12376 char_u *p;
12377 int i;
12378 int idx = 0;
12379
12380 for (i = 0; i < 4; ++i)
12381 new_wim_flags[i] = 0;
12382
12383 for (p = p_wim; *p; ++p)
12384 {
12385 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12386 ;
12387 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12388 return FAIL;
12389 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12390 new_wim_flags[idx] |= WIM_LONGEST;
12391 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12392 new_wim_flags[idx] |= WIM_FULL;
12393 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12394 new_wim_flags[idx] |= WIM_LIST;
12395 else
12396 return FAIL;
12397 p += i;
12398 if (*p == NUL)
12399 break;
12400 if (*p == ',')
12401 {
12402 if (idx == 3)
12403 return FAIL;
12404 ++idx;
12405 }
12406 }
12407
12408 /* fill remaining entries with last flag */
12409 while (idx < 3)
12410 {
12411 new_wim_flags[idx + 1] = new_wim_flags[idx];
12412 ++idx;
12413 }
12414
12415 /* only when there are no errors, wim_flags[] is changed */
12416 for (i = 0; i < 4; ++i)
12417 wim_flags[i] = new_wim_flags[i];
12418 return OK;
12419}
12420
12421/*
12422 * Check if backspacing over something is allowed.
12423 */
12424 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012425can_bs(
12426 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012427{
12428 switch (*p_bs)
12429 {
12430 case '2': return TRUE;
12431 case '1': return (what != BS_START);
12432 case '0': return FALSE;
12433 }
12434 return vim_strchr(p_bs, what) != NULL;
12435}
12436
12437/*
12438 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12439 * the file must be considered changed when the value is different.
12440 */
12441 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012442save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443{
12444 buf->b_start_ffc = *buf->b_p_ff;
12445 buf->b_start_eol = buf->b_p_eol;
12446#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012447 buf->b_start_bomb = buf->b_p_bomb;
12448
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449 /* Only use free/alloc when necessary, they take time. */
12450 if (buf->b_start_fenc == NULL
12451 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12452 {
12453 vim_free(buf->b_start_fenc);
12454 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12455 }
12456#endif
12457}
12458
12459/*
12460 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12461 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012462 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12463 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012464 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012465 * When "ignore_empty" is true don't consider a new, empty buffer to be
12466 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012467 */
12468 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012469file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012471 /* In a buffer that was never loaded the options are not valid. */
12472 if (buf->b_flags & BF_NEVERLOADED)
12473 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012474 if (ignore_empty
12475 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012476 && buf->b_ml.ml_line_count == 1
12477 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12478 return FALSE;
12479 if (buf->b_start_ffc != *buf->b_p_ff)
12480 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012481 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482 return TRUE;
12483#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012484 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12485 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012486 if (buf->b_start_fenc == NULL)
12487 return (*buf->b_p_fenc != NUL);
12488 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12489#else
12490 return FALSE;
12491#endif
12492}
12493
12494/*
12495 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12496 */
12497 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012498check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499{
12500 return check_opt_strings(p, p_ff_values, FALSE);
12501}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012502
12503/*
12504 * Return the effective shiftwidth value for current buffer, using the
12505 * 'tabstop' value when 'shiftwidth' is zero.
12506 */
12507 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012508get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012509{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012510 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012511}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012512
12513/*
12514 * Return the effective softtabstop value for the current buffer, using the
12515 * 'tabstop' value when 'softtabstop' is negative.
12516 */
12517 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012518get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012519{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012520 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012521}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012522
12523/*
12524 * Check matchpairs option for "*initc".
12525 * If there is a match set "*initc" to the matching character and "*findc" to
12526 * the opposite character. Set "*backwards" to the direction.
12527 * When "switchit" is TRUE swap the direction.
12528 */
12529 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012530find_mps_values(
12531 int *initc,
12532 int *findc,
12533 int *backwards,
12534 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012535{
12536 char_u *ptr;
12537
12538 ptr = curbuf->b_p_mps;
12539 while (*ptr != NUL)
12540 {
12541#ifdef FEAT_MBYTE
12542 if (has_mbyte)
12543 {
12544 char_u *prev;
12545
12546 if (mb_ptr2char(ptr) == *initc)
12547 {
12548 if (switchit)
12549 {
12550 *findc = *initc;
12551 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12552 *backwards = TRUE;
12553 }
12554 else
12555 {
12556 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12557 *backwards = FALSE;
12558 }
12559 return;
12560 }
12561 prev = ptr;
12562 ptr += mb_ptr2len(ptr) + 1;
12563 if (mb_ptr2char(ptr) == *initc)
12564 {
12565 if (switchit)
12566 {
12567 *findc = *initc;
12568 *initc = mb_ptr2char(prev);
12569 *backwards = FALSE;
12570 }
12571 else
12572 {
12573 *findc = mb_ptr2char(prev);
12574 *backwards = TRUE;
12575 }
12576 return;
12577 }
12578 ptr += mb_ptr2len(ptr);
12579 }
12580 else
12581#endif
12582 {
12583 if (*ptr == *initc)
12584 {
12585 if (switchit)
12586 {
12587 *backwards = TRUE;
12588 *findc = *initc;
12589 *initc = ptr[2];
12590 }
12591 else
12592 {
12593 *backwards = FALSE;
12594 *findc = ptr[2];
12595 }
12596 return;
12597 }
12598 ptr += 2;
12599 if (*ptr == *initc)
12600 {
12601 if (switchit)
12602 {
12603 *backwards = FALSE;
12604 *findc = *initc;
12605 *initc = ptr[-2];
12606 }
12607 else
12608 {
12609 *backwards = TRUE;
12610 *findc = ptr[-2];
12611 }
12612 return;
12613 }
12614 ++ptr;
12615 }
12616 if (*ptr == ',')
12617 ++ptr;
12618 }
12619}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012620
12621#if defined(FEAT_LINEBREAK) || defined(PROTO)
12622/*
12623 * This is called when 'breakindentopt' is changed and when a window is
12624 * initialized.
12625 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012626 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012627briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012628{
12629 char_u *p;
12630 int bri_shift = 0;
12631 long bri_min = 20;
12632 int bri_sbr = FALSE;
12633
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012634 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012635 while (*p != NUL)
12636 {
12637 if (STRNCMP(p, "shift:", 6) == 0
12638 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12639 {
12640 p += 6;
12641 bri_shift = getdigits(&p);
12642 }
12643 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12644 {
12645 p += 4;
12646 bri_min = getdigits(&p);
12647 }
12648 else if (STRNCMP(p, "sbr", 3) == 0)
12649 {
12650 p += 3;
12651 bri_sbr = TRUE;
12652 }
12653 if (*p != ',' && *p != NUL)
12654 return FAIL;
12655 if (*p == ',')
12656 ++p;
12657 }
12658
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012659 wp->w_p_brishift = bri_shift;
12660 wp->w_p_brimin = bri_min;
12661 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012662
12663 return OK;
12664}
12665#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012666
12667/*
12668 * Get the local or global value of 'backupcopy'.
12669 */
12670 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012671get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012672{
12673 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12674}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012675
12676#if defined(FEAT_SIGNS) || defined(PROTO)
12677/*
12678 * Return TRUE when window "wp" has a column to draw signs in.
12679 */
12680 int
12681signcolumn_on(win_T *wp)
12682{
12683 if (*wp->w_p_scl == 'n')
12684 return FALSE;
12685 if (*wp->w_p_scl == 'y')
12686 return TRUE;
12687 return (wp->w_buffer->b_signlist != NULL
12688# ifdef FEAT_NETBEANS_INTG
12689 || wp->w_buffer->b_has_sign_column
12690# endif
12691 );
12692}
12693#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012694
12695#if defined(FEAT_EVAL) || defined(PROTO)
12696/*
12697 * Get window or buffer local options.
12698 */
12699 dict_T *
12700get_winbuf_options(int bufopt)
12701{
12702 dict_T *d;
12703 int opt_idx;
12704
12705 d = dict_alloc();
12706 if (d == NULL)
12707 return NULL;
12708
12709 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12710 {
12711 struct vimoption *opt = &options[opt_idx];
12712
12713 if ((bufopt && (opt->indir & PV_BUF))
12714 || (!bufopt && (opt->indir & PV_WIN)))
12715 {
12716 char_u *varp = get_varp(opt);
12717
12718 if (varp != NULL)
12719 {
12720 if (opt->flags & P_STRING)
12721 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012722 else if (opt->flags & P_NUM)
12723 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012724 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012725 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012726 }
12727 }
12728 }
12729
12730 return d;
12731}
12732#endif