blob: 807b1e043712a4eda410c85da56461fef7a3cd55 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100117#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100140#ifdef FEAT_MBYTE
141# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
142#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#define PV_MA OPT_BUF(BV_MA)
144#define PV_ML OPT_BUF(BV_ML)
145#define PV_MOD OPT_BUF(BV_MOD)
146#define PV_MPS OPT_BUF(BV_MPS)
147#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000148#ifdef FEAT_COMPL_FUNC
149# define PV_OFU OPT_BUF(BV_OFU)
150#endif
151#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
152#define PV_PI OPT_BUF(BV_PI)
153#ifdef FEAT_TEXTOBJ
154# define PV_QE OPT_BUF(BV_QE)
155#endif
156#define PV_RO OPT_BUF(BV_RO)
157#ifdef FEAT_SMARTINDENT
158# define PV_SI OPT_BUF(BV_SI)
159#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100160#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200223#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100230#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200253# define PV_TWK OPT_WIN(WV_TWK)
254# define PV_TWS OPT_WIN(WV_TWS)
255# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283static char_u *p_bh;
284static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static int p_bl;
286static int p_ci;
287#ifdef FEAT_CINDENT
288static int p_cin;
289static char_u *p_cink;
290static char_u *p_cino;
291#endif
292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
293static char_u *p_cinw;
294#endif
295#ifdef FEAT_COMMENTS
296static char_u *p_com;
297#endif
298#ifdef FEAT_FOLDING
299static char_u *p_cms;
300#endif
301#ifdef FEAT_INS_EXPAND
302static char_u *p_cpt;
303#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200309static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_et;
311#ifdef FEAT_MBYTE
312static char_u *p_fenc;
313#endif
314static char_u *p_ff;
315static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000316static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#ifdef FEAT_TERMINAL
378static long p_twsl;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
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,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200979 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000981 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
982#ifdef FEAT_SYN_HL
983 (char_u *)VAR_WIN, PV_CUC,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100988 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989#ifdef FEAT_SYN_HL
990 (char_u *)VAR_WIN, PV_CUL,
991#else
992 (char_u *)NULL, PV_NONE,
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 {"debug", NULL, P_STRING|P_VI_DEF,
996 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200998 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001001 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002#else
1003 (char_u *)NULL, PV_NONE,
1004 {(char_u *)NULL, (char_u *)0L}
1005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1008#ifdef FEAT_MBYTE
1009 (char_u *)&p_deco, PV_NONE,
1010#else
1011 (char_u *)NULL, PV_NONE,
1012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001014 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#else
1018 (char_u *)NULL, PV_NONE,
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1022#ifdef FEAT_DIFF
1023 (char_u *)VAR_WIN, PV_DIFF,
1024#else
1025 (char_u *)NULL, PV_NONE,
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001028 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1030 (char_u *)&p_dex, PV_NONE,
1031 {(char_u *)"", (char_u *)0L}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)0L, (char_u *)0L}
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001037 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1038 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#ifdef FEAT_DIFF
1040 (char_u *)&p_dip, PV_NONE,
1041 {(char_u *)"filler", (char_u *)NULL}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)"", (char_u *)NULL}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1048#ifdef FEAT_DIGRAPHS
1049 (char_u *)&p_dg, PV_NONE,
1050#else
1051 (char_u *)NULL, PV_NONE,
1052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1055 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001058 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 (char_u *)&p_ead, PV_NONE,
1063 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1066 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001068 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1069#if defined(FEAT_MBYTE)
1070 (char_u *)&p_emoji, PV_NONE,
1071 {(char_u *)TRUE, (char_u *)0L}
1072#else
1073 (char_u *)NULL, PV_NONE,
1074 {(char_u *)0L, (char_u *)0L}
1075#endif
1076 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001077 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078#ifdef FEAT_MBYTE
1079 (char_u *)&p_enc, PV_NONE,
1080 {(char_u *)ENC_DFLT, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)0L, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1087 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1090 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001093 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1096 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1099#ifdef FEAT_QUICKFIX
1100 (char_u *)&p_ef, PV_NONE,
1101 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001109 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)NULL, (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"esckeys", "ek", P_BOOL|P_VIM,
1117 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 (char_u *)&p_ei, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1123 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1126 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1129 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130#ifdef FEAT_MBYTE
1131 (char_u *)&p_fenc, PV_FENC,
1132 {(char_u *)"", (char_u *)0L}
1133#else
1134 (char_u *)NULL, PV_NONE,
1135 {(char_u *)0L, (char_u *)0L}
1136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139#ifdef FEAT_MBYTE
1140 (char_u *)&p_fencs, PV_NONE,
1141 {(char_u *)"ucs-bom", (char_u *)0L}
1142#else
1143 (char_u *)NULL, PV_NONE,
1144 {(char_u *)0L, (char_u *)0L}
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1148 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1154 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001155 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1156 (char_u *)&p_fic, PV_NONE,
1157 {
1158#ifdef CASE_INSENSITIVE_FILENAME
1159 (char_u *)TRUE,
1160#else
1161 (char_u *)FALSE,
1162#endif
1163 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001164 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 (char_u *)&p_ft, PV_FT,
1166 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001168 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 (char_u *)&p_fcs, PV_NONE,
1170 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001172 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1173 (char_u *)&p_fixeol, PV_FIXEOL,
1174 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1176#ifdef FEAT_FKMAP
1177 (char_u *)&p_fkmap, PV_NONE,
1178#else
1179 (char_u *)NULL, PV_NONE,
1180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"flash", "fl", P_BOOL|P_VI_DEF,
1183 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001186#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188 {(char_u *)"", (char_u *)0L}
1189#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)NULL, PV_NONE,
1191 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192#endif
1193 SCRIPTID_INIT},
1194 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1195#ifdef FEAT_FOLDING
1196 (char_u *)VAR_WIN, PV_FDC,
1197 {(char_u *)FALSE, (char_u *)0L}
1198#else
1199 (char_u *)NULL, PV_NONE,
1200 {(char_u *)NULL, (char_u *)0L}
1201#endif
1202 SCRIPTID_INIT},
1203 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1204#ifdef FEAT_FOLDING
1205 (char_u *)VAR_WIN, PV_FEN,
1206 {(char_u *)TRUE, (char_u *)0L}
1207#else
1208 (char_u *)NULL, PV_NONE,
1209 {(char_u *)NULL, (char_u *)0L}
1210#endif
1211 SCRIPTID_INIT},
1212 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1213#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1214 (char_u *)VAR_WIN, PV_FDE,
1215 {(char_u *)"0", (char_u *)NULL}
1216#else
1217 (char_u *)NULL, PV_NONE,
1218 {(char_u *)NULL, (char_u *)0L}
1219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001222#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224 {(char_u *)"#", (char_u *)NULL}
1225#else
1226 (char_u *)NULL, PV_NONE,
1227 {(char_u *)NULL, (char_u *)0L}
1228#endif
1229 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001231#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001233 {(char_u *)0L, (char_u *)0L}
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
1238 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001239 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001240#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001242 {(char_u *)-1L, (char_u *)0L}
1243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
1247 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001249 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001250#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257 SCRIPTID_INIT},
1258 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1259#ifdef FEAT_FOLDING
1260 (char_u *)VAR_WIN, PV_FDM,
1261 {(char_u *)"manual", (char_u *)NULL}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
1266 SCRIPTID_INIT},
1267 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1268#ifdef FEAT_FOLDING
1269 (char_u *)VAR_WIN, PV_FML,
1270 {(char_u *)1L, (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
1275 SCRIPTID_INIT},
1276 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1277#ifdef FEAT_FOLDING
1278 (char_u *)VAR_WIN, PV_FDN,
1279 {(char_u *)20L, (char_u *)0L}
1280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
1284 SCRIPTID_INIT},
1285 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1286#ifdef FEAT_FOLDING
1287 (char_u *)&p_fdo, PV_NONE,
1288 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1289 (char_u *)0L}
1290#else
1291 (char_u *)NULL, PV_NONE,
1292 {(char_u *)NULL, (char_u *)0L}
1293#endif
1294 SCRIPTID_INIT},
1295 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1296#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1297 (char_u *)VAR_WIN, PV_FDT,
1298 {(char_u *)"foldtext()", (char_u *)NULL}
1299#else
1300 (char_u *)NULL, PV_NONE,
1301 {(char_u *)NULL, (char_u *)0L}
1302#endif
1303 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001304 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001305#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001306 (char_u *)&p_fex, PV_FEX,
1307 {(char_u *)"", (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)0L, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1314 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1316 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001317 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1318 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1320 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001322 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001324 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1325#ifdef HAVE_FSYNC
1326 (char_u *)&p_fs, PV_NONE,
1327 {(char_u *)TRUE, (char_u *)0L}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)FALSE, (char_u *)0L}
1331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1334 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336 {"graphic", "gr", P_BOOL|P_VI_DEF,
1337 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001339 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340#ifdef FEAT_QUICKFIX
1341 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#else
1344 (char_u *)NULL, PV_NONE,
1345 {(char_u *)NULL, (char_u *)0L}
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1349#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001350 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {
1352# ifdef WIN3264
1353 /* may be changed to "grep -n" in os_win32.c */
1354 (char_u *)"findstr /n",
1355# else
1356# ifdef UNIX
1357 /* Add an extra file name so that grep will always
1358 * insert a file name in the match line. */
1359 (char_u *)"grep -n $* /dev/null",
1360# else
1361# ifdef VMS
1362 (char_u *)"SEARCH/NUMBERS ",
1363# else
1364 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365# endif
1366# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#else
1370 (char_u *)NULL, PV_NONE,
1371 {(char_u *)NULL, (char_u *)0L}
1372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001374 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#ifdef CURSOR_SHAPE
1376 (char_u *)&p_guicursor, PV_NONE,
1377 {
1378# ifdef FEAT_GUI
1379 (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 +01001380# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1382# endif
1383 (char_u *)0L}
1384#else
1385 (char_u *)NULL, PV_NONE,
1386 {(char_u *)NULL, (char_u *)0L}
1387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001389 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390#ifdef FEAT_GUI
1391 (char_u *)&p_guifont, PV_NONE,
1392 {(char_u *)"", (char_u *)0L}
1393#else
1394 (char_u *)NULL, PV_NONE,
1395 {(char_u *)NULL, (char_u *)0L}
1396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001398 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1400 (char_u *)&p_guifontset, PV_NONE,
1401 {(char_u *)"", (char_u *)0L}
1402#else
1403 (char_u *)NULL, PV_NONE,
1404 {(char_u *)NULL, (char_u *)0L}
1405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001407 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1409 (char_u *)&p_guifontwide, PV_NONE,
1410 {(char_u *)"", (char_u *)0L}
1411#else
1412 (char_u *)NULL, PV_NONE,
1413 {(char_u *)NULL, (char_u *)0L}
1414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001415 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001417#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 (char_u *)&p_ghr, PV_NONE,
1419#else
1420 (char_u *)NULL, PV_NONE,
1421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001422 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001424#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001426# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001427 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001429 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430# endif
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"guipty", NULL, P_BOOL|P_VI_DEF,
1437#if defined(FEAT_GUI)
1438 (char_u *)&p_guipty, PV_NONE,
1439#else
1440 (char_u *)NULL, PV_NONE,
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001443 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001444#if defined(FEAT_GUI_TABLINE)
1445 (char_u *)&p_gtl, PV_NONE,
1446 {(char_u *)"", (char_u *)0L}
1447#else
1448 (char_u *)NULL, PV_NONE,
1449 {(char_u *)NULL, (char_u *)0L}
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001452 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001453#if defined(FEAT_GUI_TABLINE)
1454 (char_u *)&p_gtt, PV_NONE,
1455 {(char_u *)"", (char_u *)0L}
1456#else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)NULL, (char_u *)0L}
1459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1462 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001463 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1465 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001471 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472#ifdef FEAT_MULTI_LANG
1473 (char_u *)&p_hlg, PV_NONE,
1474 {(char_u *)"", (char_u *)0L}
1475#else
1476 (char_u *)NULL, PV_NONE,
1477 {(char_u *)0L, (char_u *)0L}
1478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"hidden", "hid", P_BOOL|P_VI_DEF,
1481 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001483 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001485 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"history", "hi", P_NUM|P_VIM,
1488 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001489 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1491#ifdef FEAT_RIGHTLEFT
1492 (char_u *)&p_hkmap, PV_NONE,
1493#else
1494 (char_u *)NULL, PV_NONE,
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1498#ifdef FEAT_RIGHTLEFT
1499 (char_u *)&p_hkmapp, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1505 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"icon", NULL, P_BOOL|P_VI_DEF,
1508#ifdef FEAT_TITLE
1509 (char_u *)&p_icon, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"iconstring", NULL, P_STRING|P_VI_DEF,
1515#ifdef FEAT_TITLE
1516 (char_u *)&p_iconstring, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1522 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001525#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001526 (char_u *)&p_imaf, PV_NONE,
1527 {(char_u *)"", (char_u *)NULL}
1528# else
1529 (char_u *)NULL, PV_NONE,
1530 {(char_u *)NULL, (char_u *)0L}
1531# endif
1532 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001534#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 (char_u *)&p_imak, PV_NONE,
1536#else
1537 (char_u *)NULL, PV_NONE,
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001541#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 (char_u *)&p_imcmdline, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001548#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 (char_u *)&p_imdisable, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
1553#ifdef __sgi
1554 {(char_u *)TRUE, (char_u *)0L}
1555#else
1556 {(char_u *)FALSE, (char_u *)0L}
1557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 {"iminsert", "imi", P_NUM|P_VI_DEF,
1560 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"imsearch", "ims", P_NUM|P_VI_DEF,
1564 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001565 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001567 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001568#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001569 (char_u *)&p_imsf, PV_NONE,
1570 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001571#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001572 (char_u *)NULL, PV_NONE,
1573 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001574#endif
1575 SCRIPTID_INIT},
1576 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1577#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1578 (char_u *)&p_imst, PV_NONE,
1579 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1580#else
1581 (char_u *)NULL, PV_NONE,
1582 {(char_u *)0L, (char_u *)0L}
1583#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001584 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1586#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001587 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1589#else
1590 (char_u *)NULL, PV_NONE,
1591 {(char_u *)0L, (char_u *)0L}
1592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001593 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1595#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1596 (char_u *)&p_inex, PV_INEX,
1597 {(char_u *)"", (char_u *)0L}
1598#else
1599 (char_u *)NULL, PV_NONE,
1600 {(char_u *)0L, (char_u *)0L}
1601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1604 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1607#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1608 (char_u *)&p_inde, PV_INDE,
1609 {(char_u *)"", (char_u *)0L}
1610#else
1611 (char_u *)NULL, PV_NONE,
1612 {(char_u *)0L, (char_u *)0L}
1613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001614 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001615 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1617 (char_u *)&p_indk, PV_INDK,
1618 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1619#else
1620 (char_u *)NULL, PV_NONE,
1621 {(char_u *)0L, (char_u *)0L}
1622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {"infercase", "inf", P_BOOL|P_VI_DEF,
1625 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1628 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1631 (char_u *)&p_isf, PV_NONE,
1632 {
1633#ifdef BACKSLASH_IN_FILENAME
1634 /* Excluded are: & and ^ are special in cmd.exe
1635 * ( and ) are used in text separating fnames */
1636 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1637#else
1638# ifdef AMIGA
1639 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1640# else
1641# ifdef VMS
1642 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1643# else /* UNIX et al. */
1644# ifdef EBCDIC
1645 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1646# else
1647 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1648# endif
1649# endif
1650# endif
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1654 (char_u *)&p_isi, PV_NONE,
1655 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001656#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 (char_u *)"@,48-57,_,128-167,224-235",
1658#else
1659# ifdef EBCDIC
1660 /* TODO: EBCDIC Check this! @ == isalpha()*/
1661 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1662 "112-120,128,140-142,156,158,172,"
1663 "174,186,191,203-207,219-225,235-239,"
1664 "251-254",
1665# else
1666 (char_u *)"@,48-57,_,192-255",
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1671 (char_u *)&p_isk, PV_ISK,
1672 {
1673#ifdef EBCDIC
1674 (char_u *)"@,240-249,_",
1675 /* TODO: EBCDIC Check this! @ == isalpha()*/
1676 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1677 "112-120,128,140-142,156,158,172,"
1678 "174,186,191,203-207,219-225,235-239,"
1679 "251-254",
1680#else
1681 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001682# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)"@,48-57,_,128-167,224-235"
1684# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001685 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686# endif
1687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1690 (char_u *)&p_isp, PV_NONE,
1691 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001692#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 (char_u *)"@,~-255",
1694#else
1695# ifdef EBCDIC
1696 /* all chars above 63 are printable */
1697 (char_u *)"63-255",
1698# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001699 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700# endif
1701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1704 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1707#ifdef FEAT_CRYPT
1708 (char_u *)&p_key, PV_KEY,
1709 {(char_u *)"", (char_u *)0L}
1710#else
1711 (char_u *)NULL, PV_NONE,
1712 {(char_u *)0L, (char_u *)0L}
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001715 {"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 +00001716#ifdef FEAT_KEYMAP
1717 (char_u *)&p_keymap, PV_KMAP,
1718 {(char_u *)"", (char_u *)0L}
1719#else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)"", (char_u *)0L}
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001724 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001728 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001730#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 (char_u *)":help",
1732#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001733# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001735# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001736# ifdef USEMAN_S
1737 (char_u *)"man -s",
1738# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001740# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741# endif
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001744 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745#ifdef FEAT_LANGMAP
1746 (char_u *)&p_langmap, PV_NONE,
1747 {(char_u *)"", /* unmatched } */
1748#else
1749 (char_u *)NULL, PV_NONE,
1750 {(char_u *)NULL,
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001753 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1755 (char_u *)&p_lm, PV_NONE,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001760 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1761#ifdef FEAT_LANGMAP
1762 (char_u *)&p_lnr, PV_NONE,
1763#else
1764 (char_u *)NULL, PV_NONE,
1765#endif
1766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001767 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1768#ifdef FEAT_LANGMAP
1769 (char_u *)&p_lrm, PV_NONE,
1770#else
1771 (char_u *)NULL, PV_NONE,
1772#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001773 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1778 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1781#ifdef FEAT_LINEBREAK
1782 (char_u *)VAR_WIN, PV_LBR,
1783#else
1784 (char_u *)NULL, PV_NONE,
1785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1788 (char_u *)&Rows, PV_NONE,
1789 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001790#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 (char_u *)25L,
1792#else
1793 (char_u *)24L,
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1797#ifdef FEAT_GUI
1798 (char_u *)&p_linespace, PV_NONE,
1799#else
1800 (char_u *)NULL, PV_NONE,
1801#endif
1802#ifdef FEAT_GUI_W32
1803 {(char_u *)1L, (char_u *)0L}
1804#else
1805 {(char_u *)0L, (char_u *)0L}
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"lisp", NULL, P_BOOL|P_VI_DEF,
1809#ifdef FEAT_LISP
1810 (char_u *)&p_lisp, PV_LISP,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001815 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001817 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1819#else
1820 (char_u *)NULL, PV_NONE,
1821 {(char_u *)"", (char_u *)0L}
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1825 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001827 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1831 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001833 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001834#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001835 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001836 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)"", (char_u *)0L}
1840#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001841 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001842 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001843#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001844 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001845 {(char_u *)TRUE, (char_u *)0L}
1846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001849#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"magic", NULL, P_BOOL|P_VI_DEF,
1852 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001854 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855#ifdef FEAT_QUICKFIX
1856 (char_u *)&p_mef, PV_NONE,
1857 {(char_u *)"", (char_u *)0L}
1858#else
1859 (char_u *)NULL, PV_NONE,
1860 {(char_u *)NULL, (char_u *)0L}
1861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001863 {"makeencoding","menc", P_STRING|P_VI_DEF,
1864#ifdef FEAT_MBYTE
1865 (char_u *)&p_menc, PV_MENC,
1866 {(char_u *)"", (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)0L, (char_u *)0L}
1870#endif
1871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1873#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001874 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875# ifdef VMS
1876 {(char_u *)"MMS", (char_u *)0L}
1877# else
1878 {(char_u *)"make", (char_u *)0L}
1879# endif
1880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)NULL, (char_u *)0L}
1883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001885 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"matchtime", "mat", P_NUM|P_VI_DEF,
1890 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001892 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001893#ifdef FEAT_MBYTE
1894 (char_u *)&p_mco, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1900#ifdef FEAT_EVAL
1901 (char_u *)&p_mfd, PV_NONE,
1902#else
1903 (char_u *)NULL, PV_NONE,
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"maxmem", "mm", P_NUM|P_VI_DEF,
1910 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1912 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001913 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1914 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1917 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"menuitems", "mis", P_NUM|P_VI_DEF,
1921#ifdef FEAT_MENU
1922 (char_u *)&p_mis, PV_NONE,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mesg", NULL, P_BOOL|P_VI_DEF,
1928 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001930 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001931#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001932 (char_u *)&p_msm, PV_NONE,
1933 {(char_u *)"460000,2000,500", (char_u *)0L}
1934#else
1935 (char_u *)NULL, PV_NONE,
1936 {(char_u *)0L, (char_u *)0L}
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"modeline", "ml", P_BOOL|P_VIM,
1940 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"modelines", "mls", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1946 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1949 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"more", NULL, P_BOOL|P_VIM,
1952 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1955 (char_u *)&p_mouse, PV_NONE,
1956 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001957#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 (char_u *)"a",
1959#else
1960 (char_u *)"",
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1964#ifdef FEAT_GUI
1965 (char_u *)&p_mousef, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1971#ifdef FEAT_GUI
1972 (char_u *)&p_mh, PV_NONE,
1973#else
1974 (char_u *)NULL, PV_NONE,
1975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1978 (char_u *)&p_mousem, PV_NONE,
1979 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001980#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 (char_u *)"popup",
1982#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001983# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)"popup_setpos",
1985# else
1986 (char_u *)"extend",
1987# endif
1988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001990 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991#ifdef FEAT_MOUSESHAPE
1992 (char_u *)&p_mouseshape, PV_NONE,
1993 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1994#else
1995 (char_u *)NULL, PV_NONE,
1996 {(char_u *)NULL, (char_u *)0L}
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2000 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002002 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2003#if defined(DYNAMIC_MZSCHEME)
2004 (char_u *)&p_mzschemedll, PV_NONE,
2005 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2006#else
2007 (char_u *)NULL, PV_NONE,
2008 {(char_u *)"", (char_u *)0L}
2009#endif
2010 SCRIPTID_INIT},
2011 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2012#if defined(DYNAMIC_MZSCHEME)
2013 (char_u *)&p_mzschemegcdll, PV_NONE,
2014 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2015#else
2016 (char_u *)NULL, PV_NONE,
2017 {(char_u *)"", (char_u *)0L}
2018#endif
2019 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002020 {"mzquantum", "mzq", P_NUM,
2021#ifdef FEAT_MZSCHEME
2022 (char_u *)&p_mzq, PV_NONE,
2023#else
2024 (char_u *)NULL, PV_NONE,
2025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"novice", NULL, P_BOOL|P_VI_DEF,
2028 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002030 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002032 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2035 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002037 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2038#ifdef FEAT_LINEBREAK
2039 (char_u *)VAR_WIN, PV_NUW,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002044 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002045#ifdef FEAT_COMPL_FUNC
2046 (char_u *)&p_ofu, PV_OFU,
2047 {(char_u *)"", (char_u *)0L}
2048#else
2049 (char_u *)NULL, PV_NONE,
2050 {(char_u *)0L, (char_u *)0L}
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"open", NULL, P_BOOL|P_VI_DEF,
2054 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002056 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002057#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002058 (char_u *)&p_odev, PV_NONE,
2059#else
2060 (char_u *)NULL, PV_NONE,
2061#endif
2062 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002064 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2065 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"optimize", "opt", P_BOOL|P_VI_DEF,
2068 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002072 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002073 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2074 |P_SECURE,
2075 (char_u *)&p_pp, PV_NONE,
2076 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"paragraphs", "para", P_STRING|P_VI_DEF,
2079 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002080 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002082 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2086 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2089#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2090 (char_u *)&p_pex, PV_NONE,
2091 {(char_u *)"", (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)0L, (char_u *)0L}
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002097 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002101 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002103#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 (char_u *)".,,",
2105#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002109 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002110#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002111 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002112 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002113#else
2114 (char_u *)NULL, PV_NONE,
2115 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002116#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2119 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002121 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002122#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)&p_pvh, PV_NONE,
2124#else
2125 (char_u *)NULL, PV_NONE,
2126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002129#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 (char_u *)VAR_WIN, PV_PVW,
2131#else
2132 (char_u *)NULL, PV_NONE,
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002135 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136#ifdef FEAT_PRINTER
2137 (char_u *)&p_pdev, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"printencoding", "penc", P_STRING|P_VI_DEF,
2145#ifdef FEAT_POSTSCRIPT
2146 (char_u *)&p_penc, PV_NONE,
2147 {(char_u *)"", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002153 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154#ifdef FEAT_POSTSCRIPT
2155 (char_u *)&p_pexpr, PV_NONE,
2156 {(char_u *)"", (char_u *)0L}
2157#else
2158 (char_u *)NULL, PV_NONE,
2159 {(char_u *)NULL, (char_u *)0L}
2160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"printfont", "pfn", P_STRING|P_VI_DEF,
2163#ifdef FEAT_PRINTER
2164 (char_u *)&p_pfn, PV_NONE,
2165 {
2166# ifdef MSWIN
2167 (char_u *)"Courier_New:h10",
2168# else
2169 (char_u *)"courier",
2170# endif
2171 (char_u *)0L}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2178#ifdef FEAT_PRINTER
2179 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002180 /* untranslated to avoid problems when 'encoding'
2181 * is changed */
2182 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002188 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2189#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2190 (char_u *)&p_pmcs, PV_NONE,
2191 {(char_u *)"", (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002197 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2198#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2199 (char_u *)&p_pmfn, PV_NONE,
2200 {(char_u *)"", (char_u *)0L}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002206 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207#ifdef FEAT_PRINTER
2208 (char_u *)&p_popt, PV_NONE,
2209 {(char_u *)"", (char_u *)0L}
2210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)NULL, (char_u *)0L}
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002216 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002217 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002218 {"pumheight", "ph", P_NUM|P_VI_DEF,
2219#ifdef FEAT_INS_EXPAND
2220 (char_u *)&p_ph, PV_NONE,
2221#else
2222 (char_u *)NULL, PV_NONE,
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002225 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2226#ifdef FEAT_INS_EXPAND
2227 (char_u *)&p_pw, PV_NONE,
2228#else
2229 (char_u *)NULL, PV_NONE,
2230#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002231 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002232 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002233#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002234 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002235 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002239#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002240 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002241 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2242#if defined(FEAT_PYTHON3)
2243 (char_u *)&p_py3home, PV_NONE,
2244 {(char_u *)"", (char_u *)0L}
2245#else
2246 (char_u *)NULL, PV_NONE,
2247 {(char_u *)NULL, (char_u *)0L}
2248#endif
2249 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002250 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002251#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002252 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002253 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002257#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002259 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2260#if defined(FEAT_PYTHON)
2261 (char_u *)&p_pyhome, PV_NONE,
2262 {(char_u *)"", (char_u *)0L}
2263#else
2264 (char_u *)NULL, PV_NONE,
2265 {(char_u *)NULL, (char_u *)0L}
2266#endif
2267 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002268 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2269#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2270 (char_u *)&p_pyx, PV_NONE,
2271#else
2272 (char_u *)NULL, PV_NONE,
2273#endif
2274 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2275 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002276 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2277#ifdef FEAT_TEXTOBJ
2278 (char_u *)&p_qe, PV_QE,
2279 {(char_u *)"\\", (char_u *)0L}
2280#else
2281 (char_u *)NULL, PV_NONE,
2282 {(char_u *)NULL, (char_u *)0L}
2283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2286 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"redraw", NULL, P_BOOL|P_VI_DEF,
2289 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002291 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2292#ifdef FEAT_RELTIME
2293 (char_u *)&p_rdt, PV_NONE,
2294#else
2295 (char_u *)NULL, PV_NONE,
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002298 {"regexpengine", "re", P_NUM|P_VI_DEF,
2299 (char_u *)&p_re, PV_NONE,
2300 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002301 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2302 (char_u *)VAR_WIN, PV_RNU,
2303 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"remap", NULL, P_BOOL|P_VI_DEF,
2305 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002306 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002307 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002308#ifdef FEAT_RENDER_OPTIONS
2309 (char_u *)&p_rop, PV_NONE,
2310 {(char_u *)"", (char_u *)0L}
2311#else
2312 (char_u *)NULL, PV_NONE,
2313 {(char_u *)NULL, (char_u *)0L}
2314#endif
2315 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"report", NULL, P_NUM|P_VI_DEF,
2317 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2320#ifdef WIN3264
2321 (char_u *)&p_rs, PV_NONE,
2322#else
2323 (char_u *)NULL, PV_NONE,
2324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2327#ifdef FEAT_RIGHTLEFT
2328 (char_u *)&p_ri, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2334#ifdef FEAT_RIGHTLEFT
2335 (char_u *)VAR_WIN, PV_RL,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2341#ifdef FEAT_RIGHTLEFT
2342 (char_u *)VAR_WIN, PV_RLC,
2343 {(char_u *)"search", (char_u *)NULL}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)NULL, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002349 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002350#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002351 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002352 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353#else
2354 (char_u *)NULL, PV_NONE,
2355 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002356#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002357 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2359#ifdef FEAT_CMDL_INFO
2360 (char_u *)&p_ru, PV_NONE,
2361#else
2362 (char_u *)NULL, PV_NONE,
2363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2366#ifdef FEAT_STL_OPT
2367 (char_u *)&p_ruf, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002372 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2373 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2378 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002379 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2384 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2387 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002389 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)&p_sbo, PV_NONE,
2391 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"sections", "sect", P_STRING|P_VI_DEF,
2394 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2396 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2398 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"inclusive", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002404 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002407 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408#ifdef FEAT_SESSION
2409 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002410 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 (char_u *)0L}
2412#else
2413 (char_u *)NULL, PV_NONE,
2414 {(char_u *)0L, (char_u *)0L}
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2418 (char_u *)&p_sh, PV_NONE,
2419 {
2420#ifdef VMS
2421 (char_u *)"-",
2422#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002423# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002425# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427# endif
2428#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_shcf, PV_NONE,
2432 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002433#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 (char_u *)"/c",
2435#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2440#ifdef FEAT_QUICKFIX
2441 (char_u *)&p_sp, PV_NONE,
2442 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002443#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445#else
2446 (char_u *)">",
2447#endif
2448 (char_u *)0L}
2449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)0L, (char_u *)0L}
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2455 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2458 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2461#ifdef BACKSLASH_IN_FILENAME
2462 (char_u *)&p_ssl, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002467 {"shelltemp", "stmp", P_BOOL,
2468 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shelltype", "st", P_NUM|P_VI_DEF,
2471#ifdef AMIGA
2472 (char_u *)&p_st, PV_NONE,
2473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2478 (char_u *)&p_sxq, PV_NONE,
2479 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002480#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 (char_u *)"\"",
2482#else
2483 (char_u *)"",
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002486 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2487 (char_u *)&p_sxe, PV_NONE,
2488 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002489#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002490 (char_u *)"\"&|<>()@^",
2491#else
2492 (char_u *)"",
2493#endif
2494 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2496 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2499 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2502 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)"", (char_u *)"filnxtToO"}
2504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2509#ifdef FEAT_LINEBREAK
2510 (char_u *)&p_sbr, PV_NONE,
2511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showcmd", "sc", P_BOOL|P_VIM,
2516#ifdef FEAT_CMDL_INFO
2517 (char_u *)&p_sc, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
2521 {(char_u *)FALSE,
2522#ifdef UNIX
2523 (char_u *)FALSE
2524#else
2525 (char_u *)TRUE
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2529 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2532 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"showmode", "smd", P_BOOL|P_VIM,
2535 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002537 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002538 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2541 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2544 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002546 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2547#ifdef FEAT_SIGNS
2548 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002549 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002550#else
2551 (char_u *)NULL, PV_NONE,
2552 {(char_u *)NULL, (char_u *)0L}
2553#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002554 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2556 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2559 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2562#ifdef FEAT_SMARTINDENT
2563 (char_u *)&p_si, PV_SI,
2564#else
2565 (char_u *)NULL, PV_NONE,
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2569 (char_u *)&p_sta, 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 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2572 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2575 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002577 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002578#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002579 (char_u *)VAR_WIN, PV_SPELL,
2580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002584 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002585#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002586 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002587 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002588#else
2589 (char_u *)NULL, PV_NONE,
2590 {(char_u *)0L, (char_u *)0L}
2591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002593 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2594 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002595#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002596 (char_u *)&p_spf, PV_SPF,
2597 {(char_u *)"", (char_u *)0L}
2598#else
2599 (char_u *)NULL, PV_NONE,
2600 {(char_u *)0L, (char_u *)0L}
2601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002603 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2604 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002605#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002606 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002608#else
2609 (char_u *)NULL, PV_NONE,
2610 {(char_u *)0L, (char_u *)0L}
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002613 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002614#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002615 (char_u *)&p_sps, PV_NONE,
2616 {(char_u *)"best", (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2629 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2632#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002633 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 (char_u *)&p_su, PV_NONE,
2640 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002642 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002643#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 (char_u *)&p_sua, PV_SUA,
2645 {(char_u *)"", (char_u *)0L}
2646#else
2647 (char_u *)NULL, PV_NONE,
2648 {(char_u *)0L, (char_u *)0L}
2649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2652 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"swapsync", "sws", P_STRING|P_VI_DEF,
2655 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002660 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2661#ifdef FEAT_SYN_HL
2662 (char_u *)&p_smc, PV_SMC,
2663 {(char_u *)3000L, (char_u *)0L}
2664#else
2665 (char_u *)NULL, PV_NONE,
2666 {(char_u *)0L, (char_u *)0L}
2667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002669 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670#ifdef FEAT_SYN_HL
2671 (char_u *)&p_syn, PV_SYN,
2672 {(char_u *)"", (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002678 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2679#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002680 (char_u *)&p_tal, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002685 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002686 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2689 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2692 (char_u *)&p_tbs, PV_NONE,
2693#ifdef VMS /* binary searching doesn't appear to work on VMS */
2694 {(char_u *)0L, (char_u *)0L}
2695#else
2696 {(char_u *)TRUE, (char_u *)0L}
2697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002699 {"tagcase", "tc", P_STRING|P_VIM,
2700 (char_u *)&p_tc, PV_TC,
2701 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"taglength", "tl", P_NUM|P_VI_DEF,
2703 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"tagrelative", "tr", P_BOOL|P_VIM,
2706 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002708 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002709 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {
2711#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2712 (char_u *)"./tags,./TAGS,tags,TAGS",
2713#else
2714 (char_u *)"./tags,tags",
2715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2718 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002720 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002721#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002722 (char_u *)&p_tcldll, PV_NONE,
2723 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002724#else
2725 (char_u *)NULL, PV_NONE,
2726 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002727#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2730 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2733#ifdef FEAT_ARABIC
2734 (char_u *)&p_tbidi, PV_NONE,
2735#else
2736 (char_u *)NULL, PV_NONE,
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2740#ifdef FEAT_MBYTE
2741 (char_u *)&p_tenc, PV_NONE,
2742 {(char_u *)"", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002748 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2749#ifdef FEAT_TERMGUICOLORS
2750 (char_u *)&p_tgc, PV_NONE,
2751 {(char_u *)FALSE, (char_u *)FALSE}
2752#else
2753 (char_u*)NULL, PV_NONE,
2754 {(char_u *)FALSE, (char_u *)FALSE}
2755#endif
2756 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002757 /* TODO: remove this deprecated entry */
Bram Moolenaar8c041b62018-04-14 18:14:06 +02002758 {"terminalscroll", "tlsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2759#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002760 (char_u *)&p_twsl, PV_TWSL,
Bram Moolenaar8c041b62018-04-14 18:14:06 +02002761 {(char_u *)10000L, (char_u *)10000L}
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002767 /* TODO: remove this deprecated entry */
2768 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002769#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002770 (char_u *)VAR_WIN, PV_TWK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002771 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)NULL, (char_u *)0L}
2775#endif
2776 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002777 /* TODO: remove this deprecated entry */
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002778 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2779#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002780 (char_u *)VAR_WIN, PV_TWS,
2781 {(char_u *)"", (char_u *)NULL}
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)NULL, (char_u *)0L}
2785#endif
2786 SCRIPTID_INIT},
2787 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2788#ifdef FEAT_TERMINAL
2789 (char_u *)VAR_WIN, PV_TWK,
2790 {(char_u *)"", (char_u *)NULL}
2791#else
2792 (char_u *)NULL, PV_NONE,
2793 {(char_u *)NULL, (char_u *)0L}
2794#endif
2795 SCRIPTID_INIT},
2796 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2797#ifdef FEAT_TERMINAL
2798 (char_u *)&p_twsl, PV_TWSL,
2799 {(char_u *)10000L, (char_u *)10000L}
2800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)NULL, (char_u *)0L}
2803#endif
2804 SCRIPTID_INIT},
2805 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2806#ifdef FEAT_TERMINAL
2807 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002808 {(char_u *)"", (char_u *)NULL}
2809#else
2810 (char_u *)NULL, PV_NONE,
2811 {(char_u *)NULL, (char_u *)0L}
2812#endif
2813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"terse", NULL, P_BOOL|P_VI_DEF,
2815 (char_u *)&p_terse, 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 {"textauto", "ta", P_BOOL|P_VIM,
2818 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2822 (char_u *)&p_tx, PV_TX,
2823 {
2824#ifdef USE_CRNL
2825 (char_u *)TRUE,
2826#else
2827 (char_u *)FALSE,
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002830 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002833 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002835 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836#else
2837 (char_u *)NULL, PV_NONE,
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2841 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"timeout", "to", P_BOOL|P_VI_DEF,
2844 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2847 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"title", NULL, P_BOOL|P_VI_DEF,
2850#ifdef FEAT_TITLE
2851 (char_u *)&p_title, PV_NONE,
2852#else
2853 (char_u *)NULL, PV_NONE,
2854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"titlelen", NULL, P_NUM|P_VI_DEF,
2857#ifdef FEAT_TITLE
2858 (char_u *)&p_titlelen, PV_NONE,
2859#else
2860 (char_u *)NULL, PV_NONE,
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002863 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864#ifdef FEAT_TITLE
2865 (char_u *)&p_titleold, PV_NONE,
2866 {(char_u *)N_("Thanks for flying Vim"),
2867 (char_u *)0L}
2868#else
2869 (char_u *)NULL, PV_NONE,
2870 {(char_u *)0L, (char_u *)0L}
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"titlestring", NULL, P_STRING|P_VI_DEF,
2874#ifdef FEAT_TITLE
2875 (char_u *)&p_titlestring, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002881#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)0L, (char_u *)0L}
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002890#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002892 {(char_u *)"small", (char_u *)0L}
2893#else
2894 (char_u *)NULL, PV_NONE,
2895 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2899 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2902 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2905 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2908 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2911#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2912 (char_u *)&p_ttym, PV_NONE,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2918 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2921 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002923 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2924 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002925#ifdef FEAT_PERSISTENT_UNDO
2926 (char_u *)&p_udir, PV_NONE,
2927 {(char_u *)".", (char_u *)0L}
2928#else
2929 (char_u *)NULL, PV_NONE,
2930 {(char_u *)0L, (char_u *)0L}
2931#endif
2932 SCRIPTID_INIT},
2933 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2934#ifdef FEAT_PERSISTENT_UNDO
2935 (char_u *)&p_udf, PV_UDF,
2936#else
2937 (char_u *)NULL, PV_NONE,
2938#endif
2939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002941 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002943#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 (char_u *)1000L,
2945#else
2946 (char_u *)100L,
2947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002949 {"undoreload", "ur", P_NUM|P_VI_DEF,
2950 (char_u *)&p_ur, PV_NONE,
2951 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"updatecount", "uc", P_NUM|P_VI_DEF,
2953 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"updatetime", "ut", P_NUM|P_VI_DEF,
2956 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"verbose", "vbs", P_NUM|P_VI_DEF,
2959 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002961 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2962 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002963 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2965#ifdef FEAT_SESSION
2966 (char_u *)&p_vdir, PV_NONE,
2967 {(char_u *)DFLT_VDIR, (char_u *)0L}
2968#else
2969 (char_u *)NULL, PV_NONE,
2970 {(char_u *)0L, (char_u *)0L}
2971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002973 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974#ifdef FEAT_SESSION
2975 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002976 {(char_u *)"folds,options,cursor,curdir",
2977 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978#else
2979 (char_u *)NULL, PV_NONE,
2980 {(char_u *)0L, (char_u *)0L}
2981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002983 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984#ifdef FEAT_VIMINFO
2985 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002986#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002987 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988#else
2989# ifdef AMIGA
2990 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002991 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002993 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994# endif
2995#endif
2996#else
2997 (char_u *)NULL, PV_NONE,
2998 {(char_u *)0L, (char_u *)0L}
2999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02003001 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
3002#ifdef FEAT_VIMINFO
3003 (char_u *)&p_viminfofile, PV_NONE,
3004 {(char_u *)"", (char_u *)0L}
3005#else
3006 (char_u *)NULL, PV_NONE,
3007 {(char_u *)0L, (char_u *)0L}
3008#endif
3009 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003010 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
3011 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_VIRTUALEDIT
3013 (char_u *)&p_ve, PV_NONE,
3014 {(char_u *)"", (char_u *)""}
3015#else
3016 (char_u *)NULL, PV_NONE,
3017 {(char_u *)0L, (char_u *)0L}
3018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3021 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"w300", NULL, P_NUM|P_VI_DEF,
3024 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003025 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"w1200", NULL, P_NUM|P_VI_DEF,
3027 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"w9600", NULL, P_NUM|P_VI_DEF,
3030 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"warn", NULL, P_BOOL|P_VI_DEF,
3033 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3036 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003038 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"wildchar", "wc", P_NUM|P_VIM,
3042 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3044 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003045 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003048 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_WILDIGN
3050 (char_u *)&p_wig, PV_NONE,
3051#else
3052 (char_u *)NULL, PV_NONE,
3053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003055 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3056 (char_u *)&p_wic, PV_NONE,
3057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3059#ifdef FEAT_WILDMENU
3060 (char_u *)&p_wmnu, PV_NONE,
3061#else
3062 (char_u *)NULL, PV_NONE,
3063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003065 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003068 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3069#ifdef FEAT_CMDL_COMPL
3070 (char_u *)&p_wop, PV_NONE,
3071 {(char_u *)"", (char_u *)0L}
3072#else
3073 (char_u *)NULL, PV_NONE,
3074 {(char_u *)NULL, (char_u *)0L}
3075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3078#ifdef FEAT_WAK
3079 (char_u *)&p_wak, PV_NONE,
3080 {(char_u *)"menu", (char_u *)0L}
3081#else
3082 (char_u *)NULL, PV_NONE,
3083 {(char_u *)NULL, (char_u *)0L}
3084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003087 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003091 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003095 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003096 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003104 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003105#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003106 (char_u *)&p_winptydll, PV_NONE, {
3107# ifdef _WIN64
3108 (char_u *)"winpty64.dll",
3109# else
3110 (char_u *)"winpty32.dll",
3111# endif
3112 (char_u *)0L}
3113#else
3114 (char_u *)NULL, PV_NONE,
3115 {(char_u *)0L, (char_u *)0L}
3116#endif
3117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003120 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3122 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3125 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003126 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3128 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003129 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 {"write", NULL, P_BOOL|P_VI_DEF,
3131 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"writeany", "wa", P_BOOL|P_VI_DEF,
3134 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3137 (char_u *)&p_wb, PV_NONE,
3138 {
3139#ifdef FEAT_WRITEBACKUP
3140 (char_u *)TRUE,
3141#else
3142 (char_u *)FALSE,
3143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writedelay", "wd", P_NUM|P_VI_DEF,
3146 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003147 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148
3149/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003150#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003152 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153
3154 p_term("t_AB", T_CAB)
3155 p_term("t_AF", T_CAF)
3156 p_term("t_AL", T_CAL)
3157 p_term("t_al", T_AL)
3158 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003159 p_term("t_BE", T_BE)
3160 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_cd", T_CD)
3162 p_term("t_ce", T_CE)
3163 p_term("t_cl", T_CL)
3164 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003165 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_Co", T_CCO)
3167 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003168 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_da", T_DA)
3172 p_term("t_db", T_DB)
3173 p_term("t_DL", T_CDL)
3174 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_IE", T_CIE)
3180 p_term("t_IS", T_CIS)
3181 p_term("t_ke", T_KE)
3182 p_term("t_ks", T_KS)
3183 p_term("t_le", T_LE)
3184 p_term("t_mb", T_MB)
3185 p_term("t_md", T_MD)
3186 p_term("t_me", T_ME)
3187 p_term("t_mr", T_MR)
3188 p_term("t_ms", T_MS)
3189 p_term("t_nd", T_ND)
3190 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003191 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003193 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003195 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 p_term("t_RV", T_CRV)
3197 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003198 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003200 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003201 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003202 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003204 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003206 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 p_term("t_te", T_TE)
3208 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003209 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003210 p_term("t_ts", T_TS)
3211 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_ue", T_UE)
3213 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003214 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 p_term("t_vb", T_VB)
3216 p_term("t_ve", T_VE)
3217 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003218 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 p_term("t_vs", T_VS)
3220 p_term("t_WP", T_CWP)
3221 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003222 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 p_term("t_xs", T_XS)
3224 p_term("t_ZH", T_CZH)
3225 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003226 p_term("t_8f", T_8F)
3227 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228
3229/* terminal key codes are not in here */
3230
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003231 /* end marker */
3232 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233};
3234
3235#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3236
3237#ifdef FEAT_MBYTE
3238static char *(p_ambw_values[]) = {"single", "double", NULL};
3239#endif
3240static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003241static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003243#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003244static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003245#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003246#ifdef FEAT_CMDL_COMPL
3247static char *(p_wop_values[]) = {"tagfile", NULL};
3248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#ifdef FEAT_WAK
3250static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3251#endif
3252static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3254static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_BROWSE
3257static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003260static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003262static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003263static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3265#ifdef FEAT_FOLDING
3266static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003267# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003269# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270 NULL};
3271static char *(p_fcl_values[]) = {"all", NULL};
3272#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003273#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003274static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003275#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003276#ifdef FEAT_SIGNS
3277static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static void set_option_default(int, int opt_flags, int compatible);
3281static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003282static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static char_u *term_bg_default(void);
3284static void did_set_option(int opt_idx, int opt_flags, int new_value);
3285static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288#endif
3289#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static char_u *option_expand(int opt_idx, char_u *val);
3293static void didset_options(void);
3294static void didset_options2(void);
3295static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003296#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003298#else
3299# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static void set_string_option_global(int opt_idx, char_u **varp);
3302static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3303static 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);
3304static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003305#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003311#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static char_u *did_set_spell_option(int is_spellfile);
3313static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003314#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003315#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003317#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3319static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3320static void check_redraw(long_u flags);
3321static int findoption(char_u *);
3322static int find_key_option(char_u *);
3323static void showoptions(int all, int opt_flags);
3324static int optval_default(struct vimoption *, char_u *varp);
3325static void showoneopt(struct vimoption *, int opt_flags);
3326static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3327static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3328static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3329static int istermoption(struct vimoption *);
3330static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3331static char_u *get_varp(struct vimoption *);
3332static void option_value2string(struct vimoption *, int opt_flags);
3333static void check_winopt(winopt_T *wop);
3334static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003336static void langmap_init(void);
3337static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003339static void paste_option_changed(void);
3340static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003342static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003344static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3345static int check_opt_strings(char_u *val, char **values, int);
3346static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003347#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003348static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350
3351/*
3352 * Initialize the options, first part.
3353 *
3354 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003355 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 */
3357 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003358set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359{
3360 char_u *p;
3361 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003362 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364#ifdef FEAT_LANGMAP
3365 langmap_init();
3366#endif
3367
3368 /* Be Vi compatible by default */
3369 p_cp = TRUE;
3370
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003371 /* Use POSIX compatibility when $VIM_POSIX is set. */
3372 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003373 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003374 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003375 set_string_default("shm", (char_u *)"A");
3376 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003377
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 /*
3379 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003380 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003382 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003383#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003384 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003386 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387# endif
3388#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003389 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003390 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
3392#ifdef FEAT_WILDIGN
3393 /*
3394 * Set the default for 'backupskip' to include environment variables for
3395 * temp files.
3396 */
3397 {
3398# ifdef UNIX
3399 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3400# else
3401 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3402# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003403 int len;
3404 garray_T ga;
3405 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406
3407 ga_init2(&ga, 1, 100);
3408 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3409 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003410 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411# ifdef UNIX
3412 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003413# ifdef MACOS_X
3414 p = (char_u *)"/private/tmp";
3415# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003417# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 else
3419# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003420 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 if (p != NULL && *p != NUL)
3422 {
3423 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003424 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 if (ga_grow(&ga, len) == OK)
3426 {
3427 if (ga.ga_len > 0)
3428 STRCAT(ga.ga_data, ",");
3429 STRCAT(ga.ga_data, p);
3430 add_pathsep(ga.ga_data);
3431 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 ga.ga_len += len;
3433 }
3434 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003435 if (mustfree)
3436 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 }
3438 if (ga.ga_data != NULL)
3439 {
3440 set_string_default("bsk", ga.ga_data);
3441 vim_free(ga.ga_data);
3442 }
3443 }
3444#endif
3445
3446 /*
3447 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3448 */
3449 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003450 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003452#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3453 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3454#endif
3455 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003458 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459#else
3460# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003461 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003462 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003464 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465# endif
3466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003468 opt_idx = findoption((char_u *)"maxmem");
3469 if (opt_idx >= 0)
3470 {
3471#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003472 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3473 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003474#endif
3475 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3476 }
3477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 }
3479
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480#ifdef FEAT_SEARCHPATH
3481 {
3482 char_u *cdpath;
3483 char_u *buf;
3484 int i;
3485 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003486 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487
3488 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003489 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 if (cdpath != NULL)
3491 {
3492 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3493 if (buf != NULL)
3494 {
3495 buf[0] = ','; /* start with ",", current dir first */
3496 j = 1;
3497 for (i = 0; cdpath[i] != NUL; ++i)
3498 {
3499 if (vim_ispathlistsep(cdpath[i]))
3500 buf[j++] = ',';
3501 else
3502 {
3503 if (cdpath[i] == ' ' || cdpath[i] == ',')
3504 buf[j++] = '\\';
3505 buf[j++] = cdpath[i];
3506 }
3507 }
3508 buf[j] = NUL;
3509 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 {
3512 options[opt_idx].def_val[VI_DEFAULT] = buf;
3513 options[opt_idx].flags |= P_DEF_ALLOCED;
3514 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003515 else
3516 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003518 if (mustfree)
3519 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520 }
3521 }
3522#endif
3523
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003524#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525 /* Set print encoding on platforms that don't default to latin1 */
3526 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003527# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 (char_u *)"cp1252"
3529# else
3530# ifdef VMS
3531 (char_u *)"dec-mcs"
3532# else
3533# ifdef EBCDIC
3534 (char_u *)"ebcdic-uk"
3535# else
3536# ifdef MAC
3537 (char_u *)"mac-roman"
3538# else /* HPUX */
3539 (char_u *)"hp-roman8"
3540# endif
3541# endif
3542# endif
3543# endif
3544 );
3545#endif
3546
3547#ifdef FEAT_POSTSCRIPT
3548 /* 'printexpr' must be allocated to be able to evaluate it. */
3549 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003550# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003551 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552# else
3553# ifdef VMS
3554 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3555
3556# else
3557 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3558# endif
3559# endif
3560 );
3561#endif
3562
3563 /*
3564 * Set all the options (except the terminal options) to their default
3565 * value. Also set the global value for local options.
3566 */
3567 set_options_default(0);
3568
Bram Moolenaar07268702018-03-01 21:57:32 +01003569#ifdef CLEAN_RUNTIMEPATH
3570 if (clean_arg)
3571 {
3572 opt_idx = findoption((char_u *)"runtimepath");
3573 if (opt_idx >= 0)
3574 {
3575 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3576 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3577 }
3578 opt_idx = findoption((char_u *)"packpath");
3579 if (opt_idx >= 0)
3580 {
3581 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3582 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3583 }
3584 }
3585#endif
3586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587#ifdef FEAT_GUI
3588 if (found_reverse_arg)
3589 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3590#endif
3591
3592 curbuf->b_p_initialized = TRUE;
3593 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003594 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595 check_buf_options(curbuf);
3596 check_win_options(curwin);
3597 check_options();
3598
3599 /* Must be before option_expand(), because that one needs vim_isIDc() */
3600 didset_options();
3601
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003602#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003603 /* Use the current chartab for the generic chartab. This is not in
3604 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003605 init_spell_chartab();
3606#endif
3607
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 /*
3609 * Expand environment variables and things like "~" for the defaults.
3610 * If option_expand() returns non-NULL the variable is expanded. This can
3611 * only happen for non-indirect options.
3612 * Also set the default to the expanded value, so ":set" does not list
3613 * them.
3614 * Don't set the P_ALLOCED flag, because we don't want to free the
3615 * default.
3616 */
3617 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3618 {
3619 if ((options[opt_idx].flags & P_GETTEXT)
3620 && options[opt_idx].var != NULL)
3621 p = (char_u *)_(*(char **)options[opt_idx].var);
3622 else
3623 p = option_expand(opt_idx, NULL);
3624 if (p != NULL && (p = vim_strsave(p)) != NULL)
3625 {
3626 *(char_u **)options[opt_idx].var = p;
3627 /* VIMEXP
3628 * Defaults for all expanded options are currently the same for Vi
3629 * and Vim. When this changes, add some code here! Also need to
3630 * split P_DEF_ALLOCED in two.
3631 */
3632 if (options[opt_idx].flags & P_DEF_ALLOCED)
3633 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3634 options[opt_idx].def_val[VI_DEFAULT] = p;
3635 options[opt_idx].flags |= P_DEF_ALLOCED;
3636 }
3637 }
3638
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639 save_file_ff(curbuf); /* Buffer is unchanged */
3640
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641#if defined(FEAT_ARABIC)
3642 /* Detect use of mlterm.
3643 * Mlterm is a terminal emulator akin to xterm that has some special
3644 * abilities (bidi namely).
3645 * NOTE: mlterm's author is being asked to 'set' a variable
3646 * instead of an environment variable due to inheritance.
3647 */
3648 if (mch_getenv((char_u *)"MLTERM") != NULL)
3649 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3650#endif
3651
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003652 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653
3654#ifdef FEAT_MBYTE
3655# if defined(WIN3264) && defined(FEAT_GETTEXT)
3656 /*
3657 * If $LANG isn't set, try to get a good value for it. This makes the
3658 * right language be used automatically. Don't do this for English.
3659 */
3660 if (mch_getenv((char_u *)"LANG") == NULL)
3661 {
3662 char buf[20];
3663
3664 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3665 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3666 * only the first two. */
3667 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3668 (LPTSTR)buf, 20);
3669 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3670 {
3671 /* There are a few exceptions (probably more) */
3672 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3673 STRCPY(buf, "zh_TW");
3674 else if (STRNICMP(buf, "chs", 3) == 0
3675 || STRNICMP(buf, "zhc", 3) == 0)
3676 STRCPY(buf, "zh_CN");
3677 else if (STRNICMP(buf, "jp", 2) == 0)
3678 STRCPY(buf, "ja");
3679 else
3680 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003681 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 }
3683 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003684# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003685# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003686 /* Moved to os_mac_conv.c to avoid dependency problems. */
3687 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003688# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689# endif
3690
3691 /* enc_locale() will try to find the encoding of the current locale. */
3692 p = enc_locale();
3693 if (p != NULL)
3694 {
3695 char_u *save_enc;
3696
3697 /* Try setting 'encoding' and check if the value is valid.
3698 * If not, go back to the default "latin1". */
3699 save_enc = p_enc;
3700 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003701 if (STRCMP(p_enc, "gb18030") == 0)
3702 {
3703 /* We don't support "gb18030", but "cp936" is a good substitute
3704 * for practical purposes, thus use that. It's not an alias to
3705 * still support conversion between gb18030 and utf-8. */
3706 p_enc = vim_strsave((char_u *)"cp936");
3707 vim_free(p);
3708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 if (mb_init() == NULL)
3710 {
3711 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003712 if (opt_idx >= 0)
3713 {
3714 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3715 options[opt_idx].flags |= P_DEF_ALLOCED;
3716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717
Bram Moolenaard0573012017-10-28 21:11:06 +02003718#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003719 if (STRCMP(p_enc, "latin1") == 0
3720# ifdef FEAT_MBYTE
3721 || enc_utf8
3722# endif
3723 )
3724 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003725 /* Adjust the default for 'isprint' and 'iskeyword' to match
3726 * latin1. Also set the defaults for when 'nocompatible' is
3727 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003728 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003729 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003730 set_string_option_direct((char_u *)"isk", -1,
3731 ISK_LATIN1, OPT_FREE, SID_NONE);
3732 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003733 if (opt_idx >= 0)
3734 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003735 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003736 if (opt_idx >= 0)
3737 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003738 (void)init_chartab();
3739 }
3740#endif
3741
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742# if defined(WIN3264) && !defined(FEAT_GUI)
3743 /* Win32 console: When GetACP() returns a different value from
3744 * GetConsoleCP() set 'termencoding'. */
3745 if (GetACP() != GetConsoleCP())
3746 {
3747 char buf[50];
3748
3749 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3750 p_tenc = vim_strsave((char_u *)buf);
3751 if (p_tenc != NULL)
3752 {
3753 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003754 if (opt_idx >= 0)
3755 {
3756 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3757 options[opt_idx].flags |= P_DEF_ALLOCED;
3758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 convert_setup(&input_conv, p_tenc, p_enc);
3760 convert_setup(&output_conv, p_enc, p_tenc);
3761 }
3762 else
3763 p_tenc = empty_option;
3764 }
3765# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003766# if defined(WIN3264) && defined(FEAT_MBYTE)
3767 /* $HOME may have characters in active code page. */
3768 init_homedir();
3769# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 }
3771 else
3772 {
3773 vim_free(p_enc);
3774 p_enc = save_enc;
3775 }
3776 }
3777#endif
3778
3779#ifdef FEAT_MULTI_LANG
3780 /* Set the default for 'helplang'. */
3781 set_helplang_default(get_mess_lang());
3782#endif
3783}
3784
3785/*
3786 * Set an option to its default value.
3787 * This does not take care of side effects!
3788 */
3789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003790set_option_default(
3791 int opt_idx,
3792 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3793 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794{
3795 char_u *varp; /* pointer to variable for current option */
3796 int dvi; /* index in def_val[] */
3797 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003798 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3800
3801 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3802 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003803 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 {
3805 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3806 if (flags & P_STRING)
3807 {
Bram Moolenaar09d1d512018-04-24 20:23:56 +02003808 /* skip 'termkey' and 'termsize, they are duplicates of
3809 * 'termwinkey' and 'termwinsize' */
3810 if (STRCMP(options[opt_idx].fullname, "termkey") != 0
3811 && STRCMP(options[opt_idx].fullname, "termsize") != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 {
Bram Moolenaar09d1d512018-04-24 20:23:56 +02003813 /* Use set_string_option_direct() for local options to handle
3814 * freeing and allocating the value. */
3815 if (options[opt_idx].indir != PV_NONE)
3816 set_string_option_direct(NULL, opt_idx,
3817 options[opt_idx].def_val[dvi], opt_flags, 0);
3818 else
3819 {
3820 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3821 free_string_option(*(char_u **)(varp));
3822 *(char_u **)varp = options[opt_idx].def_val[dvi];
3823 options[opt_idx].flags &= ~P_ALLOCED;
3824 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 }
3826 }
3827 else if (flags & P_NUM)
3828 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003829 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 win_comp_scroll(curwin);
3831 else
3832 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003833 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 /* May also set global value for local option. */
3835 if (both)
3836 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3837 *(long *)varp;
3838 }
3839 }
3840 else /* P_BOOL */
3841 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003842 /* the cast to long is required for Manx C, long_i is needed for
3843 * MSVC */
3844 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003845#ifdef UNIX
3846 /* 'modeline' defaults to off for root */
3847 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3848 *(int *)varp = FALSE;
3849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 /* May also set global value for local option. */
3851 if (both)
3852 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3853 *(int *)varp;
3854 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003855
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003856 /* The default value is not insecure. */
3857 flagsp = insecure_flag(opt_idx, opt_flags);
3858 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 }
3860
3861#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003862 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863#endif
3864}
3865
3866/*
3867 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003868 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 */
3870 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003871set_options_default(
3872 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873{
3874 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003876 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877
3878 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003879 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003880#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003881 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003882 || (TRUE
3883# if defined(FEAT_MBYTE)
3884 && options[i].var != (char_u *)&p_enc
3885# endif
3886# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003887 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003888 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003889# endif
3890 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003891#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003892 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 set_option_default(i, opt_flags, p_cp);
3894
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003896 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003898#ifdef FEAT_CINDENT
3899 parse_cino(curbuf);
3900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901}
3902
3903/*
3904 * Set the Vi-default value of a string option.
3905 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003906 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003908 static void
3909set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910{
3911 char_u *p;
3912 int opt_idx;
3913
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003914 if (escape && vim_strchr(val, ' ') != NULL)
3915 p = vim_strsave_escaped(val, (char_u *)" ");
3916 else
3917 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 if (p != NULL) /* we don't want a NULL */
3919 {
3920 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003921 if (opt_idx >= 0)
3922 {
3923 if (options[opt_idx].flags & P_DEF_ALLOCED)
3924 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3925 options[opt_idx].def_val[VI_DEFAULT] = p;
3926 options[opt_idx].flags |= P_DEF_ALLOCED;
3927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 }
3929}
3930
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003931 void
3932set_string_default(char *name, char_u *val)
3933{
3934 set_string_default_esc(name, val, FALSE);
3935}
3936
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937/*
3938 * Set the Vi-default value of a number option.
3939 * Used for 'lines' and 'columns'.
3940 */
3941 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003942set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003944 int opt_idx;
3945
3946 opt_idx = findoption((char_u *)name);
3947 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003948 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949}
3950
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003951#if defined(EXITFREE) || defined(PROTO)
3952/*
3953 * Free all options.
3954 */
3955 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003956free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003957{
3958 int i;
3959
3960 for (i = 0; !istermoption(&options[i]); i++)
3961 {
3962 if (options[i].indir == PV_NONE)
3963 {
3964 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003965 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003966 free_string_option(*(char_u **)options[i].var);
3967 if (options[i].flags & P_DEF_ALLOCED)
3968 free_string_option(options[i].def_val[VI_DEFAULT]);
3969 }
3970 else if (options[i].var != VAR_WIN
3971 && (options[i].flags & P_STRING))
3972 /* buffer-local option: free global value */
3973 free_string_option(*(char_u **)options[i].var);
3974 }
3975}
3976#endif
3977
3978
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979/*
3980 * Initialize the options, part two: After getting Rows and Columns and
3981 * setting 'term'.
3982 */
3983 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003984set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003986 int idx;
3987
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003989 * 'scroll' defaults to half the window height. The stored default is zero,
3990 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003992 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003993 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003994 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 comp_col();
3996
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003997 /*
3998 * 'window' is only for backwards compatibility with Vi.
3999 * Default is Rows - 1.
4000 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00004001 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00004002 p_window = Rows - 1;
4003 set_number_default("window", Rows - 1);
4004
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004006#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004007 /*
4008 * If 'background' wasn't set by the user, try guessing the value,
4009 * depending on the terminal name. Only need to check for terminals
4010 * with a dark background, that can handle color.
4011 */
4012 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004013 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4014 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004016 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004017 /* don't mark it as set, when starting the GUI it may be
4018 * changed again */
4019 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 }
4021#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004022
4023#ifdef CURSOR_SHAPE
4024 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4025#endif
4026#ifdef FEAT_MOUSESHAPE
4027 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4028#endif
4029#ifdef FEAT_PRINTER
4030 (void)parse_printoptions(); /* parse 'printoptions' default value */
4031#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032}
4033
4034/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004035 * Return "dark" or "light" depending on the kind of terminal.
4036 * This is just guessing! Recognized are:
4037 * "linux" Linux console
4038 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004039 * "cygwin.*" Cygwin shell
4040 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004041 * We also check the COLORFGBG environment variable, which is set by
4042 * rxvt and derivatives. This variable contains either two or three
4043 * values separated by semicolons; we want the last value in either
4044 * case. If this value is 0-6 or 8, our background is dark.
4045 */
4046 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004047term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004048{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004049#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004050 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004051 return (char_u *)"dark";
4052#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004053 char_u *p;
4054
Bram Moolenaarf740b292006-02-16 22:11:02 +00004055 if (STRCMP(T_NAME, "linux") == 0
4056 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004057 || STRNCMP(T_NAME, "cygwin", 6) == 0
4058 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004059 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4060 && (p = vim_strrchr(p, ';')) != NULL
4061 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4062 && p[2] == NUL))
4063 return (char_u *)"dark";
4064 return (char_u *)"light";
4065#endif
4066}
4067
4068/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 * Initialize the options, part three: After reading the .vimrc
4070 */
4071 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004072set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075/*
4076 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4077 * This is done after other initializations, where 'shell' might have been
4078 * set, but only if they have not been set before.
4079 */
4080 char_u *p;
4081 int idx_srr;
4082 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 int idx_sp;
4085 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087
4088 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004089 if (idx_srr < 0)
4090 do_srr = FALSE;
4091 else
4092 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004095 if (idx_sp < 0)
4096 do_sp = FALSE;
4097 else
4098 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004100 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 if (p != NULL)
4102 {
4103 /*
4104 * Default for p_sp is "| tee", for p_srr is ">".
4105 * For known shells it is changed here to include stderr.
4106 */
4107 if ( fnamecmp(p, "csh") == 0
4108 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 || fnamecmp(p, "csh.exe") == 0
4111 || fnamecmp(p, "tcsh.exe") == 0
4112# endif
4113 )
4114 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 if (do_sp)
4117 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004118# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004120# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4124 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004125# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 if (do_srr)
4127 {
4128 p_srr = (char_u *)">&";
4129 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4130 }
4131 }
4132 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004133 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 if ( fnamecmp(p, "sh") == 0
4135 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004136 || fnamecmp(p, "mksh") == 0
4137 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004139 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004141 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004142# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 || fnamecmp(p, "cmd") == 0
4144 || fnamecmp(p, "sh.exe") == 0
4145 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004146 || fnamecmp(p, "mksh.exe") == 0
4147 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004149 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 || fnamecmp(p, "bash.exe") == 0
4151 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004153 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004155# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 if (do_sp)
4157 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004158# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004160# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004162# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4164 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004165# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 if (do_srr)
4167 {
4168 p_srr = (char_u *)">%s 2>&1";
4169 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4170 }
4171 }
4172 vim_free(p);
4173 }
4174#endif
4175
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004176#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004178 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4179 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 * This is done after other initializations, where 'shell' might have been
4181 * set, but only if they have not been set before. Default for p_shcf is
4182 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004183 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004185 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 {
4187 int idx3;
4188
4189 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004190 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 {
4192 p_shcf = (char_u *)"-c";
4193 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4194 }
4195
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196 /* Somehow Win32 requires the quotes around the redirection too */
4197 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004198 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 {
4200 p_sxq = (char_u *)"\"";
4201 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4202 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004204 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4205 {
4206 int idx3;
4207
4208 /*
4209 * cmd.exe on Windows will strip the first and last double quote given
4210 * on the command line, e.g. most of the time things like:
4211 * cmd /c "my path/to/echo" "my args to echo"
4212 * become:
4213 * my path/to/echo" "my args to echo
4214 * when executed.
4215 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004216 * To avoid this, set shellxquote to surround the command in
4217 * parenthesis. This appears to make most commands work, without
4218 * breaking commands that worked previously, such as
4219 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004220 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004221 idx3 = findoption((char_u *)"sxq");
4222 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4223 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004224 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004225 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4226 }
4227
Bram Moolenaara64ba222012-02-12 23:23:31 +01004228 idx3 = findoption((char_u *)"shcf");
4229 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4230 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004231 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004232 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4233 }
4234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235#endif
4236
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004237 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004238 {
4239 int idx_ffs = findoption((char_u *)"ffs");
4240
4241 /* Apply the first entry of 'fileformats' to the initial buffer. */
4242 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4243 set_fileformat(default_fileformat(), OPT_LOCAL);
4244 }
4245
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246#ifdef FEAT_TITLE
4247 set_title_defaults();
4248#endif
4249}
4250
4251#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4252/*
4253 * When 'helplang' is still at its default value, set it to "lang".
4254 * Only the first two characters of "lang" are used.
4255 */
4256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004257set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258{
4259 int idx;
4260
4261 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4262 return;
4263 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004264 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 {
4266 if (options[idx].flags & P_ALLOCED)
4267 free_string_option(p_hlg);
4268 p_hlg = vim_strsave(lang);
4269 if (p_hlg == NULL)
4270 p_hlg = empty_option;
4271 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004272 {
4273 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4274 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4275 {
4276 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4277 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281 options[idx].flags |= P_ALLOCED;
4282 }
4283}
4284#endif
4285
4286#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004287static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288
4289 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004290gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291{
4292 if (gui_get_lightness(gui.back_pixel) < 127)
4293 return (char_u *)"dark";
4294 return (char_u *)"light";
4295}
4296
4297/*
4298 * Option initializations that can only be done after opening the GUI window.
4299 */
4300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004301init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302{
4303 /* Set the 'background' option according to the lightness of the
4304 * background color, unless the user has set it already. */
4305 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4306 {
4307 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4308 highlight_changed();
4309 }
4310}
4311#endif
4312
4313#ifdef FEAT_TITLE
4314/*
4315 * 'title' and 'icon' only default to true if they have not been set or reset
4316 * in .vimrc and we can read the old value.
4317 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4318 * they can be reset. This reduces startup time when using X on a remote
4319 * machine.
4320 */
4321 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004322set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323{
4324 int idx1;
4325 long val;
4326
4327 /*
4328 * If GUI is (going to be) used, we can always set the window title and
4329 * icon name. Saves a bit of time, because the X11 display server does
4330 * not need to be contacted.
4331 */
4332 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004333 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 {
4335#ifdef FEAT_GUI
4336 if (gui.starting || gui.in_use)
4337 val = TRUE;
4338 else
4339#endif
4340 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004341 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342 p_title = val;
4343 }
4344 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004345 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 {
4347#ifdef FEAT_GUI
4348 if (gui.starting || gui.in_use)
4349 val = TRUE;
4350 else
4351#endif
4352 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004353 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354 p_icon = val;
4355 }
4356}
4357#endif
4358
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004359#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004360 static void
4361trigger_optionsset_string(
4362 int opt_idx,
4363 int opt_flags,
4364 char_u *oldval,
4365 char_u *newval)
4366{
4367 if (oldval != NULL && newval != NULL)
4368 {
4369 char_u buf_type[7];
4370
4371 sprintf((char *)buf_type, "%s",
4372 (opt_flags & OPT_LOCAL) ? "local" : "global");
4373 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4374 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4375 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4376 apply_autocmds(EVENT_OPTIONSET,
4377 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4378 reset_v_option_vars();
4379 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004380}
4381#endif
4382
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383/*
4384 * Parse 'arg' for option settings.
4385 *
4386 * 'arg' may be IObuff, but only when no errors can be present and option
4387 * does not need to be expanded with option_expand().
4388 * "opt_flags":
4389 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004390 * OPT_GLOBAL for ":setglobal"
4391 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004393 * OPT_WINONLY to only set window-local options
4394 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004395 *
4396 * returns FAIL if an error is detected, OK otherwise
4397 */
4398 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004399do_set(
4400 char_u *arg, /* option string (may be written to!) */
4401 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402{
4403 int opt_idx;
4404 char_u *errmsg;
4405 char_u errbuf[80];
4406 char_u *startarg;
4407 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4408 int nextchar; /* next non-white char after option name */
4409 int afterchar; /* character just after option name */
4410 int len;
4411 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004412 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413 int key;
4414 long_u flags; /* flags for current option */
4415 char_u *varp = NULL; /* pointer to variable for current option */
4416 int did_show = FALSE; /* already showed one value */
4417 int adding; /* "opt+=arg" */
4418 int prepending; /* "opt^=arg" */
4419 int removing; /* "opt-=arg" */
4420 int cp_val = 0;
4421 char_u key_name[2];
4422
4423 if (*arg == NUL)
4424 {
4425 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004426 did_show = TRUE;
4427 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004428 }
4429
4430 while (*arg != NUL) /* loop to process all options */
4431 {
4432 errmsg = NULL;
4433 startarg = arg; /* remember for error message */
4434
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004435 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4436 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 {
4438 /*
4439 * ":set all" show all options.
4440 * ":set all&" set all options to their default value.
4441 */
4442 arg += 3;
4443 if (*arg == '&')
4444 {
4445 ++arg;
4446 /* Only for :set command set global value of local options. */
4447 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004448 didset_options();
4449 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004450 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451 }
4452 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004453 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004454 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004455 did_show = TRUE;
4456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004457 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004458 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004459 {
4460 showoptions(2, opt_flags);
4461 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004462 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463 arg += 7;
4464 }
4465 else
4466 {
4467 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004468 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469 {
4470 prefix = 0;
4471 arg += 2;
4472 }
4473 else if (STRNCMP(arg, "inv", 3) == 0)
4474 {
4475 prefix = 2;
4476 arg += 3;
4477 }
4478
4479 /* find end of name */
4480 key = 0;
4481 if (*arg == '<')
4482 {
4483 nextchar = 0;
4484 opt_idx = -1;
4485 /* look out for <t_>;> */
4486 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4487 len = 5;
4488 else
4489 {
4490 len = 1;
4491 while (arg[len] != NUL && arg[len] != '>')
4492 ++len;
4493 }
4494 if (arg[len] != '>')
4495 {
4496 errmsg = e_invarg;
4497 goto skip;
4498 }
4499 arg[len] = NUL; /* put NUL after name */
4500 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4501 opt_idx = findoption(arg + 1);
4502 arg[len++] = '>'; /* restore '>' */
4503 if (opt_idx == -1)
4504 key = find_key_option(arg + 1);
4505 }
4506 else
4507 {
4508 len = 0;
4509 /*
4510 * The two characters after "t_" may not be alphanumeric.
4511 */
4512 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4513 len = 4;
4514 else
4515 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4516 ++len;
4517 nextchar = arg[len];
4518 arg[len] = NUL; /* put NUL after name */
4519 opt_idx = findoption(arg);
4520 arg[len] = nextchar; /* restore nextchar */
4521 if (opt_idx == -1)
4522 key = find_key_option(arg);
4523 }
4524
4525 /* remember character after option name */
4526 afterchar = arg[len];
4527
4528 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004529 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004530 ++len;
4531
4532 adding = FALSE;
4533 prepending = FALSE;
4534 removing = FALSE;
4535 if (arg[len] != NUL && arg[len + 1] == '=')
4536 {
4537 if (arg[len] == '+')
4538 {
4539 adding = TRUE; /* "+=" */
4540 ++len;
4541 }
4542 else if (arg[len] == '^')
4543 {
4544 prepending = TRUE; /* "^=" */
4545 ++len;
4546 }
4547 else if (arg[len] == '-')
4548 {
4549 removing = TRUE; /* "-=" */
4550 ++len;
4551 }
4552 }
4553 nextchar = arg[len];
4554
4555 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4556 {
4557 errmsg = (char_u *)N_("E518: Unknown option");
4558 goto skip;
4559 }
4560
4561 if (opt_idx >= 0)
4562 {
4563 if (options[opt_idx].var == NULL) /* hidden option: skip */
4564 {
4565 /* Only give an error message when requesting the value of
4566 * a hidden option, ignore setting it. */
4567 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4568 && (!(options[opt_idx].flags & P_BOOL)
4569 || nextchar == '?'))
4570 errmsg = (char_u *)N_("E519: Option not supported");
4571 goto skip;
4572 }
4573
4574 flags = options[opt_idx].flags;
4575 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4576 }
4577 else
4578 {
4579 flags = P_STRING;
4580 if (key < 0)
4581 {
4582 key_name[0] = KEY2TERMCAP0(key);
4583 key_name[1] = KEY2TERMCAP1(key);
4584 }
4585 else
4586 {
4587 key_name[0] = KS_KEY;
4588 key_name[1] = (key & 0xff);
4589 }
4590 }
4591
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004592 /* Skip all options that are not window-local (used when showing
4593 * an already loaded buffer in a window). */
4594 if ((opt_flags & OPT_WINONLY)
4595 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4596 goto skip;
4597
Bram Moolenaara3227e22006-03-08 21:32:40 +00004598 /* Skip all options that are window-local (used for :vimgrep). */
4599 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4600 && options[opt_idx].var == VAR_WIN)
4601 goto skip;
4602
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004603 /* Disallow changing some options from modelines. */
4604 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004605 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004606 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004607 {
4608 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4609 goto skip;
4610 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004611#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004612 /* In diff mode some options are overruled. This avoids that
4613 * 'foldmethod' becomes "marker" instead of "diff" and that
4614 * "wrap" gets set. */
4615 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004616 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004617 && (
4618#ifdef FEAT_FOLDING
4619 options[opt_idx].indir == PV_FDM ||
4620#endif
4621 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004622 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 }
4625
4626#ifdef HAVE_SANDBOX
4627 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004628 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 {
4630 errmsg = (char_u *)_(e_sandbox);
4631 goto skip;
4632 }
4633#endif
4634
4635 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4636 {
4637 arg += len;
4638 cp_val = p_cp;
4639 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4640 {
4641 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4642 {
4643 cp_val = FALSE;
4644 arg += 3;
4645 }
4646 else /* "opt&vi": set to Vi default */
4647 {
4648 cp_val = TRUE;
4649 arg += 2;
4650 }
4651 }
4652 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004653 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004654 {
4655 errmsg = e_trailing;
4656 goto skip;
4657 }
4658 }
4659
4660 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004661 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4662 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004663 */
4664 if (nextchar == '?'
4665 || (prefix == 1
4666 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4667 && !(flags & P_BOOL)))
4668 {
4669 /*
4670 * print value
4671 */
4672 if (did_show)
4673 msg_putchar('\n'); /* cursor below last one */
4674 else
4675 {
4676 gotocmdline(TRUE); /* cursor at status line */
4677 did_show = TRUE; /* remember that we did a line */
4678 }
4679 if (opt_idx >= 0)
4680 {
4681 showoneopt(&options[opt_idx], opt_flags);
4682#ifdef FEAT_EVAL
4683 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004684 {
4685 /* Mention where the option was last set. */
4686 if (varp == options[opt_idx].var)
4687 last_set_msg(options[opt_idx].scriptID);
4688 else if ((int)options[opt_idx].indir & PV_WIN)
4689 last_set_msg(curwin->w_p_scriptID[
4690 (int)options[opt_idx].indir & PV_MASK]);
4691 else if ((int)options[opt_idx].indir & PV_BUF)
4692 last_set_msg(curbuf->b_p_scriptID[
4693 (int)options[opt_idx].indir & PV_MASK]);
4694 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695#endif
4696 }
4697 else
4698 {
4699 char_u *p;
4700
4701 p = find_termcode(key_name);
4702 if (p == NULL)
4703 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004704 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004705 goto skip;
4706 }
4707 else
4708 (void)show_one_termcode(key_name, p, TRUE);
4709 }
4710 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004711 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 errmsg = e_trailing;
4713 }
4714 else
4715 {
4716 if (flags & P_BOOL) /* boolean */
4717 {
4718 if (nextchar == '=' || nextchar == ':')
4719 {
4720 errmsg = e_invarg;
4721 goto skip;
4722 }
4723
4724 /*
4725 * ":set opt!": invert
4726 * ":set opt&": reset to default value
4727 * ":set opt<": reset to global value
4728 */
4729 if (nextchar == '!')
4730 value = *(int *)(varp) ^ 1;
4731 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004732 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004733 ((flags & P_VI_DEF) || cp_val)
4734 ? VI_DEFAULT : VIM_DEFAULT];
4735 else if (nextchar == '<')
4736 {
4737 /* For 'autoread' -1 means to use global value. */
4738 if ((int *)varp == &curbuf->b_p_ar
4739 && opt_flags == OPT_LOCAL)
4740 value = -1;
4741 else
4742 value = *(int *)get_varp_scope(&(options[opt_idx]),
4743 OPT_GLOBAL);
4744 }
4745 else
4746 {
4747 /*
4748 * ":set invopt": invert
4749 * ":set opt" or ":set noopt": set or reset
4750 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004751 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 {
4753 errmsg = e_trailing;
4754 goto skip;
4755 }
4756 if (prefix == 2) /* inv */
4757 value = *(int *)(varp) ^ 1;
4758 else
4759 value = prefix;
4760 }
4761
4762 errmsg = set_bool_option(opt_idx, varp, (int)value,
4763 opt_flags);
4764 }
4765 else /* numeric or string */
4766 {
4767 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4768 || prefix != 1)
4769 {
4770 errmsg = e_invarg;
4771 goto skip;
4772 }
4773
4774 if (flags & P_NUM) /* numeric */
4775 {
4776 /*
4777 * Different ways to set a number option:
4778 * & set to default value
4779 * < set to global value
4780 * <xx> accept special key codes for 'wildchar'
4781 * c accept any non-digit for 'wildchar'
4782 * [-]0-9 set number
4783 * other error
4784 */
4785 ++arg;
4786 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004787 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 ((flags & P_VI_DEF) || cp_val)
4789 ? VI_DEFAULT : VIM_DEFAULT];
4790 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004791 {
4792 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4793 * use the global value. */
4794 if ((long *)varp == &curbuf->b_p_ul
4795 && opt_flags == OPT_LOCAL)
4796 value = NO_LOCAL_UNDOLEVEL;
4797 else
4798 value = *(long *)get_varp_scope(
4799 &(options[opt_idx]), OPT_GLOBAL);
4800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004801 else if (((long *)varp == &p_wc
4802 || (long *)varp == &p_wcm)
4803 && (*arg == '<'
4804 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004805 || (*arg != NUL
4806 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 && !VIM_ISDIGIT(*arg))))
4808 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004809 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 if (value == 0 && (long *)varp != &p_wcm)
4811 {
4812 errmsg = e_invarg;
4813 goto skip;
4814 }
4815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004816 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4817 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004818 /* Allow negative (for 'undolevels'), octal and
4819 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004820 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4821 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004822 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823 {
4824 errmsg = e_invarg;
4825 goto skip;
4826 }
4827 }
4828 else
4829 {
4830 errmsg = (char_u *)N_("E521: Number required after =");
4831 goto skip;
4832 }
4833
4834 if (adding)
4835 value = *(long *)varp + value;
4836 if (prepending)
4837 value = *(long *)varp * value;
4838 if (removing)
4839 value = *(long *)varp - value;
4840 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004841 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004842 }
4843 else if (opt_idx >= 0) /* string */
4844 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004845 char_u *save_arg = NULL;
4846 char_u *s = NULL;
4847 char_u *oldval = NULL; /* previous value if *varp */
4848 char_u *newval;
4849 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004850#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004851 char_u *saved_origval = NULL;
4852 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004853#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004854 unsigned newlen;
4855 int comma;
4856 int bs;
4857 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004858 was allocated */
4859
4860 /* When using ":set opt=val" for a global option
4861 * with a local value the local value will be
4862 * reset, use the global value here. */
4863 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004864 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 varp = options[opt_idx].var;
4866
4867 /* The old value is kept until we are sure that the
4868 * new value is valid. */
4869 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004870
4871 /* When setting the local value of a global
4872 * option, the old value may be the global value. */
4873 if (((int)options[opt_idx].indir & PV_BOTH)
4874 && (opt_flags & OPT_LOCAL))
4875 origval = *(char_u **)get_varp(
4876 &options[opt_idx]);
4877 else
4878 origval = oldval;
4879
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 if (nextchar == '&') /* set to default val */
4881 {
4882 newval = options[opt_idx].def_val[
4883 ((flags & P_VI_DEF) || cp_val)
4884 ? VI_DEFAULT : VIM_DEFAULT];
4885 if ((char_u **)varp == &p_bg)
4886 {
4887 /* guess the value of 'background' */
4888#ifdef FEAT_GUI
4889 if (gui.in_use)
4890 newval = gui_bg_default();
4891 else
4892#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004893 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004894 }
4895
4896 /* expand environment variables and ~ (since the
4897 * default value was already expanded, only
4898 * required when an environment variable was set
4899 * later */
4900 if (newval == NULL)
4901 newval = empty_option;
4902 else
4903 {
4904 s = option_expand(opt_idx, newval);
4905 if (s == NULL)
4906 s = newval;
4907 newval = vim_strsave(s);
4908 }
4909 new_value_alloced = TRUE;
4910 }
4911 else if (nextchar == '<') /* set to global val */
4912 {
4913 newval = vim_strsave(*(char_u **)get_varp_scope(
4914 &(options[opt_idx]), OPT_GLOBAL));
4915 new_value_alloced = TRUE;
4916 }
4917 else
4918 {
4919 ++arg; /* jump to after the '=' or ':' */
4920
4921 /*
4922 * Set 'keywordprg' to ":help" if an empty
4923 * value was passed to :set by the user.
4924 * Misuse errbuf[] for the resulting string.
4925 */
4926 if (varp == (char_u *)&p_kp
4927 && (*arg == NUL || *arg == ' '))
4928 {
4929 STRCPY(errbuf, ":help");
4930 save_arg = arg;
4931 arg = errbuf;
4932 }
4933 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004934 * Convert 'backspace' number to string, for
4935 * adding, prepending and removing string.
4936 */
4937 else if (varp == (char_u *)&p_bs
4938 && VIM_ISDIGIT(**(char_u **)varp))
4939 {
4940 i = getdigits((char_u **)varp);
4941 switch (i)
4942 {
4943 case 0:
4944 *(char_u **)varp = empty_option;
4945 break;
4946 case 1:
4947 *(char_u **)varp = vim_strsave(
4948 (char_u *)"indent,eol");
4949 break;
4950 case 2:
4951 *(char_u **)varp = vim_strsave(
4952 (char_u *)"indent,eol,start");
4953 break;
4954 }
4955 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004956 if (origval == oldval)
4957 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004958 oldval = *(char_u **)varp;
4959 }
4960 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 * Convert 'whichwrap' number to string, for
4962 * backwards compatibility with Vim 3.0.
4963 * Misuse errbuf[] for the resulting string.
4964 */
4965 else if (varp == (char_u *)&p_ww
4966 && VIM_ISDIGIT(*arg))
4967 {
4968 *errbuf = NUL;
4969 i = getdigits(&arg);
4970 if (i & 1)
4971 STRCAT(errbuf, "b,");
4972 if (i & 2)
4973 STRCAT(errbuf, "s,");
4974 if (i & 4)
4975 STRCAT(errbuf, "h,l,");
4976 if (i & 8)
4977 STRCAT(errbuf, "<,>,");
4978 if (i & 16)
4979 STRCAT(errbuf, "[,],");
4980 if (*errbuf != NUL) /* remove trailing , */
4981 errbuf[STRLEN(errbuf) - 1] = NUL;
4982 save_arg = arg;
4983 arg = errbuf;
4984 }
4985 /*
4986 * Remove '>' before 'dir' and 'bdir', for
4987 * backwards compatibility with version 3.0
4988 */
4989 else if ( *arg == '>'
4990 && (varp == (char_u *)&p_dir
4991 || varp == (char_u *)&p_bdir))
4992 {
4993 ++arg;
4994 }
4995
Bram Moolenaar071d4272004-06-13 20:20:40 +00004996 /*
4997 * Copy the new string into allocated memory.
4998 * Can't use set_string_option_direct(), because
4999 * we need to remove the backslashes.
5000 */
5001 /* get a bit too much */
5002 newlen = (unsigned)STRLEN(arg) + 1;
5003 if (adding || prepending || removing)
5004 newlen += (unsigned)STRLEN(origval) + 1;
5005 newval = alloc(newlen);
5006 if (newval == NULL) /* out of mem, don't change */
5007 break;
5008 s = newval;
5009
5010 /*
5011 * Copy the string, skip over escaped chars.
5012 * For MS-DOS and WIN32 backslashes before normal
5013 * file name characters are not removed, and keep
5014 * backslash at start, for "\\machine\path", but
5015 * do remove it for "\\\\machine\\path".
5016 * The reverse is found in ExpandOldSetting().
5017 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005018 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 {
5020 if (*arg == '\\' && arg[1] != NUL
5021#ifdef BACKSLASH_IN_FILENAME
5022 && !((flags & P_EXPAND)
5023 && vim_isfilec(arg[1])
5024 && (arg[1] != '\\'
5025 || (s == newval
5026 && arg[2] != '\\')))
5027#endif
5028 )
5029 ++arg; /* remove backslash */
5030#ifdef FEAT_MBYTE
5031 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005032 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005033 {
5034 /* copy multibyte char */
5035 mch_memmove(s, arg, (size_t)i);
5036 arg += i;
5037 s += i;
5038 }
5039 else
5040#endif
5041 *s++ = *arg++;
5042 }
5043 *s = NUL;
5044
5045 /*
5046 * Expand environment variables and ~.
5047 * Don't do it when adding without inserting a
5048 * comma.
5049 */
5050 if (!(adding || prepending || removing)
5051 || (flags & P_COMMA))
5052 {
5053 s = option_expand(opt_idx, newval);
5054 if (s != NULL)
5055 {
5056 vim_free(newval);
5057 newlen = (unsigned)STRLEN(s) + 1;
5058 if (adding || prepending || removing)
5059 newlen += (unsigned)STRLEN(origval) + 1;
5060 newval = alloc(newlen);
5061 if (newval == NULL)
5062 break;
5063 STRCPY(newval, s);
5064 }
5065 }
5066
5067 /* locate newval[] in origval[] when removing it
5068 * and when adding to avoid duplicates */
5069 i = 0; /* init for GCC */
5070 if (removing || (flags & P_NODUP))
5071 {
5072 i = (int)STRLEN(newval);
5073 bs = 0;
5074 for (s = origval; *s; ++s)
5075 {
5076 if ((!(flags & P_COMMA)
5077 || s == origval
5078 || (s[-1] == ',' && !(bs & 1)))
5079 && STRNCMP(s, newval, i) == 0
5080 && (!(flags & P_COMMA)
5081 || s[i] == ','
5082 || s[i] == NUL))
5083 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005084 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005085 * even number of backslashes or a single
5086 * backslash preceded by a comma before it
5087 * is recognized as a separator */
5088 if ((s > origval + 1
5089 && s[-1] == '\\'
5090 && s[-2] != ',')
5091 || (s == origval + 1
5092 && s[-1] == '\\'))
5093
Bram Moolenaar071d4272004-06-13 20:20:40 +00005094 ++bs;
5095 else
5096 bs = 0;
5097 }
5098
5099 /* do not add if already there */
5100 if ((adding || prepending) && *s)
5101 {
5102 prepending = FALSE;
5103 adding = FALSE;
5104 STRCPY(newval, origval);
5105 }
5106 }
5107
5108 /* concatenate the two strings; add a ',' if
5109 * needed */
5110 if (adding || prepending)
5111 {
5112 comma = ((flags & P_COMMA) && *origval != NUL
5113 && *newval != NUL);
5114 if (adding)
5115 {
5116 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005117 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005118 if (comma && i > 1
5119 && (flags & P_ONECOMMA) == P_ONECOMMA
5120 && origval[i - 1] == ','
5121 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005122 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005123 mch_memmove(newval + i + comma, newval,
5124 STRLEN(newval) + 1);
5125 mch_memmove(newval, origval, (size_t)i);
5126 }
5127 else
5128 {
5129 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005130 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 }
5132 if (comma)
5133 newval[i] = ',';
5134 }
5135
5136 /* Remove newval[] from origval[]. (Note: "i" has
5137 * been set above and is used here). */
5138 if (removing)
5139 {
5140 STRCPY(newval, origval);
5141 if (*s)
5142 {
5143 /* may need to remove a comma */
5144 if (flags & P_COMMA)
5145 {
5146 if (s == origval)
5147 {
5148 /* include comma after string */
5149 if (s[i] == ',')
5150 ++i;
5151 }
5152 else
5153 {
5154 /* include comma before string */
5155 --s;
5156 ++i;
5157 }
5158 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005159 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 }
5161 }
5162
5163 if (flags & P_FLAGLIST)
5164 {
5165 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005166 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005167 {
5168 /* if options have P_FLAGLIST and
5169 * P_ONECOMMA such as 'whichwrap' */
5170 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005172 if (*s != ',' && *(s + 1) == ','
5173 && vim_strchr(s + 2, *s) != NULL)
5174 {
5175 /* Remove the duplicated value and
5176 * the next comma. */
5177 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005178 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005181 else
5182 {
5183 if ((!(flags & P_COMMA) || *s != ',')
5184 && vim_strchr(s + 1, *s) != NULL)
5185 {
5186 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005187 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005188 }
5189 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005190 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005191 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 }
5193
5194 if (save_arg != NULL) /* number for 'whichwrap' */
5195 arg = save_arg;
5196 new_value_alloced = TRUE;
5197 }
5198
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005199 /*
5200 * Set the new value.
5201 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005202 *(char_u **)(varp) = newval;
5203
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005204#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005205 if (!starting
5206# ifdef FEAT_CRYPT
5207 && options[opt_idx].indir != PV_KEY
5208# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005209 && origval != NULL && newval != NULL)
5210 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005211 /* origval may be freed by
5212 * did_set_string_option(), make a copy. */
5213 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005214 /* newval (and varp) may become invalid if the
5215 * buffer is closed by autocommands. */
5216 saved_newval = vim_strsave(newval);
5217 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005218#endif
5219
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005221 * ":set" on local options. Note: when setting 'syntax'
5222 * or 'filetype' autocommands may be triggered that can
5223 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5225 new_value_alloced, oldval, errbuf, opt_flags);
5226
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005227#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005228 if (errmsg == NULL)
5229 trigger_optionsset_string(opt_idx, opt_flags,
5230 saved_origval, saved_newval);
5231 vim_free(saved_origval);
5232 vim_free(saved_newval);
5233#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 /* If error detected, print the error message. */
5235 if (errmsg != NULL)
5236 goto skip;
5237 }
5238 else /* key code option */
5239 {
5240 char_u *p;
5241
5242 if (nextchar == '&')
5243 {
5244 if (add_termcap_entry(key_name, TRUE) == FAIL)
5245 errmsg = (char_u *)N_("E522: Not found in termcap");
5246 }
5247 else
5248 {
5249 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005250 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 if (*p == '\\' && p[1] != NUL)
5252 ++p;
5253 nextchar = *p;
5254 *p = NUL;
5255 add_termcode(key_name, arg, FALSE);
5256 *p = nextchar;
5257 }
5258 if (full_screen)
5259 ttest(FALSE);
5260 redraw_all_later(CLEAR);
5261 }
5262 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005263
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005265 did_set_option(opt_idx, opt_flags,
5266 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 }
5268
5269skip:
5270 /*
5271 * Advance to next argument.
5272 * - skip until a blank found, taking care of backslashes
5273 * - skip blanks
5274 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5275 */
5276 for (i = 0; i < 2 ; ++i)
5277 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005278 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279 if (*arg++ == '\\' && *arg != NUL)
5280 ++arg;
5281 arg = skipwhite(arg);
5282 if (*arg != '=')
5283 break;
5284 }
5285 }
5286
5287 if (errmsg != NULL)
5288 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005289 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005290 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291 if (i + (arg - startarg) < IOSIZE)
5292 {
5293 /* append the argument with the error */
5294 STRCAT(IObuff, ": ");
5295 mch_memmove(IObuff + i, startarg, (arg - startarg));
5296 IObuff[i + (arg - startarg)] = NUL;
5297 }
5298 /* make sure all characters are printable */
5299 trans_characters(IObuff, IOSIZE);
5300
5301 ++no_wait_return; /* wait_return done later */
5302 emsg(IObuff); /* show error highlighted */
5303 --no_wait_return;
5304
5305 return FAIL;
5306 }
5307
5308 arg = skipwhite(arg);
5309 }
5310
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005311theend:
5312 if (silent_mode && did_show)
5313 {
5314 /* After displaying option values in silent mode. */
5315 silent_mode = FALSE;
5316 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5317 msg_putchar('\n');
5318 cursor_on(); /* msg_start() switches it off */
5319 out_flush();
5320 silent_mode = TRUE;
5321 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5322 }
5323
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324 return OK;
5325}
5326
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005327/*
5328 * Call this when an option has been given a new value through a user command.
5329 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5330 */
5331 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005332did_set_option(
5333 int opt_idx,
5334 int opt_flags, /* possibly with OPT_MODELINE */
5335 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005337 long_u *p;
5338
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005339 options[opt_idx].flags |= P_WAS_SET;
5340
5341 /* When an option is set in the sandbox, from a modeline or in secure mode
5342 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005343 * flag. */
5344 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005345 if (secure
5346#ifdef HAVE_SANDBOX
5347 || sandbox != 0
5348#endif
5349 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005350 *p = *p | P_INSECURE;
5351 else if (new_value)
5352 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005353}
5354
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005356illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357{
5358 if (errbuf == NULL)
5359 return (char_u *)"";
5360 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005361 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 return errbuf;
5363}
5364
5365/*
5366 * Convert a key name or string into a key value.
5367 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005368 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005370 int
5371string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372{
5373 if (*arg == '<')
5374 return find_key_option(arg + 1);
5375 if (*arg == '^')
5376 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005377 if (multi_byte)
5378 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 return *arg;
5380}
5381
5382#ifdef FEAT_CMDWIN
5383/*
5384 * Check value of 'cedit' and set cedit_key.
5385 * Returns NULL if value is OK, error message otherwise.
5386 */
5387 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005388check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389{
5390 int n;
5391
5392 if (*p_cedit == NUL)
5393 cedit_key = -1;
5394 else
5395 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005396 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397 if (vim_isprintc(n))
5398 return e_invarg;
5399 cedit_key = n;
5400 }
5401 return NULL;
5402}
5403#endif
5404
5405#ifdef FEAT_TITLE
5406/*
5407 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5408 * maketitle() to create and display it.
5409 * When switching the title or icon off, call mch_restore_title() to get
5410 * the old value back.
5411 */
5412 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005413did_set_title(
5414 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005415{
5416 if (starting != NO_SCREEN
5417#ifdef FEAT_GUI
5418 && !gui.starting
5419#endif
5420 )
5421 {
5422 maketitle();
5423 if (icon)
5424 {
5425 if (!p_icon)
5426 mch_restore_title(2);
5427 }
5428 else
5429 {
5430 if (!p_title)
5431 mch_restore_title(1);
5432 }
5433 }
5434}
5435#endif
5436
5437/*
5438 * set_options_bin - called when 'bin' changes value.
5439 */
5440 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005441set_options_bin(
5442 int oldval,
5443 int newval,
5444 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005445{
5446 /*
5447 * The option values that are changed when 'bin' changes are
5448 * copied when 'bin is set and restored when 'bin' is reset.
5449 */
5450 if (newval)
5451 {
5452 if (!oldval) /* switched on */
5453 {
5454 if (!(opt_flags & OPT_GLOBAL))
5455 {
5456 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5457 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5458 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5459 curbuf->b_p_et_nobin = curbuf->b_p_et;
5460 }
5461 if (!(opt_flags & OPT_LOCAL))
5462 {
5463 p_tw_nobin = p_tw;
5464 p_wm_nobin = p_wm;
5465 p_ml_nobin = p_ml;
5466 p_et_nobin = p_et;
5467 }
5468 }
5469
5470 if (!(opt_flags & OPT_GLOBAL))
5471 {
5472 curbuf->b_p_tw = 0; /* no automatic line wrap */
5473 curbuf->b_p_wm = 0; /* no automatic line wrap */
5474 curbuf->b_p_ml = 0; /* no modelines */
5475 curbuf->b_p_et = 0; /* no expandtab */
5476 }
5477 if (!(opt_flags & OPT_LOCAL))
5478 {
5479 p_tw = 0;
5480 p_wm = 0;
5481 p_ml = FALSE;
5482 p_et = FALSE;
5483 p_bin = TRUE; /* needed when called for the "-b" argument */
5484 }
5485 }
5486 else if (oldval) /* switched off */
5487 {
5488 if (!(opt_flags & OPT_GLOBAL))
5489 {
5490 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5491 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5492 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5493 curbuf->b_p_et = curbuf->b_p_et_nobin;
5494 }
5495 if (!(opt_flags & OPT_LOCAL))
5496 {
5497 p_tw = p_tw_nobin;
5498 p_wm = p_wm_nobin;
5499 p_ml = p_ml_nobin;
5500 p_et = p_et_nobin;
5501 }
5502 }
5503}
5504
5505#ifdef FEAT_VIMINFO
5506/*
5507 * Find the parameter represented by the given character (eg ', :, ", or /),
5508 * and return its associated value in the 'viminfo' string.
5509 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005510 * If the parameter is not specified in the string or there is no following
5511 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512 */
5513 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005514get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515{
5516 char_u *p;
5517
5518 p = find_viminfo_parameter(type);
5519 if (p != NULL && VIM_ISDIGIT(*p))
5520 return atoi((char *)p);
5521 return -1;
5522}
5523
5524/*
5525 * Find the parameter represented by the given character (eg ''', ':', '"', or
5526 * '/') in the 'viminfo' option and return a pointer to the string after it.
5527 * Return NULL if the parameter is not specified in the string.
5528 */
5529 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005530find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531{
5532 char_u *p;
5533
5534 for (p = p_viminfo; *p; ++p)
5535 {
5536 if (*p == type)
5537 return p + 1;
5538 if (*p == 'n') /* 'n' is always the last one */
5539 break;
5540 p = vim_strchr(p, ','); /* skip until next ',' */
5541 if (p == NULL) /* hit the end without finding parameter */
5542 break;
5543 }
5544 return NULL;
5545}
5546#endif
5547
5548/*
5549 * Expand environment variables for some string options.
5550 * These string options cannot be indirect!
5551 * If "val" is NULL expand the current value of the option.
5552 * Return pointer to NameBuff, or NULL when not expanded.
5553 */
5554 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005555option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556{
5557 /* if option doesn't need expansion nothing to do */
5558 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5559 return NULL;
5560
5561 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5562 * expand_env() would truncate the string. */
5563 if (val != NULL && STRLEN(val) > MAXPATHL)
5564 return NULL;
5565
5566 if (val == NULL)
5567 val = *(char_u **)options[opt_idx].var;
5568
5569 /*
5570 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5571 * Escape spaces when expanding 'tags', they are used to separate file
5572 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005573 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574 */
5575 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005576 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005577#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005578 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5579#endif
5580 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5582 return NULL;
5583
5584 return NameBuff;
5585}
5586
5587/*
5588 * After setting various option values: recompute variables that depend on
5589 * option values.
5590 */
5591 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005592didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593{
5594 /* initialize the table for 'iskeyword' et.al. */
5595 (void)init_chartab();
5596
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005597#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005601 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602#ifdef FEAT_SESSION
5603 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5604 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5605#endif
5606#ifdef FEAT_FOLDING
5607 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5608#endif
5609 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005610 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611#ifdef FEAT_VIRTUALEDIT
5612 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5613#endif
5614#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5615 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5616#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005617#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005618 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005619 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005620 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005621 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005623#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5624 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5625#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005626#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5628#endif
5629#ifdef FEAT_CMDWIN
5630 /* set cedit_key */
5631 (void)check_cedit();
5632#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005633#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005634 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005635#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005636#ifdef FEAT_LINEBREAK
5637 /* initialize the table for 'breakat'. */
5638 fill_breakat_flags();
5639#endif
5640
5641}
5642
5643/*
5644 * More side effects of setting options.
5645 */
5646 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005647didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005648{
5649 /* Initialize the highlight_attr[] table. */
5650 (void)highlight_changed();
5651
5652 /* Parse default for 'wildmode' */
5653 check_opt_wim();
5654
5655 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005656 /* Parse default for 'fillchars'. */
5657 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005658
5659#ifdef FEAT_CLIPBOARD
5660 /* Parse default for 'clipboard' */
5661 (void)check_clipboard_option();
5662#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663}
5664
5665/*
5666 * Check for string options that are NULL (normally only termcap options).
5667 */
5668 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005669check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670{
5671 int opt_idx;
5672
5673 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5674 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5675 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5676}
5677
5678/*
5679 * Check string options in a buffer for NULL value.
5680 */
5681 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005682check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 check_string_option(&buf->b_p_bh);
5685 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686#ifdef FEAT_MBYTE
5687 check_string_option(&buf->b_p_fenc);
5688#endif
5689 check_string_option(&buf->b_p_ff);
5690#ifdef FEAT_FIND_ID
5691 check_string_option(&buf->b_p_def);
5692 check_string_option(&buf->b_p_inc);
5693# ifdef FEAT_EVAL
5694 check_string_option(&buf->b_p_inex);
5695# endif
5696#endif
5697#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5698 check_string_option(&buf->b_p_inde);
5699 check_string_option(&buf->b_p_indk);
5700#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005701#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5702 check_string_option(&buf->b_p_bexpr);
5703#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005704#if defined(FEAT_CRYPT)
5705 check_string_option(&buf->b_p_cm);
5706#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005707 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005708#if defined(FEAT_EVAL)
5709 check_string_option(&buf->b_p_fex);
5710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711#ifdef FEAT_CRYPT
5712 check_string_option(&buf->b_p_key);
5713#endif
5714 check_string_option(&buf->b_p_kp);
5715 check_string_option(&buf->b_p_mps);
5716 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005717 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718 check_string_option(&buf->b_p_isk);
5719#ifdef FEAT_COMMENTS
5720 check_string_option(&buf->b_p_com);
5721#endif
5722#ifdef FEAT_FOLDING
5723 check_string_option(&buf->b_p_cms);
5724#endif
5725 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005726#ifdef FEAT_TEXTOBJ
5727 check_string_option(&buf->b_p_qe);
5728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729#ifdef FEAT_SYN_HL
5730 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005731 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005732#endif
5733#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005734 check_string_option(&buf->b_s.b_p_spc);
5735 check_string_option(&buf->b_s.b_p_spf);
5736 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737#endif
5738#ifdef FEAT_SEARCHPATH
5739 check_string_option(&buf->b_p_sua);
5740#endif
5741#ifdef FEAT_CINDENT
5742 check_string_option(&buf->b_p_cink);
5743 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005744 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5748 check_string_option(&buf->b_p_cinw);
5749#endif
5750#ifdef FEAT_INS_EXPAND
5751 check_string_option(&buf->b_p_cpt);
5752#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005753#ifdef FEAT_COMPL_FUNC
5754 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005755 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757#ifdef FEAT_KEYMAP
5758 check_string_option(&buf->b_p_keymap);
5759#endif
5760#ifdef FEAT_QUICKFIX
5761 check_string_option(&buf->b_p_gp);
5762 check_string_option(&buf->b_p_mp);
5763 check_string_option(&buf->b_p_efm);
5764#endif
5765 check_string_option(&buf->b_p_ep);
5766 check_string_option(&buf->b_p_path);
5767 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005768 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769#ifdef FEAT_INS_EXPAND
5770 check_string_option(&buf->b_p_dict);
5771 check_string_option(&buf->b_p_tsr);
5772#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005773#ifdef FEAT_LISP
5774 check_string_option(&buf->b_p_lw);
5775#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005776 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005777#ifdef FEAT_MBYTE
5778 check_string_option(&buf->b_p_menc);
5779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780}
5781
5782/*
5783 * Free the string allocated for an option.
5784 * Checks for the string being empty_option. This may happen if we're out of
5785 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5786 * check_options().
5787 * Does NOT check for P_ALLOCED flag!
5788 */
5789 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005790free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791{
5792 if (p != empty_option)
5793 vim_free(p);
5794}
5795
5796 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005797clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798{
5799 if (*pp != empty_option)
5800 vim_free(*pp);
5801 *pp = empty_option;
5802}
5803
5804 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005805check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005806{
5807 if (*pp == NULL)
5808 *pp = empty_option;
5809}
5810
5811/*
5812 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5813 */
5814 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005815set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005816{
5817 int opt_idx;
5818
5819 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5820 if (options[opt_idx].var == (char_u *)p)
5821 {
5822 options[opt_idx].flags |= P_ALLOCED;
5823 return;
5824 }
5825 return; /* cannot happen: didn't find it! */
5826}
5827
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005828#if defined(FEAT_EVAL) || defined(PROTO)
5829/*
5830 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5831 * Return FALSE when it wasn't.
5832 * Return -1 for an unknown option.
5833 */
5834 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005835was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005836{
5837 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005838 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005839
5840 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005841 {
5842 flagp = insecure_flag(idx, opt_flags);
5843 return (*flagp & P_INSECURE) != 0;
5844 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005845 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005846 return -1;
5847}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005848
5849/*
5850 * Get a pointer to the flags used for the P_INSECURE flag of option
5851 * "opt_idx". For some local options a local flags field is used.
5852 */
5853 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005854insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855{
5856 if (opt_flags & OPT_LOCAL)
5857 switch ((int)options[opt_idx].indir)
5858 {
5859#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005860 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005861#endif
5862#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005863# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005864 case PV_FDE: return &curwin->w_p_fde_flags;
5865 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005866# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005867# ifdef FEAT_BEVAL
5868 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5869# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005870# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005871 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005872# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005873 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005874# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005875 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005876# endif
5877#endif
5878 }
5879
5880 /* Nothing special, return global flags field. */
5881 return &options[opt_idx].flags;
5882}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005883#endif
5884
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005885#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005886static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005887
5888/*
5889 * Redraw the window title and/or tab page text later.
5890 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005891static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005892{
5893 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005894 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005895}
5896#endif
5897
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898/*
5899 * Set a string option to a new value (without checking the effect).
5900 * The string is copied into allocated memory.
5901 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005902 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005903 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 */
5905 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005906set_string_option_direct(
5907 char_u *name,
5908 int opt_idx,
5909 char_u *val,
5910 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5911 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912{
5913 char_u *s;
5914 char_u **varp;
5915 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005916 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917
Bram Moolenaar89d40322006-08-29 15:30:07 +00005918 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005920 idx = findoption(name);
5921 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005922 {
5923 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005924 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005926 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 }
5928
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 return;
5931
5932 s = vim_strsave(val);
5933 if (s != NULL)
5934 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005935 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005937 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 free_string_option(*varp);
5939 *varp = s;
5940
5941 /* For buffer/window local option may also set the global value. */
5942 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005943 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944
Bram Moolenaar89d40322006-08-29 15:30:07 +00005945 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946
5947 /* When setting both values of a global option with a local value,
5948 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005949 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 {
5951 free_string_option(*varp);
5952 *varp = empty_option;
5953 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005954# ifdef FEAT_EVAL
5955 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005956 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005957 set_sid == 0 ? current_SID : set_sid);
5958# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959 }
5960}
5961
5962/*
5963 * Set global value for string option when it's a local option.
5964 */
5965 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005966set_string_option_global(
5967 int opt_idx, /* option index */
5968 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969{
5970 char_u **p, *s;
5971
5972 /* the global value is always allocated */
5973 if (options[opt_idx].var == VAR_WIN)
5974 p = (char_u **)GLOBAL_WO(varp);
5975 else
5976 p = (char_u **)options[opt_idx].var;
5977 if (options[opt_idx].indir != PV_NONE
5978 && p != varp
5979 && (s = vim_strsave(*varp)) != NULL)
5980 {
5981 free_string_option(*p);
5982 *p = s;
5983 }
5984}
5985
5986/*
5987 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005988 *
5989 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005991 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005992set_string_option(
5993 int opt_idx,
5994 char_u *value,
5995 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996{
5997 char_u *s;
5998 char_u **varp;
5999 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006000#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02006001 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006002 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006003#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006004 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005
6006 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006007 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008
6009 s = vim_strsave(value);
6010 if (s != NULL)
6011 {
6012 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6013 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006014 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006015 ? OPT_GLOBAL : OPT_LOCAL)
6016 : opt_flags);
6017 oldval = *varp;
6018 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006019
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006020#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006021 if (!starting
6022# ifdef FEAT_CRYPT
6023 && options[opt_idx].indir != PV_KEY
6024# endif
6025 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006026 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006027 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006028 saved_newval = vim_strsave(s);
6029 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006030#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006031 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6032 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006033 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006034
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006035#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006036 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006037 if (r == NULL)
6038 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006039 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006040 vim_free(saved_oldval);
6041 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006044 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006045}
6046
6047/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006048 * Return TRUE if "val" is a valid 'filetype' name.
6049 * Also used for 'syntax' and 'keymap'.
6050 */
6051 static int
6052valid_filetype(char_u *val)
6053{
6054 char_u *s;
6055
6056 for (s = val; *s != NUL; ++s)
6057 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6058 return FALSE;
6059 return TRUE;
6060}
6061
6062/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 * Handle string options that need some action to perform when changed.
6064 * Returns NULL for success, or an error message for an error.
6065 */
6066 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006067did_set_string_option(
6068 int opt_idx, /* index in options[] table */
6069 char_u **varp, /* pointer to the option variable */
6070 int new_value_alloced, /* new value was allocated */
6071 char_u *oldval, /* previous value of the option */
6072 char_u *errbuf, /* buffer for errors, or NULL */
6073 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074{
6075 char_u *errmsg = NULL;
6076 char_u *s, *p;
6077 int did_chartab = FALSE;
6078 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006079 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006080#ifdef FEAT_GUI
6081 /* set when changing an option that only requires a redraw in the GUI */
6082 int redraw_gui_only = FALSE;
6083#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006084 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085
6086 /* Get the global option to compare with, otherwise we would have to check
6087 * two values for all local options. */
6088 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6089
6090 /* Disallow changing some options from secure mode */
6091 if ((secure
6092#ifdef HAVE_SANDBOX
6093 || sandbox != 0
6094#endif
6095 ) && (options[opt_idx].flags & P_SECURE))
6096 {
6097 errmsg = e_secure;
6098 }
6099
Bram Moolenaar7554da42016-11-25 22:04:13 +01006100 /* Check for a "normal" directory or file name in some options. Disallow a
6101 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006102 * are often illegal in a file name. Be more permissive if "secure" is off.
6103 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006104 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006105 && vim_strpbrk(*varp, (char_u *)(secure
6106 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006107 || ((options[opt_idx].flags & P_NDNAME)
6108 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006109 {
6110 errmsg = e_invarg;
6111 }
6112
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 /* 'term' */
6114 else if (varp == &T_NAME)
6115 {
6116 if (T_NAME[0] == NUL)
6117 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6118#ifdef FEAT_GUI
6119 if (gui.in_use)
6120 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6121 else if (term_is_gui(T_NAME))
6122 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6123#endif
6124 else if (set_termname(T_NAME) == FAIL)
6125 errmsg = (char_u *)N_("E522: Not found in termcap");
6126 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006127 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 /* Screen colors may have changed. */
6129 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006130
6131 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6132 * P_ALLOCED flag on 'term'. */
6133 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006134 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 }
6137
6138 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006139 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006141 char_u *bkc = p_bkc;
6142 unsigned int *flags = &bkc_flags;
6143
6144 if (opt_flags & OPT_LOCAL)
6145 {
6146 bkc = curbuf->b_p_bkc;
6147 flags = &curbuf->b_bkc_flags;
6148 }
6149
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006150 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6151 /* make the local value empty: use the global value */
6152 *flags = 0;
6153 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006155 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6156 errmsg = e_invarg;
6157 if ((((int)*flags & BKC_AUTO) != 0)
6158 + (((int)*flags & BKC_YES) != 0)
6159 + (((int)*flags & BKC_NO) != 0) != 1)
6160 {
6161 /* Must have exactly one of "auto", "yes" and "no". */
6162 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6163 errmsg = e_invarg;
6164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165 }
6166 }
6167
6168 /* 'backupext' and 'patchmode' */
6169 else if (varp == &p_bex || varp == &p_pm)
6170 {
6171 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6172 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6173 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6174 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006175#ifdef FEAT_LINEBREAK
6176 /* 'breakindentopt' */
6177 else if (varp == &curwin->w_p_briopt)
6178 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006179 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006180 errmsg = e_invarg;
6181 }
6182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183
6184 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006185 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006186 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006187 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 */
6189 else if ( varp == &p_isi
6190 || varp == &(curbuf->b_p_isk)
6191 || varp == &p_isp
6192 || varp == &p_isf)
6193 {
6194 if (init_chartab() == FAIL)
6195 {
6196 did_chartab = TRUE; /* need to restore it below */
6197 errmsg = e_invarg; /* error in value */
6198 }
6199 }
6200
6201 /* 'helpfile' */
6202 else if (varp == &p_hf)
6203 {
6204 /* May compute new values for $VIM and $VIMRUNTIME */
6205 if (didset_vim)
6206 {
6207 vim_setenv((char_u *)"VIM", (char_u *)"");
6208 didset_vim = FALSE;
6209 }
6210 if (didset_vimruntime)
6211 {
6212 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6213 didset_vimruntime = FALSE;
6214 }
6215 }
6216
Bram Moolenaar1a384422010-07-14 19:53:30 +02006217#ifdef FEAT_SYN_HL
6218 /* 'colorcolumn' */
6219 else if (varp == &curwin->w_p_cc)
6220 errmsg = check_colorcolumn(curwin);
6221#endif
6222
Bram Moolenaar071d4272004-06-13 20:20:40 +00006223#ifdef FEAT_MULTI_LANG
6224 /* 'helplang' */
6225 else if (varp == &p_hlg)
6226 {
6227 /* Check for "", "ab", "ab,cd", etc. */
6228 for (s = p_hlg; *s != NUL; s += 3)
6229 {
6230 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6231 {
6232 errmsg = e_invarg;
6233 break;
6234 }
6235 if (s[2] == NUL)
6236 break;
6237 }
6238 }
6239#endif
6240
6241 /* 'highlight' */
6242 else if (varp == &p_hl)
6243 {
6244 if (highlight_changed() == FAIL)
6245 errmsg = e_invarg; /* invalid flags */
6246 }
6247
6248 /* 'nrformats' */
6249 else if (gvarp == &p_nf)
6250 {
6251 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6252 errmsg = e_invarg;
6253 }
6254
6255#ifdef FEAT_SESSION
6256 /* 'sessionoptions' */
6257 else if (varp == &p_ssop)
6258 {
6259 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6260 errmsg = e_invarg;
6261 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6262 {
6263 /* Don't allow both "sesdir" and "curdir". */
6264 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6265 errmsg = e_invarg;
6266 }
6267 }
6268 /* 'viewoptions' */
6269 else if (varp == &p_vop)
6270 {
6271 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6272 errmsg = e_invarg;
6273 }
6274#endif
6275
6276 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277 else if (varp == &p_sbo)
6278 {
6279 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6280 errmsg = e_invarg;
6281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282
6283 /* 'ambiwidth' */
6284#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006285 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286 {
6287 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6288 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006289 else if (set_chars_option(&p_lcs) != NULL)
6290 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006291 else if (set_chars_option(&p_fcs) != NULL)
6292 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 }
6294#endif
6295
6296 /* 'background' */
6297 else if (varp == &p_bg)
6298 {
6299 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6300 {
6301#ifdef FEAT_EVAL
6302 int dark = (*p_bg == 'd');
6303#endif
6304
6305 init_highlight(FALSE, FALSE);
6306
6307#ifdef FEAT_EVAL
6308 if (dark != (*p_bg == 'd')
6309 && get_var_value((char_u *)"g:colors_name") != NULL)
6310 {
6311 /* The color scheme must have set 'background' back to another
6312 * value, that's not what we want here. Disable the color
6313 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006314 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 free_string_option(p_bg);
6316 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6317 check_string_option(&p_bg);
6318 init_highlight(FALSE, FALSE);
6319 }
6320#endif
6321 }
6322 else
6323 errmsg = e_invarg;
6324 }
6325
6326 /* 'wildmode' */
6327 else if (varp == &p_wim)
6328 {
6329 if (check_opt_wim() == FAIL)
6330 errmsg = e_invarg;
6331 }
6332
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006333#ifdef FEAT_CMDL_COMPL
6334 /* 'wildoptions' */
6335 else if (varp == &p_wop)
6336 {
6337 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6338 errmsg = e_invarg;
6339 }
6340#endif
6341
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342#ifdef FEAT_WAK
6343 /* 'winaltkeys' */
6344 else if (varp == &p_wak)
6345 {
6346 if (*p_wak == NUL
6347 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6348 errmsg = e_invarg;
6349# ifdef FEAT_MENU
6350# ifdef FEAT_GUI_MOTIF
6351 else if (gui.in_use)
6352 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6353# else
6354# ifdef FEAT_GUI_GTK
6355 else if (gui.in_use)
6356 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6357# endif
6358# endif
6359# endif
6360 }
6361#endif
6362
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 /* 'eventignore' */
6364 else if (varp == &p_ei)
6365 {
6366 if (check_ei() == FAIL)
6367 errmsg = e_invarg;
6368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369
6370#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006371 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6372 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6373 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 {
6375 if (gvarp == &p_fenc)
6376 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006377 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 errmsg = e_modifiable;
6379 else if (vim_strchr(*varp, ',') != NULL)
6380 /* No comma allowed in 'fileencoding'; catches confusing it
6381 * with 'fileencodings'. */
6382 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006384 {
6385# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006387 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006389 /* Add 'fileencoding' to the swap file. */
6390 ml_setflags(curbuf);
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
6393 if (errmsg == NULL)
6394 {
6395 /* canonize the value, so that STRCMP() can be used on it */
6396 p = enc_canonize(*varp);
6397 if (p != NULL)
6398 {
6399 vim_free(*varp);
6400 *varp = p;
6401 }
6402 if (varp == &p_enc)
6403 {
6404 errmsg = mb_init();
6405# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006406 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006407# endif
6408 }
6409 }
6410
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006411# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6413 {
6414 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6415 if (STRCMP(p_tenc, "utf-8") != 0)
6416 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6417 }
6418# endif
6419
6420 if (errmsg == NULL)
6421 {
6422# ifdef FEAT_KEYMAP
6423 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6424 * (with another encoding). */
6425 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6426 (void)keymap_init();
6427# endif
6428
6429 /* When 'termencoding' is not empty and 'encoding' changes or when
6430 * 'termencoding' changes, need to setup for keyboard input and
6431 * display output conversion. */
6432 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6433 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006434 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6435 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6436 {
6437 EMSG3(_("E950: Cannot convert between %s and %s"),
6438 p_tenc, p_enc);
6439 errmsg = e_invarg;
6440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006442
6443# if defined(WIN3264) && defined(FEAT_MBYTE)
6444 /* $HOME may have characters in active code page. */
6445 if (varp == &p_enc)
6446 init_homedir();
6447# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 }
6449 }
6450#endif
6451
6452#if defined(FEAT_POSTSCRIPT)
6453 else if (varp == &p_penc)
6454 {
6455 /* Canonize printencoding if VIM standard one */
6456 p = enc_canonize(p_penc);
6457 if (p != NULL)
6458 {
6459 vim_free(p_penc);
6460 p_penc = p;
6461 }
6462 else
6463 {
6464 /* Ensure lower case and '-' for '_' */
6465 for (s = p_penc; *s != NUL; s++)
6466 {
6467 if (*s == '_')
6468 *s = '-';
6469 else
6470 *s = TOLOWER_ASC(*s);
6471 }
6472 }
6473 }
6474#endif
6475
Bram Moolenaar9372a112005-12-06 19:59:18 +00006476#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 else if (varp == &p_imak)
6478 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006479 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 errmsg = e_invarg;
6481 }
6482#endif
6483
6484#ifdef FEAT_KEYMAP
6485 else if (varp == &curbuf->b_p_keymap)
6486 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006487 if (!valid_filetype(*varp))
6488 errmsg = e_invarg;
6489 else
6490 /* load or unload key mapping tables */
6491 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492
Bram Moolenaarfab06232009-03-04 03:13:35 +00006493 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006495 if (*curbuf->b_p_keymap != NUL)
6496 {
6497 /* Installed a new keymap, switch on using it. */
6498 curbuf->b_p_iminsert = B_IMODE_LMAP;
6499 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6500 curbuf->b_p_imsearch = B_IMODE_LMAP;
6501 }
6502 else
6503 {
6504 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6505 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6506 curbuf->b_p_iminsert = B_IMODE_NONE;
6507 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6508 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6509 }
6510 if ((opt_flags & OPT_LOCAL) == 0)
6511 {
6512 set_iminsert_global();
6513 set_imsearch_global();
6514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006515 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516 }
6517 }
6518#endif
6519
6520 /* 'fileformat' */
6521 else if (gvarp == &p_ff)
6522 {
6523 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6524 errmsg = e_modifiable;
6525 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6526 errmsg = e_invarg;
6527 else
6528 {
6529 /* may also change 'textmode' */
6530 if (get_fileformat(curbuf) == EOL_DOS)
6531 curbuf->b_p_tx = TRUE;
6532 else
6533 curbuf->b_p_tx = FALSE;
6534#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006535 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006537 /* update flag in swap file */
6538 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006539 /* Redraw needed when switching to/from "mac": a CR in the text
6540 * will be displayed differently. */
6541 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6542 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543 }
6544 }
6545
6546 /* 'fileformats' */
6547 else if (varp == &p_ffs)
6548 {
6549 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6550 errmsg = e_invarg;
6551 else
6552 {
6553 /* also change 'textauto' */
6554 if (*p_ffs == NUL)
6555 p_ta = FALSE;
6556 else
6557 p_ta = TRUE;
6558 }
6559 }
6560
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006561#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 /* 'cryptkey' */
6563 else if (gvarp == &p_key)
6564 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006565# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 /* Make sure the ":set" command doesn't show the new value in the
6567 * history. */
6568 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006569# endif
6570 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6571 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006572 ml_set_crypt_key(curbuf, oldval,
6573 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006574 }
6575
6576 else if (gvarp == &p_cm)
6577 {
6578 if (opt_flags & OPT_LOCAL)
6579 p = curbuf->b_p_cm;
6580 else
6581 p = p_cm;
6582 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6583 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006584 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006585 errmsg = e_invarg;
6586 else
6587 {
6588 /* When setting the global value to empty, make it "zip". */
6589 if (*p_cm == NUL)
6590 {
6591 if (new_value_alloced)
6592 free_string_option(p_cm);
6593 p_cm = vim_strsave((char_u *)"zip");
6594 new_value_alloced = TRUE;
6595 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006596 /* When using ":set cm=name" the local value is going to be empty.
6597 * Do that here, otherwise the crypt functions will still use the
6598 * local value. */
6599 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6600 {
6601 free_string_option(curbuf->b_p_cm);
6602 curbuf->b_p_cm = empty_option;
6603 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006604
6605 /* Need to update the swapfile when the effective method changed.
6606 * Set "s" to the effective old value, "p" to the effective new
6607 * method and compare. */
6608 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6609 s = p_cm; /* was previously using the global value */
6610 else
6611 s = oldval;
6612 if (*curbuf->b_p_cm == NUL)
6613 p = p_cm; /* is now using the global value */
6614 else
6615 p = curbuf->b_p_cm;
6616 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006617 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006618
6619 /* If the global value changes need to update the swapfile for all
6620 * buffers using that value. */
6621 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6622 {
6623 buf_T *buf;
6624
Bram Moolenaar29323592016-07-24 22:04:11 +02006625 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006626 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006627 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006628 }
6629 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006630 }
6631#endif
6632
6633 /* 'matchpairs' */
6634 else if (gvarp == &p_mps)
6635 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006636#ifdef FEAT_MBYTE
6637 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006639 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006640 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006641 int x2 = -1;
6642 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006643
6644 if (*p != NUL)
6645 p += mb_ptr2len(p);
6646 if (*p != NUL)
6647 x2 = *p++;
6648 if (*p != NUL)
6649 {
6650 x3 = mb_ptr2char(p);
6651 p += mb_ptr2len(p);
6652 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006653 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006654 {
6655 errmsg = e_invarg;
6656 break;
6657 }
6658 if (*p == NUL)
6659 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006661 }
6662 else
6663#endif
6664 {
6665 /* Check for "x:y,x:y" */
6666 for (p = *varp; *p != NUL; p += 4)
6667 {
6668 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6669 {
6670 errmsg = e_invarg;
6671 break;
6672 }
6673 if (p[3] == NUL)
6674 break;
6675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006676 }
6677 }
6678
6679#ifdef FEAT_COMMENTS
6680 /* 'comments' */
6681 else if (gvarp == &p_com)
6682 {
6683 for (s = *varp; *s; )
6684 {
6685 while (*s && *s != ':')
6686 {
6687 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6688 && !VIM_ISDIGIT(*s) && *s != '-')
6689 {
6690 errmsg = illegal_char(errbuf, *s);
6691 break;
6692 }
6693 ++s;
6694 }
6695 if (*s++ == NUL)
6696 errmsg = (char_u *)N_("E524: Missing colon");
6697 else if (*s == ',' || *s == NUL)
6698 errmsg = (char_u *)N_("E525: Zero length string");
6699 if (errmsg != NULL)
6700 break;
6701 while (*s && *s != ',')
6702 {
6703 if (*s == '\\' && s[1] != NUL)
6704 ++s;
6705 ++s;
6706 }
6707 s = skip_to_option_part(s);
6708 }
6709 }
6710#endif
6711
6712 /* 'listchars' */
6713 else if (varp == &p_lcs)
6714 {
6715 errmsg = set_chars_option(varp);
6716 }
6717
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 /* 'fillchars' */
6719 else if (varp == &p_fcs)
6720 {
6721 errmsg = set_chars_option(varp);
6722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723
6724#ifdef FEAT_CMDWIN
6725 /* 'cedit' */
6726 else if (varp == &p_cedit)
6727 {
6728 errmsg = check_cedit();
6729 }
6730#endif
6731
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006732 /* 'verbosefile' */
6733 else if (varp == &p_vfile)
6734 {
6735 verbose_stop();
6736 if (*p_vfile != NUL && verbose_open() == FAIL)
6737 errmsg = e_invarg;
6738 }
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740#ifdef FEAT_VIMINFO
6741 /* 'viminfo' */
6742 else if (varp == &p_viminfo)
6743 {
6744 for (s = p_viminfo; *s;)
6745 {
6746 /* Check it's a valid character */
6747 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6748 {
6749 errmsg = illegal_char(errbuf, *s);
6750 break;
6751 }
6752 if (*s == 'n') /* name is always last one */
6753 {
6754 break;
6755 }
6756 else if (*s == 'r') /* skip until next ',' */
6757 {
6758 while (*++s && *s != ',')
6759 ;
6760 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006761 else if (*s == '%')
6762 {
6763 /* optional number */
6764 while (vim_isdigit(*++s))
6765 ;
6766 }
6767 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 ++s; /* no extra chars */
6769 else /* must have a number */
6770 {
6771 while (vim_isdigit(*++s))
6772 ;
6773
6774 if (!VIM_ISDIGIT(*(s - 1)))
6775 {
6776 if (errbuf != NULL)
6777 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006778 sprintf((char *)errbuf,
6779 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 transchar_byte(*(s - 1)));
6781 errmsg = errbuf;
6782 }
6783 else
6784 errmsg = (char_u *)"";
6785 break;
6786 }
6787 }
6788 if (*s == ',')
6789 ++s;
6790 else if (*s)
6791 {
6792 if (errbuf != NULL)
6793 errmsg = (char_u *)N_("E527: Missing comma");
6794 else
6795 errmsg = (char_u *)"";
6796 break;
6797 }
6798 }
6799 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6800 errmsg = (char_u *)N_("E528: Must specify a ' value");
6801 }
6802#endif /* FEAT_VIMINFO */
6803
6804 /* terminal options */
6805 else if (istermoption(&options[opt_idx]) && full_screen)
6806 {
6807 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6808 if (varp == &T_CCO)
6809 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006810 int colors = atoi((char *)T_CCO);
6811
6812 /* Only reinitialize colors if t_Co value has really changed to
6813 * avoid expensive reload of colorscheme if t_Co is set to the
6814 * same value multiple times. */
6815 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006817 t_colors = colors;
6818 if (t_colors <= 1)
6819 {
6820 if (new_value_alloced)
6821 vim_free(T_CCO);
6822 T_CCO = empty_option;
6823 }
6824 /* We now have a different color setup, initialize it again. */
6825 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 }
6828 ttest(FALSE);
6829 if (varp == &T_ME)
6830 {
6831 out_str(T_ME);
6832 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006833#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834 /* Since t_me has been set, this probably means that the user
6835 * wants to use this as default colors. Need to reset default
6836 * background/foreground colors. */
6837 mch_set_normal_colors();
6838#endif
6839 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006840 if (varp == &T_BE && termcap_active)
6841 {
6842 if (*T_BE == NUL)
6843 /* When clearing t_BE we assume the user no longer wants
6844 * bracketed paste, thus disable it by writing t_BD. */
6845 out_str(T_BD);
6846 else
6847 out_str(T_BE);
6848 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849 }
6850
6851#ifdef FEAT_LINEBREAK
6852 /* 'showbreak' */
6853 else if (varp == &p_sbr)
6854 {
6855 for (s = p_sbr; *s; )
6856 {
6857 if (ptr2cells(s) != 1)
6858 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006859 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006860 }
6861 }
6862#endif
6863
6864#ifdef FEAT_GUI
6865 /* 'guifont' */
6866 else if (varp == &p_guifont)
6867 {
6868 if (gui.in_use)
6869 {
6870 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006871# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 /*
6873 * Put up a font dialog and let the user select a new value.
6874 * If this is cancelled go back to the old value but don't
6875 * give an error message.
6876 */
6877 if (STRCMP(p, "*") == 0)
6878 {
6879 p = gui_mch_font_dialog(oldval);
6880
6881 if (new_value_alloced)
6882 free_string_option(p_guifont);
6883
6884 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6885 new_value_alloced = TRUE;
6886 }
6887# endif
6888 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6889 {
6890# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6891 if (STRCMP(p_guifont, "*") == 0)
6892 {
6893 /* Dialog was cancelled: Keep the old value without giving
6894 * an error message. */
6895 if (new_value_alloced)
6896 free_string_option(p_guifont);
6897 p_guifont = vim_strsave(oldval);
6898 new_value_alloced = TRUE;
6899 }
6900 else
6901# endif
6902 errmsg = (char_u *)N_("E596: Invalid font(s)");
6903 }
6904 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006905 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 }
6907# ifdef FEAT_XFONTSET
6908 else if (varp == &p_guifontset)
6909 {
6910 if (STRCMP(p_guifontset, "*") == 0)
6911 errmsg = (char_u *)N_("E597: can't select fontset");
6912 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6913 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006914 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915 }
6916# endif
6917# ifdef FEAT_MBYTE
6918 else if (varp == &p_guifontwide)
6919 {
6920 if (STRCMP(p_guifontwide, "*") == 0)
6921 errmsg = (char_u *)N_("E533: can't select wide font");
6922 else if (gui_get_wide_font() == FAIL)
6923 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006924 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 }
6926# endif
6927#endif
6928
6929#ifdef CURSOR_SHAPE
6930 /* 'guicursor' */
6931 else if (varp == &p_guicursor)
6932 errmsg = parse_shape_opt(SHAPE_CURSOR);
6933#endif
6934
6935#ifdef FEAT_MOUSESHAPE
6936 /* 'mouseshape' */
6937 else if (varp == &p_mouseshape)
6938 {
6939 errmsg = parse_shape_opt(SHAPE_MOUSE);
6940 update_mouseshape(-1);
6941 }
6942#endif
6943
6944#ifdef FEAT_PRINTER
6945 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006946 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006947# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006948 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006949 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006950# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951#endif
6952
6953#ifdef FEAT_LANGMAP
6954 /* 'langmap' */
6955 else if (varp == &p_langmap)
6956 langmap_set();
6957#endif
6958
6959#ifdef FEAT_LINEBREAK
6960 /* 'breakat' */
6961 else if (varp == &p_breakat)
6962 fill_breakat_flags();
6963#endif
6964
6965#ifdef FEAT_TITLE
6966 /* 'titlestring' and 'iconstring' */
6967 else if (varp == &p_titlestring || varp == &p_iconstring)
6968 {
6969# ifdef FEAT_STL_OPT
6970 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6971
6972 /* NULL => statusline syntax */
6973 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6974 stl_syntax |= flagval;
6975 else
6976 stl_syntax &= ~flagval;
6977# endif
6978 did_set_title(varp == &p_iconstring);
6979
6980 }
6981#endif
6982
6983#ifdef FEAT_GUI
6984 /* 'guioptions' */
6985 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006986 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006988 redraw_gui_only = TRUE;
6989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990#endif
6991
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006992#if defined(FEAT_GUI_TABLINE)
6993 /* 'guitablabel' */
6994 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006995 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006996 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006997 redraw_gui_only = TRUE;
6998 }
6999 /* 'guitabtooltip' */
7000 else if (varp == &p_gtt)
7001 {
7002 redraw_gui_only = TRUE;
7003 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007004#endif
7005
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7007 /* 'ttymouse' */
7008 else if (varp == &p_ttym)
7009 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007010 /* Switch the mouse off before changing the escape sequences used for
7011 * that. */
7012 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7014 errmsg = e_invarg;
7015 else
7016 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007017 if (termcap_active)
7018 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 }
7020#endif
7021
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 /* 'selection' */
7023 else if (varp == &p_sel)
7024 {
7025 if (*p_sel == NUL
7026 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7027 errmsg = e_invarg;
7028 }
7029
7030 /* 'selectmode' */
7031 else if (varp == &p_slm)
7032 {
7033 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7034 errmsg = e_invarg;
7035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036
7037#ifdef FEAT_BROWSE
7038 /* 'browsedir' */
7039 else if (varp == &p_bsdir)
7040 {
7041 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7042 && !mch_isdir(p_bsdir))
7043 errmsg = e_invarg;
7044 }
7045#endif
7046
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 /* 'keymodel' */
7048 else if (varp == &p_km)
7049 {
7050 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7051 errmsg = e_invarg;
7052 else
7053 {
7054 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7055 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7056 }
7057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058
7059 /* 'mousemodel' */
7060 else if (varp == &p_mousem)
7061 {
7062 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7063 errmsg = e_invarg;
7064#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7065 else if (*p_mousem != *oldval)
7066 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7067 * to create or delete the popup menus. */
7068 gui_motif_update_mousemodel(root_menu);
7069#endif
7070 }
7071
7072 /* 'switchbuf' */
7073 else if (varp == &p_swb)
7074 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007075 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076 errmsg = e_invarg;
7077 }
7078
7079 /* 'debug' */
7080 else if (varp == &p_debug)
7081 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007082 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 errmsg = e_invarg;
7084 }
7085
7086 /* 'display' */
7087 else if (varp == &p_dy)
7088 {
7089 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7090 errmsg = e_invarg;
7091 else
7092 (void)init_chartab();
7093
7094 }
7095
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 /* 'eadirection' */
7097 else if (varp == &p_ead)
7098 {
7099 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7100 errmsg = e_invarg;
7101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102
7103#ifdef FEAT_CLIPBOARD
7104 /* 'clipboard' */
7105 else if (varp == &p_cb)
7106 errmsg = check_clipboard_option();
7107#endif
7108
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007109#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007110 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7111 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007112 else if (varp == &(curwin->w_s->b_p_spl)
7113 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007114 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007115 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007116 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007117 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007118 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007119 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007120 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007121 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007122 /* 'spellsuggest' */
7123 else if (varp == &p_sps)
7124 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007125 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007126 errmsg = e_invarg;
7127 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007128 /* 'mkspellmem' */
7129 else if (varp == &p_msm)
7130 {
7131 if (spell_check_msm() != OK)
7132 errmsg = e_invarg;
7133 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007134#endif
7135
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136 /* When 'bufhidden' is set, check for valid value. */
7137 else if (gvarp == &p_bh)
7138 {
7139 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7140 errmsg = e_invarg;
7141 }
7142
7143 /* When 'buftype' is set, check for valid value. */
7144 else if (gvarp == &p_bt)
7145 {
7146 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7147 errmsg = e_invarg;
7148 else
7149 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 if (curwin->w_status_height)
7151 {
7152 curwin->w_redr_status = TRUE;
7153 redraw_later(VALID);
7154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007156#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007157 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007158#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007159 }
7160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007161
7162#ifdef FEAT_STL_OPT
7163 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007164 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 {
7166 int wid;
7167
7168 if (varp == &p_ruf) /* reset ru_wid first */
7169 ru_wid = 0;
7170 s = *varp;
7171 if (varp == &p_ruf && *s == '%')
7172 {
7173 /* set ru_wid if 'ruf' starts with "%99(" */
7174 if (*++s == '-') /* ignore a '-' */
7175 s++;
7176 wid = getdigits(&s);
7177 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7178 ru_wid = wid;
7179 else
7180 errmsg = check_stl_option(p_ruf);
7181 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007182 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007183 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007185 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186 comp_col();
7187 }
7188#endif
7189
7190#ifdef FEAT_INS_EXPAND
7191 /* check if it is a valid value for 'complete' -- Acevedo */
7192 else if (gvarp == &p_cpt)
7193 {
7194 for (s = *varp; *s;)
7195 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007196 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 s++;
7198 if (!*s)
7199 break;
7200 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7201 {
7202 errmsg = illegal_char(errbuf, *s);
7203 break;
7204 }
7205 if (*++s != NUL && *s != ',' && *s != ' ')
7206 {
7207 if (s[-1] == 'k' || s[-1] == 's')
7208 {
7209 /* skip optional filename after 'k' and 's' */
7210 while (*s && *s != ',' && *s != ' ')
7211 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007212 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213 ++s;
7214 ++s;
7215 }
7216 }
7217 else
7218 {
7219 if (errbuf != NULL)
7220 {
7221 sprintf((char *)errbuf,
7222 _("E535: Illegal character after <%c>"),
7223 *--s);
7224 errmsg = errbuf;
7225 }
7226 else
7227 errmsg = (char_u *)"";
7228 break;
7229 }
7230 }
7231 }
7232 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007233
7234 /* 'completeopt' */
7235 else if (varp == &p_cot)
7236 {
7237 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7238 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007239 else
7240 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242#endif /* FEAT_INS_EXPAND */
7243
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007244#ifdef FEAT_SIGNS
7245 /* 'signcolumn' */
7246 else if (varp == &curwin->w_p_scl)
7247 {
7248 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7249 errmsg = e_invarg;
7250 }
7251#endif
7252
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253
7254#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007255 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256 else if (varp == &p_toolbar)
7257 {
7258 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7259 &toolbar_flags, TRUE) != OK)
7260 errmsg = e_invarg;
7261 else
7262 {
7263 out_flush();
7264 gui_mch_show_toolbar((toolbar_flags &
7265 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7266 }
7267 }
7268#endif
7269
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007270#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 /* 'toolbariconsize': GTK+ 2 only */
7272 else if (varp == &p_tbis)
7273 {
7274 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7275 errmsg = e_invarg;
7276 else
7277 {
7278 out_flush();
7279 gui_mch_show_toolbar((toolbar_flags &
7280 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7281 }
7282 }
7283#endif
7284
7285 /* 'pastetoggle': translate key codes like in a mapping */
7286 else if (varp == &p_pt)
7287 {
7288 if (*p_pt)
7289 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007290 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 if (p != NULL)
7292 {
7293 if (new_value_alloced)
7294 free_string_option(p_pt);
7295 p_pt = p;
7296 new_value_alloced = TRUE;
7297 }
7298 }
7299 }
7300
7301 /* 'backspace' */
7302 else if (varp == &p_bs)
7303 {
7304 if (VIM_ISDIGIT(*p_bs))
7305 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007306 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307 errmsg = e_invarg;
7308 }
7309 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7310 errmsg = e_invarg;
7311 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007312 else if (varp == &p_bo)
7313 {
7314 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007318 /* 'tagcase' */
7319 else if (gvarp == &p_tc)
7320 {
7321 unsigned int *flags;
7322
7323 if (opt_flags & OPT_LOCAL)
7324 {
7325 p = curbuf->b_p_tc;
7326 flags = &curbuf->b_tc_flags;
7327 }
7328 else
7329 {
7330 p = p_tc;
7331 flags = &tc_flags;
7332 }
7333
7334 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7335 /* make the local value empty: use the global value */
7336 *flags = 0;
7337 else if (*p == NUL
7338 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7339 errmsg = e_invarg;
7340 }
7341
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007342#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 /* 'casemap' */
7344 else if (varp == &p_cmp)
7345 {
7346 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7347 errmsg = e_invarg;
7348 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350
7351#ifdef FEAT_DIFF
7352 /* 'diffopt' */
7353 else if (varp == &p_dip)
7354 {
7355 if (diffopt_changed() == FAIL)
7356 errmsg = e_invarg;
7357 }
7358#endif
7359
7360#ifdef FEAT_FOLDING
7361 /* 'foldmethod' */
7362 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7363 {
7364 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7365 || *curwin->w_p_fdm == NUL)
7366 errmsg = e_invarg;
7367 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007368 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007370 if (foldmethodIsDiff(curwin))
7371 newFoldLevel();
7372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 }
7374# ifdef FEAT_EVAL
7375 /* 'foldexpr' */
7376 else if (varp == &curwin->w_p_fde)
7377 {
7378 if (foldmethodIsExpr(curwin))
7379 foldUpdateAll(curwin);
7380 }
7381# endif
7382 /* 'foldmarker' */
7383 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7384 {
7385 p = vim_strchr(*varp, ',');
7386 if (p == NULL)
7387 errmsg = (char_u *)N_("E536: comma required");
7388 else if (p == *varp || p[1] == NUL)
7389 errmsg = e_invarg;
7390 else if (foldmethodIsMarker(curwin))
7391 foldUpdateAll(curwin);
7392 }
7393 /* 'commentstring' */
7394 else if (gvarp == &p_cms)
7395 {
7396 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7397 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7398 }
7399 /* 'foldopen' */
7400 else if (varp == &p_fdo)
7401 {
7402 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7403 errmsg = e_invarg;
7404 }
7405 /* 'foldclose' */
7406 else if (varp == &p_fcl)
7407 {
7408 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7409 errmsg = e_invarg;
7410 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007411 /* 'foldignore' */
7412 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7413 {
7414 if (foldmethodIsIndent(curwin))
7415 foldUpdateAll(curwin);
7416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007417#endif
7418
7419#ifdef FEAT_VIRTUALEDIT
7420 /* 'virtualedit' */
7421 else if (varp == &p_ve)
7422 {
7423 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7424 errmsg = e_invarg;
7425 else if (STRCMP(p_ve, oldval) != 0)
7426 {
7427 /* Recompute cursor position in case the new 've' setting
7428 * changes something. */
7429 validate_virtcol();
7430 coladvance(curwin->w_virtcol);
7431 }
7432 }
7433#endif
7434
7435#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7436 else if (varp == &p_csqf)
7437 {
7438 if (p_csqf != NULL)
7439 {
7440 p = p_csqf;
7441 while (*p != NUL)
7442 {
7443 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7444 || p[1] == NUL
7445 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7446 || (p[2] != NUL && p[2] != ','))
7447 {
7448 errmsg = e_invarg;
7449 break;
7450 }
7451 else if (p[2] == NUL)
7452 break;
7453 else
7454 p += 3;
7455 }
7456 }
7457 }
7458#endif
7459
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007460#ifdef FEAT_CINDENT
7461 /* 'cinoptions' */
7462 else if (gvarp == &p_cino)
7463 {
7464 /* TODO: recognize errors */
7465 parse_cino(curbuf);
7466 }
7467#endif
7468
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007469#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007470 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007471 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007472 {
7473 if (!gui_mch_set_rendering_options(p_rop))
7474 errmsg = e_invarg;
7475 }
7476#endif
7477
Bram Moolenaard0b51382016-11-04 15:23:45 +01007478 else if (gvarp == &p_ft)
7479 {
7480 if (!valid_filetype(*varp))
7481 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007482 else
7483 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007484 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007485
7486#ifdef FEAT_SYN_HL
7487 else if (gvarp == &p_syn)
7488 {
7489 if (!valid_filetype(*varp))
7490 errmsg = e_invarg;
7491 }
7492#endif
7493
Bram Moolenaar825680f2017-07-22 17:04:02 +02007494#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007495 /* 'termwinkey' */
7496 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007497 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007498 if (*curwin->w_p_twk != NUL
7499 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007500 errmsg = e_invarg;
7501 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007502 /* 'termwinsize' */
7503 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007504 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007505 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007506 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007507 p = skipdigits(curwin->w_p_tws);
7508 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007509 || (*p != 'x' && *p != '*')
7510 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007511 errmsg = e_invarg;
7512 }
7513 }
7514#endif
7515
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 /* Options that are a list of flags. */
7517 else
7518 {
7519 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007520 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007522 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007524 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007526 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007528#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007529 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007530 p = (char_u *)COCU_ALL;
7531#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007532 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 {
7534#ifdef FEAT_MOUSE
7535 p = (char_u *)MOUSE_ALL;
7536#else
7537 if (*p_mouse != NUL)
7538 errmsg = (char_u *)N_("E538: No mouse support");
7539#endif
7540 }
7541#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007542 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 p = (char_u *)GO_ALL;
7544#endif
7545 if (p != NULL)
7546 {
7547 for (s = *varp; *s; ++s)
7548 if (vim_strchr(p, *s) == NULL)
7549 {
7550 errmsg = illegal_char(errbuf, *s);
7551 break;
7552 }
7553 }
7554 }
7555
7556 /*
7557 * If error detected, restore the previous value.
7558 */
7559 if (errmsg != NULL)
7560 {
7561 if (new_value_alloced)
7562 free_string_option(*varp);
7563 *varp = oldval;
7564 /*
7565 * When resetting some values, need to act on it.
7566 */
7567 if (did_chartab)
7568 (void)init_chartab();
7569 if (varp == &p_hl)
7570 (void)highlight_changed();
7571 }
7572 else
7573 {
7574#ifdef FEAT_EVAL
7575 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007576 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577#endif
7578 /*
7579 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007580 * Use "free_oldval", because recursiveness may change the flags under
7581 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007582 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007583 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584 free_string_option(oldval);
7585 if (new_value_alloced)
7586 options[opt_idx].flags |= P_ALLOCED;
7587 else
7588 options[opt_idx].flags &= ~P_ALLOCED;
7589
7590 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007591 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 {
7593 /* global option with local value set to use global value; free
7594 * the local value and make it empty */
7595 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7596 free_string_option(*(char_u **)p);
7597 *(char_u **)p = empty_option;
7598 }
7599
7600 /* May set global value for local option. */
7601 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7602 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007603
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007604 /*
7605 * Trigger the autocommand only after setting the flags.
7606 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007607#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007608 /* When 'syntax' is set, load the syntax of that name */
7609 if (varp == &(curbuf->b_p_syn))
7610 {
7611 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7612 curbuf->b_fname, TRUE, curbuf);
7613 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007614#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007615 else if (varp == &(curbuf->b_p_ft))
7616 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007617 /* 'filetype' is set, trigger the FileType autocommand.
7618 * Skip this when called from a modeline and the filetype was
7619 * already set to this value. */
7620 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7621 {
7622 did_filetype = TRUE;
7623 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007624 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007625 /* Just in case the old "curbuf" is now invalid. */
7626 if (varp != &(curbuf->b_p_ft))
7627 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007628 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007629 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007630#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007631 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007632 {
7633 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007634 char_u *q = curwin->w_s->b_p_spl;
7635
7636 /* Skip the first name if it is "cjk". */
7637 if (STRNCMP(q, "cjk,", 4) == 0)
7638 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007639
7640 /*
7641 * Source the spell/LANG.vim in 'runtimepath'.
7642 * They could set 'spellcapcheck' depending on the language.
7643 * Use the first name in 'spelllang' up to '_region' or
7644 * '.encoding'.
7645 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007646 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007647 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7648 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007649 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007650 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007651 }
7652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007653 }
7654
7655#ifdef FEAT_MOUSE
7656 if (varp == &p_mouse)
7657 {
7658# ifdef FEAT_MOUSE_TTY
7659 if (*p_mouse == NUL)
7660 mch_setmouse(FALSE); /* switch mouse off */
7661 else
7662# endif
7663 setmouse(); /* in case 'mouse' changed */
7664 }
7665#endif
7666
Bram Moolenaar913077c2012-03-28 19:59:04 +02007667 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007668 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007669 curwin->w_set_curswant = TRUE;
7670
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007671#ifdef FEAT_GUI
7672 /* check redraw when it's not a GUI option or the GUI is active. */
7673 if (!redraw_gui_only || gui.in_use)
7674#endif
7675 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676
7677 return errmsg;
7678}
7679
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007680#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007681/*
7682 * Simple int comparison function for use with qsort()
7683 */
7684 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007685int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007686{
7687 return *(const int *)a - *(const int *)b;
7688}
7689
7690/*
7691 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7692 * Returns error message, NULL if it's OK.
7693 */
7694 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007695check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007696{
7697 char_u *s;
7698 int col;
7699 int count = 0;
7700 int color_cols[256];
7701 int i;
7702 int j = 0;
7703
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007704 if (wp->w_buffer == NULL)
7705 return NULL; /* buffer was closed */
7706
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007707 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007708 {
7709 if (*s == '-' || *s == '+')
7710 {
7711 /* -N and +N: add to 'textwidth' */
7712 col = (*s == '-') ? -1 : 1;
7713 ++s;
7714 if (!VIM_ISDIGIT(*s))
7715 return e_invarg;
7716 col = col * getdigits(&s);
7717 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007718 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007719 col += wp->w_buffer->b_p_tw;
7720 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007721 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007722 }
7723 else if (VIM_ISDIGIT(*s))
7724 col = getdigits(&s);
7725 else
7726 return e_invarg;
7727 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007728skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007729 if (*s == NUL)
7730 break;
7731 if (*s != ',')
7732 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007733 if (*++s == NUL)
7734 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007735 }
7736
7737 vim_free(wp->w_p_cc_cols);
7738 if (count == 0)
7739 wp->w_p_cc_cols = NULL;
7740 else
7741 {
7742 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7743 if (wp->w_p_cc_cols != NULL)
7744 {
7745 /* sort the columns for faster usage on screen redraw inside
7746 * win_line() */
7747 qsort(color_cols, count, sizeof(int), int_cmp);
7748
7749 for (i = 0; i < count; ++i)
7750 /* skip duplicates */
7751 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7752 wp->w_p_cc_cols[j++] = color_cols[i];
7753 wp->w_p_cc_cols[j] = -1; /* end marker */
7754 }
7755 }
7756
7757 return NULL; /* no error */
7758}
7759#endif
7760
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761/*
7762 * Handle setting 'listchars' or 'fillchars'.
7763 * Returns error message, NULL if it's OK.
7764 */
7765 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007766set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767{
7768 int round, i, len, entries;
7769 char_u *p, *s;
7770 int c1, c2 = 0;
7771 struct charstab
7772 {
7773 int *cp;
7774 char *name;
7775 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776 static struct charstab filltab[] =
7777 {
7778 {&fill_stl, "stl"},
7779 {&fill_stlnc, "stlnc"},
7780 {&fill_vert, "vert"},
7781 {&fill_fold, "fold"},
7782 {&fill_diff, "diff"},
7783 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 static struct charstab lcstab[] =
7785 {
7786 {&lcs_eol, "eol"},
7787 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007788 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007790 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 {&lcs_tab2, "tab"},
7792 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007793#ifdef FEAT_CONCEAL
7794 {&lcs_conceal, "conceal"},
7795#else
7796 {NULL, "conceal"},
7797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 };
7799 struct charstab *tab;
7800
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007802 {
7803 tab = lcstab;
7804 entries = sizeof(lcstab) / sizeof(struct charstab);
7805 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007806 else
7807 {
7808 tab = filltab;
7809 entries = sizeof(filltab) / sizeof(struct charstab);
7810 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007811
7812 /* first round: check for valid value, second round: assign values */
7813 for (round = 0; round <= 1; ++round)
7814 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007815 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 {
7817 /* After checking that the value is valid: set defaults: space for
7818 * 'fillchars', NUL for 'listchars' */
7819 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007820 if (tab[i].cp != NULL)
7821 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822 if (varp == &p_lcs)
7823 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824 else
7825 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 }
7827 p = *varp;
7828 while (*p)
7829 {
7830 for (i = 0; i < entries; ++i)
7831 {
7832 len = (int)STRLEN(tab[i].name);
7833 if (STRNCMP(p, tab[i].name, len) == 0
7834 && p[len] == ':'
7835 && p[len + 1] != NUL)
7836 {
7837 s = p + len + 1;
7838#ifdef FEAT_MBYTE
7839 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007840 if (mb_char2cells(c1) > 1)
7841 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842#else
7843 c1 = *s++;
7844#endif
7845 if (tab[i].cp == &lcs_tab2)
7846 {
7847 if (*s == NUL)
7848 continue;
7849#ifdef FEAT_MBYTE
7850 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007851 if (mb_char2cells(c2) > 1)
7852 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007853#else
7854 c2 = *s++;
7855#endif
7856 }
7857 if (*s == ',' || *s == NUL)
7858 {
7859 if (round)
7860 {
7861 if (tab[i].cp == &lcs_tab2)
7862 {
7863 lcs_tab1 = c1;
7864 lcs_tab2 = c2;
7865 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007866 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867 *(tab[i].cp) = c1;
7868
7869 }
7870 p = s;
7871 break;
7872 }
7873 }
7874 }
7875
7876 if (i == entries)
7877 return e_invarg;
7878 if (*p == ',')
7879 ++p;
7880 }
7881 }
7882
7883 return NULL; /* no error */
7884}
7885
7886#ifdef FEAT_STL_OPT
7887/*
7888 * Check validity of options with the 'statusline' format.
7889 * Return error message or NULL.
7890 */
7891 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007892check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893{
7894 int itemcnt = 0;
7895 int groupdepth = 0;
7896 static char_u errbuf[80];
7897
7898 while (*s && itemcnt < STL_MAX_ITEM)
7899 {
7900 /* Check for valid keys after % sequences */
7901 while (*s && *s != '%')
7902 s++;
7903 if (!*s)
7904 break;
7905 s++;
7906 if (*s != '%' && *s != ')')
7907 ++itemcnt;
7908 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7909 {
7910 s++;
7911 continue;
7912 }
7913 if (*s == ')')
7914 {
7915 s++;
7916 if (--groupdepth < 0)
7917 break;
7918 continue;
7919 }
7920 if (*s == '-')
7921 s++;
7922 while (VIM_ISDIGIT(*s))
7923 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007924 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 continue;
7926 if (*s == '.')
7927 {
7928 s++;
7929 while (*s && VIM_ISDIGIT(*s))
7930 s++;
7931 }
7932 if (*s == '(')
7933 {
7934 groupdepth++;
7935 continue;
7936 }
7937 if (vim_strchr(STL_ALL, *s) == NULL)
7938 {
7939 return illegal_char(errbuf, *s);
7940 }
7941 if (*s == '{')
7942 {
7943 s++;
7944 while (*s != '}' && *s)
7945 s++;
7946 if (*s != '}')
7947 return (char_u *)N_("E540: Unclosed expression sequence");
7948 }
7949 }
7950 if (itemcnt >= STL_MAX_ITEM)
7951 return (char_u *)N_("E541: too many items");
7952 if (groupdepth != 0)
7953 return (char_u *)N_("E542: unbalanced groups");
7954 return NULL;
7955}
7956#endif
7957
7958#ifdef FEAT_CLIPBOARD
7959/*
7960 * Extract the items in the 'clipboard' option and set global values.
7961 */
7962 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007963check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007965 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007966 int new_autoselect_star = FALSE;
7967 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007969 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 regprog_T *new_exclude_prog = NULL;
7971 char_u *errmsg = NULL;
7972 char_u *p;
7973
7974 for (p = p_cb; *p != NUL; )
7975 {
7976 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7977 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007978 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 p += 7;
7980 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007981 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007982 && (p[11] == ',' || p[11] == NUL))
7983 {
7984 new_unnamed |= CLIP_UNNAMED_PLUS;
7985 p += 11;
7986 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007988 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007990 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 p += 10;
7992 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007993 else if (STRNCMP(p, "autoselectplus", 14) == 0
7994 && (p[14] == ',' || p[14] == NUL))
7995 {
7996 new_autoselect_plus = TRUE;
7997 p += 14;
7998 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008000 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 {
8002 new_autoselectml = TRUE;
8003 p += 12;
8004 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008005 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8006 {
8007 new_html = TRUE;
8008 p += 4;
8009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8011 {
8012 p += 8;
8013 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8014 if (new_exclude_prog == NULL)
8015 errmsg = e_invarg;
8016 break;
8017 }
8018 else
8019 {
8020 errmsg = e_invarg;
8021 break;
8022 }
8023 if (*p == ',')
8024 ++p;
8025 }
8026 if (errmsg == NULL)
8027 {
8028 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008029 clip_autoselect_star = new_autoselect_star;
8030 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008032 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008033 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008035#ifdef FEAT_GUI_GTK
8036 if (gui.in_use)
8037 {
8038 gui_gtk_set_selection_targets();
8039 gui_gtk_set_dnd_targets();
8040 }
8041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 }
8043 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008044 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045
8046 return errmsg;
8047}
8048#endif
8049
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008050#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008051 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008052did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008053{
8054 char_u *errmsg = NULL;
8055 win_T *wp;
8056 int l;
8057
8058 if (is_spellfile)
8059 {
8060 l = (int)STRLEN(curwin->w_s->b_p_spf);
8061 if (l > 0 && (l < 4
8062 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8063 errmsg = e_invarg;
8064 }
8065
8066 if (errmsg == NULL)
8067 {
8068 FOR_ALL_WINDOWS(wp)
8069 if (wp->w_buffer == curbuf && wp->w_p_spell)
8070 {
8071 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008072 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008073 }
8074 }
8075 return errmsg;
8076}
8077
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008078/*
8079 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8080 * Return error message when failed, NULL when OK.
8081 */
8082 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008083compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008084{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008085 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008086 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008087
Bram Moolenaar860cae12010-06-05 23:22:07 +02008088 if (*synblock->b_p_spc == NUL)
8089 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008090 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008091 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008092 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008093 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008094 if (re != NULL)
8095 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008096 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008097 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008098 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008099 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008100 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008101 return e_invarg;
8102 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008103 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008104 }
8105
Bram Moolenaar473de612013-06-08 18:19:48 +02008106 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008107 return NULL;
8108}
8109#endif
8110
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008111#if defined(FEAT_EVAL) || defined(PROTO)
8112/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008113 * Set the scriptID for an option, taking care of setting the buffer- or
8114 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008115 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008116 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008117set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008118{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008119 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8120 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008121
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008122 /* Remember where the option was set. For local options need to do that
8123 * in the buffer or window structure. */
8124 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008125 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008126 if (both || (opt_flags & OPT_LOCAL))
8127 {
8128 if (indir & PV_BUF)
8129 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8130 else if (indir & PV_WIN)
8131 curwin->w_p_scriptID[indir & PV_MASK] = id;
8132 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008133}
8134#endif
8135
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136/*
8137 * Set the value of a boolean option, and take care of side effects.
8138 * Returns NULL for success, or an error message for an error.
8139 */
8140 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008141set_bool_option(
8142 int opt_idx, /* index in options[] table */
8143 char_u *varp, /* pointer to the option variable */
8144 int value, /* new value */
8145 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146{
8147 int old_value = *(int *)varp;
8148
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 /* Disallow changing some options from secure mode */
8150 if ((secure
8151#ifdef HAVE_SANDBOX
8152 || sandbox != 0
8153#endif
8154 ) && (options[opt_idx].flags & P_SECURE))
8155 return e_secure;
8156
8157 *(int *)varp = value; /* set the new value */
8158#ifdef FEAT_EVAL
8159 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008160 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161#endif
8162
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008163#ifdef FEAT_GUI
8164 need_mouse_correct = TRUE;
8165#endif
8166
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 /* May set global value for local option. */
8168 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8169 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8170
8171 /*
8172 * Handle side effects of changing a bool option.
8173 */
8174
8175 /* 'compatible' */
8176 if ((int *)varp == &p_cp)
8177 {
8178 compatible_set();
8179 }
8180
Bram Moolenaar920694c2016-08-21 17:45:02 +02008181#ifdef FEAT_LANGMAP
8182 if ((int *)varp == &p_lrm)
8183 /* 'langremap' -> !'langnoremap' */
8184 p_lnr = !p_lrm;
8185 else if ((int *)varp == &p_lnr)
8186 /* 'langnoremap' -> !'langremap' */
8187 p_lrm = !p_lnr;
8188#endif
8189
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008190#ifdef FEAT_PERSISTENT_UNDO
8191 /* 'undofile' */
8192 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8193 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008194 /* Only take action when the option was set. When reset we do not
8195 * delete the undo file, the option may be set again without making
8196 * any changes in between. */
8197 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008198 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008199 char_u hash[UNDO_HASH_SIZE];
8200 buf_T *save_curbuf = curbuf;
8201
Bram Moolenaar29323592016-07-24 22:04:11 +02008202 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008203 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008204 /* When 'undofile' is set globally: for every buffer, otherwise
8205 * only for the current buffer: Try to read in the undofile,
8206 * if one exists, the buffer wasn't changed and the buffer was
8207 * loaded */
8208 if ((curbuf == save_curbuf
8209 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8210 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8211 {
8212 u_compute_hash(hash);
8213 u_read_undo(NULL, hash, curbuf->b_fname);
8214 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008215 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008216 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008217 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008218 }
8219#endif
8220
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221 else if ((int *)varp == &curbuf->b_p_ro)
8222 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008223 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8225 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008226
8227 /* when 'readonly' is set may give W10 again */
8228 if (curbuf->b_p_ro)
8229 curbuf->b_did_warn = FALSE;
8230
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008232 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233#endif
8234 }
8235
Bram Moolenaar9c449722010-07-20 18:44:27 +02008236#ifdef FEAT_GUI
8237 else if ((int *)varp == &p_mh)
8238 {
8239 if (!p_mh)
8240 gui_mch_mousehide(FALSE);
8241 }
8242#endif
8243
Bram Moolenaara539df02010-08-01 14:35:05 +02008244 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008246 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008247# ifdef FEAT_TERMINAL
8248 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008249 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8250 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008251 {
8252 curbuf->b_p_ma = FALSE;
8253 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8254 }
8255# endif
8256# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008257 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008258# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008259 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008260#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 /* when 'endofline' is changed, redraw the window title */
8262 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008263 {
8264 redraw_titles();
8265 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008266 /* when 'fixeol' is changed, redraw the window title */
8267 else if ((int *)varp == &curbuf->b_p_fixeol)
8268 {
8269 redraw_titles();
8270 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008271# ifdef FEAT_MBYTE
8272 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008273 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008274 {
8275 redraw_titles();
8276 }
8277# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278#endif
8279
8280 /* when 'bin' is set also set some other options */
8281 else if ((int *)varp == &curbuf->b_p_bin)
8282 {
8283 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8284#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008285 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286#endif
8287 }
8288
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 /* when 'buflisted' changes, trigger autocommands */
8290 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8291 {
8292 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8293 NULL, NULL, TRUE, curbuf);
8294 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295
8296 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8297 else if ((int *)varp == &curbuf->b_p_swf)
8298 {
8299 if (curbuf->b_p_swf && p_uc)
8300 ml_open_file(curbuf); /* create the swap file */
8301 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008302 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8303 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 mf_close_file(curbuf, TRUE); /* remove the swap file */
8305 }
8306
8307 /* when 'terse' is set change 'shortmess' */
8308 else if ((int *)varp == &p_terse)
8309 {
8310 char_u *p;
8311
8312 p = vim_strchr(p_shm, SHM_SEARCH);
8313
8314 /* insert 's' in p_shm */
8315 if (p_terse && p == NULL)
8316 {
8317 STRCPY(IObuff, p_shm);
8318 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008319 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321 /* remove 's' from p_shm */
8322 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008323 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 }
8325
8326 /* when 'paste' is set or reset also change other options */
8327 else if ((int *)varp == &p_paste)
8328 {
8329 paste_option_changed();
8330 }
8331
8332 /* when 'insertmode' is set from an autocommand need to do work here */
8333 else if ((int *)varp == &p_im)
8334 {
8335 if (p_im)
8336 {
8337 if ((State & INSERT) == 0)
8338 need_start_insertmode = TRUE;
8339 stop_insert_mode = FALSE;
8340 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008341 /* only reset if it was set previously */
8342 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 {
8344 need_start_insertmode = FALSE;
8345 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008346 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347 clear_cmdline = TRUE; /* remove "(insert)" */
8348 restart_edit = 0;
8349 }
8350 }
8351
8352 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8353 else if ((int *)varp == &p_ic && p_hls)
8354 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008355 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 }
8357
8358#ifdef FEAT_SEARCH_EXTRA
8359 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8360 else if ((int *)varp == &p_hls)
8361 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008362 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 }
8364#endif
8365
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8367 * at the end of normal_cmd() */
8368 else if ((int *)varp == &curwin->w_p_scb)
8369 {
8370 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008371 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008373 curwin->w_scbind_pos = curwin->w_topline;
8374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376
Bram Moolenaar4033c552017-09-16 20:54:51 +02008377#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 /* There can be only one window with 'previewwindow' set. */
8379 else if ((int *)varp == &curwin->w_p_pvw)
8380 {
8381 if (curwin->w_p_pvw)
8382 {
8383 win_T *win;
8384
Bram Moolenaar29323592016-07-24 22:04:11 +02008385 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 if (win->w_p_pvw && win != curwin)
8387 {
8388 curwin->w_p_pvw = FALSE;
8389 return (char_u *)N_("E590: A preview window already exists");
8390 }
8391 }
8392 }
8393#endif
8394
8395 /* when 'textmode' is set or reset also change 'fileformat' */
8396 else if ((int *)varp == &curbuf->b_p_tx)
8397 {
8398 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8399 }
8400
8401 /* when 'textauto' is set or reset also change 'fileformats' */
8402 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 set_string_option_direct((char_u *)"ffs", -1,
8404 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008405 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406
8407 /*
8408 * When 'lisp' option changes include/exclude '-' in
8409 * keyword characters.
8410 */
8411#ifdef FEAT_LISP
8412 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8413 {
8414 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8415 }
8416#endif
8417
8418#ifdef FEAT_TITLE
8419 /* when 'title' changed, may need to change the title; same for 'icon' */
8420 else if ((int *)varp == &p_title)
8421 {
8422 did_set_title(FALSE);
8423 }
8424
8425 else if ((int *)varp == &p_icon)
8426 {
8427 did_set_title(TRUE);
8428 }
8429#endif
8430
8431 else if ((int *)varp == &curbuf->b_changed)
8432 {
8433 if (!value)
8434 save_file_ff(curbuf); /* Buffer is unchanged */
8435#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008436 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 }
8440
8441#ifdef BACKSLASH_IN_FILENAME
8442 else if ((int *)varp == &p_ssl)
8443 {
8444 if (p_ssl)
8445 {
8446 psepc = '/';
8447 psepcN = '\\';
8448 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 }
8450 else
8451 {
8452 psepc = '\\';
8453 psepcN = '/';
8454 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 }
8456
8457 /* need to adjust the file name arguments and buffer names. */
8458 buflist_slash_adjust();
8459 alist_slash_adjust();
8460# ifdef FEAT_EVAL
8461 scriptnames_slash_adjust();
8462# endif
8463 }
8464#endif
8465
8466 /* If 'wrap' is set, set w_leftcol to zero. */
8467 else if ((int *)varp == &curwin->w_p_wrap)
8468 {
8469 if (curwin->w_p_wrap)
8470 curwin->w_leftcol = 0;
8471 }
8472
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 else if ((int *)varp == &p_ea)
8474 {
8475 if (p_ea && !old_value)
8476 win_equal(curwin, FALSE, 0);
8477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478
8479 else if ((int *)varp == &p_wiv)
8480 {
8481 /*
8482 * When 'weirdinvert' changed, set/reset 't_xs'.
8483 * Then set 'weirdinvert' according to value of 't_xs'.
8484 */
8485 if (p_wiv && !old_value)
8486 T_XS = (char_u *)"y";
8487 else if (!p_wiv && old_value)
8488 T_XS = empty_option;
8489 p_wiv = (*T_XS != NUL);
8490 }
8491
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008492#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 else if ((int *)varp == &p_beval)
8494 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008495 if (!balloonEvalForTerm)
8496 {
8497 if (p_beval && !old_value)
8498 gui_mch_enable_beval_area(balloonEval);
8499 else if (!p_beval && old_value)
8500 gui_mch_disable_beval_area(balloonEval);
8501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008503#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008504#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008505 else if ((int *)varp == &p_bevalterm)
8506 {
8507 mch_bevalterm_changed();
8508 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008511#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 else if ((int *)varp == &p_acd)
8513 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008514 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008515 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 }
8517#endif
8518
8519#ifdef FEAT_DIFF
8520 /* 'diff' */
8521 else if ((int *)varp == &curwin->w_p_diff)
8522 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008523 /* May add or remove the buffer from the list of diff buffers. */
8524 diff_buf_adjust(curwin);
8525# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 if (foldmethodIsDiff(curwin))
8527 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008528# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 }
8530#endif
8531
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008532#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 /* 'imdisable' */
8534 else if ((int *)varp == &p_imdisable)
8535 {
8536 /* Only de-activate it here, it will be enabled when changing mode. */
8537 if (p_imdisable)
8538 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008539 else if (State & INSERT)
8540 /* When the option is set from an autocommand, it may need to take
8541 * effect right away. */
8542 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 }
8544#endif
8545
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008546#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008547 /* 'spell' */
8548 else if ((int *)varp == &curwin->w_p_spell)
8549 {
8550 if (curwin->w_p_spell)
8551 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008552 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008553 if (errmsg != NULL)
8554 EMSG(_(errmsg));
8555 }
8556 }
8557#endif
8558
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559#ifdef FEAT_FKMAP
8560 else if ((int *)varp == &p_altkeymap)
8561 {
8562 if (old_value != p_altkeymap)
8563 {
8564 if (!p_altkeymap)
8565 {
8566 p_hkmap = p_fkmap;
8567 p_fkmap = 0;
8568 }
8569 else
8570 {
8571 p_fkmap = p_hkmap;
8572 p_hkmap = 0;
8573 }
8574 (void)init_chartab();
8575 }
8576 }
8577
8578 /*
8579 * In case some second language keymapping options have changed, check
8580 * and correct the setting in a consistent way.
8581 */
8582
8583 /*
8584 * If hkmap or fkmap are set, reset Arabic keymapping.
8585 */
8586 if ((p_hkmap || p_fkmap) && p_altkeymap)
8587 {
8588 p_altkeymap = p_fkmap;
8589# ifdef FEAT_ARABIC
8590 curwin->w_p_arab = FALSE;
8591# endif
8592 (void)init_chartab();
8593 }
8594
8595 /*
8596 * If hkmap set, reset Farsi keymapping.
8597 */
8598 if (p_hkmap && p_altkeymap)
8599 {
8600 p_altkeymap = 0;
8601 p_fkmap = 0;
8602# ifdef FEAT_ARABIC
8603 curwin->w_p_arab = FALSE;
8604# endif
8605 (void)init_chartab();
8606 }
8607
8608 /*
8609 * If fkmap set, reset Hebrew keymapping.
8610 */
8611 if (p_fkmap && !p_altkeymap)
8612 {
8613 p_altkeymap = 1;
8614 p_hkmap = 0;
8615# ifdef FEAT_ARABIC
8616 curwin->w_p_arab = FALSE;
8617# endif
8618 (void)init_chartab();
8619 }
8620#endif
8621
8622#ifdef FEAT_ARABIC
8623 if ((int *)varp == &curwin->w_p_arab)
8624 {
8625 if (curwin->w_p_arab)
8626 {
8627 /*
8628 * 'arabic' is set, handle various sub-settings.
8629 */
8630 if (!p_tbidi)
8631 {
8632 /* set rightleft mode */
8633 if (!curwin->w_p_rl)
8634 {
8635 curwin->w_p_rl = TRUE;
8636 changed_window_setting();
8637 }
8638
8639 /* Enable Arabic shaping (major part of what Arabic requires) */
8640 if (!p_arshape)
8641 {
8642 p_arshape = TRUE;
8643 redraw_later_clear();
8644 }
8645 }
8646
8647 /* Arabic requires a utf-8 encoding, inform the user if its not
8648 * set. */
8649 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008650 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008651 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8652
Bram Moolenaar8820b482017-03-16 17:23:31 +01008653 msg_source(HL_ATTR(HLF_W));
8654 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008655#ifdef FEAT_EVAL
8656 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8657#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659
8660# ifdef FEAT_MBYTE
8661 /* set 'delcombine' */
8662 p_deco = TRUE;
8663# endif
8664
8665# ifdef FEAT_KEYMAP
8666 /* Force-set the necessary keymap for arabic */
8667 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8668 OPT_LOCAL);
8669# endif
8670# ifdef FEAT_FKMAP
8671 p_altkeymap = 0;
8672 p_hkmap = 0;
8673 p_fkmap = 0;
8674 (void)init_chartab();
8675# endif
8676 }
8677 else
8678 {
8679 /*
8680 * 'arabic' is reset, handle various sub-settings.
8681 */
8682 if (!p_tbidi)
8683 {
8684 /* reset rightleft mode */
8685 if (curwin->w_p_rl)
8686 {
8687 curwin->w_p_rl = FALSE;
8688 changed_window_setting();
8689 }
8690
8691 /* 'arabicshape' isn't reset, it is a global option and
8692 * another window may still need it "on". */
8693 }
8694
8695 /* 'delcombine' isn't reset, it is a global option and another
8696 * window may still want it "on". */
8697
8698# ifdef FEAT_KEYMAP
8699 /* Revert to the default keymap */
8700 curbuf->b_p_iminsert = B_IMODE_NONE;
8701 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8702# endif
8703 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008704 }
8705
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008706#endif
8707
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008708#ifdef FEAT_TERMGUICOLORS
8709 /* 'termguicolors' */
8710 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008711 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008712# ifdef FEAT_VTP
8713 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8714 if (!has_vtp_working())
8715 {
8716 p_tgc = 0;
8717 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8718 }
8719 swap_tcap();
8720# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008721# ifdef FEAT_GUI
8722 if (!gui.in_use && !gui.starting)
8723# endif
8724 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008725# ifdef FEAT_VTP
8726 control_console_color_rgb();
8727 /* reset t_Co */
8728 if (STRCMP(T_NAME, "win32") == 0)
8729 set_termname(T_NAME);
8730# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008731 }
8732#endif
8733
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 /*
8735 * End of handling side effects for bool options.
8736 */
8737
Bram Moolenaar53744302015-07-17 17:38:22 +02008738 /* after handling side effects, call autocommand */
8739
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 options[opt_idx].flags |= P_WAS_SET;
8741
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008742#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008743 if (!starting)
8744 {
8745 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008746 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8747 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8748 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008749 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8750 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8751 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8752 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8753 reset_v_option_vars();
8754 }
8755#endif
8756
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008758 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008759 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008760 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 check_redraw(options[opt_idx].flags);
8762
8763 return NULL;
8764}
8765
8766/*
8767 * Set the value of a number option, and take care of side effects.
8768 * Returns NULL for success, or an error message for an error.
8769 */
8770 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008771set_num_option(
8772 int opt_idx, /* index in options[] table */
8773 char_u *varp, /* pointer to the option variable */
8774 long value, /* new value */
8775 char_u *errbuf, /* buffer for error messages */
8776 size_t errbuflen, /* length of "errbuf" */
8777 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 OPT_MODELINE */
8779{
8780 char_u *errmsg = NULL;
8781 long old_value = *(long *)varp;
8782 long old_Rows = Rows; /* remember old Rows */
8783 long old_Columns = Columns; /* remember old Columns */
8784 long *pp = (long *)varp;
8785
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008786 /* Disallow changing some options from secure mode. */
8787 if ((secure
8788#ifdef HAVE_SANDBOX
8789 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008791 ) && (options[opt_idx].flags & P_SECURE))
8792 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793
8794 *pp = value;
8795#ifdef FEAT_EVAL
8796 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008797 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008799#ifdef FEAT_GUI
8800 need_mouse_correct = TRUE;
8801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802
Bram Moolenaar14f24742012-08-08 18:01:05 +02008803 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 {
8805 errmsg = e_positive;
8806 curbuf->b_p_sw = curbuf->b_p_ts;
8807 }
8808
8809 /*
8810 * Number options that need some action when changed
8811 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812 if (pp == &p_wh || pp == &p_hh)
8813 {
8814 if (p_wh < 1)
8815 {
8816 errmsg = e_positive;
8817 p_wh = 1;
8818 }
8819 if (p_wmh > p_wh)
8820 {
8821 errmsg = e_winheight;
8822 p_wh = p_wmh;
8823 }
8824 if (p_hh < 0)
8825 {
8826 errmsg = e_positive;
8827 p_hh = 0;
8828 }
8829
8830 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008831 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 {
8833 if (pp == &p_wh && curwin->w_height < p_wh)
8834 win_setheight((int)p_wh);
8835 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8836 win_setheight((int)p_hh);
8837 }
8838 }
8839
8840 /* 'winminheight' */
8841 else if (pp == &p_wmh)
8842 {
8843 if (p_wmh < 0)
8844 {
8845 errmsg = e_positive;
8846 p_wmh = 0;
8847 }
8848 if (p_wmh > p_wh)
8849 {
8850 errmsg = e_winheight;
8851 p_wmh = p_wh;
8852 }
8853 win_setminheight();
8854 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008855 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 {
8857 if (p_wiw < 1)
8858 {
8859 errmsg = e_positive;
8860 p_wiw = 1;
8861 }
8862 if (p_wmw > p_wiw)
8863 {
8864 errmsg = e_winwidth;
8865 p_wiw = p_wmw;
8866 }
8867
8868 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008869 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 win_setwidth((int)p_wiw);
8871 }
8872
8873 /* 'winminwidth' */
8874 else if (pp == &p_wmw)
8875 {
8876 if (p_wmw < 0)
8877 {
8878 errmsg = e_positive;
8879 p_wmw = 0;
8880 }
8881 if (p_wmw > p_wiw)
8882 {
8883 errmsg = e_winwidth;
8884 p_wmw = p_wiw;
8885 }
8886 win_setminheight();
8887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 /* (re)set last window status line */
8890 else if (pp == &p_ls)
8891 {
8892 last_status(FALSE);
8893 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008894
8895 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008896 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008897 {
8898 shell_new_rows(); /* recompute window positions and heights */
8899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900
8901#ifdef FEAT_GUI
8902 else if (pp == &p_linespace)
8903 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008904 /* Recompute gui.char_height and resize the Vim window to keep the
8905 * same number of lines. */
8906 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008907 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 }
8909#endif
8910
8911#ifdef FEAT_FOLDING
8912 /* 'foldlevel' */
8913 else if (pp == &curwin->w_p_fdl)
8914 {
8915 if (curwin->w_p_fdl < 0)
8916 curwin->w_p_fdl = 0;
8917 newFoldLevel();
8918 }
8919
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008920 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 else if (pp == &curwin->w_p_fml)
8922 {
8923 foldUpdateAll(curwin);
8924 }
8925
8926 /* 'foldnestmax' */
8927 else if (pp == &curwin->w_p_fdn)
8928 {
8929 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8930 foldUpdateAll(curwin);
8931 }
8932
8933 /* 'foldcolumn' */
8934 else if (pp == &curwin->w_p_fdc)
8935 {
8936 if (curwin->w_p_fdc < 0)
8937 {
8938 errmsg = e_positive;
8939 curwin->w_p_fdc = 0;
8940 }
8941 else if (curwin->w_p_fdc > 12)
8942 {
8943 errmsg = e_invarg;
8944 curwin->w_p_fdc = 12;
8945 }
8946 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008947#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008949#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950 /* 'shiftwidth' or 'tabstop' */
8951 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8952 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008953# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 if (foldmethodIsIndent(curwin))
8955 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008956# endif
8957# ifdef FEAT_CINDENT
8958 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8959 * parse 'cinoptions'. */
8960 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8961 parse_cino(curbuf);
8962# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008966#ifdef FEAT_MBYTE
8967 /* 'maxcombine' */
8968 else if (pp == &p_mco)
8969 {
8970 if (p_mco > MAX_MCO)
8971 p_mco = MAX_MCO;
8972 else if (p_mco < 0)
8973 p_mco = 0;
8974 screenclear(); /* will re-allocate the screen */
8975 }
8976#endif
8977
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 else if (pp == &curbuf->b_p_iminsert)
8979 {
8980 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8981 {
8982 errmsg = e_invarg;
8983 curbuf->b_p_iminsert = B_IMODE_NONE;
8984 }
8985 p_iminsert = curbuf->b_p_iminsert;
8986 if (termcap_active) /* don't do this in the alternate screen */
8987 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008988#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989 /* Show/unshow value of 'keymap' in status lines. */
8990 status_redraw_curbuf();
8991#endif
8992 }
8993
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008994#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8995 /* 'imstyle' */
8996 else if (pp == &p_imst)
8997 {
8998 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8999 errmsg = e_invarg;
9000 }
9001#endif
9002
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009003 else if (pp == &p_window)
9004 {
9005 if (p_window < 1)
9006 p_window = 1;
9007 else if (p_window >= Rows)
9008 p_window = Rows - 1;
9009 }
9010
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 else if (pp == &curbuf->b_p_imsearch)
9012 {
9013 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9014 {
9015 errmsg = e_invarg;
9016 curbuf->b_p_imsearch = B_IMODE_NONE;
9017 }
9018 p_imsearch = curbuf->b_p_imsearch;
9019 }
9020
9021#ifdef FEAT_TITLE
9022 /* if 'titlelen' has changed, redraw the title */
9023 else if (pp == &p_titlelen)
9024 {
9025 if (p_titlelen < 0)
9026 {
9027 errmsg = e_positive;
9028 p_titlelen = 85;
9029 }
9030 if (starting != NO_SCREEN && old_value != p_titlelen)
9031 need_maketitle = TRUE;
9032 }
9033#endif
9034
9035 /* if p_ch changed value, change the command line height */
9036 else if (pp == &p_ch)
9037 {
9038 if (p_ch < 1)
9039 {
9040 errmsg = e_positive;
9041 p_ch = 1;
9042 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009043 if (p_ch > Rows - min_rows() + 1)
9044 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045
9046 /* Only compute the new window layout when startup has been
9047 * completed. Otherwise the frame sizes may be wrong. */
9048 if (p_ch != old_value && full_screen
9049#ifdef FEAT_GUI
9050 && !gui.starting
9051#endif
9052 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009053 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 }
9055
9056 /* when 'updatecount' changes from zero to non-zero, open swap files */
9057 else if (pp == &p_uc)
9058 {
9059 if (p_uc < 0)
9060 {
9061 errmsg = e_positive;
9062 p_uc = 100;
9063 }
9064 if (p_uc && !old_value)
9065 ml_open_files();
9066 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009067#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009068 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009069 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009070 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009071 {
9072 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009073 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009074 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009075 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009076 {
9077 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009078 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009079 }
9080 }
9081#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009082#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009083 else if (pp == &p_mzq)
9084 mzvim_reset_timer();
9085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009087#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9088 /* 'pyxversion' */
9089 else if (pp == &p_pyx)
9090 {
9091 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9092 errmsg = e_invarg;
9093 }
9094#endif
9095
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 /* sync undo before 'undolevels' changes */
9097 else if (pp == &p_ul)
9098 {
9099 /* use the old value, otherwise u_sync() may not work properly */
9100 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009101 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 p_ul = value;
9103 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009104 else if (pp == &curbuf->b_p_ul)
9105 {
9106 /* use the old value, otherwise u_sync() may not work properly */
9107 curbuf->b_p_ul = old_value;
9108 u_sync(TRUE);
9109 curbuf->b_p_ul = value;
9110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009112#ifdef FEAT_LINEBREAK
9113 /* 'numberwidth' must be positive */
9114 else if (pp == &curwin->w_p_nuw)
9115 {
9116 if (curwin->w_p_nuw < 1)
9117 {
9118 errmsg = e_positive;
9119 curwin->w_p_nuw = 1;
9120 }
9121 if (curwin->w_p_nuw > 10)
9122 {
9123 errmsg = e_invarg;
9124 curwin->w_p_nuw = 10;
9125 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009126 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009127 }
9128#endif
9129
Bram Moolenaar1a384422010-07-14 19:53:30 +02009130 else if (pp == &curbuf->b_p_tw)
9131 {
9132 if (curbuf->b_p_tw < 0)
9133 {
9134 errmsg = e_positive;
9135 curbuf->b_p_tw = 0;
9136 }
9137#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009138 {
9139 win_T *wp;
9140 tabpage_T *tp;
9141
9142 FOR_ALL_TAB_WINDOWS(tp, wp)
9143 check_colorcolumn(wp);
9144 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009145#endif
9146 }
9147
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 /*
9149 * Check the bounds for numeric options here
9150 */
9151 if (Rows < min_rows() && full_screen)
9152 {
9153 if (errbuf != NULL)
9154 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009155 vim_snprintf((char *)errbuf, errbuflen,
9156 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 errmsg = errbuf;
9158 }
9159 Rows = min_rows();
9160 }
9161 if (Columns < MIN_COLUMNS && full_screen)
9162 {
9163 if (errbuf != NULL)
9164 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009165 vim_snprintf((char *)errbuf, errbuflen,
9166 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 errmsg = errbuf;
9168 }
9169 Columns = MIN_COLUMNS;
9170 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009171 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173 /*
9174 * If the screen (shell) height has been changed, assume it is the
9175 * physical screenheight.
9176 */
9177 if (old_Rows != Rows || old_Columns != Columns)
9178 {
9179 /* Changing the screen size is not allowed while updating the screen. */
9180 if (updating_screen)
9181 *pp = old_value;
9182 else if (full_screen
9183#ifdef FEAT_GUI
9184 && !gui.starting
9185#endif
9186 )
9187 set_shellsize((int)Columns, (int)Rows, TRUE);
9188 else
9189 {
9190 /* Postpone the resizing; check the size and cmdline position for
9191 * messages. */
9192 check_shellsize();
9193 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9194 cmdline_row = Rows - p_ch;
9195 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009196 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009197 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 }
9199
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 if (curbuf->b_p_ts <= 0)
9201 {
9202 errmsg = e_positive;
9203 curbuf->b_p_ts = 8;
9204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 if (p_tm < 0)
9206 {
9207 errmsg = e_positive;
9208 p_tm = 0;
9209 }
9210 if ((curwin->w_p_scr <= 0
9211 || (curwin->w_p_scr > curwin->w_height
9212 && curwin->w_height > 0))
9213 && full_screen)
9214 {
9215 if (pp == &(curwin->w_p_scr))
9216 {
9217 if (curwin->w_p_scr != 0)
9218 errmsg = e_scroll;
9219 win_comp_scroll(curwin);
9220 }
9221 /* If 'scroll' became invalid because of a side effect silently adjust
9222 * it. */
9223 else if (curwin->w_p_scr <= 0)
9224 curwin->w_p_scr = 1;
9225 else /* curwin->w_p_scr > curwin->w_height */
9226 curwin->w_p_scr = curwin->w_height;
9227 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009228 if (p_hi < 0)
9229 {
9230 errmsg = e_positive;
9231 p_hi = 0;
9232 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009233 else if (p_hi > 10000)
9234 {
9235 errmsg = e_invarg;
9236 p_hi = 10000;
9237 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009238 if (p_re < 0 || p_re > 2)
9239 {
9240 errmsg = e_invarg;
9241 p_re = 0;
9242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 if (p_report < 0)
9244 {
9245 errmsg = e_positive;
9246 p_report = 1;
9247 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009248 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 {
9250 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9251 p_sj = Rows / 2;
9252 else
9253 {
9254 errmsg = e_scroll;
9255 p_sj = 1;
9256 }
9257 }
9258 if (p_so < 0 && full_screen)
9259 {
9260 errmsg = e_scroll;
9261 p_so = 0;
9262 }
9263 if (p_siso < 0 && full_screen)
9264 {
9265 errmsg = e_positive;
9266 p_siso = 0;
9267 }
9268#ifdef FEAT_CMDWIN
9269 if (p_cwh < 1)
9270 {
9271 errmsg = e_positive;
9272 p_cwh = 1;
9273 }
9274#endif
9275 if (p_ut < 0)
9276 {
9277 errmsg = e_positive;
9278 p_ut = 2000;
9279 }
9280 if (p_ss < 0)
9281 {
9282 errmsg = e_positive;
9283 p_ss = 0;
9284 }
9285
9286 /* May set global value for local option. */
9287 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9288 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9289
9290 options[opt_idx].flags |= P_WAS_SET;
9291
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009292#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009293 if (!starting && errmsg == NULL)
9294 {
9295 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009296 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9297 vim_snprintf((char *)buf_new, 10, "%ld", value);
9298 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009299 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9300 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9301 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9302 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9303 reset_v_option_vars();
9304 }
9305#endif
9306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009308 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009309 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009310 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 check_redraw(options[opt_idx].flags);
9312
9313 return errmsg;
9314}
9315
9316/*
9317 * Called after an option changed: check if something needs to be redrawn.
9318 */
9319 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009320check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321{
9322 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009323 int doclear = (flags & P_RCLR) == P_RCLR;
9324 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9327 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328
9329 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9330 changed_window_setting();
9331 if (flags & P_RBUF)
9332 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009333 if (flags & P_RWINONLY)
9334 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009335 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 redraw_all_later(CLEAR);
9337 else if (all)
9338 redraw_all_later(NOT_VALID);
9339}
9340
9341/*
9342 * Find index for option 'arg'.
9343 * Return -1 if not found.
9344 */
9345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009346findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347{
9348 int opt_idx;
9349 char *s, *p;
9350 static short quick_tab[27] = {0, 0}; /* quick access table */
9351 int is_term_opt;
9352
9353 /*
9354 * For first call: Initialize the quick-access table.
9355 * It contains the index for the first option that starts with a certain
9356 * letter. There are 26 letters, plus the first "t_" option.
9357 */
9358 if (quick_tab[1] == 0)
9359 {
9360 p = options[0].fullname;
9361 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9362 {
9363 if (s[0] != p[0])
9364 {
9365 if (s[0] == 't' && s[1] == '_')
9366 quick_tab[26] = opt_idx;
9367 else
9368 quick_tab[CharOrdLow(s[0])] = opt_idx;
9369 }
9370 p = s;
9371 }
9372 }
9373
9374 /*
9375 * Check for name starting with an illegal character.
9376 */
9377#ifdef EBCDIC
9378 if (!islower(arg[0]))
9379#else
9380 if (arg[0] < 'a' || arg[0] > 'z')
9381#endif
9382 return -1;
9383
9384 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9385 if (is_term_opt)
9386 opt_idx = quick_tab[26];
9387 else
9388 opt_idx = quick_tab[CharOrdLow(arg[0])];
9389 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9390 {
9391 if (STRCMP(arg, s) == 0) /* match full name */
9392 break;
9393 }
9394 if (s == NULL && !is_term_opt)
9395 {
9396 opt_idx = quick_tab[CharOrdLow(arg[0])];
9397 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9398 {
9399 s = options[opt_idx].shortname;
9400 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9401 break;
9402 s = NULL;
9403 }
9404 }
9405 if (s == NULL)
9406 opt_idx = -1;
9407 return opt_idx;
9408}
9409
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009410#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411/*
9412 * Get the value for an option.
9413 *
9414 * Returns:
9415 * Number or Toggle option: 1, *numval gets value.
9416 * String option: 0, *stringval gets allocated string.
9417 * Hidden Number or Toggle option: -1.
9418 * hidden String option: -2.
9419 * unknown option: -3.
9420 */
9421 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009422get_option_value(
9423 char_u *name,
9424 long *numval,
9425 char_u **stringval, /* NULL when only checking existence */
9426 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427{
9428 int opt_idx;
9429 char_u *varp;
9430
9431 opt_idx = findoption(name);
9432 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009433 {
9434 int key;
9435
9436 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9437 && (key = find_key_option(name)) != 0)
9438 {
9439 char_u key_name[2];
9440 char_u *p;
9441
9442 if (key < 0)
9443 {
9444 key_name[0] = KEY2TERMCAP0(key);
9445 key_name[1] = KEY2TERMCAP1(key);
9446 }
9447 else
9448 {
9449 key_name[0] = KS_KEY;
9450 key_name[1] = (key & 0xff);
9451 }
9452 p = find_termcode(key_name);
9453 if (p != NULL)
9454 {
9455 if (stringval != NULL)
9456 *stringval = vim_strsave(p);
9457 return 0;
9458 }
9459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462
9463 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9464
9465 if (options[opt_idx].flags & P_STRING)
9466 {
9467 if (varp == NULL) /* hidden option */
9468 return -2;
9469 if (stringval != NULL)
9470 {
9471#ifdef FEAT_CRYPT
9472 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009473 if ((char_u **)varp == &curbuf->b_p_key
9474 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 *stringval = vim_strsave((char_u *)"*****");
9476 else
9477#endif
9478 *stringval = vim_strsave(*(char_u **)(varp));
9479 }
9480 return 0;
9481 }
9482
9483 if (varp == NULL) /* hidden option */
9484 return -1;
9485 if (options[opt_idx].flags & P_NUM)
9486 *numval = *(long *)varp;
9487 else
9488 {
9489 /* Special case: 'modified' is b_changed, but we also want to consider
9490 * it set when 'ff' or 'fenc' changed. */
9491 if ((int *)varp == &curbuf->b_changed)
9492 *numval = curbufIsChanged();
9493 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009494 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495 }
9496 return 1;
9497}
9498#endif
9499
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009500#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009501/*
9502 * Returns the option attributes and its value. Unlike the above function it
9503 * will return either global value or local value of the option depending on
9504 * what was requested, but it will never return global value if it was
9505 * requested to return local one and vice versa. Neither it will return
9506 * buffer-local value if it was requested to return window-local one.
9507 *
9508 * Pretends that option is absent if it is not present in the requested scope
9509 * (i.e. has no global, window-local or buffer-local value depending on
9510 * opt_type). Uses
9511 *
9512 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009513 * 0 hidden or unknown option, also option that does not have requested
9514 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009515 * see SOPT_* in vim.h for other flags
9516 *
9517 * Possible opt_type values: see SREQ_* in vim.h
9518 */
9519 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009520get_option_value_strict(
9521 char_u *name,
9522 long *numval,
9523 char_u **stringval, /* NULL when only obtaining attributes */
9524 int opt_type,
9525 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009526{
9527 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009528 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009529 struct vimoption *p;
9530 int r = 0;
9531
9532 opt_idx = findoption(name);
9533 if (opt_idx < 0)
9534 return 0;
9535
9536 p = &(options[opt_idx]);
9537
9538 /* Hidden option */
9539 if (p->var == NULL)
9540 return 0;
9541
9542 if (p->flags & P_BOOL)
9543 r |= SOPT_BOOL;
9544 else if (p->flags & P_NUM)
9545 r |= SOPT_NUM;
9546 else if (p->flags & P_STRING)
9547 r |= SOPT_STRING;
9548
9549 if (p->indir == PV_NONE)
9550 {
9551 if (opt_type == SREQ_GLOBAL)
9552 r |= SOPT_GLOBAL;
9553 else
9554 return 0; /* Did not request global-only option */
9555 }
9556 else
9557 {
9558 if (p->indir & PV_BOTH)
9559 r |= SOPT_GLOBAL;
9560 else if (opt_type == SREQ_GLOBAL)
9561 return 0; /* Requested global option */
9562
9563 if (p->indir & PV_WIN)
9564 {
9565 if (opt_type == SREQ_BUF)
9566 return 0; /* Did not request window-local option */
9567 else
9568 r |= SOPT_WIN;
9569 }
9570 else if (p->indir & PV_BUF)
9571 {
9572 if (opt_type == SREQ_WIN)
9573 return 0; /* Did not request buffer-local option */
9574 else
9575 r |= SOPT_BUF;
9576 }
9577 }
9578
9579 if (stringval == NULL)
9580 return r;
9581
9582 if (opt_type == SREQ_GLOBAL)
9583 varp = p->var;
9584 else
9585 {
9586 if (opt_type == SREQ_BUF)
9587 {
9588 /* Special case: 'modified' is b_changed, but we also want to
9589 * consider it set when 'ff' or 'fenc' changed. */
9590 if (p->indir == PV_MOD)
9591 {
9592 *numval = bufIsChanged((buf_T *) from);
9593 varp = NULL;
9594 }
9595#ifdef FEAT_CRYPT
9596 else if (p->indir == PV_KEY)
9597 {
9598 /* never return the value of the crypt key */
9599 *stringval = NULL;
9600 varp = NULL;
9601 }
9602#endif
9603 else
9604 {
9605 aco_save_T aco;
9606 aucmd_prepbuf(&aco, (buf_T *) from);
9607 varp = get_varp(p);
9608 aucmd_restbuf(&aco);
9609 }
9610 }
9611 else if (opt_type == SREQ_WIN)
9612 {
9613 win_T *save_curwin;
9614 save_curwin = curwin;
9615 curwin = (win_T *) from;
9616 curbuf = curwin->w_buffer;
9617 varp = get_varp(p);
9618 curwin = save_curwin;
9619 curbuf = curwin->w_buffer;
9620 }
9621 if (varp == p->var)
9622 return (r | SOPT_UNSET);
9623 }
9624
9625 if (varp != NULL)
9626 {
9627 if (p->flags & P_STRING)
9628 *stringval = vim_strsave(*(char_u **)(varp));
9629 else if (p->flags & P_NUM)
9630 *numval = *(long *) varp;
9631 else
9632 *numval = *(int *)varp;
9633 }
9634
9635 return r;
9636}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009637
9638/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009639 * Iterate over options. First argument is a pointer to a pointer to a
9640 * structure inside options[] array, second is option type like in the above
9641 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009642 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009643 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009644 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009645 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009646 * first argument to NULL.
9647 *
9648 * Returns full option name for current option on each call.
9649 */
9650 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009651option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009652{
9653 struct vimoption *ret = NULL;
9654 do
9655 {
9656 if (*option == NULL)
9657 *option = (void *) options;
9658 else if (((struct vimoption *) (*option))->fullname == NULL)
9659 {
9660 *option = NULL;
9661 return NULL;
9662 }
9663 else
9664 *option = (void *) (((struct vimoption *) (*option)) + 1);
9665
9666 ret = ((struct vimoption *) (*option));
9667
9668 /* Hidden option */
9669 if (ret->var == NULL)
9670 {
9671 ret = NULL;
9672 continue;
9673 }
9674
9675 switch (opt_type)
9676 {
9677 case SREQ_GLOBAL:
9678 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9679 ret = NULL;
9680 break;
9681 case SREQ_BUF:
9682 if (!(ret->indir & PV_BUF))
9683 ret = NULL;
9684 break;
9685 case SREQ_WIN:
9686 if (!(ret->indir & PV_WIN))
9687 ret = NULL;
9688 break;
9689 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009690 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009691 return NULL;
9692 }
9693 }
9694 while (ret == NULL);
9695
9696 return (char_u *)ret->fullname;
9697}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009698#endif
9699
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700/*
9701 * Set the value of option "name".
9702 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009703 *
9704 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009706 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009707set_option_value(
9708 char_u *name,
9709 long number,
9710 char_u *string,
9711 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712{
9713 int opt_idx;
9714 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009715 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716
9717 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009718 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009719 {
9720 int key;
9721
9722 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9723 && (key = find_key_option(name)) != 0)
9724 {
9725 char_u key_name[2];
9726
9727 if (key < 0)
9728 {
9729 key_name[0] = KEY2TERMCAP0(key);
9730 key_name[1] = KEY2TERMCAP1(key);
9731 }
9732 else
9733 {
9734 key_name[0] = KS_KEY;
9735 key_name[1] = (key & 0xff);
9736 }
9737 add_termcode(key_name, string, FALSE);
9738 if (full_screen)
9739 ttest(FALSE);
9740 redraw_all_later(CLEAR);
9741 return NULL;
9742 }
9743
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009745 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 else
9747 {
9748 flags = options[opt_idx].flags;
9749#ifdef HAVE_SANDBOX
9750 /* Disallow changing some options in the sandbox */
9751 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009752 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009754 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009757 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009758 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 else
9760 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009761 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 if (varp != NULL) /* hidden option is not changed */
9763 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009764 if (number == 0 && string != NULL)
9765 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009766 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009767
9768 /* Either we are given a string or we are setting option
9769 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009770 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009771 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009772 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009773 {
9774 /* There's another character after zeros or the string
9775 * is empty. In both cases, we are trying to set a
9776 * num option using a string. */
9777 EMSG3(_("E521: Number required: &%s = '%s'"),
9778 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009779 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009780
9781 }
9782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009784 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009785 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009787 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009788 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789 }
9790 }
9791 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009792 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009793}
9794
9795/*
9796 * Get the terminal code for a terminal option.
9797 * Returns NULL when not found.
9798 */
9799 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009800get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801{
9802 int opt_idx;
9803 char_u *varp;
9804
9805 if (tname[0] != 't' || tname[1] != '_' ||
9806 tname[2] == NUL || tname[3] == NUL)
9807 return NULL;
9808 if ((opt_idx = findoption(tname)) >= 0)
9809 {
9810 varp = get_varp(&(options[opt_idx]));
9811 if (varp != NULL)
9812 varp = *(char_u **)(varp);
9813 return varp;
9814 }
9815 return find_termcode(tname + 2);
9816}
9817
9818 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009819get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009820{
9821 int i;
9822
9823 i = findoption((char_u *)"hl");
9824 if (i >= 0)
9825 return options[i].def_val[VI_DEFAULT];
9826 return (char_u *)NULL;
9827}
9828
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009829#if defined(FEAT_MBYTE) || defined(PROTO)
9830 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009831get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009832{
9833 int i;
9834
9835 i = findoption((char_u *)"enc");
9836 if (i >= 0)
9837 return options[i].def_val[VI_DEFAULT];
9838 return (char_u *)NULL;
9839}
9840#endif
9841
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842/*
9843 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9844 */
9845 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009846find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847{
9848 int key;
9849 int modifiers;
9850
9851 /*
9852 * Don't use get_special_key_code() for t_xx, we don't want it to call
9853 * add_termcap_entry().
9854 */
9855 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9856 key = TERMCAP2KEY(arg[2], arg[3]);
9857 else
9858 {
9859 --arg; /* put arg at the '<' */
9860 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009861 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009862 if (modifiers) /* can't handle modifiers here */
9863 key = 0;
9864 }
9865 return key;
9866}
9867
9868/*
9869 * if 'all' == 0: show changed options
9870 * if 'all' == 1: show all normal options
9871 * if 'all' == 2: show all terminal options
9872 */
9873 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009874showoptions(
9875 int all,
9876 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877{
9878 struct vimoption *p;
9879 int col;
9880 int isterm;
9881 char_u *varp;
9882 struct vimoption **items;
9883 int item_count;
9884 int run;
9885 int row, rows;
9886 int cols;
9887 int i;
9888 int len;
9889
9890#define INC 20
9891#define GAP 3
9892
9893 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9894 PARAM_COUNT));
9895 if (items == NULL)
9896 return;
9897
9898 /* Highlight title */
9899 if (all == 2)
9900 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9901 else if (opt_flags & OPT_GLOBAL)
9902 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9903 else if (opt_flags & OPT_LOCAL)
9904 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9905 else
9906 MSG_PUTS_TITLE(_("\n--- Options ---"));
9907
9908 /*
9909 * do the loop two times:
9910 * 1. display the short items
9911 * 2. display the long items (only strings and numbers)
9912 */
9913 for (run = 1; run <= 2 && !got_int; ++run)
9914 {
9915 /*
9916 * collect the items in items[]
9917 */
9918 item_count = 0;
9919 for (p = &options[0]; p->fullname != NULL; p++)
9920 {
9921 varp = NULL;
9922 isterm = istermoption(p);
9923 if (opt_flags != 0)
9924 {
9925 if (p->indir != PV_NONE && !isterm)
9926 varp = get_varp_scope(p, opt_flags);
9927 }
9928 else
9929 varp = get_varp(p);
9930 if (varp != NULL
9931 && ((all == 2 && isterm)
9932 || (all == 1 && !isterm)
9933 || (all == 0 && !optval_default(p, varp))))
9934 {
9935 if (p->flags & P_BOOL)
9936 len = 1; /* a toggle option fits always */
9937 else
9938 {
9939 option_value2string(p, opt_flags);
9940 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9941 }
9942 if ((len <= INC - GAP && run == 1) ||
9943 (len > INC - GAP && run == 2))
9944 items[item_count++] = p;
9945 }
9946 }
9947
9948 /*
9949 * display the items
9950 */
9951 if (run == 1)
9952 {
9953 cols = (Columns + GAP - 3) / INC;
9954 if (cols == 0)
9955 cols = 1;
9956 rows = (item_count + cols - 1) / cols;
9957 }
9958 else /* run == 2 */
9959 rows = item_count;
9960 for (row = 0; row < rows && !got_int; ++row)
9961 {
9962 msg_putchar('\n'); /* go to next line */
9963 if (got_int) /* 'q' typed in more */
9964 break;
9965 col = 0;
9966 for (i = row; i < item_count; i += rows)
9967 {
9968 msg_col = col; /* make columns */
9969 showoneopt(items[i], opt_flags);
9970 col += INC;
9971 }
9972 out_flush();
9973 ui_breakcheck();
9974 }
9975 }
9976 vim_free(items);
9977}
9978
9979/*
9980 * Return TRUE if option "p" has its default value.
9981 */
9982 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009983optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984{
9985 int dvi;
9986
9987 if (varp == NULL)
9988 return TRUE; /* hidden option is always at default */
9989 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9990 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009991 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009993 /* the cast to long is required for Manx C, long_i is
9994 * needed for MSVC */
9995 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 /* P_STRING */
9997 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9998}
9999
10000/*
10001 * showoneopt: show the value of one option
10002 * must not be called with a hidden option!
10003 */
10004 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010005showoneopt(
10006 struct vimoption *p,
10007 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010009 char_u *varp;
10010 int save_silent = silent_mode;
10011
10012 silent_mode = FALSE;
10013 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014
10015 varp = get_varp_scope(p, opt_flags);
10016
10017 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10018 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10019 ? !curbufIsChanged() : !*(int *)varp))
10020 MSG_PUTS("no");
10021 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10022 MSG_PUTS("--");
10023 else
10024 MSG_PUTS(" ");
10025 MSG_PUTS(p->fullname);
10026 if (!(p->flags & P_BOOL))
10027 {
10028 msg_putchar('=');
10029 /* put value string in NameBuff */
10030 option_value2string(p, opt_flags);
10031 msg_outtrans(NameBuff);
10032 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010033
10034 silent_mode = save_silent;
10035 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036}
10037
10038/*
10039 * Write modified options as ":set" commands to a file.
10040 *
10041 * There are three values for "opt_flags":
10042 * OPT_GLOBAL: Write global option values and fresh values of
10043 * buffer-local options (used for start of a session
10044 * file).
10045 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10046 * curwin (used for a vimrc file).
10047 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10048 * and local values for window-local options of
10049 * curwin. Local values are also written when at the
10050 * default value, because a modeline or autocommand
10051 * may have set them when doing ":edit file" and the
10052 * user has set them back at the default or fresh
10053 * value.
10054 * When "local_only" is TRUE, don't write fresh
10055 * values, only local values (for ":mkview").
10056 * (fresh value = value used for a new buffer or window for a local option).
10057 *
10058 * Return FAIL on error, OK otherwise.
10059 */
10060 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010061makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062{
10063 struct vimoption *p;
10064 char_u *varp; /* currently used value */
10065 char_u *varp_fresh; /* local value */
10066 char_u *varp_local = NULL; /* fresh value */
10067 char *cmd;
10068 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010069 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070
10071 /*
10072 * The options that don't have a default (terminal name, columns, lines)
10073 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010074 * Do the loop over "options[]" twice: once for options with the
10075 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010077 for (pri = 1; pri >= 0; --pri)
10078 {
10079 for (p = &options[0]; !istermoption(p); p++)
10080 if (!(p->flags & P_NO_MKRC)
10081 && !istermoption(p)
10082 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010083 {
10084 /* skip global option when only doing locals */
10085 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10086 continue;
10087
10088 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10089 * file, they are always buffer-specific. */
10090 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10091 continue;
10092
10093 /* Global values are only written when not at the default value. */
10094 varp = get_varp_scope(p, opt_flags);
10095 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10096 continue;
10097
10098 round = 2;
10099 if (p->indir != PV_NONE)
10100 {
10101 if (p->var == VAR_WIN)
10102 {
10103 /* skip window-local option when only doing globals */
10104 if (!(opt_flags & OPT_LOCAL))
10105 continue;
10106 /* When fresh value of window-local option is not at the
10107 * default, need to write it too. */
10108 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10109 {
10110 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10111 if (!optval_default(p, varp_fresh))
10112 {
10113 round = 1;
10114 varp_local = varp;
10115 varp = varp_fresh;
10116 }
10117 }
10118 }
10119 }
10120
10121 /* Round 1: fresh value for window-local options.
10122 * Round 2: other values */
10123 for ( ; round <= 2; varp = varp_local, ++round)
10124 {
10125 if (round == 1 || (opt_flags & OPT_GLOBAL))
10126 cmd = "set";
10127 else
10128 cmd = "setlocal";
10129
10130 if (p->flags & P_BOOL)
10131 {
10132 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10133 return FAIL;
10134 }
10135 else if (p->flags & P_NUM)
10136 {
10137 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10138 return FAIL;
10139 }
10140 else /* P_STRING */
10141 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010142 int do_endif = FALSE;
10143
Bram Moolenaar071d4272004-06-13 20:20:40 +000010144 /* Don't set 'syntax' and 'filetype' again if the value is
10145 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010146 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010147#if defined(FEAT_SYN_HL)
10148 p->indir == PV_SYN ||
10149#endif
10150 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 {
10152 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10153 *(char_u **)(varp)) < 0
10154 || put_eol(fd) < 0)
10155 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157 }
10158 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10159 (p->flags & P_EXPAND) != 0) == FAIL)
10160 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010161 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162 {
10163 if (put_line(fd, "endif") == FAIL)
10164 return FAIL;
10165 }
10166 }
10167 }
10168 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 return OK;
10171}
10172
10173#if defined(FEAT_FOLDING) || defined(PROTO)
10174/*
10175 * Generate set commands for the local fold options only. Used when
10176 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10177 */
10178 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010179makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180{
10181 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10182# ifdef FEAT_EVAL
10183 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10184 == FAIL
10185# endif
10186 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10187 == FAIL
10188 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10189 == FAIL
10190 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10191 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10192 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10193 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10194 )
10195 return FAIL;
10196
10197 return OK;
10198}
10199#endif
10200
10201 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010202put_setstring(
10203 FILE *fd,
10204 char *cmd,
10205 char *name,
10206 char_u **valuep,
10207 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208{
10209 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010210 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211
10212 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10213 return FAIL;
10214 if (*valuep != NULL)
10215 {
10216 /* Output 'pastetoggle' as key names. For other
10217 * options some characters have to be escaped with
10218 * CTRL-V or backslash */
10219 if (valuep == &p_pt)
10220 {
10221 s = *valuep;
10222 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010223 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 return FAIL;
10225 }
10226 else if (expand)
10227 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010228 buf = alloc(MAXPATHL);
10229 if (buf == NULL)
10230 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10232 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010233 {
10234 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010236 }
10237 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238 }
10239 else if (put_escstr(fd, *valuep, 2) == FAIL)
10240 return FAIL;
10241 }
10242 if (put_eol(fd) < 0)
10243 return FAIL;
10244 return OK;
10245}
10246
10247 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010248put_setnum(
10249 FILE *fd,
10250 char *cmd,
10251 char *name,
10252 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253{
10254 long wc;
10255
10256 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10257 return FAIL;
10258 if (wc_use_keyname((char_u *)valuep, &wc))
10259 {
10260 /* print 'wildchar' and 'wildcharm' as a key name */
10261 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10262 return FAIL;
10263 }
10264 else if (fprintf(fd, "%ld", *valuep) < 0)
10265 return FAIL;
10266 if (put_eol(fd) < 0)
10267 return FAIL;
10268 return OK;
10269}
10270
10271 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010272put_setbool(
10273 FILE *fd,
10274 char *cmd,
10275 char *name,
10276 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277{
Bram Moolenaar893de922007-10-02 18:40:57 +000010278 if (value < 0) /* global/local option using global value */
10279 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10281 || put_eol(fd) < 0)
10282 return FAIL;
10283 return OK;
10284}
10285
10286/*
10287 * Clear all the terminal options.
10288 * If the option has been allocated, free the memory.
10289 * Terminal options are never hidden or indirect.
10290 */
10291 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010292clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 /*
10295 * Reset a few things before clearing the old options. This may cause
10296 * outputting a few things that the terminal doesn't understand, but the
10297 * screen will be cleared later, so this is OK.
10298 */
10299#ifdef FEAT_MOUSE_TTY
10300 mch_setmouse(FALSE); /* switch mouse off */
10301#endif
10302#ifdef FEAT_TITLE
10303 mch_restore_title(3); /* restore window titles */
10304#endif
10305#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10306 /* When starting the GUI close the display opened for the clipboard.
10307 * After restoring the title, because that will need the display. */
10308 if (gui.starting)
10309 clear_xterm_clip();
10310#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010311 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010313 free_termoptions();
10314}
10315
10316 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010317free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010318{
10319 struct vimoption *p;
10320
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 for (p = &options[0]; p->fullname != NULL; p++)
10322 if (istermoption(p))
10323 {
10324 if (p->flags & P_ALLOCED)
10325 free_string_option(*(char_u **)(p->var));
10326 if (p->flags & P_DEF_ALLOCED)
10327 free_string_option(p->def_val[VI_DEFAULT]);
10328 *(char_u **)(p->var) = empty_option;
10329 p->def_val[VI_DEFAULT] = empty_option;
10330 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10331 }
10332 clear_termcodes();
10333}
10334
10335/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010336 * Free the string for one term option, if it was allocated.
10337 * Set the string to empty_option and clear allocated flag.
10338 * "var" points to the option value.
10339 */
10340 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010341free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010342{
10343 struct vimoption *p;
10344
10345 for (p = &options[0]; p->fullname != NULL; p++)
10346 if (p->var == var)
10347 {
10348 if (p->flags & P_ALLOCED)
10349 free_string_option(*(char_u **)(p->var));
10350 *(char_u **)(p->var) = empty_option;
10351 p->flags &= ~P_ALLOCED;
10352 break;
10353 }
10354}
10355
10356/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 * Set the terminal option defaults to the current value.
10358 * Used after setting the terminal name.
10359 */
10360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010361set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362{
10363 struct vimoption *p;
10364
10365 for (p = &options[0]; p->fullname != NULL; p++)
10366 {
10367 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10368 {
10369 if (p->flags & P_DEF_ALLOCED)
10370 {
10371 free_string_option(p->def_val[VI_DEFAULT]);
10372 p->flags &= ~P_DEF_ALLOCED;
10373 }
10374 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10375 if (p->flags & P_ALLOCED)
10376 {
10377 p->flags |= P_DEF_ALLOCED;
10378 p->flags &= ~P_ALLOCED; /* don't free the value now */
10379 }
10380 }
10381 }
10382}
10383
10384/*
10385 * return TRUE if 'p' starts with 't_'
10386 */
10387 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010388istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389{
10390 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10391}
10392
10393/*
10394 * Compute columns for ruler and shown command. 'sc_col' is also used to
10395 * decide what the maximum length of a message on the status line can be.
10396 * If there is a status line for the last window, 'sc_col' is independent
10397 * of 'ru_col'.
10398 */
10399
10400#define COL_RULER 17 /* columns needed by standard ruler */
10401
10402 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010403comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010405#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010406 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407
10408 sc_col = 0;
10409 ru_col = 0;
10410 if (p_ru)
10411 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010412# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010414# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010416# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417 /* no last status line, adjust sc_col */
10418 if (!last_has_status)
10419 sc_col = ru_col;
10420 }
10421 if (p_sc)
10422 {
10423 sc_col += SHOWCMD_COLS;
10424 if (!p_ru || last_has_status) /* no need for separating space */
10425 ++sc_col;
10426 }
10427 sc_col = Columns - sc_col;
10428 ru_col = Columns - ru_col;
10429 if (sc_col <= 0) /* screen too narrow, will become a mess */
10430 sc_col = 1;
10431 if (ru_col <= 0)
10432 ru_col = 1;
10433#else
10434 sc_col = Columns;
10435 ru_col = Columns;
10436#endif
10437}
10438
10439/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010440 * Unset local option value, similar to ":set opt<".
10441 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010443unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444{
10445 struct vimoption *p;
10446 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010447 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010448
10449 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010450 if (opt_idx < 0)
10451 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 p = &(options[opt_idx]);
10453
10454 switch ((int)p->indir)
10455 {
10456 /* global option with local value: use local value if it's been set */
10457 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010458 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010459 break;
10460 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010461 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462 break;
10463 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010464 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010465 break;
10466 case PV_AR:
10467 buf->b_p_ar = -1;
10468 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010469 case PV_BKC:
10470 clear_string_option(&buf->b_p_bkc);
10471 buf->b_bkc_flags = 0;
10472 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010473 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010474 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010475 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010476 case PV_TC:
10477 clear_string_option(&buf->b_p_tc);
10478 buf->b_tc_flags = 0;
10479 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010480#ifdef FEAT_FIND_ID
10481 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010482 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010483 break;
10484 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010485 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010486 break;
10487#endif
10488#ifdef FEAT_INS_EXPAND
10489 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010490 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010491 break;
10492 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010493 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010494 break;
10495#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010496 case PV_FP:
10497 clear_string_option(&buf->b_p_fp);
10498 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499#ifdef FEAT_QUICKFIX
10500 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010501 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010502 break;
10503 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010504 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010505 break;
10506 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010507 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010508 break;
10509#endif
10510#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10511 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010512 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010513 break;
10514#endif
10515#if defined(FEAT_CRYPT)
10516 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010517 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010518 break;
10519#endif
10520#ifdef FEAT_STL_OPT
10521 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010522 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010523 break;
10524#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010525 case PV_UL:
10526 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10527 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010528#ifdef FEAT_LISP
10529 case PV_LW:
10530 clear_string_option(&buf->b_p_lw);
10531 break;
10532#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010533#ifdef FEAT_MBYTE
10534 case PV_MENC:
10535 clear_string_option(&buf->b_p_menc);
10536 break;
10537#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010538 }
10539}
10540
10541/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 * Get pointer to option variable, depending on local or global scope.
10543 */
10544 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010545get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546{
10547 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10548 {
10549 if (p->var == VAR_WIN)
10550 return (char_u *)GLOBAL_WO(get_varp(p));
10551 return p->var;
10552 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010553 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 {
10555 switch ((int)p->indir)
10556 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010557 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10560 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10561 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10564 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10565 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010566 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010568 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010570 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10571 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572#endif
10573#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010574 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10575 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010577#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10578 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10579#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010580#if defined(FEAT_CRYPT)
10581 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10582#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010583#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010585#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010586 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010587#ifdef FEAT_LISP
10588 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10589#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010590 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010591#ifdef FEAT_MBYTE
10592 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 }
10595 return NULL; /* "cannot happen" */
10596 }
10597 return get_varp(p);
10598}
10599
10600/*
10601 * Get pointer to option variable.
10602 */
10603 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010604get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605{
10606 /* hidden option, always return NULL */
10607 if (p->var == NULL)
10608 return NULL;
10609
10610 switch ((int)p->indir)
10611 {
10612 case PV_NONE: return p->var;
10613
10614 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010615 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010617 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010619 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010621 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010623 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010625 case PV_TC: return *curbuf->b_p_tc != NUL
10626 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010627 case PV_BKC: return *curbuf->b_p_bkc != NUL
10628 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010630 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010632 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10634#endif
10635#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010636 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010638 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10640#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010641 case PV_FP: return *curbuf->b_p_fp != NUL
10642 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010644 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010645 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010646 case PV_GP: return *curbuf->b_p_gp != NUL
10647 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10648 case PV_MP: return *curbuf->b_p_mp != NUL
10649 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010651#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10652 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10653 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10654#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010655#if defined(FEAT_CRYPT)
10656 case PV_CM: return *curbuf->b_p_cm != NUL
10657 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10658#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010659#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010660 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010661 ? (char_u *)&(curwin->w_p_stl) : p->var;
10662#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010663 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10664 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010665#ifdef FEAT_LISP
10666 case PV_LW: return *curbuf->b_p_lw != NUL
10667 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10668#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010669#ifdef FEAT_MBYTE
10670 case PV_MENC: return *curbuf->b_p_menc != NUL
10671 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673
10674#ifdef FEAT_ARABIC
10675 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10676#endif
10677 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010678#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010679 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10680#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010681#ifdef FEAT_SYN_HL
10682 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10683 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010684 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686#ifdef FEAT_DIFF
10687 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10688#endif
10689#ifdef FEAT_FOLDING
10690 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10691 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10692 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10693 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10694 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10695 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10696 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10697# ifdef FEAT_EVAL
10698 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10699 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10700# endif
10701 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10702#endif
10703 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010704 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010705#ifdef FEAT_LINEBREAK
10706 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010709 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010710#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10712#endif
10713#ifdef FEAT_RIGHTLEFT
10714 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10715 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10716#endif
10717 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10718 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10719#ifdef FEAT_LINEBREAK
10720 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010721 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10722 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010725 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010726#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010727 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10728 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10729#endif
10730#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010731 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10732 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10733 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735
10736 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10737 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10738#ifdef FEAT_MBYTE
10739 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10742 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10744 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10745#ifdef FEAT_CINDENT
10746 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10747 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10748 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10749#endif
10750#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10751 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10752#endif
10753#ifdef FEAT_COMMENTS
10754 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10755#endif
10756#ifdef FEAT_FOLDING
10757 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10758#endif
10759#ifdef FEAT_INS_EXPAND
10760 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10761#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010762#ifdef FEAT_COMPL_FUNC
10763 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010764 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010767 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10769#ifdef FEAT_MBYTE
10770 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10771#endif
10772 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010775 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10777 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10778 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10779 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10780#ifdef FEAT_FIND_ID
10781# ifdef FEAT_EVAL
10782 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10783# endif
10784#endif
10785#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10786 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10787 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10788#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010789#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010790 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792#ifdef FEAT_CRYPT
10793 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10794#endif
10795#ifdef FEAT_LISP
10796 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10797#endif
10798 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10799 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10800 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10801 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10802 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010804#ifdef FEAT_TEXTOBJ
10805 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10808#ifdef FEAT_SMARTINDENT
10809 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010812 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10813#ifdef FEAT_SEARCHPATH
10814 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10815#endif
10816 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10817#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010818 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010819 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10820#endif
10821#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010822 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10823 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10824 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825#endif
10826 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10827 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10828 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10829 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010830#ifdef FEAT_PERSISTENT_UNDO
10831 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10834#ifdef FEAT_KEYMAP
10835 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10836#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010837#ifdef FEAT_SIGNS
10838 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10839#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010840 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841 }
10842 /* always return a valid pointer to avoid a crash! */
10843 return (char_u *)&(curbuf->b_p_wm);
10844}
10845
10846/*
10847 * Get the value of 'equalprg', either the buffer-local one or the global one.
10848 */
10849 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010850get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851{
10852 if (*curbuf->b_p_ep == NUL)
10853 return p_ep;
10854 return curbuf->b_p_ep;
10855}
10856
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857/*
10858 * Copy options from one window to another.
10859 * Used when splitting a window.
10860 */
10861 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010862win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863{
10864 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10865 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10866# ifdef FEAT_RIGHTLEFT
10867# ifdef FEAT_FKMAP
10868 /* Is this right? */
10869 wp_to->w_farsi = wp_from->w_farsi;
10870# endif
10871# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010872#if defined(FEAT_LINEBREAK)
10873 briopt_check(wp_to);
10874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010875}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876
10877/*
10878 * Copy the options from one winopt_T to another.
10879 * Doesn't free the old option values in "to", use clear_winopt() for that.
10880 * The 'scroll' option is not copied, because it depends on the window height.
10881 * The 'previewwindow' option is reset, there can be only one preview window.
10882 */
10883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010884copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010885{
10886#ifdef FEAT_ARABIC
10887 to->wo_arab = from->wo_arab;
10888#endif
10889 to->wo_list = from->wo_list;
10890 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010891 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010892#ifdef FEAT_LINEBREAK
10893 to->wo_nuw = from->wo_nuw;
10894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895#ifdef FEAT_RIGHTLEFT
10896 to->wo_rl = from->wo_rl;
10897 to->wo_rlc = vim_strsave(from->wo_rlc);
10898#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010899#ifdef FEAT_STL_OPT
10900 to->wo_stl = vim_strsave(from->wo_stl);
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010903#ifdef FEAT_DIFF
10904 to->wo_wrap_save = from->wo_wrap_save;
10905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906#ifdef FEAT_LINEBREAK
10907 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010908 to->wo_bri = from->wo_bri;
10909 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010912 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010913 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010914 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010915#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010916 to->wo_spell = from->wo_spell;
10917#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010918#ifdef FEAT_SYN_HL
10919 to->wo_cuc = from->wo_cuc;
10920 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010921 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923#ifdef FEAT_DIFF
10924 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010925 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010927#ifdef FEAT_CONCEAL
10928 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010929 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010930#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010931#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010932 to->wo_twk = vim_strsave(from->wo_twk);
10933 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935#ifdef FEAT_FOLDING
10936 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010937 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010939 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 to->wo_fdi = vim_strsave(from->wo_fdi);
10941 to->wo_fml = from->wo_fml;
10942 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010943 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010945 to->wo_fdm_save = from->wo_diff_saved
10946 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 to->wo_fdn = from->wo_fdn;
10948# ifdef FEAT_EVAL
10949 to->wo_fde = vim_strsave(from->wo_fde);
10950 to->wo_fdt = vim_strsave(from->wo_fdt);
10951# endif
10952 to->wo_fmr = vim_strsave(from->wo_fmr);
10953#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010954#ifdef FEAT_SIGNS
10955 to->wo_scl = vim_strsave(from->wo_scl);
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 check_winopt(to); /* don't want NULL pointers */
10958}
10959
10960/*
10961 * Check string options in a window for a NULL value.
10962 */
10963 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010964check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965{
10966 check_winopt(&win->w_onebuf_opt);
10967 check_winopt(&win->w_allbuf_opt);
10968}
10969
10970/*
10971 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10972 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010973 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010974check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975{
10976#ifdef FEAT_FOLDING
10977 check_string_option(&wop->wo_fdi);
10978 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010979 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980# ifdef FEAT_EVAL
10981 check_string_option(&wop->wo_fde);
10982 check_string_option(&wop->wo_fdt);
10983# endif
10984 check_string_option(&wop->wo_fmr);
10985#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010986#ifdef FEAT_SIGNS
10987 check_string_option(&wop->wo_scl);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989#ifdef FEAT_RIGHTLEFT
10990 check_string_option(&wop->wo_rlc);
10991#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010992#ifdef FEAT_STL_OPT
10993 check_string_option(&wop->wo_stl);
10994#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010995#ifdef FEAT_SYN_HL
10996 check_string_option(&wop->wo_cc);
10997#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010998#ifdef FEAT_CONCEAL
10999 check_string_option(&wop->wo_cocu);
11000#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011001#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011002 check_string_option(&wop->wo_twk);
11003 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011004#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011005#ifdef FEAT_LINEBREAK
11006 check_string_option(&wop->wo_briopt);
11007#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008}
11009
11010/*
11011 * Free the allocated memory inside a winopt_T.
11012 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011014clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015{
11016#ifdef FEAT_FOLDING
11017 clear_string_option(&wop->wo_fdi);
11018 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011019 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020# ifdef FEAT_EVAL
11021 clear_string_option(&wop->wo_fde);
11022 clear_string_option(&wop->wo_fdt);
11023# endif
11024 clear_string_option(&wop->wo_fmr);
11025#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011026#ifdef FEAT_SIGNS
11027 clear_string_option(&wop->wo_scl);
11028#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011029#ifdef FEAT_LINEBREAK
11030 clear_string_option(&wop->wo_briopt);
11031#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032#ifdef FEAT_RIGHTLEFT
11033 clear_string_option(&wop->wo_rlc);
11034#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011035#ifdef FEAT_STL_OPT
11036 clear_string_option(&wop->wo_stl);
11037#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011038#ifdef FEAT_SYN_HL
11039 clear_string_option(&wop->wo_cc);
11040#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011041#ifdef FEAT_CONCEAL
11042 clear_string_option(&wop->wo_cocu);
11043#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011044#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011045 clear_string_option(&wop->wo_twk);
11046 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011047#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048}
11049
11050/*
11051 * Copy global option values to local options for one buffer.
11052 * Used when creating a new buffer and sometimes when entering a buffer.
11053 * flags:
11054 * BCO_ENTER We will enter the buf buffer.
11055 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11056 * appropriate.
11057 * BCO_NOHELP Don't copy the values to a help buffer.
11058 */
11059 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011060buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061{
11062 int should_copy = TRUE;
11063 char_u *save_p_isk = NULL; /* init for GCC */
11064 int dont_do_help;
11065 int did_isk = FALSE;
11066
11067 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011068 * Skip this when the option defaults have not been set yet. Happens when
11069 * main() allocates the first buffer.
11070 */
11071 if (p_cpo != NULL)
11072 {
11073 /*
11074 * Always copy when entering and 'cpo' contains 'S'.
11075 * Don't copy when already initialized.
11076 * Don't copy when 'cpo' contains 's' and not entering.
11077 * 'S' BCO_ENTER initialized 's' should_copy
11078 * yes yes X X TRUE
11079 * yes no yes X FALSE
11080 * no X yes X FALSE
11081 * X no no yes FALSE
11082 * X no no no TRUE
11083 * no yes no X TRUE
11084 */
11085 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11086 && (buf->b_p_initialized
11087 || (!(flags & BCO_ENTER)
11088 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11089 should_copy = FALSE;
11090
11091 if (should_copy || (flags & BCO_ALWAYS))
11092 {
11093 /* Don't copy the options specific to a help buffer when
11094 * BCO_NOHELP is given or the options were initialized already
11095 * (jumping back to a help file with CTRL-T or CTRL-O) */
11096 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11097 || buf->b_p_initialized;
11098 if (dont_do_help) /* don't free b_p_isk */
11099 {
11100 save_p_isk = buf->b_p_isk;
11101 buf->b_p_isk = NULL;
11102 }
11103 /*
11104 * Always free the allocated strings.
11105 * If not already initialized, set 'readonly' and copy 'fileformat'.
11106 */
11107 if (!buf->b_p_initialized)
11108 {
11109 free_buf_options(buf, TRUE);
11110 buf->b_p_ro = FALSE; /* don't copy readonly */
11111 buf->b_p_tx = p_tx;
11112#ifdef FEAT_MBYTE
11113 buf->b_p_fenc = vim_strsave(p_fenc);
11114#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011115 switch (*p_ffs)
11116 {
11117 case 'm':
11118 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11119 case 'd':
11120 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11121 case 'u':
11122 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11123 default:
11124 buf->b_p_ff = vim_strsave(p_ff);
11125 }
11126 if (buf->b_p_ff != NULL)
11127 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128 buf->b_p_bh = empty_option;
11129 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130 }
11131 else
11132 free_buf_options(buf, FALSE);
11133
11134 buf->b_p_ai = p_ai;
11135 buf->b_p_ai_nopaste = p_ai_nopaste;
11136 buf->b_p_sw = p_sw;
11137 buf->b_p_tw = p_tw;
11138 buf->b_p_tw_nopaste = p_tw_nopaste;
11139 buf->b_p_tw_nobin = p_tw_nobin;
11140 buf->b_p_wm = p_wm;
11141 buf->b_p_wm_nopaste = p_wm_nopaste;
11142 buf->b_p_wm_nobin = p_wm_nobin;
11143 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011144#ifdef FEAT_MBYTE
11145 buf->b_p_bomb = p_bomb;
11146#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011147 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148 buf->b_p_et = p_et;
11149 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011150 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151 buf->b_p_ml = p_ml;
11152 buf->b_p_ml_nobin = p_ml_nobin;
11153 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011154 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155#ifdef FEAT_INS_EXPAND
11156 buf->b_p_cpt = vim_strsave(p_cpt);
11157#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011158#ifdef FEAT_COMPL_FUNC
11159 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011160 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162 buf->b_p_sts = p_sts;
11163 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165#ifdef FEAT_COMMENTS
11166 buf->b_p_com = vim_strsave(p_com);
11167#endif
11168#ifdef FEAT_FOLDING
11169 buf->b_p_cms = vim_strsave(p_cms);
11170#endif
11171 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011172 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173 buf->b_p_nf = vim_strsave(p_nf);
11174 buf->b_p_mps = vim_strsave(p_mps);
11175#ifdef FEAT_SMARTINDENT
11176 buf->b_p_si = p_si;
11177#endif
11178 buf->b_p_ci = p_ci;
11179#ifdef FEAT_CINDENT
11180 buf->b_p_cin = p_cin;
11181 buf->b_p_cink = vim_strsave(p_cink);
11182 buf->b_p_cino = vim_strsave(p_cino);
11183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184 /* Don't copy 'filetype', it must be detected */
11185 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186 buf->b_p_pi = p_pi;
11187#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11188 buf->b_p_cinw = vim_strsave(p_cinw);
11189#endif
11190#ifdef FEAT_LISP
11191 buf->b_p_lisp = p_lisp;
11192#endif
11193#ifdef FEAT_SYN_HL
11194 /* Don't copy 'syntax', it must be set */
11195 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011196 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011197 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011198#endif
11199#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011200 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011201 (void)compile_cap_prog(&buf->b_s);
11202 buf->b_s.b_p_spf = vim_strsave(p_spf);
11203 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204#endif
11205#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11206 buf->b_p_inde = vim_strsave(p_inde);
11207 buf->b_p_indk = vim_strsave(p_indk);
11208#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011209 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011210#if defined(FEAT_EVAL)
11211 buf->b_p_fex = vim_strsave(p_fex);
11212#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011213#ifdef FEAT_CRYPT
11214 buf->b_p_key = vim_strsave(p_key);
11215#endif
11216#ifdef FEAT_SEARCHPATH
11217 buf->b_p_sua = vim_strsave(p_sua);
11218#endif
11219#ifdef FEAT_KEYMAP
11220 buf->b_p_keymap = vim_strsave(p_keymap);
11221 buf->b_kmap_state |= KEYMAP_INIT;
11222#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011223#ifdef FEAT_TERMINAL
11224 buf->b_p_twsl = p_twsl;
11225#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226 /* This isn't really an option, but copying the langmap and IME
11227 * state from the current buffer is better than resetting it. */
11228 buf->b_p_iminsert = p_iminsert;
11229 buf->b_p_imsearch = p_imsearch;
11230
11231 /* options that are normally global but also have a local value
11232 * are not copied, start using the global value */
11233 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011234 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011235 buf->b_p_bkc = empty_option;
11236 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237#ifdef FEAT_QUICKFIX
11238 buf->b_p_gp = empty_option;
11239 buf->b_p_mp = empty_option;
11240 buf->b_p_efm = empty_option;
11241#endif
11242 buf->b_p_ep = empty_option;
11243 buf->b_p_kp = empty_option;
11244 buf->b_p_path = empty_option;
11245 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011246 buf->b_p_tc = empty_option;
11247 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248#ifdef FEAT_FIND_ID
11249 buf->b_p_def = empty_option;
11250 buf->b_p_inc = empty_option;
11251# ifdef FEAT_EVAL
11252 buf->b_p_inex = vim_strsave(p_inex);
11253# endif
11254#endif
11255#ifdef FEAT_INS_EXPAND
11256 buf->b_p_dict = empty_option;
11257 buf->b_p_tsr = empty_option;
11258#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011259#ifdef FEAT_TEXTOBJ
11260 buf->b_p_qe = vim_strsave(p_qe);
11261#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011262#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11263 buf->b_p_bexpr = empty_option;
11264#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011265#if defined(FEAT_CRYPT)
11266 buf->b_p_cm = empty_option;
11267#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011268#ifdef FEAT_PERSISTENT_UNDO
11269 buf->b_p_udf = p_udf;
11270#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011271#ifdef FEAT_LISP
11272 buf->b_p_lw = empty_option;
11273#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011274#ifdef FEAT_MBYTE
11275 buf->b_p_menc = empty_option;
11276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277
11278 /*
11279 * Don't copy the options set by ex_help(), use the saved values,
11280 * when going from a help buffer to a non-help buffer.
11281 * Don't touch these at all when BCO_NOHELP is used and going from
11282 * or to a help buffer.
11283 */
11284 if (dont_do_help)
11285 buf->b_p_isk = save_p_isk;
11286 else
11287 {
11288 buf->b_p_isk = vim_strsave(p_isk);
11289 did_isk = TRUE;
11290 buf->b_p_ts = p_ts;
11291 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011292 if (buf->b_p_bt[0] == 'h')
11293 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294 buf->b_p_ma = p_ma;
11295 }
11296 }
11297
11298 /*
11299 * When the options should be copied (ignoring BCO_ALWAYS), set the
11300 * flag that indicates that the options have been initialized.
11301 */
11302 if (should_copy)
11303 buf->b_p_initialized = TRUE;
11304 }
11305
11306 check_buf_options(buf); /* make sure we don't have NULLs */
11307 if (did_isk)
11308 (void)buf_init_chartab(buf, FALSE);
11309}
11310
11311/*
11312 * Reset the 'modifiable' option and its default value.
11313 */
11314 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011315reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316{
11317 int opt_idx;
11318
11319 curbuf->b_p_ma = FALSE;
11320 p_ma = FALSE;
11321 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011322 if (opt_idx >= 0)
11323 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324}
11325
11326/*
11327 * Set the global value for 'iminsert' to the local value.
11328 */
11329 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011330set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331{
11332 p_iminsert = curbuf->b_p_iminsert;
11333}
11334
11335/*
11336 * Set the global value for 'imsearch' to the local value.
11337 */
11338 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011339set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340{
11341 p_imsearch = curbuf->b_p_imsearch;
11342}
11343
11344#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11345static int expand_option_idx = -1;
11346static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11347static int expand_option_flags = 0;
11348
11349 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011350set_context_in_set_cmd(
11351 expand_T *xp,
11352 char_u *arg,
11353 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354{
11355 int nextchar;
11356 long_u flags = 0; /* init for GCC */
11357 int opt_idx = 0; /* init for GCC */
11358 char_u *p;
11359 char_u *s;
11360 int is_term_option = FALSE;
11361 int key;
11362
11363 expand_option_flags = opt_flags;
11364
11365 xp->xp_context = EXPAND_SETTINGS;
11366 if (*arg == NUL)
11367 {
11368 xp->xp_pattern = arg;
11369 return;
11370 }
11371 p = arg + STRLEN(arg) - 1;
11372 if (*p == ' ' && *(p - 1) != '\\')
11373 {
11374 xp->xp_pattern = p + 1;
11375 return;
11376 }
11377 while (p > arg)
11378 {
11379 s = p;
11380 /* count number of backslashes before ' ' or ',' */
11381 if (*p == ' ' || *p == ',')
11382 {
11383 while (s > arg && *(s - 1) == '\\')
11384 --s;
11385 }
11386 /* break at a space with an even number of backslashes */
11387 if (*p == ' ' && ((p - s) & 1) == 0)
11388 {
11389 ++p;
11390 break;
11391 }
11392 --p;
11393 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011394 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395 {
11396 xp->xp_context = EXPAND_BOOL_SETTINGS;
11397 p += 2;
11398 }
11399 if (STRNCMP(p, "inv", 3) == 0)
11400 {
11401 xp->xp_context = EXPAND_BOOL_SETTINGS;
11402 p += 3;
11403 }
11404 xp->xp_pattern = arg = p;
11405 if (*arg == '<')
11406 {
11407 while (*p != '>')
11408 if (*p++ == NUL) /* expand terminal option name */
11409 return;
11410 key = get_special_key_code(arg + 1);
11411 if (key == 0) /* unknown name */
11412 {
11413 xp->xp_context = EXPAND_NOTHING;
11414 return;
11415 }
11416 nextchar = *++p;
11417 is_term_option = TRUE;
11418 expand_option_name[2] = KEY2TERMCAP0(key);
11419 expand_option_name[3] = KEY2TERMCAP1(key);
11420 }
11421 else
11422 {
11423 if (p[0] == 't' && p[1] == '_')
11424 {
11425 p += 2;
11426 if (*p != NUL)
11427 ++p;
11428 if (*p == NUL)
11429 return; /* expand option name */
11430 nextchar = *++p;
11431 is_term_option = TRUE;
11432 expand_option_name[2] = p[-2];
11433 expand_option_name[3] = p[-1];
11434 }
11435 else
11436 {
11437 /* Allow * wildcard */
11438 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11439 p++;
11440 if (*p == NUL)
11441 return;
11442 nextchar = *p;
11443 *p = NUL;
11444 opt_idx = findoption(arg);
11445 *p = nextchar;
11446 if (opt_idx == -1 || options[opt_idx].var == NULL)
11447 {
11448 xp->xp_context = EXPAND_NOTHING;
11449 return;
11450 }
11451 flags = options[opt_idx].flags;
11452 if (flags & P_BOOL)
11453 {
11454 xp->xp_context = EXPAND_NOTHING;
11455 return;
11456 }
11457 }
11458 }
11459 /* handle "-=" and "+=" */
11460 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11461 {
11462 ++p;
11463 nextchar = '=';
11464 }
11465 if ((nextchar != '=' && nextchar != ':')
11466 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11467 {
11468 xp->xp_context = EXPAND_UNSUCCESSFUL;
11469 return;
11470 }
11471 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11472 {
11473 xp->xp_context = EXPAND_OLD_SETTING;
11474 if (is_term_option)
11475 expand_option_idx = -1;
11476 else
11477 expand_option_idx = opt_idx;
11478 xp->xp_pattern = p + 1;
11479 return;
11480 }
11481 xp->xp_context = EXPAND_NOTHING;
11482 if (is_term_option || (flags & P_NUM))
11483 return;
11484
11485 xp->xp_pattern = p + 1;
11486
11487 if (flags & P_EXPAND)
11488 {
11489 p = options[opt_idx].var;
11490 if (p == (char_u *)&p_bdir
11491 || p == (char_u *)&p_dir
11492 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011493 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494 || p == (char_u *)&p_rtp
11495#ifdef FEAT_SEARCHPATH
11496 || p == (char_u *)&p_cdpath
11497#endif
11498#ifdef FEAT_SESSION
11499 || p == (char_u *)&p_vdir
11500#endif
11501 )
11502 {
11503 xp->xp_context = EXPAND_DIRECTORIES;
11504 if (p == (char_u *)&p_path
11505#ifdef FEAT_SEARCHPATH
11506 || p == (char_u *)&p_cdpath
11507#endif
11508 )
11509 xp->xp_backslash = XP_BS_THREE;
11510 else
11511 xp->xp_backslash = XP_BS_ONE;
11512 }
11513 else
11514 {
11515 xp->xp_context = EXPAND_FILES;
11516 /* for 'tags' need three backslashes for a space */
11517 if (p == (char_u *)&p_tags)
11518 xp->xp_backslash = XP_BS_THREE;
11519 else
11520 xp->xp_backslash = XP_BS_ONE;
11521 }
11522 }
11523
11524 /* For an option that is a list of file names, find the start of the
11525 * last file name. */
11526 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11527 {
11528 /* count number of backslashes before ' ' or ',' */
11529 if (*p == ' ' || *p == ',')
11530 {
11531 s = p;
11532 while (s > xp->xp_pattern && *(s - 1) == '\\')
11533 --s;
11534 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11535 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11536 {
11537 xp->xp_pattern = p + 1;
11538 break;
11539 }
11540 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011541
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011542#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011543 /* for 'spellsuggest' start at "file:" */
11544 if (options[opt_idx].var == (char_u *)&p_sps
11545 && STRNCMP(p, "file:", 5) == 0)
11546 {
11547 xp->xp_pattern = p + 5;
11548 break;
11549 }
11550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551 }
11552
11553 return;
11554}
11555
11556 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011557ExpandSettings(
11558 expand_T *xp,
11559 regmatch_T *regmatch,
11560 int *num_file,
11561 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562{
11563 int num_normal = 0; /* Nr of matching non-term-code settings */
11564 int num_term = 0; /* Nr of matching terminal code settings */
11565 int opt_idx;
11566 int match;
11567 int count = 0;
11568 char_u *str;
11569 int loop;
11570 int is_term_opt;
11571 char_u name_buf[MAX_KEY_NAME_LEN];
11572 static char *(names[]) = {"all", "termcap"};
11573 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11574
11575 /* do this loop twice:
11576 * loop == 0: count the number of matching options
11577 * loop == 1: copy the matching options into allocated memory
11578 */
11579 for (loop = 0; loop <= 1; ++loop)
11580 {
11581 regmatch->rm_ic = ic;
11582 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11583 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011584 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11585 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11587 {
11588 if (loop == 0)
11589 num_normal++;
11590 else
11591 (*file)[count++] = vim_strsave((char_u *)names[match]);
11592 }
11593 }
11594 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11595 opt_idx++)
11596 {
11597 if (options[opt_idx].var == NULL)
11598 continue;
11599 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11600 && !(options[opt_idx].flags & P_BOOL))
11601 continue;
11602 is_term_opt = istermoption(&options[opt_idx]);
11603 if (is_term_opt && num_normal > 0)
11604 continue;
11605 match = FALSE;
11606 if (vim_regexec(regmatch, str, (colnr_T)0)
11607 || (options[opt_idx].shortname != NULL
11608 && vim_regexec(regmatch,
11609 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11610 match = TRUE;
11611 else if (is_term_opt)
11612 {
11613 name_buf[0] = '<';
11614 name_buf[1] = 't';
11615 name_buf[2] = '_';
11616 name_buf[3] = str[2];
11617 name_buf[4] = str[3];
11618 name_buf[5] = '>';
11619 name_buf[6] = NUL;
11620 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11621 {
11622 match = TRUE;
11623 str = name_buf;
11624 }
11625 }
11626 if (match)
11627 {
11628 if (loop == 0)
11629 {
11630 if (is_term_opt)
11631 num_term++;
11632 else
11633 num_normal++;
11634 }
11635 else
11636 (*file)[count++] = vim_strsave(str);
11637 }
11638 }
11639 /*
11640 * Check terminal key codes, these are not in the option table
11641 */
11642 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11643 {
11644 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11645 {
11646 if (!isprint(str[0]) || !isprint(str[1]))
11647 continue;
11648
11649 name_buf[0] = 't';
11650 name_buf[1] = '_';
11651 name_buf[2] = str[0];
11652 name_buf[3] = str[1];
11653 name_buf[4] = NUL;
11654
11655 match = FALSE;
11656 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11657 match = TRUE;
11658 else
11659 {
11660 name_buf[0] = '<';
11661 name_buf[1] = 't';
11662 name_buf[2] = '_';
11663 name_buf[3] = str[0];
11664 name_buf[4] = str[1];
11665 name_buf[5] = '>';
11666 name_buf[6] = NUL;
11667
11668 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11669 match = TRUE;
11670 }
11671 if (match)
11672 {
11673 if (loop == 0)
11674 num_term++;
11675 else
11676 (*file)[count++] = vim_strsave(name_buf);
11677 }
11678 }
11679
11680 /*
11681 * Check special key names.
11682 */
11683 regmatch->rm_ic = TRUE; /* ignore case here */
11684 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11685 {
11686 name_buf[0] = '<';
11687 STRCPY(name_buf + 1, str);
11688 STRCAT(name_buf, ">");
11689
11690 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11691 {
11692 if (loop == 0)
11693 num_term++;
11694 else
11695 (*file)[count++] = vim_strsave(name_buf);
11696 }
11697 }
11698 }
11699 if (loop == 0)
11700 {
11701 if (num_normal > 0)
11702 *num_file = num_normal;
11703 else if (num_term > 0)
11704 *num_file = num_term;
11705 else
11706 return OK;
11707 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11708 if (*file == NULL)
11709 {
11710 *file = (char_u **)"";
11711 return FAIL;
11712 }
11713 }
11714 }
11715 return OK;
11716}
11717
11718 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011719ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720{
11721 char_u *var = NULL; /* init for GCC */
11722 char_u *buf;
11723
11724 *num_file = 0;
11725 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11726 if (*file == NULL)
11727 return FAIL;
11728
11729 /*
11730 * For a terminal key code expand_option_idx is < 0.
11731 */
11732 if (expand_option_idx < 0)
11733 {
11734 var = find_termcode(expand_option_name + 2);
11735 if (var == NULL)
11736 expand_option_idx = findoption(expand_option_name);
11737 }
11738
11739 if (expand_option_idx >= 0)
11740 {
11741 /* put string of option value in NameBuff */
11742 option_value2string(&options[expand_option_idx], expand_option_flags);
11743 var = NameBuff;
11744 }
11745 else if (var == NULL)
11746 var = (char_u *)"";
11747
11748 /* A backslash is required before some characters. This is the reverse of
11749 * what happens in do_set(). */
11750 buf = vim_strsave_escaped(var, escape_chars);
11751
11752 if (buf == NULL)
11753 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011754 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755 return FAIL;
11756 }
11757
11758#ifdef BACKSLASH_IN_FILENAME
11759 /* For MS-Windows et al. we don't double backslashes at the start and
11760 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011761 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762 if (var[0] == '\\' && var[1] == '\\'
11763 && expand_option_idx >= 0
11764 && (options[expand_option_idx].flags & P_EXPAND)
11765 && vim_isfilec(var[2])
11766 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011767 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768#endif
11769
11770 *file[0] = buf;
11771 *num_file = 1;
11772 return OK;
11773}
11774#endif
11775
11776/*
11777 * Get the value for the numeric or string option *opp in a nice format into
11778 * NameBuff[]. Must not be called with a hidden option!
11779 */
11780 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011781option_value2string(
11782 struct vimoption *opp,
11783 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784{
11785 char_u *varp;
11786
11787 varp = get_varp_scope(opp, opt_flags);
11788
11789 if (opp->flags & P_NUM)
11790 {
11791 long wc = 0;
11792
11793 if (wc_use_keyname(varp, &wc))
11794 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11795 else if (wc != 0)
11796 STRCPY(NameBuff, transchar((int)wc));
11797 else
11798 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11799 }
11800 else /* P_STRING */
11801 {
11802 varp = *(char_u **)(varp);
11803 if (varp == NULL) /* just in case */
11804 NameBuff[0] = NUL;
11805#ifdef FEAT_CRYPT
11806 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011807 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011808 STRCPY(NameBuff, "*****");
11809#endif
11810 else if (opp->flags & P_EXPAND)
11811 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11812 /* Translate 'pastetoggle' into special key names */
11813 else if ((char_u **)opp->var == &p_pt)
11814 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11815 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011816 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 }
11818}
11819
11820/*
11821 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11822 * printed as a keyname.
11823 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11824 */
11825 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011826wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011827{
11828 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11829 {
11830 *wcp = *(long *)varp;
11831 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11832 return TRUE;
11833 }
11834 return FALSE;
11835}
11836
Bram Moolenaar01615492015-02-03 13:00:38 +010011837#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011839 * Any character has an equivalent 'langmap' character. This is used for
11840 * keyboards that have a special language mode that sends characters above
11841 * 128 (although other characters can be translated too). The "to" field is a
11842 * Vim command character. This avoids having to switch the keyboard back to
11843 * ASCII mode when leaving Insert mode.
11844 *
11845 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11846 * commands.
11847 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11848 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11849 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011851# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011852/*
11853 * With multi-byte support use growarray for 'langmap' chars >= 256
11854 */
11855typedef struct
11856{
11857 int from;
11858 int to;
11859} langmap_entry_T;
11860
11861static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011862static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011863
11864/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011865 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11866 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011867 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011868 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011869langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011870{
11871 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011872 int a = 0;
11873 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011874
11875 /* Do a binary search for an existing entry. */
11876 while (a != b)
11877 {
11878 int i = (a + b) / 2;
11879 int d = entries[i].from - from;
11880
11881 if (d == 0)
11882 {
11883 entries[i].to = to;
11884 return;
11885 }
11886 if (d < 0)
11887 a = i + 1;
11888 else
11889 b = i;
11890 }
11891
11892 if (ga_grow(&langmap_mapga, 1) != OK)
11893 return; /* out of memory */
11894
11895 /* insert new entry at position "a" */
11896 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11897 mch_memmove(entries + 1, entries,
11898 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11899 ++langmap_mapga.ga_len;
11900 entries[0].from = from;
11901 entries[0].to = to;
11902}
11903
11904/*
11905 * Apply 'langmap' to multi-byte character "c" and return the result.
11906 */
11907 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011908langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011909{
11910 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11911 int a = 0;
11912 int b = langmap_mapga.ga_len;
11913
11914 while (a != b)
11915 {
11916 int i = (a + b) / 2;
11917 int d = entries[i].from - c;
11918
11919 if (d == 0)
11920 return entries[i].to; /* found matching entry */
11921 if (d < 0)
11922 a = i + 1;
11923 else
11924 b = i;
11925 }
11926 return c; /* no entry found, return "c" unmodified */
11927}
11928# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929
11930 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011931langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932{
11933 int i;
11934
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011935 for (i = 0; i < 256; i++)
11936 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11937# ifdef FEAT_MBYTE
11938 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940}
11941
11942/*
11943 * Called when langmap option is set; the language map can be
11944 * changed at any time!
11945 */
11946 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011947langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948{
11949 char_u *p;
11950 char_u *p2;
11951 int from, to;
11952
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011953#ifdef FEAT_MBYTE
11954 ga_clear(&langmap_mapga); /* clear the previous map first */
11955#endif
11956 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957
11958 for (p = p_langmap; p[0] != NUL; )
11959 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011960 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011961 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962 {
11963 if (p2[0] == '\\' && p2[1] != NUL)
11964 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965 }
11966 if (p2[0] == ';')
11967 ++p2; /* abcd;ABCD form, p2 points to A */
11968 else
11969 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11970 while (p[0])
11971 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011972 if (p[0] == ',')
11973 {
11974 ++p;
11975 break;
11976 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977 if (p[0] == '\\' && p[1] != NUL)
11978 ++p;
11979#ifdef FEAT_MBYTE
11980 from = (*mb_ptr2char)(p);
11981#else
11982 from = p[0];
11983#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011984 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985 if (p2 == NULL)
11986 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011987 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011988 if (p[0] != ',')
11989 {
11990 if (p[0] == '\\')
11991 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011993 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011995 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011997 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 }
11999 else
12000 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012001 if (p2[0] != ',')
12002 {
12003 if (p2[0] == '\\')
12004 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012006 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012007#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012008 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012009#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011 }
12012 if (to == NUL)
12013 {
12014 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12015 transchar(from));
12016 return;
12017 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012018
12019#ifdef FEAT_MBYTE
12020 if (from >= 256)
12021 langmap_set_entry(from, to);
12022 else
12023#endif
12024 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025
12026 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012027 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012028 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012030 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031 if (*p == ';')
12032 {
12033 p = p2;
12034 if (p[0] != NUL)
12035 {
12036 if (p[0] != ',')
12037 {
12038 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12039 return;
12040 }
12041 ++p;
12042 }
12043 break;
12044 }
12045 }
12046 }
12047 }
12048}
12049#endif
12050
12051/*
12052 * Return TRUE if format option 'x' is in effect.
12053 * Take care of no formatting when 'paste' is set.
12054 */
12055 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012056has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057{
12058 if (p_paste)
12059 return FALSE;
12060 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12061}
12062
12063/*
12064 * Return TRUE if "x" is present in 'shortmess' option, or
12065 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12066 */
12067 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012068shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012070 return p_shm != NULL &&
12071 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072 || (vim_strchr(p_shm, 'a') != NULL
12073 && vim_strchr((char_u *)SHM_A, x) != NULL));
12074}
12075
12076/*
12077 * paste_option_changed() - Called after p_paste was set or reset.
12078 */
12079 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012080paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081{
12082 static int old_p_paste = FALSE;
12083 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012084 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012085#ifdef FEAT_CMDL_INFO
12086 static int save_ru = 0;
12087#endif
12088#ifdef FEAT_RIGHTLEFT
12089 static int save_ri = 0;
12090 static int save_hkmap = 0;
12091#endif
12092 buf_T *buf;
12093
12094 if (p_paste)
12095 {
12096 /*
12097 * Paste switched from off to on.
12098 * Save the current values, so they can be restored later.
12099 */
12100 if (!old_p_paste)
12101 {
12102 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012103 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 {
12105 buf->b_p_tw_nopaste = buf->b_p_tw;
12106 buf->b_p_wm_nopaste = buf->b_p_wm;
12107 buf->b_p_sts_nopaste = buf->b_p_sts;
12108 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012109 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110 }
12111
12112 /* save global options */
12113 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012114 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115#ifdef FEAT_CMDL_INFO
12116 save_ru = p_ru;
12117#endif
12118#ifdef FEAT_RIGHTLEFT
12119 save_ri = p_ri;
12120 save_hkmap = p_hkmap;
12121#endif
12122 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012123 p_ai_nopaste = p_ai;
12124 p_et_nopaste = p_et;
12125 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 p_tw_nopaste = p_tw;
12127 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 }
12129
12130 /*
12131 * Always set the option values, also when 'paste' is set when it is
12132 * already on.
12133 */
12134 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012135 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 {
12137 buf->b_p_tw = 0; /* textwidth is 0 */
12138 buf->b_p_wm = 0; /* wrapmargin is 0 */
12139 buf->b_p_sts = 0; /* softtabstop is 0 */
12140 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012141 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 }
12143
12144 /* set global options */
12145 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012146 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148 if (p_ru)
12149 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150 p_ru = 0; /* no ruler */
12151#endif
12152#ifdef FEAT_RIGHTLEFT
12153 p_ri = 0; /* no reverse insert */
12154 p_hkmap = 0; /* no Hebrew keyboard */
12155#endif
12156 /* set global values for local buffer options */
12157 p_tw = 0;
12158 p_wm = 0;
12159 p_sts = 0;
12160 p_ai = 0;
12161 }
12162
12163 /*
12164 * Paste switched from on to off: Restore saved values.
12165 */
12166 else if (old_p_paste)
12167 {
12168 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012169 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170 {
12171 buf->b_p_tw = buf->b_p_tw_nopaste;
12172 buf->b_p_wm = buf->b_p_wm_nopaste;
12173 buf->b_p_sts = buf->b_p_sts_nopaste;
12174 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012175 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176 }
12177
12178 /* restore global options */
12179 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012180 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012182 if (p_ru != save_ru)
12183 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184 p_ru = save_ru;
12185#endif
12186#ifdef FEAT_RIGHTLEFT
12187 p_ri = save_ri;
12188 p_hkmap = save_hkmap;
12189#endif
12190 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012191 p_ai = p_ai_nopaste;
12192 p_et = p_et_nopaste;
12193 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194 p_tw = p_tw_nopaste;
12195 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 }
12197
12198 old_p_paste = p_paste;
12199}
12200
12201/*
12202 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12203 *
12204 * Reset 'compatible' and set the values for options that didn't get set yet
12205 * to the Vim defaults.
12206 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012207 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208 */
12209 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012210vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012212 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012213 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012214 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215
12216 if (!option_was_set((char_u *)"cp"))
12217 {
12218 p_cp = FALSE;
12219 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12220 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12221 set_option_default(opt_idx, OPT_FREE, FALSE);
12222 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012223 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012224 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012225
12226 if (fname != NULL)
12227 {
12228 p = vim_getenv(envname, &dofree);
12229 if (p == NULL)
12230 {
12231 /* Set $MYVIMRC to the first vimrc file found. */
12232 p = FullName_save(fname, FALSE);
12233 if (p != NULL)
12234 {
12235 vim_setenv(envname, p);
12236 vim_free(p);
12237 }
12238 }
12239 else if (dofree)
12240 vim_free(p);
12241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242}
12243
12244/*
12245 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12246 */
12247 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012250 int opt_idx;
12251
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252 if (p_cp != on)
12253 {
12254 p_cp = on;
12255 compatible_set();
12256 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012257 opt_idx = findoption((char_u *)"cp");
12258 if (opt_idx >= 0)
12259 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012260}
12261
12262/*
12263 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012264 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265 */
12266 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
12269 int idx;
12270
12271 idx = findoption(name);
12272 if (idx < 0) /* unknown option */
12273 return FALSE;
12274 if (options[idx].flags & P_WAS_SET)
12275 return TRUE;
12276 return FALSE;
12277}
12278
12279/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012280 * Reset the flag indicating option "name" was set.
12281 */
12282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012283reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012284{
12285 int idx = findoption(name);
12286
12287 if (idx >= 0)
12288 options[idx].flags &= ~P_WAS_SET;
12289}
12290
12291/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012292 * compatible_set() - Called when 'compatible' has been set or unset.
12293 *
12294 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12295 * flag) to a Vi compatible value.
12296 * When 'compatible' is unset: Set all options that have a different default
12297 * for Vim (without the P_VI_DEF flag) to that default.
12298 */
12299 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012300compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301{
12302 int opt_idx;
12303
12304 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12305 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12306 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12307 set_option_default(opt_idx, OPT_FREE, p_cp);
12308 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012309 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012310}
12311
12312#ifdef FEAT_LINEBREAK
12313
12314# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12315 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012316 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012317# endif
12318
12319/*
12320 * fill_breakat_flags() -- called when 'breakat' changes value.
12321 */
12322 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012323fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012325 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012326 int i;
12327
12328 for (i = 0; i < 256; i++)
12329 breakat_flags[i] = FALSE;
12330
12331 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012332 for (p = p_breakat; *p; p++)
12333 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012334}
12335
12336# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012337 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012338# endif
12339
12340#endif
12341
12342/*
12343 * Check an option that can be a range of string values.
12344 *
12345 * Return OK for correct value, FAIL otherwise.
12346 * Empty is always OK.
12347 */
12348 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012349check_opt_strings(
12350 char_u *val,
12351 char **values,
12352 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353{
12354 return opt_strings_flags(val, values, NULL, list);
12355}
12356
12357/*
12358 * Handle an option that can be a range of string values.
12359 * Set a flag in "*flagp" for each string present.
12360 *
12361 * Return OK for correct value, FAIL otherwise.
12362 * Empty is always OK.
12363 */
12364 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012365opt_strings_flags(
12366 char_u *val, /* new value */
12367 char **values, /* array of valid string values */
12368 unsigned *flagp,
12369 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012370{
12371 int i;
12372 int len;
12373 unsigned new_flags = 0;
12374
12375 while (*val)
12376 {
12377 for (i = 0; ; ++i)
12378 {
12379 if (values[i] == NULL) /* val not found in values[] */
12380 return FAIL;
12381
12382 len = (int)STRLEN(values[i]);
12383 if (STRNCMP(values[i], val, len) == 0
12384 && ((list && val[len] == ',') || val[len] == NUL))
12385 {
12386 val += len + (val[len] == ',');
12387 new_flags |= (1 << i);
12388 break; /* check next item in val list */
12389 }
12390 }
12391 }
12392 if (flagp != NULL)
12393 *flagp = new_flags;
12394
12395 return OK;
12396}
12397
12398/*
12399 * Read the 'wildmode' option, fill wim_flags[].
12400 */
12401 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012402check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012403{
12404 char_u new_wim_flags[4];
12405 char_u *p;
12406 int i;
12407 int idx = 0;
12408
12409 for (i = 0; i < 4; ++i)
12410 new_wim_flags[i] = 0;
12411
12412 for (p = p_wim; *p; ++p)
12413 {
12414 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12415 ;
12416 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12417 return FAIL;
12418 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12419 new_wim_flags[idx] |= WIM_LONGEST;
12420 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12421 new_wim_flags[idx] |= WIM_FULL;
12422 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12423 new_wim_flags[idx] |= WIM_LIST;
12424 else
12425 return FAIL;
12426 p += i;
12427 if (*p == NUL)
12428 break;
12429 if (*p == ',')
12430 {
12431 if (idx == 3)
12432 return FAIL;
12433 ++idx;
12434 }
12435 }
12436
12437 /* fill remaining entries with last flag */
12438 while (idx < 3)
12439 {
12440 new_wim_flags[idx + 1] = new_wim_flags[idx];
12441 ++idx;
12442 }
12443
12444 /* only when there are no errors, wim_flags[] is changed */
12445 for (i = 0; i < 4; ++i)
12446 wim_flags[i] = new_wim_flags[i];
12447 return OK;
12448}
12449
12450/*
12451 * Check if backspacing over something is allowed.
12452 */
12453 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012454can_bs(
12455 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456{
12457 switch (*p_bs)
12458 {
12459 case '2': return TRUE;
12460 case '1': return (what != BS_START);
12461 case '0': return FALSE;
12462 }
12463 return vim_strchr(p_bs, what) != NULL;
12464}
12465
12466/*
12467 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12468 * the file must be considered changed when the value is different.
12469 */
12470 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
12473 buf->b_start_ffc = *buf->b_p_ff;
12474 buf->b_start_eol = buf->b_p_eol;
12475#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012476 buf->b_start_bomb = buf->b_p_bomb;
12477
Bram Moolenaar071d4272004-06-13 20:20:40 +000012478 /* Only use free/alloc when necessary, they take time. */
12479 if (buf->b_start_fenc == NULL
12480 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12481 {
12482 vim_free(buf->b_start_fenc);
12483 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12484 }
12485#endif
12486}
12487
12488/*
12489 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12490 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012491 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12492 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012493 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012494 * When "ignore_empty" is true don't consider a new, empty buffer to be
12495 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496 */
12497 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012498file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012500 /* In a buffer that was never loaded the options are not valid. */
12501 if (buf->b_flags & BF_NEVERLOADED)
12502 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012503 if (ignore_empty
12504 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505 && buf->b_ml.ml_line_count == 1
12506 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12507 return FALSE;
12508 if (buf->b_start_ffc != *buf->b_p_ff)
12509 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012510 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012511 return TRUE;
12512#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012513 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12514 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012515 if (buf->b_start_fenc == NULL)
12516 return (*buf->b_p_fenc != NUL);
12517 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12518#else
12519 return FALSE;
12520#endif
12521}
12522
12523/*
12524 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12525 */
12526 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012527check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012528{
12529 return check_opt_strings(p, p_ff_values, FALSE);
12530}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012531
12532/*
12533 * Return the effective shiftwidth value for current buffer, using the
12534 * 'tabstop' value when 'shiftwidth' is zero.
12535 */
12536 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012537get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012538{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012539 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012540}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012541
12542/*
12543 * Return the effective softtabstop value for the current buffer, using the
12544 * 'tabstop' value when 'softtabstop' is negative.
12545 */
12546 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012547get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012548{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012549 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012550}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012551
12552/*
12553 * Check matchpairs option for "*initc".
12554 * If there is a match set "*initc" to the matching character and "*findc" to
12555 * the opposite character. Set "*backwards" to the direction.
12556 * When "switchit" is TRUE swap the direction.
12557 */
12558 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012559find_mps_values(
12560 int *initc,
12561 int *findc,
12562 int *backwards,
12563 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012564{
12565 char_u *ptr;
12566
12567 ptr = curbuf->b_p_mps;
12568 while (*ptr != NUL)
12569 {
12570#ifdef FEAT_MBYTE
12571 if (has_mbyte)
12572 {
12573 char_u *prev;
12574
12575 if (mb_ptr2char(ptr) == *initc)
12576 {
12577 if (switchit)
12578 {
12579 *findc = *initc;
12580 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12581 *backwards = TRUE;
12582 }
12583 else
12584 {
12585 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12586 *backwards = FALSE;
12587 }
12588 return;
12589 }
12590 prev = ptr;
12591 ptr += mb_ptr2len(ptr) + 1;
12592 if (mb_ptr2char(ptr) == *initc)
12593 {
12594 if (switchit)
12595 {
12596 *findc = *initc;
12597 *initc = mb_ptr2char(prev);
12598 *backwards = FALSE;
12599 }
12600 else
12601 {
12602 *findc = mb_ptr2char(prev);
12603 *backwards = TRUE;
12604 }
12605 return;
12606 }
12607 ptr += mb_ptr2len(ptr);
12608 }
12609 else
12610#endif
12611 {
12612 if (*ptr == *initc)
12613 {
12614 if (switchit)
12615 {
12616 *backwards = TRUE;
12617 *findc = *initc;
12618 *initc = ptr[2];
12619 }
12620 else
12621 {
12622 *backwards = FALSE;
12623 *findc = ptr[2];
12624 }
12625 return;
12626 }
12627 ptr += 2;
12628 if (*ptr == *initc)
12629 {
12630 if (switchit)
12631 {
12632 *backwards = FALSE;
12633 *findc = *initc;
12634 *initc = ptr[-2];
12635 }
12636 else
12637 {
12638 *backwards = TRUE;
12639 *findc = ptr[-2];
12640 }
12641 return;
12642 }
12643 ++ptr;
12644 }
12645 if (*ptr == ',')
12646 ++ptr;
12647 }
12648}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012649
12650#if defined(FEAT_LINEBREAK) || defined(PROTO)
12651/*
12652 * This is called when 'breakindentopt' is changed and when a window is
12653 * initialized.
12654 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012655 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012656briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012657{
12658 char_u *p;
12659 int bri_shift = 0;
12660 long bri_min = 20;
12661 int bri_sbr = FALSE;
12662
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012663 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012664 while (*p != NUL)
12665 {
12666 if (STRNCMP(p, "shift:", 6) == 0
12667 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12668 {
12669 p += 6;
12670 bri_shift = getdigits(&p);
12671 }
12672 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12673 {
12674 p += 4;
12675 bri_min = getdigits(&p);
12676 }
12677 else if (STRNCMP(p, "sbr", 3) == 0)
12678 {
12679 p += 3;
12680 bri_sbr = TRUE;
12681 }
12682 if (*p != ',' && *p != NUL)
12683 return FAIL;
12684 if (*p == ',')
12685 ++p;
12686 }
12687
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012688 wp->w_p_brishift = bri_shift;
12689 wp->w_p_brimin = bri_min;
12690 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012691
12692 return OK;
12693}
12694#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012695
12696/*
12697 * Get the local or global value of 'backupcopy'.
12698 */
12699 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012700get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012701{
12702 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12703}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012704
12705#if defined(FEAT_SIGNS) || defined(PROTO)
12706/*
12707 * Return TRUE when window "wp" has a column to draw signs in.
12708 */
12709 int
12710signcolumn_on(win_T *wp)
12711{
12712 if (*wp->w_p_scl == 'n')
12713 return FALSE;
12714 if (*wp->w_p_scl == 'y')
12715 return TRUE;
12716 return (wp->w_buffer->b_signlist != NULL
12717# ifdef FEAT_NETBEANS_INTG
12718 || wp->w_buffer->b_has_sign_column
12719# endif
12720 );
12721}
12722#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012723
12724#if defined(FEAT_EVAL) || defined(PROTO)
12725/*
12726 * Get window or buffer local options.
12727 */
12728 dict_T *
12729get_winbuf_options(int bufopt)
12730{
12731 dict_T *d;
12732 int opt_idx;
12733
12734 d = dict_alloc();
12735 if (d == NULL)
12736 return NULL;
12737
12738 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12739 {
12740 struct vimoption *opt = &options[opt_idx];
12741
12742 if ((bufopt && (opt->indir & PV_BUF))
12743 || (!bufopt && (opt->indir & PV_WIN)))
12744 {
12745 char_u *varp = get_varp(opt);
12746
12747 if (varp != NULL)
12748 {
12749 if (opt->flags & P_STRING)
12750 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012751 else if (opt->flags & P_NUM)
12752 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012753 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012754 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012755 }
12756 }
12757 }
12758
12759 return d;
12760}
12761#endif