blob: a9ee0673cd81bb2a2e816c674579beff42474997 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
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.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * 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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#ifdef FEAT_COMPL_FUNC
144# define PV_OFU OPT_BUF(BV_OFU)
145#endif
146#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
147#define PV_PI OPT_BUF(BV_PI)
148#ifdef FEAT_TEXTOBJ
149# define PV_QE OPT_BUF(BV_QE)
150#endif
151#define PV_RO OPT_BUF(BV_RO)
152#ifdef FEAT_SMARTINDENT
153# define PV_SI OPT_BUF(BV_SI)
154#endif
155#ifndef SHORT_FNAME
156# define PV_SN OPT_BUF(BV_SN)
157#endif
158#ifdef FEAT_SYN_HL
159# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000160# define PV_SYN OPT_BUF(BV_SYN)
161#endif
162#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163# define PV_SPC OPT_BUF(BV_SPC)
164# define PV_SPF OPT_BUF(BV_SPF)
165# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166#endif
167#define PV_STS OPT_BUF(BV_STS)
168#ifdef FEAT_SEARCHPATH
169# define PV_SUA OPT_BUF(BV_SUA)
170#endif
171#define PV_SW OPT_BUF(BV_SW)
172#define PV_SWF OPT_BUF(BV_SWF)
173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
174#define PV_TS OPT_BUF(BV_TS)
175#define PV_TW OPT_BUF(BV_TW)
176#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200177#ifdef FEAT_PERSISTENT_UNDO
178# define PV_UDF OPT_BUF(BV_UDF)
179#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000181
182/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183 * Definition of the PV_ values for window-local options.
184 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186#define PV_LIST OPT_WIN(WV_LIST)
187#ifdef FEAT_ARABIC
188# define PV_ARAB OPT_WIN(WV_ARAB)
189#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000190#ifdef FEAT_DIFF
191# define PV_DIFF OPT_WIN(WV_DIFF)
192#endif
193#ifdef FEAT_FOLDING
194# define PV_FDC OPT_WIN(WV_FDC)
195# define PV_FEN OPT_WIN(WV_FEN)
196# define PV_FDI OPT_WIN(WV_FDI)
197# define PV_FDL OPT_WIN(WV_FDL)
198# define PV_FDM OPT_WIN(WV_FDM)
199# define PV_FML OPT_WIN(WV_FML)
200# define PV_FDN OPT_WIN(WV_FDN)
201# ifdef FEAT_EVAL
202# define PV_FDE OPT_WIN(WV_FDE)
203# define PV_FDT OPT_WIN(WV_FDT)
204# endif
205# define PV_FMR OPT_WIN(WV_FMR)
206#endif
207#ifdef FEAT_LINEBREAK
208# define PV_LBR OPT_WIN(WV_LBR)
209#endif
210#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200211#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000212#ifdef FEAT_LINEBREAK
213# define PV_NUW OPT_WIN(WV_NUW)
214#endif
215#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216# define PV_PVW OPT_WIN(WV_PVW)
217#endif
218#ifdef FEAT_RIGHTLEFT
219# define PV_RL OPT_WIN(WV_RL)
220# define PV_RLC OPT_WIN(WV_RLC)
221#endif
222#ifdef FEAT_SCROLLBIND
223# define PV_SCBIND OPT_WIN(WV_SCBIND)
224#endif
225#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000226#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_SPELL OPT_WIN(WV_SPELL)
228#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SYN_HL
230# define PV_CUC OPT_WIN(WV_CUC)
231# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200232# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234#ifdef FEAT_STL_OPT
235# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
236#endif
237#ifdef FEAT_WINDOWS
238# define PV_WFH OPT_WIN(WV_WFH)
239#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000240#ifdef FEAT_VERTSPLIT
241# define PV_WFW OPT_WIN(WV_WFW)
242#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200244#ifdef FEAT_CURSORBIND
245# define PV_CRBIND OPT_WIN(WV_CRBIND)
246#endif
247#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200248# define PV_COCU OPT_WIN(WV_COCU)
249# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251
252/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253typedef enum
254{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000255 PV_NONE = 0,
256 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257} idopt_T;
258
259/*
260 * Options local to a window have a value local to a buffer and global to all
261 * buffers. Indicate this by setting "var" to VAR_WIN.
262 */
263#define VAR_WIN ((char_u *)-1)
264
265/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000266 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267 * Only to be used in option.c!
268 */
269static int p_ai;
270static int p_bin;
271#ifdef FEAT_MBYTE
272static int p_bomb;
273#endif
274#if defined(FEAT_QUICKFIX)
275static char_u *p_bh;
276static char_u *p_bt;
277#endif
278static int p_bl;
279static int p_ci;
280#ifdef FEAT_CINDENT
281static int p_cin;
282static char_u *p_cink;
283static char_u *p_cino;
284#endif
285#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
286static char_u *p_cinw;
287#endif
288#ifdef FEAT_COMMENTS
289static char_u *p_com;
290#endif
291#ifdef FEAT_FOLDING
292static char_u *p_cms;
293#endif
294#ifdef FEAT_INS_EXPAND
295static char_u *p_cpt;
296#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000297#ifdef FEAT_COMPL_FUNC
298static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000299static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301static int p_eol;
302static int p_et;
303#ifdef FEAT_MBYTE
304static char_u *p_fenc;
305#endif
306static char_u *p_ff;
307static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000308static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309#ifdef FEAT_AUTOCMD
310static char_u *p_ft;
311#endif
312static long p_iminsert;
313static long p_imsearch;
314#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
315static char_u *p_inex;
316#endif
317#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
318static char_u *p_inde;
319static char_u *p_indk;
320#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000321#if defined(FEAT_EVAL)
322static char_u *p_fex;
323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324static int p_inf;
325static char_u *p_isk;
326#ifdef FEAT_CRYPT
327static char_u *p_key;
328#endif
329#ifdef FEAT_LISP
330static int p_lisp;
331#endif
332static int p_ml;
333static int p_ma;
334static int p_mod;
335static char_u *p_mps;
336static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338#ifdef FEAT_TEXTOBJ
339static char_u *p_qe;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_ro;
342#ifdef FEAT_SMARTINDENT
343static int p_si;
344#endif
345#ifndef SHORT_FNAME
346static int p_sn;
347#endif
348static long p_sts;
349#if defined(FEAT_SEARCHPATH)
350static char_u *p_sua;
351#endif
352static long p_sw;
353static int p_swf;
354#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000355static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000357#endif
358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000359static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000360static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000361static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362#endif
363static long p_ts;
364static long p_tw;
365static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200366#ifdef FEAT_PERSISTENT_UNDO
367static int p_udf;
368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static long p_wm;
370#ifdef FEAT_KEYMAP
371static char_u *p_keymap;
372#endif
373
374/* Saved values for when 'bin' is set. */
375static int p_et_nobin;
376static int p_ml_nobin;
377static long p_tw_nobin;
378static long p_wm_nobin;
379
380/* Saved values for when 'paste' is set */
381static long p_tw_nopaste;
382static long p_wm_nopaste;
383static long p_sts_nopaste;
384static int p_ai_nopaste;
385
386struct vimoption
387{
388 char *fullname; /* full option name */
389 char *shortname; /* permissible abbreviation */
390 long_u flags; /* see below */
391 char_u *var; /* global option: pointer to variable;
392 * window-local option: VAR_WIN;
393 * buffer-local option: global value */
394 idopt_T indir; /* global option: PV_NONE;
395 * local option: indirect option index */
396 char_u *def_val[2]; /* default values for variable (vi and vim) */
397#ifdef FEAT_EVAL
398 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000399# define SCRIPTID_INIT , 0
400#else
401# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402#endif
403};
404
405#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
406#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
407
408/*
409 * Flags
410 */
411#define P_BOOL 0x01 /* the option is boolean */
412#define P_NUM 0x02 /* the option is numeric */
413#define P_STRING 0x04 /* the option is a string */
414#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000415 must use free_string_option() when
416 assigning new value. Not set if default is
417 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
419 never be used for local or hidden options! */
420#define P_NODEFAULT 0x40 /* don't set to default value */
421#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
422 use vim_free() when assigning new value */
423#define P_WAS_SET 0x100 /* option has been set/reset */
424#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
425#define P_VI_DEF 0x400 /* Use Vi default for Vim */
426#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
427
428 /* when option changed, what to display: */
429#define P_RSTAT 0x1000 /* redraw status lines */
430#define P_RWIN 0x2000 /* redraw current window */
431#define P_RBUF 0x4000 /* redraw current buffer */
432#define P_RALL 0x6000 /* redraw all windows */
433#define P_RCLR 0x7000 /* clear and redraw all */
434
435#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200436#define P_NODUP 0x10000L /* don't allow duplicate strings */
437#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438
Bram Moolenaar913077c2012-03-28 19:59:04 +0200439#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
440#define P_GETTEXT 0x80000L /* expand default value with _() */
441#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
442#define P_NFNAME 0x200000L /* only normal file name chars allowed */
443#define P_INSECURE 0x400000L /* option was set from a modeline */
444#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000445 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200446#define P_NO_ML 0x1000000L /* not allowed in modeline */
447#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
448 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000450#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
451
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000452/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
453 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000454#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000455# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000456#else
457# define ISP_LATIN1 (char_u *)"@,161-255"
458#endif
459
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000460/* The 16 bit MS-DOS version is low on space, make the string as short as
461 * possible when compiling with few features. */
462#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
463 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200464 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100465# define HIGHLIGHT_INIT "8:SpecialKey,@: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"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100467# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#endif
469
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470/*
471 * options[] is initialized here.
472 * The order of the options MUST be alphabetic for ":set all" and findoption().
473 * All option names MUST start with a lowercase letter (for findoption()).
474 * Exception: "t_" options are at the end.
475 * The options with a NULL variable are 'hidden': a set command for them is
476 * ignored and they are not printed.
477 */
478static struct vimoption
479#ifdef FEAT_GUI_W16
480 _far
481#endif
482 options[] =
483{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200484 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485#ifdef FEAT_RIGHTLEFT
486 (char_u *)&p_aleph, PV_NONE,
487#else
488 (char_u *)NULL, PV_NONE,
489#endif
490 {
491#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
492 (char_u *)128L,
493#else
494 (char_u *)224L,
495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000496 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
498#if defined(FEAT_GUI) && defined(MACOS_X)
499 (char_u *)&p_antialias, PV_NONE,
500 {(char_u *)FALSE, (char_u *)FALSE}
501#else
502 (char_u *)NULL, PV_NONE,
503 {(char_u *)FALSE, (char_u *)FALSE}
504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000505 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_ARABIC
508 (char_u *)VAR_WIN, PV_ARAB,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
514#ifdef FEAT_ARABIC
515 (char_u *)&p_arshape, PV_NONE,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
521#ifdef FEAT_RIGHTLEFT
522 (char_u *)&p_ari, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
528#ifdef FEAT_FKMAP
529 (char_u *)&p_altkeymap, PV_NONE,
530#else
531 (char_u *)NULL, PV_NONE,
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
535#if defined(FEAT_MBYTE)
536 (char_u *)&p_ambw, PV_NONE,
537 {(char_u *)"single", (char_u *)0L}
538#else
539 (char_u *)NULL, PV_NONE,
540 {(char_u *)0L, (char_u *)0L}
541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000543#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 {"autochdir", "acd", P_BOOL|P_VI_DEF,
545 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547#endif
548 {"autoindent", "ai", P_BOOL|P_VI_DEF,
549 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"autoprint", "ap", P_BOOL|P_VI_DEF,
552 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000555 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autowrite", "aw", P_BOOL|P_VI_DEF,
558 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autowriteall","awa", P_BOOL|P_VI_DEF,
561 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
564 (char_u *)&p_bg, PV_NONE,
565 {
566#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
567 (char_u *)"dark",
568#else
569 (char_u *)"light",
570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
573 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
576 (char_u *)&p_bk, 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 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
579 (char_u *)&p_bkc, PV_NONE,
580#ifdef UNIX
581 {(char_u *)"yes", (char_u *)"auto"}
582#else
583 {(char_u *)"auto", (char_u *)"auto"}
584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
587 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000589 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bex, PV_NONE,
591 {
592#ifdef VMS
593 (char_u *)"_",
594#else
595 (char_u *)"~",
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
599#ifdef FEAT_WILDIGN
600 (char_u *)&p_bsk, PV_NONE,
601 {(char_u *)"", (char_u *)0L}
602#else
603 (char_u *)NULL, PV_NONE,
604 {(char_u *)0L, (char_u *)0L}
605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000606 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607#ifdef FEAT_BEVAL
608 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
609 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000610 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
612 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000614# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000615 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000616 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000618# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#endif
620 {"beautify", "bf", P_BOOL|P_VI_DEF,
621 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
624 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
627#ifdef MSDOS
628 (char_u *)&p_biosk, PV_NONE,
629#else
630 (char_u *)NULL, PV_NONE,
631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
634#ifdef FEAT_MBYTE
635 (char_u *)&p_bomb, PV_BOMB,
636#else
637 (char_u *)NULL, PV_NONE,
638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
641#ifdef FEAT_LINEBREAK
642 (char_u *)&p_breakat, PV_NONE,
643 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
644#else
645 (char_u *)NULL, PV_NONE,
646 {(char_u *)0L, (char_u *)0L}
647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000648 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
650#ifdef FEAT_BROWSE
651 (char_u *)&p_bsdir, PV_NONE,
652 {(char_u *)"last", (char_u *)0L}
653#else
654 (char_u *)NULL, PV_NONE,
655 {(char_u *)0L, (char_u *)0L}
656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000657 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
659#if defined(FEAT_QUICKFIX)
660 (char_u *)&p_bh, PV_BH,
661 {(char_u *)"", (char_u *)0L}
662#else
663 (char_u *)NULL, PV_NONE,
664 {(char_u *)0L, (char_u *)0L}
665#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
668 (char_u *)&p_bl, PV_BL,
669 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
672#if defined(FEAT_QUICKFIX)
673 (char_u *)&p_bt, PV_BT,
674 {(char_u *)"", (char_u *)0L}
675#else
676 (char_u *)NULL, PV_NONE,
677 {(char_u *)0L, (char_u *)0L}
678#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000679 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000681#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 (char_u *)&p_cmp, PV_NONE,
683 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000688 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
690#ifdef FEAT_SEARCHPATH
691 (char_u *)&p_cdpath, PV_NONE,
692 {(char_u *)",,", (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 {"cedit", NULL, P_STRING,
699#ifdef FEAT_CMDWIN
700 (char_u *)&p_cedit, PV_NONE,
701 {(char_u *)"", (char_u *)CTRL_F_STR}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)0L, (char_u *)0L}
705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
708#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
709 (char_u *)&p_ccv, PV_NONE,
710 {(char_u *)"", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
717#ifdef FEAT_CINDENT
718 (char_u *)&p_cin, PV_CIN,
719#else
720 (char_u *)NULL, PV_NONE,
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
724#ifdef FEAT_CINDENT
725 (char_u *)&p_cink, PV_CINK,
726 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
733#ifdef FEAT_CINDENT
734 (char_u *)&p_cino, PV_CINO,
735#else
736 (char_u *)NULL, PV_NONE,
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
740#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
741 (char_u *)&p_cinw, PV_CINW,
742 {(char_u *)"if,else,while,do,for,switch",
743 (char_u *)0L}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
750#ifdef FEAT_CLIPBOARD
751 (char_u *)&p_cb, PV_NONE,
752# ifdef FEAT_XCLIPBOARD
753 {(char_u *)"autoselect,exclude:cons\\|linux",
754 (char_u *)0L}
755# else
756 {(char_u *)"", (char_u *)0L}
757# endif
758#else
759 (char_u *)NULL, PV_NONE,
760 {(char_u *)"", (char_u *)0L}
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
764 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
767#ifdef FEAT_CMDWIN
768 (char_u *)&p_cwh, PV_NONE,
769#else
770 (char_u *)NULL, PV_NONE,
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200773 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
774#ifdef FEAT_SYN_HL
775 (char_u *)VAR_WIN, PV_CC,
776#else
777 (char_u *)NULL, PV_NONE,
778#endif
779 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
781 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200783 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_COMMENTS
785 (char_u *)&p_com, PV_COM,
786 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
787 (char_u *)0L}
788#else
789 (char_u *)NULL, PV_NONE,
790 {(char_u *)0L, (char_u *)0L}
791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000792 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200793 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000794#ifdef FEAT_FOLDING
795 (char_u *)&p_cms, PV_CMS,
796 {(char_u *)"/*%s*/", (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000802 /* P_PRI_MKRC isn't needed here, optval_default()
803 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"compatible", "cp", P_BOOL|P_RALL,
805 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
808#ifdef FEAT_INS_EXPAND
809 (char_u *)&p_cpt, PV_CPT,
810 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)0L, (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200816 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200817#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200818 (char_u *)VAR_WIN, PV_COCU,
819 {(char_u *)"", (char_u *)NULL}
820#else
821 (char_u *)NULL, PV_NONE,
822 {(char_u *)NULL, (char_u *)0L}
823#endif
824 SCRIPTID_INIT},
825 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
826#ifdef FEAT_CONCEAL
827 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200828#else
829 (char_u *)NULL, PV_NONE,
830#endif
831 {(char_u *)0L, (char_u *)0L}
832 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000833 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
834#ifdef FEAT_COMPL_FUNC
835 (char_u *)&p_cfu, PV_CFU,
836 {(char_u *)"", (char_u *)0L}
837#else
838 (char_u *)NULL, PV_NONE,
839 {(char_u *)0L, (char_u *)0L}
840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000841 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000842 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
843#ifdef FEAT_INS_EXPAND
844 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000845 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000846#else
847 (char_u *)NULL, PV_NONE,
848 {(char_u *)0L, (char_u *)0L}
849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851 {"confirm", "cf", P_BOOL|P_VI_DEF,
852#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
853 (char_u *)&p_confirm, PV_NONE,
854#else
855 (char_u *)NULL, PV_NONE,
856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"conskey", "consk",P_BOOL|P_VI_DEF,
859#ifdef MSDOS
860 (char_u *)&p_consk, PV_NONE,
861#else
862 (char_u *)NULL, PV_NONE,
863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
866 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
869 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000870 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
871 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200872 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200873#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200874 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200875 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200876#else
877 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200878 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200879#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
882#ifdef FEAT_CSCOPE
883 (char_u *)&p_cspc, PV_NONE,
884#else
885 (char_u *)NULL, PV_NONE,
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
889#ifdef FEAT_CSCOPE
890 (char_u *)&p_csprg, PV_NONE,
891 {(char_u *)"cscope", (char_u *)0L}
892#else
893 (char_u *)NULL, PV_NONE,
894 {(char_u *)0L, (char_u *)0L}
895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
898#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
899 (char_u *)&p_csqf, PV_NONE,
900 {(char_u *)"", (char_u *)0L}
901#else
902 (char_u *)NULL, PV_NONE,
903 {(char_u *)0L, (char_u *)0L}
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200906 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_csre, PV_NONE,
909#else
910 (char_u *)NULL, PV_NONE,
911#endif
912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
914#ifdef FEAT_CSCOPE
915 (char_u *)&p_cst, PV_NONE,
916#else
917 (char_u *)NULL, PV_NONE,
918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000919 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_csto, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csverbose, PV_NONE,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200934 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
935#ifdef FEAT_CURSORBIND
936 (char_u *)VAR_WIN, PV_CRBIND,
937#else
938 (char_u *)NULL, PV_NONE,
939#endif
940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000941 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
942#ifdef FEAT_SYN_HL
943 (char_u *)VAR_WIN, PV_CUC,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000947 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000948 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
949#ifdef FEAT_SYN_HL
950 (char_u *)VAR_WIN, PV_CUL,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"debug", NULL, P_STRING|P_VI_DEF,
956 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200958 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000960 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000961 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962#else
963 (char_u *)NULL, PV_NONE,
964 {(char_u *)NULL, (char_u *)0L}
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_MBYTE
969 (char_u *)&p_deco, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
975#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000976 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977#else
978 (char_u *)NULL, PV_NONE,
979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000980 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000981 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
982#ifdef FEAT_DIFF
983 (char_u *)VAR_WIN, PV_DIFF,
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 Moolenaar913077c2012-03-28 19:59:04 +0200988 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
990 (char_u *)&p_dex, PV_NONE,
991 {(char_u *)"", (char_u *)0L}
992#else
993 (char_u *)NULL, PV_NONE,
994 {(char_u *)0L, (char_u *)0L}
995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
998#ifdef FEAT_DIFF
999 (char_u *)&p_dip, PV_NONE,
1000 {(char_u *)"filler", (char_u *)NULL}
1001#else
1002 (char_u *)NULL, PV_NONE,
1003 {(char_u *)"", (char_u *)NULL}
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1007#ifdef FEAT_DIGRAPHS
1008 (char_u *)&p_dg, PV_NONE,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1014 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1017 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001018 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019 {"eadirection", "ead", P_STRING|P_VI_DEF,
1020#ifdef FEAT_VERTSPLIT
1021 (char_u *)&p_ead, PV_NONE,
1022 {(char_u *)"both", (char_u *)0L}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)NULL, (char_u *)0L}
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1029 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001031 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_MBYTE
1033 (char_u *)&p_enc, PV_NONE,
1034 {(char_u *)ENC_DFLT, (char_u *)0L}
1035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)0L, (char_u *)0L}
1038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1041 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1044 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001047 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1050 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1053#ifdef FEAT_QUICKFIX
1054 (char_u *)&p_ef, PV_NONE,
1055 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1056#else
1057 (char_u *)NULL, PV_NONE,
1058 {(char_u *)NULL, (char_u *)0L}
1059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001063 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065#else
1066 (char_u *)NULL, PV_NONE,
1067 {(char_u *)NULL, (char_u *)0L}
1068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"esckeys", "ek", P_BOOL|P_VIM,
1071 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1074#ifdef FEAT_AUTOCMD
1075 (char_u *)&p_ei, PV_NONE,
1076#else
1077 (char_u *)NULL, PV_NONE,
1078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1081 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1084 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1087#ifdef FEAT_MBYTE
1088 (char_u *)&p_fenc, PV_FENC,
1089 {(char_u *)"", (char_u *)0L}
1090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)0L, (char_u *)0L}
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1096#ifdef FEAT_MBYTE
1097 (char_u *)&p_fencs, PV_NONE,
1098 {(char_u *)"ucs-bom", (char_u *)0L}
1099#else
1100 (char_u *)NULL, PV_NONE,
1101 {(char_u *)0L, (char_u *)0L}
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001104 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1108 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1110 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001111 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1112 (char_u *)&p_fic, PV_NONE,
1113 {
1114#ifdef CASE_INSENSITIVE_FILENAME
1115 (char_u *)TRUE,
1116#else
1117 (char_u *)FALSE,
1118#endif
1119 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001120 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121#ifdef FEAT_AUTOCMD
1122 (char_u *)&p_ft, PV_FT,
1123 {(char_u *)"", (char_u *)0L}
1124#else
1125 (char_u *)NULL, PV_NONE,
1126 {(char_u *)0L, (char_u *)0L}
1127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1130#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1131 (char_u *)&p_fcs, PV_NONE,
1132 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1133#else
1134 (char_u *)NULL, PV_NONE,
1135 {(char_u *)"", (char_u *)0L}
1136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1139#ifdef FEAT_FKMAP
1140 (char_u *)&p_fkmap, PV_NONE,
1141#else
1142 (char_u *)NULL, PV_NONE,
1143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 {"flash", "fl", P_BOOL|P_VI_DEF,
1146 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148#ifdef FEAT_FOLDING
1149 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1150 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001151 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1153 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1156 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1159# ifdef FEAT_EVAL
1160 (char_u *)VAR_WIN, PV_FDE,
1161 {(char_u *)"0", (char_u *)NULL}
1162# else
1163 (char_u *)NULL, PV_NONE,
1164 {(char_u *)NULL, (char_u *)0L}
1165# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001166 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1168 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1171 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001173 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1177 P_RWIN|P_COMMA|P_NODUP,
1178 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)"{{{,}}}", (char_u *)NULL}
1180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1182 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001183 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1185 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001186 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1188 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001190 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 (char_u *)&p_fdo, PV_NONE,
1192 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1195# ifdef FEAT_EVAL
1196 (char_u *)VAR_WIN, PV_FDT,
1197 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001198# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 (char_u *)NULL, PV_NONE,
1200 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001201# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001204 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001205#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001206 (char_u *)&p_fex, PV_FEX,
1207 {(char_u *)"", (char_u *)0L}
1208#else
1209 (char_u *)NULL, PV_NONE,
1210 {(char_u *)0L, (char_u *)0L}
1211#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1214 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1216 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001217 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1218 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1220 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1222 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001224 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1225#ifdef HAVE_FSYNC
1226 (char_u *)&p_fs, PV_NONE,
1227 {(char_u *)TRUE, (char_u *)0L}
1228#else
1229 (char_u *)NULL, PV_NONE,
1230 {(char_u *)FALSE, (char_u *)0L}
1231#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001232 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1234 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001235 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 {"graphic", "gr", P_BOOL|P_VI_DEF,
1237 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001238 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1240#ifdef FEAT_QUICKFIX
1241 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001242 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1249#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001250 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 {
1252# ifdef WIN3264
1253 /* may be changed to "grep -n" in os_win32.c */
1254 (char_u *)"findstr /n",
1255# else
1256# ifdef UNIX
1257 /* Add an extra file name so that grep will always
1258 * insert a file name in the match line. */
1259 (char_u *)"grep -n $* /dev/null",
1260# else
1261# ifdef VMS
1262 (char_u *)"SEARCH/NUMBERS ",
1263# else
1264 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001265# endif
1266# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001268 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001273 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1275#ifdef CURSOR_SHAPE
1276 (char_u *)&p_guicursor, PV_NONE,
1277 {
1278# ifdef FEAT_GUI
1279 (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",
1280# else /* MSDOS or Win32 console */
1281 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1282# endif
1283 (char_u *)0L}
1284#else
1285 (char_u *)NULL, PV_NONE,
1286 {(char_u *)NULL, (char_u *)0L}
1287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1290#ifdef FEAT_GUI
1291 (char_u *)&p_guifont, PV_NONE,
1292 {(char_u *)"", (char_u *)0L}
1293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1299#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1300 (char_u *)&p_guifontset, PV_NONE,
1301 {(char_u *)"", (char_u *)0L}
1302#else
1303 (char_u *)NULL, PV_NONE,
1304 {(char_u *)NULL, (char_u *)0L}
1305#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001306 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1308#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1309 (char_u *)&p_guifontwide, PV_NONE,
1310 {(char_u *)"", (char_u *)0L}
1311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001317#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 (char_u *)&p_ghr, PV_NONE,
1319#else
1320 (char_u *)NULL, PV_NONE,
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001324#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 (char_u *)&p_go, PV_NONE,
1326# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001327 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001329 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330# endif
1331#else
1332 (char_u *)NULL, PV_NONE,
1333 {(char_u *)NULL, (char_u *)0L}
1334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001335 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336 {"guipty", NULL, P_BOOL|P_VI_DEF,
1337#if defined(FEAT_GUI)
1338 (char_u *)&p_guipty, PV_NONE,
1339#else
1340 (char_u *)NULL, PV_NONE,
1341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001343 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001344#if defined(FEAT_GUI_TABLINE)
1345 (char_u *)&p_gtl, PV_NONE,
1346 {(char_u *)"", (char_u *)0L}
1347#else
1348 (char_u *)NULL, PV_NONE,
1349 {(char_u *)NULL, (char_u *)0L}
1350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001352 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001353#if defined(FEAT_GUI_TABLINE)
1354 (char_u *)&p_gtt, PV_NONE,
1355 {(char_u *)"", (char_u *)0L}
1356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1362 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1365 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"helpheight", "hh", P_NUM|P_VI_DEF,
1369#ifdef FEAT_WINDOWS
1370 (char_u *)&p_hh, PV_NONE,
1371#else
1372 (char_u *)NULL, PV_NONE,
1373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1376#ifdef FEAT_MULTI_LANG
1377 (char_u *)&p_hlg, PV_NONE,
1378 {(char_u *)"", (char_u *)0L}
1379#else
1380 (char_u *)NULL, PV_NONE,
1381 {(char_u *)0L, (char_u *)0L}
1382#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001383 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 {"hidden", "hid", P_BOOL|P_VI_DEF,
1385 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1388 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001389 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1390 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 {"history", "hi", P_NUM|P_VIM,
1392 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1395#ifdef FEAT_RIGHTLEFT
1396 (char_u *)&p_hkmap, PV_NONE,
1397#else
1398 (char_u *)NULL, PV_NONE,
1399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1402#ifdef FEAT_RIGHTLEFT
1403 (char_u *)&p_hkmapp, PV_NONE,
1404#else
1405 (char_u *)NULL, PV_NONE,
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1409 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {"icon", NULL, P_BOOL|P_VI_DEF,
1412#ifdef FEAT_TITLE
1413 (char_u *)&p_icon, PV_NONE,
1414#else
1415 (char_u *)NULL, PV_NONE,
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"iconstring", NULL, P_STRING|P_VI_DEF,
1419#ifdef FEAT_TITLE
1420 (char_u *)&p_iconstring, PV_NONE,
1421#else
1422 (char_u *)NULL, PV_NONE,
1423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001424 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1426 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001427 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001429#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 (char_u *)&p_imak, PV_NONE,
1431#else
1432 (char_u *)NULL, PV_NONE,
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1436#ifdef USE_IM_CONTROL
1437 (char_u *)&p_imcmdline, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1443#ifdef USE_IM_CONTROL
1444 (char_u *)&p_imdisable, PV_NONE,
1445#else
1446 (char_u *)NULL, PV_NONE,
1447#endif
1448#ifdef __sgi
1449 {(char_u *)TRUE, (char_u *)0L}
1450#else
1451 {(char_u *)FALSE, (char_u *)0L}
1452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 {"iminsert", "imi", P_NUM|P_VI_DEF,
1455 (char_u *)&p_iminsert, PV_IMI,
1456#ifdef B_IMODE_IM
1457 {(char_u *)B_IMODE_IM, (char_u *)0L}
1458#else
1459 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"imsearch", "ims", P_NUM|P_VI_DEF,
1463 (char_u *)&p_imsearch, PV_IMS,
1464#ifdef B_IMODE_IM
1465 {(char_u *)B_IMODE_IM, (char_u *)0L}
1466#else
1467 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001469 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1471#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001472 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1474#else
1475 (char_u *)NULL, PV_NONE,
1476 {(char_u *)0L, (char_u *)0L}
1477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1480#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1481 (char_u *)&p_inex, PV_INEX,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1489 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1492#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1493 (char_u *)&p_inde, PV_INDE,
1494 {(char_u *)"", (char_u *)0L}
1495#else
1496 (char_u *)NULL, PV_NONE,
1497 {(char_u *)0L, (char_u *)0L}
1498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1501#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1502 (char_u *)&p_indk, PV_INDK,
1503 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1504#else
1505 (char_u *)NULL, PV_NONE,
1506 {(char_u *)0L, (char_u *)0L}
1507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001508 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"infercase", "inf", P_BOOL|P_VI_DEF,
1510 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1513 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1516 (char_u *)&p_isf, PV_NONE,
1517 {
1518#ifdef BACKSLASH_IN_FILENAME
1519 /* Excluded are: & and ^ are special in cmd.exe
1520 * ( and ) are used in text separating fnames */
1521 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1522#else
1523# ifdef AMIGA
1524 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1525# else
1526# ifdef VMS
1527 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1528# else /* UNIX et al. */
1529# ifdef EBCDIC
1530 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1531# else
1532 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1533# endif
1534# endif
1535# endif
1536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001537 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1539 (char_u *)&p_isi, PV_NONE,
1540 {
1541#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1542 (char_u *)"@,48-57,_,128-167,224-235",
1543#else
1544# ifdef EBCDIC
1545 /* TODO: EBCDIC Check this! @ == isalpha()*/
1546 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1547 "112-120,128,140-142,156,158,172,"
1548 "174,186,191,203-207,219-225,235-239,"
1549 "251-254",
1550# else
1551 (char_u *)"@,48-57,_,192-255",
1552# endif
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1556 (char_u *)&p_isk, PV_ISK,
1557 {
1558#ifdef EBCDIC
1559 (char_u *)"@,240-249,_",
1560 /* TODO: EBCDIC Check this! @ == isalpha()*/
1561 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1562 "112-120,128,140-142,156,158,172,"
1563 "174,186,191,203-207,219-225,235-239,"
1564 "251-254",
1565#else
1566 (char_u *)"@,48-57,_",
1567# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1568 (char_u *)"@,48-57,_,128-167,224-235"
1569# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001570 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571# endif
1572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001573 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1575 (char_u *)&p_isp, PV_NONE,
1576 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001577#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1578 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 || defined(VMS)
1580 (char_u *)"@,~-255",
1581#else
1582# ifdef EBCDIC
1583 /* all chars above 63 are printable */
1584 (char_u *)"63-255",
1585# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001586 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587# endif
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1591 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001592 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1594#ifdef FEAT_CRYPT
1595 (char_u *)&p_key, PV_KEY,
1596 {(char_u *)"", (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001602 {"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 +00001603#ifdef FEAT_KEYMAP
1604 (char_u *)&p_keymap, PV_KMAP,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)"", (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1612#ifdef FEAT_VISUAL
1613 (char_u *)&p_km, PV_NONE,
1614#else
1615 (char_u *)NULL, PV_NONE,
1616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001619 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {
1621#if defined(MSDOS) || defined(MSWIN)
1622 (char_u *)":help",
1623#else
1624#ifdef VMS
1625 (char_u *)"help",
1626#else
1627# if defined(OS2)
1628 (char_u *)"view /",
1629# else
1630# ifdef USEMAN_S
1631 (char_u *)"man -s",
1632# else
1633 (char_u *)"man",
1634# endif
1635# endif
1636#endif
1637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001638 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1640#ifdef FEAT_LANGMAP
1641 (char_u *)&p_langmap, PV_NONE,
1642 {(char_u *)"", /* unmatched } */
1643#else
1644 (char_u *)NULL, PV_NONE,
1645 {(char_u *)NULL,
1646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001647 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001648 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1650 (char_u *)&p_lm, PV_NONE,
1651#else
1652 (char_u *)NULL, PV_NONE,
1653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1656#ifdef FEAT_WINDOWS
1657 (char_u *)&p_ls, PV_NONE,
1658#else
1659 (char_u *)NULL, PV_NONE,
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1663 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1666#ifdef FEAT_LINEBREAK
1667 (char_u *)VAR_WIN, PV_LBR,
1668#else
1669 (char_u *)NULL, PV_NONE,
1670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1673 (char_u *)&Rows, PV_NONE,
1674 {
1675#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1676 (char_u *)25L,
1677#else
1678 (char_u *)24L,
1679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001680 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1682#ifdef FEAT_GUI
1683 (char_u *)&p_linespace, PV_NONE,
1684#else
1685 (char_u *)NULL, PV_NONE,
1686#endif
1687#ifdef FEAT_GUI_W32
1688 {(char_u *)1L, (char_u *)0L}
1689#else
1690 {(char_u *)0L, (char_u *)0L}
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"lisp", NULL, P_BOOL|P_VI_DEF,
1694#ifdef FEAT_LISP
1695 (char_u *)&p_lisp, PV_LISP,
1696#else
1697 (char_u *)NULL, PV_NONE,
1698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1701#ifdef FEAT_LISP
1702 (char_u *)&p_lispwords, PV_NONE,
1703 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1704#else
1705 (char_u *)NULL, PV_NONE,
1706 {(char_u *)"", (char_u *)0L}
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1710 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1713 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1716 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001718#ifdef FEAT_GUI_MAC
1719 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1720 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"magic", NULL, P_BOOL|P_VI_DEF,
1724 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001726 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727#ifdef FEAT_QUICKFIX
1728 (char_u *)&p_mef, PV_NONE,
1729 {(char_u *)"", (char_u *)0L}
1730#else
1731 (char_u *)NULL, PV_NONE,
1732 {(char_u *)NULL, (char_u *)0L}
1733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1736#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001737 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738# ifdef VMS
1739 {(char_u *)"MMS", (char_u *)0L}
1740# else
1741 {(char_u *)"make", (char_u *)0L}
1742# endif
1743#else
1744 (char_u *)NULL, PV_NONE,
1745 {(char_u *)NULL, (char_u *)0L}
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1749 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 {"matchtime", "mat", P_NUM|P_VI_DEF,
1753 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001755 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001756#ifdef FEAT_MBYTE
1757 (char_u *)&p_mco, PV_NONE,
1758#else
1759 (char_u *)NULL, PV_NONE,
1760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1763#ifdef FEAT_EVAL
1764 (char_u *)&p_mfd, PV_NONE,
1765#else
1766 (char_u *)NULL, PV_NONE,
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1770 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"maxmem", "mm", P_NUM|P_VI_DEF,
1773 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1775 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001776 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1777 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1780 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"menuitems", "mis", P_NUM|P_VI_DEF,
1784#ifdef FEAT_MENU
1785 (char_u *)&p_mis, PV_NONE,
1786#else
1787 (char_u *)NULL, PV_NONE,
1788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"mesg", NULL, P_BOOL|P_VI_DEF,
1791 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001793 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001794#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001795 (char_u *)&p_msm, PV_NONE,
1796 {(char_u *)"460000,2000,500", (char_u *)0L}
1797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)0L, (char_u *)0L}
1800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 {"modeline", "ml", P_BOOL|P_VIM,
1803 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"modelines", "mls", P_NUM|P_VI_DEF,
1806 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1809 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1812 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {"more", NULL, P_BOOL|P_VIM,
1815 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1818 (char_u *)&p_mouse, PV_NONE,
1819 {
1820#if defined(MSDOS) || defined(WIN3264)
1821 (char_u *)"a",
1822#else
1823 (char_u *)"",
1824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1827#ifdef FEAT_GUI
1828 (char_u *)&p_mousef, PV_NONE,
1829#else
1830 (char_u *)NULL, PV_NONE,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1834#ifdef FEAT_GUI
1835 (char_u *)&p_mh, PV_NONE,
1836#else
1837 (char_u *)NULL, PV_NONE,
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1841 (char_u *)&p_mousem, PV_NONE,
1842 {
1843#if defined(MSDOS) || defined(MSWIN)
1844 (char_u *)"popup",
1845#else
1846# if defined(MACOS)
1847 (char_u *)"popup_setpos",
1848# else
1849 (char_u *)"extend",
1850# endif
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1854#ifdef FEAT_MOUSESHAPE
1855 (char_u *)&p_mouseshape, PV_NONE,
1856 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1857#else
1858 (char_u *)NULL, PV_NONE,
1859 {(char_u *)NULL, (char_u *)0L}
1860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1863 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001865 {"mzquantum", "mzq", P_NUM,
1866#ifdef FEAT_MZSCHEME
1867 (char_u *)&p_mzq, PV_NONE,
1868#else
1869 (char_u *)NULL, PV_NONE,
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"novice", NULL, P_BOOL|P_VI_DEF,
1873 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1876 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)"octal,hex", (char_u *)0L}
1878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1880 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001882 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1883#ifdef FEAT_LINEBREAK
1884 (char_u *)VAR_WIN, PV_NUW,
1885#else
1886 (char_u *)NULL, PV_NONE,
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001889 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001890#ifdef FEAT_COMPL_FUNC
1891 (char_u *)&p_ofu, PV_OFU,
1892 {(char_u *)"", (char_u *)0L}
1893#else
1894 (char_u *)NULL, PV_NONE,
1895 {(char_u *)0L, (char_u *)0L}
1896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 {"open", NULL, P_BOOL|P_VI_DEF,
1899 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001901 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1902#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1903 (char_u *)&p_odev, PV_NONE,
1904#else
1905 (char_u *)NULL, PV_NONE,
1906#endif
1907 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001909 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1910 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"optimize", "opt", P_BOOL|P_VI_DEF,
1913 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"paragraphs", "para", P_STRING|P_VI_DEF,
1919 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001920 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001922 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1926 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1929#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1930 (char_u *)&p_pex, PV_NONE,
1931 {(char_u *)"", (char_u *)0L}
1932#else
1933 (char_u *)NULL, PV_NONE,
1934 {(char_u *)0L, (char_u *)0L}
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001937 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001941 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {
1943#if defined AMIGA || defined MSDOS || defined MSWIN
1944 (char_u *)".,,",
1945#else
1946# if defined(__EMX__)
1947 (char_u *)".,/emx/include,,",
1948# else /* Unix, probably */
1949 (char_u *)".,/usr/include,,",
1950# endif
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1954 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001956 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1958 (char_u *)&p_pvh, PV_NONE,
1959#else
1960 (char_u *)NULL, PV_NONE,
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1964#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1965 (char_u *)VAR_WIN, PV_PVW,
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 Moolenaar293ee4d2004-12-09 21:34:53 +00001970 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971#ifdef FEAT_PRINTER
1972 (char_u *)&p_pdev, PV_NONE,
1973 {(char_u *)"", (char_u *)0L}
1974#else
1975 (char_u *)NULL, PV_NONE,
1976 {(char_u *)NULL, (char_u *)0L}
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"printencoding", "penc", P_STRING|P_VI_DEF,
1980#ifdef FEAT_POSTSCRIPT
1981 (char_u *)&p_penc, PV_NONE,
1982 {(char_u *)"", (char_u *)0L}
1983#else
1984 (char_u *)NULL, PV_NONE,
1985 {(char_u *)NULL, (char_u *)0L}
1986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1989#ifdef FEAT_POSTSCRIPT
1990 (char_u *)&p_pexpr, PV_NONE,
1991 {(char_u *)"", (char_u *)0L}
1992#else
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)NULL, (char_u *)0L}
1995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"printfont", "pfn", P_STRING|P_VI_DEF,
1998#ifdef FEAT_PRINTER
1999 (char_u *)&p_pfn, PV_NONE,
2000 {
2001# ifdef MSWIN
2002 (char_u *)"Courier_New:h10",
2003# else
2004 (char_u *)"courier",
2005# endif
2006 (char_u *)0L}
2007#else
2008 (char_u *)NULL, PV_NONE,
2009 {(char_u *)NULL, (char_u *)0L}
2010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002011 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2013#ifdef FEAT_PRINTER
2014 (char_u *)&p_header, PV_NONE,
2015 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2016#else
2017 (char_u *)NULL, PV_NONE,
2018 {(char_u *)NULL, (char_u *)0L}
2019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002021 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2022#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2023 (char_u *)&p_pmcs, PV_NONE,
2024 {(char_u *)"", (char_u *)0L}
2025#else
2026 (char_u *)NULL, PV_NONE,
2027 {(char_u *)NULL, (char_u *)0L}
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002030 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2031#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2032 (char_u *)&p_pmfn, PV_NONE,
2033 {(char_u *)"", (char_u *)0L}
2034#else
2035 (char_u *)NULL, PV_NONE,
2036 {(char_u *)NULL, (char_u *)0L}
2037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2040#ifdef FEAT_PRINTER
2041 (char_u *)&p_popt, PV_NONE,
2042 {(char_u *)"", (char_u *)0L}
2043#else
2044 (char_u *)NULL, PV_NONE,
2045 {(char_u *)NULL, (char_u *)0L}
2046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002049 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002051 {"pumheight", "ph", P_NUM|P_VI_DEF,
2052#ifdef FEAT_INS_EXPAND
2053 (char_u *)&p_ph, PV_NONE,
2054#else
2055 (char_u *)NULL, PV_NONE,
2056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002058 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2059#ifdef FEAT_TEXTOBJ
2060 (char_u *)&p_qe, PV_QE,
2061 {(char_u *)"\\", (char_u *)0L}
2062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)NULL, (char_u *)0L}
2065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2068 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"redraw", NULL, P_BOOL|P_VI_DEF,
2071 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002073 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2074#ifdef FEAT_RELTIME
2075 (char_u *)&p_rdt, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002080 {"regexpengine", "re", P_NUM|P_VI_DEF,
2081 (char_u *)&p_re, PV_NONE,
2082 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002083 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2084 (char_u *)VAR_WIN, PV_RNU,
2085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"remap", NULL, P_BOOL|P_VI_DEF,
2087 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"report", NULL, P_NUM|P_VI_DEF,
2090 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2093#ifdef WIN3264
2094 (char_u *)&p_rs, PV_NONE,
2095#else
2096 (char_u *)NULL, PV_NONE,
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2100#ifdef FEAT_RIGHTLEFT
2101 (char_u *)&p_ri, PV_NONE,
2102#else
2103 (char_u *)NULL, PV_NONE,
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2107#ifdef FEAT_RIGHTLEFT
2108 (char_u *)VAR_WIN, PV_RL,
2109#else
2110 (char_u *)NULL, PV_NONE,
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2114#ifdef FEAT_RIGHTLEFT
2115 (char_u *)VAR_WIN, PV_RLC,
2116 {(char_u *)"search", (char_u *)NULL}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)NULL, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2123#ifdef FEAT_CMDL_INFO
2124 (char_u *)&p_ru, PV_NONE,
2125#else
2126 (char_u *)NULL, PV_NONE,
2127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2130#ifdef FEAT_STL_OPT
2131 (char_u *)&p_ruf, PV_NONE,
2132#else
2133 (char_u *)NULL, PV_NONE,
2134#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002135 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2137 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2141 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002142 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2144#ifdef FEAT_SCROLLBIND
2145 (char_u *)VAR_WIN, PV_SCBIND,
2146#else
2147 (char_u *)NULL, PV_NONE,
2148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2151 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2154 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2157#ifdef FEAT_SCROLLBIND
2158 (char_u *)&p_sbo, PV_NONE,
2159 {(char_u *)"ver,jump", (char_u *)0L}
2160#else
2161 (char_u *)NULL, PV_NONE,
2162 {(char_u *)0L, (char_u *)0L}
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 {"sections", "sect", P_STRING|P_VI_DEF,
2166 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2170 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"selection", "sel", P_STRING|P_VI_DEF,
2173#ifdef FEAT_VISUAL
2174 (char_u *)&p_sel, PV_NONE,
2175#else
2176 (char_u *)NULL, PV_NONE,
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 {(char_u *)"inclusive", (char_u *)0L}
2179 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2181#ifdef FEAT_VISUAL
2182 (char_u *)&p_slm, PV_NONE,
2183#else
2184 (char_u *)NULL, PV_NONE,
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2188#ifdef FEAT_SESSION
2189 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002190 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)0L, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2198 (char_u *)&p_sh, PV_NONE,
2199 {
2200#ifdef VMS
2201 (char_u *)"-",
2202#else
2203# if defined(MSDOS)
2204 (char_u *)"command",
2205# else
2206# if defined(WIN16)
2207 (char_u *)"command.com",
2208# else
2209# if defined(WIN3264)
2210 (char_u *)"", /* set in set_init_1() */
2211# else
2212# if defined(OS2)
2213 (char_u *)"cmd.exe",
2214# else
2215# if defined(ARCHIE)
2216 (char_u *)"gos",
2217# else
2218 (char_u *)"sh",
2219# endif
2220# endif
2221# endif
2222# endif
2223# endif
2224#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2227 (char_u *)&p_shcf, PV_NONE,
2228 {
2229#if defined(MSDOS) || defined(MSWIN)
2230 (char_u *)"/c",
2231#else
2232# if defined(OS2)
2233 (char_u *)"/c",
2234# else
2235 (char_u *)"-c",
2236# endif
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2240#ifdef FEAT_QUICKFIX
2241 (char_u *)&p_sp, PV_NONE,
2242 {
2243#if defined(UNIX) || defined(OS2)
2244# ifdef ARCHIE
2245 (char_u *)"2>",
2246# else
2247 (char_u *)"| tee",
2248# endif
2249#else
2250 (char_u *)">",
2251#endif
2252 (char_u *)0L}
2253#else
2254 (char_u *)NULL, PV_NONE,
2255 {(char_u *)0L, (char_u *)0L}
2256#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002257 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2259 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002260 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2262 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002263 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2265#ifdef BACKSLASH_IN_FILENAME
2266 (char_u *)&p_ssl, PV_NONE,
2267#else
2268 (char_u *)NULL, PV_NONE,
2269#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002271 {"shelltemp", "stmp", P_BOOL,
2272 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"shelltype", "st", P_NUM|P_VI_DEF,
2275#ifdef AMIGA
2276 (char_u *)&p_st, PV_NONE,
2277#else
2278 (char_u *)NULL, PV_NONE,
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2282 (char_u *)&p_sxq, PV_NONE,
2283 {
2284#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2285 (char_u *)"\"",
2286#else
2287 (char_u *)"",
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002290 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2291 (char_u *)&p_sxe, PV_NONE,
2292 {
2293#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2294 (char_u *)"\"&|<>()@^",
2295#else
2296 (char_u *)"",
2297#endif
2298 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2300 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2303 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2306 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)"", (char_u *)"filnxtToO"}
2308 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"shortname", "sn", P_BOOL|P_VI_DEF,
2310#ifdef SHORT_FNAME
2311 (char_u *)NULL, PV_NONE,
2312#else
2313 (char_u *)&p_sn, PV_SN,
2314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2317#ifdef FEAT_LINEBREAK
2318 (char_u *)&p_sbr, PV_NONE,
2319#else
2320 (char_u *)NULL, PV_NONE,
2321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"showcmd", "sc", P_BOOL|P_VIM,
2324#ifdef FEAT_CMDL_INFO
2325 (char_u *)&p_sc, PV_NONE,
2326#else
2327 (char_u *)NULL, PV_NONE,
2328#endif
2329 {(char_u *)FALSE,
2330#ifdef UNIX
2331 (char_u *)FALSE
2332#else
2333 (char_u *)TRUE
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2337 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2340 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002341 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"showmode", "smd", P_BOOL|P_VIM,
2343 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002345 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2346#ifdef FEAT_WINDOWS
2347 (char_u *)&p_stal, PV_NONE,
2348#else
2349 (char_u *)NULL, PV_NONE,
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2353 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2356 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2359 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2362 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2365#ifdef FEAT_SMARTINDENT
2366 (char_u *)&p_si, PV_SI,
2367#else
2368 (char_u *)NULL, PV_NONE,
2369#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2372 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2375 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2378 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002379 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002380 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002381#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002382 (char_u *)VAR_WIN, PV_SPELL,
2383#else
2384 (char_u *)NULL, PV_NONE,
2385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002386 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002387 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002388#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002389 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002390 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002391#else
2392 (char_u *)NULL, PV_NONE,
2393 {(char_u *)0L, (char_u *)0L}
2394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002396 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002397#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002398 (char_u *)&p_spf, PV_SPF,
2399 {(char_u *)"", (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002405 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002406#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002407 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002408 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002409#else
2410 (char_u *)NULL, PV_NONE,
2411 {(char_u *)0L, (char_u *)0L}
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002414 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002415#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002416 (char_u *)&p_sps, PV_NONE,
2417 {(char_u *)"best", (char_u *)0L}
2418#else
2419 (char_u *)NULL, PV_NONE,
2420 {(char_u *)0L, (char_u *)0L}
2421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2424#ifdef FEAT_WINDOWS
2425 (char_u *)&p_sb, PV_NONE,
2426#else
2427 (char_u *)NULL, PV_NONE,
2428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"splitright", "spr", P_BOOL|P_VI_DEF,
2431#ifdef FEAT_VERTSPLIT
2432 (char_u *)&p_spr, PV_NONE,
2433#else
2434 (char_u *)NULL, PV_NONE,
2435#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2438 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2441#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002442 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443#else
2444 (char_u *)NULL, PV_NONE,
2445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2448 (char_u *)&p_su, PV_NONE,
2449 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002452#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 (char_u *)&p_sua, PV_SUA,
2454 {(char_u *)"", (char_u *)0L}
2455#else
2456 (char_u *)NULL, PV_NONE,
2457 {(char_u *)0L, (char_u *)0L}
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2461 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 {"swapsync", "sws", P_STRING|P_VI_DEF,
2464 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2467 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002469 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2470#ifdef FEAT_SYN_HL
2471 (char_u *)&p_smc, PV_SMC,
2472 {(char_u *)3000L, (char_u *)0L}
2473#else
2474 (char_u *)NULL, PV_NONE,
2475 {(char_u *)0L, (char_u *)0L}
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002478 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479#ifdef FEAT_SYN_HL
2480 (char_u *)&p_syn, PV_SYN,
2481 {(char_u *)"", (char_u *)0L}
2482#else
2483 (char_u *)NULL, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L}
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002487 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2488#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002489 (char_u *)&p_tal, PV_NONE,
2490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002494 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2495#ifdef FEAT_WINDOWS
2496 (char_u *)&p_tpm, PV_NONE,
2497#else
2498 (char_u *)NULL, PV_NONE,
2499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2502 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2505 (char_u *)&p_tbs, PV_NONE,
2506#ifdef VMS /* binary searching doesn't appear to work on VMS */
2507 {(char_u *)0L, (char_u *)0L}
2508#else
2509 {(char_u *)TRUE, (char_u *)0L}
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"taglength", "tl", P_NUM|P_VI_DEF,
2513 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"tagrelative", "tr", P_BOOL|P_VIM,
2516 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002519 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {
2521#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2522 (char_u *)"./tags,./TAGS,tags,TAGS",
2523#else
2524 (char_u *)"./tags,tags",
2525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2528 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2531 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002533 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2534#ifdef FEAT_ARABIC
2535 (char_u *)&p_tbidi, PV_NONE,
2536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2541#ifdef FEAT_MBYTE
2542 (char_u *)&p_tenc, PV_NONE,
2543 {(char_u *)"", (char_u *)0L}
2544#else
2545 (char_u *)NULL, PV_NONE,
2546 {(char_u *)0L, (char_u *)0L}
2547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 {"terse", NULL, P_BOOL|P_VI_DEF,
2550 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"textauto", "ta", P_BOOL|P_VIM,
2553 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2555 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2557 (char_u *)&p_tx, PV_TX,
2558 {
2559#ifdef USE_CRNL
2560 (char_u *)TRUE,
2561#else
2562 (char_u *)FALSE,
2563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002565 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2569#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002570 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571#else
2572 (char_u *)NULL, PV_NONE,
2573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2576 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"timeout", "to", P_BOOL|P_VI_DEF,
2579 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2582 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"title", NULL, P_BOOL|P_VI_DEF,
2585#ifdef FEAT_TITLE
2586 (char_u *)&p_title, PV_NONE,
2587#else
2588 (char_u *)NULL, PV_NONE,
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"titlelen", NULL, P_NUM|P_VI_DEF,
2592#ifdef FEAT_TITLE
2593 (char_u *)&p_titlelen, PV_NONE,
2594#else
2595 (char_u *)NULL, PV_NONE,
2596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002598 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599#ifdef FEAT_TITLE
2600 (char_u *)&p_titleold, PV_NONE,
2601 {(char_u *)N_("Thanks for flying Vim"),
2602 (char_u *)0L}
2603#else
2604 (char_u *)NULL, PV_NONE,
2605 {(char_u *)0L, (char_u *)0L}
2606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"titlestring", NULL, P_STRING|P_VI_DEF,
2609#ifdef FEAT_TITLE
2610 (char_u *)&p_titlestring, PV_NONE,
2611#else
2612 (char_u *)NULL, PV_NONE,
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2616 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2617 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)"icons,tooltips", (char_u *)0L}
2619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002621#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2623 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625#endif
2626 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2627 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2630 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2633 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2636 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2639#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2640 (char_u *)&p_ttym, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2646 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2649 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002651 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2652#ifdef FEAT_PERSISTENT_UNDO
2653 (char_u *)&p_udir, PV_NONE,
2654 {(char_u *)".", (char_u *)0L}
2655#else
2656 (char_u *)NULL, PV_NONE,
2657 {(char_u *)0L, (char_u *)0L}
2658#endif
2659 SCRIPTID_INIT},
2660 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2661#ifdef FEAT_PERSISTENT_UNDO
2662 (char_u *)&p_udf, PV_UDF,
2663#else
2664 (char_u *)NULL, PV_NONE,
2665#endif
2666 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"undolevels", "ul", P_NUM|P_VI_DEF,
2668 (char_u *)&p_ul, PV_NONE,
2669 {
2670#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2671 (char_u *)1000L,
2672#else
2673 (char_u *)100L,
2674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002676 {"undoreload", "ur", P_NUM|P_VI_DEF,
2677 (char_u *)&p_ur, PV_NONE,
2678 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"updatecount", "uc", P_NUM|P_VI_DEF,
2680 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"updatetime", "ut", P_NUM|P_VI_DEF,
2683 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"verbose", "vbs", P_NUM|P_VI_DEF,
2686 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002688 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2689 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2692#ifdef FEAT_SESSION
2693 (char_u *)&p_vdir, PV_NONE,
2694 {(char_u *)DFLT_VDIR, (char_u *)0L}
2695#else
2696 (char_u *)NULL, PV_NONE,
2697 {(char_u *)0L, (char_u *)0L}
2698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2701#ifdef FEAT_SESSION
2702 (char_u *)&p_vop, PV_NONE,
2703 {(char_u *)"folds,options,cursor", (char_u *)0L}
2704#else
2705 (char_u *)NULL, PV_NONE,
2706 {(char_u *)0L, (char_u *)0L}
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2710#ifdef FEAT_VIMINFO
2711 (char_u *)&p_viminfo, PV_NONE,
2712#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002713 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714#else
2715# ifdef AMIGA
2716 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002717 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002719 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720# endif
2721#endif
2722#else
2723 (char_u *)NULL, PV_NONE,
2724 {(char_u *)0L, (char_u *)0L}
2725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002727 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728#ifdef FEAT_VIRTUALEDIT
2729 (char_u *)&p_ve, PV_NONE,
2730 {(char_u *)"", (char_u *)""}
2731#else
2732 (char_u *)NULL, PV_NONE,
2733 {(char_u *)0L, (char_u *)0L}
2734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2737 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"w300", NULL, P_NUM|P_VI_DEF,
2740 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"w1200", NULL, P_NUM|P_VI_DEF,
2743 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"w9600", NULL, P_NUM|P_VI_DEF,
2746 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"warn", NULL, P_BOOL|P_VI_DEF,
2749 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2752 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2755 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"wildchar", "wc", P_NUM|P_VIM,
2758 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2760 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002761 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2765#ifdef FEAT_WILDIGN
2766 (char_u *)&p_wig, PV_NONE,
2767#else
2768 (char_u *)NULL, PV_NONE,
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002771 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2772 (char_u *)&p_wic, PV_NONE,
2773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2775#ifdef FEAT_WILDMENU
2776 (char_u *)&p_wmnu, PV_NONE,
2777#else
2778 (char_u *)NULL, PV_NONE,
2779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2782 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002784 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2785#ifdef FEAT_CMDL_COMPL
2786 (char_u *)&p_wop, PV_NONE,
2787 {(char_u *)"", (char_u *)0L}
2788#else
2789 (char_u *)NULL, PV_NONE,
2790 {(char_u *)NULL, (char_u *)0L}
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2794#ifdef FEAT_WAK
2795 (char_u *)&p_wak, PV_NONE,
2796 {(char_u *)"menu", (char_u *)0L}
2797#else
2798 (char_u *)NULL, PV_NONE,
2799 {(char_u *)NULL, (char_u *)0L}
2800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002803 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"winheight", "wh", P_NUM|P_VI_DEF,
2806#ifdef FEAT_WINDOWS
2807 (char_u *)&p_wh, PV_NONE,
2808#else
2809 (char_u *)NULL, PV_NONE,
2810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002813#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 (char_u *)VAR_WIN, PV_WFH,
2815#else
2816 (char_u *)NULL, PV_NONE,
2817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002819 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2820#ifdef FEAT_VERTSPLIT
2821 (char_u *)VAR_WIN, PV_WFW,
2822#else
2823 (char_u *)NULL, PV_NONE,
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2827#ifdef FEAT_WINDOWS
2828 (char_u *)&p_wmh, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2834#ifdef FEAT_VERTSPLIT
2835 (char_u *)&p_wmw, PV_NONE,
2836#else
2837 (char_u *)NULL, PV_NONE,
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2841#ifdef FEAT_VERTSPLIT
2842 (char_u *)&p_wiw, PV_NONE,
2843#else
2844 (char_u *)NULL, PV_NONE,
2845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2848 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2851 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2854 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"write", NULL, P_BOOL|P_VI_DEF,
2857 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"writeany", "wa", P_BOOL|P_VI_DEF,
2860 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2863 (char_u *)&p_wb, PV_NONE,
2864 {
2865#ifdef FEAT_WRITEBACKUP
2866 (char_u *)TRUE,
2867#else
2868 (char_u *)FALSE,
2869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"writedelay", "wd", P_NUM|P_VI_DEF,
2872 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874
2875/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002876#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879
2880 p_term("t_AB", T_CAB)
2881 p_term("t_AF", T_CAF)
2882 p_term("t_AL", T_CAL)
2883 p_term("t_al", T_AL)
2884 p_term("t_bc", T_BC)
2885 p_term("t_cd", T_CD)
2886 p_term("t_ce", T_CE)
2887 p_term("t_cl", T_CL)
2888 p_term("t_cm", T_CM)
2889 p_term("t_Co", T_CCO)
2890 p_term("t_CS", T_CCS)
2891 p_term("t_cs", T_CS)
2892#ifdef FEAT_VERTSPLIT
2893 p_term("t_CV", T_CSV)
2894#endif
2895 p_term("t_ut", T_UT)
2896 p_term("t_da", T_DA)
2897 p_term("t_db", T_DB)
2898 p_term("t_DL", T_CDL)
2899 p_term("t_dl", T_DL)
2900 p_term("t_fs", T_FS)
2901 p_term("t_IE", T_CIE)
2902 p_term("t_IS", T_CIS)
2903 p_term("t_ke", T_KE)
2904 p_term("t_ks", T_KS)
2905 p_term("t_le", T_LE)
2906 p_term("t_mb", T_MB)
2907 p_term("t_md", T_MD)
2908 p_term("t_me", T_ME)
2909 p_term("t_mr", T_MR)
2910 p_term("t_ms", T_MS)
2911 p_term("t_nd", T_ND)
2912 p_term("t_op", T_OP)
2913 p_term("t_RI", T_CRI)
2914 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002915 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 p_term("t_Sb", T_CSB)
2917 p_term("t_Sf", T_CSF)
2918 p_term("t_se", T_SE)
2919 p_term("t_so", T_SO)
2920 p_term("t_sr", T_SR)
2921 p_term("t_ts", T_TS)
2922 p_term("t_te", T_TE)
2923 p_term("t_ti", T_TI)
2924 p_term("t_ue", T_UE)
2925 p_term("t_us", T_US)
2926 p_term("t_vb", T_VB)
2927 p_term("t_ve", T_VE)
2928 p_term("t_vi", T_VI)
2929 p_term("t_vs", T_VS)
2930 p_term("t_WP", T_CWP)
2931 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002932 p_term("t_SI", T_CSI)
2933 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 p_term("t_xs", T_XS)
2935 p_term("t_ZH", T_CZH)
2936 p_term("t_ZR", T_CZR)
2937
2938/* terminal key codes are not in here */
2939
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 /* end marker */
2941 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942};
2943
2944#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2945
2946#ifdef FEAT_MBYTE
2947static char *(p_ambw_values[]) = {"single", "double", NULL};
2948#endif
2949static char *(p_bg_values[]) = {"light", "dark", NULL};
2950static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2951static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002952#ifdef FEAT_CRYPT
2953static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2954#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002955#ifdef FEAT_CMDL_COMPL
2956static char *(p_wop_values[]) = {"tagfile", NULL};
2957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958#ifdef FEAT_WAK
2959static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2960#endif
2961static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2962#ifdef FEAT_VISUAL
2963static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2964static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2965#endif
2966#ifdef FEAT_VISUAL
2967static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2968#endif
2969#ifdef FEAT_BROWSE
2970static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2971#endif
2972#ifdef FEAT_SCROLLBIND
2973static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2974#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002975static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976#ifdef FEAT_VERTSPLIT
2977static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2978#endif
2979#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002980# ifdef FEAT_AUTOCMD
2981static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2982# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002984# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2986#endif
2987static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2988#ifdef FEAT_FOLDING
2989static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002990# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002992# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 NULL};
2994static char *(p_fcl_values[]) = {"all", NULL};
2995#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002996#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002997static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999
3000static void set_option_default __ARGS((int, int opt_flags, int compatible));
3001static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003002static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003003static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004static char_u *illegal_char __ARGS((char_u *, int));
3005static int string_to_key __ARGS((char_u *arg));
3006#ifdef FEAT_CMDWIN
3007static char_u *check_cedit __ARGS((void));
3008#endif
3009#ifdef FEAT_TITLE
3010static void did_set_title __ARGS((int icon));
3011#endif
3012static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3013static void didset_options __ARGS((void));
3014static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003015#if defined(FEAT_EVAL) || defined(PROTO)
3016static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3017#else
3018# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003021static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3023static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003024#ifdef FEAT_SYN_HL
3025static int int_cmp __ARGS((const void *a, const void *b));
3026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027#ifdef FEAT_CLIPBOARD
3028static char_u *check_clipboard_option __ARGS((void));
3029#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003030#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003031static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003032#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003033#ifdef FEAT_EVAL
3034static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003037static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038static void check_redraw __ARGS((long_u flags));
3039static int findoption __ARGS((char_u *));
3040static int find_key_option __ARGS((char_u *));
3041static void showoptions __ARGS((int all, int opt_flags));
3042static int optval_default __ARGS((struct vimoption *, char_u *varp));
3043static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3044static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3045static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3046static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3047static int istermoption __ARGS((struct vimoption *));
3048static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3049static char_u *get_varp __ARGS((struct vimoption *));
3050static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3051static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3052#ifdef FEAT_LANGMAP
3053static void langmap_init __ARGS((void));
3054static void langmap_set __ARGS((void));
3055#endif
3056static void paste_option_changed __ARGS((void));
3057static void compatible_set __ARGS((void));
3058#ifdef FEAT_LINEBREAK
3059static void fill_breakat_flags __ARGS((void));
3060#endif
3061static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3062static int check_opt_strings __ARGS((char_u *val, char **values, int));
3063static int check_opt_wim __ARGS((void));
3064
3065/*
3066 * Initialize the options, first part.
3067 *
3068 * Called only once from main(), just after creating the first buffer.
3069 */
3070 void
3071set_init_1()
3072{
3073 char_u *p;
3074 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003075 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076
3077#ifdef FEAT_LANGMAP
3078 langmap_init();
3079#endif
3080
3081 /* Be Vi compatible by default */
3082 p_cp = TRUE;
3083
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003084 /* Use POSIX compatibility when $VIM_POSIX is set. */
3085 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003086 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003087 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003088 set_string_default("shm", (char_u *)"A");
3089 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003090
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 /*
3092 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003093 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003095 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3097# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003098 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003100 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003102 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103# endif
3104#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003105 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 set_string_default("sh", p);
3107
3108#ifdef FEAT_WILDIGN
3109 /*
3110 * Set the default for 'backupskip' to include environment variables for
3111 * temp files.
3112 */
3113 {
3114# ifdef UNIX
3115 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3116# else
3117 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3118# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003119 int len;
3120 garray_T ga;
3121 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122
3123 ga_init2(&ga, 1, 100);
3124 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3125 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003126 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127# ifdef UNIX
3128 if (*names[n] == NUL)
3129 p = (char_u *)"/tmp";
3130 else
3131# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003132 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 if (p != NULL && *p != NUL)
3134 {
3135 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003136 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 if (ga_grow(&ga, len) == OK)
3138 {
3139 if (ga.ga_len > 0)
3140 STRCAT(ga.ga_data, ",");
3141 STRCAT(ga.ga_data, p);
3142 add_pathsep(ga.ga_data);
3143 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 ga.ga_len += len;
3145 }
3146 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003147 if (mustfree)
3148 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 }
3150 if (ga.ga_data != NULL)
3151 {
3152 set_string_default("bsk", ga.ga_data);
3153 vim_free(ga.ga_data);
3154 }
3155 }
3156#endif
3157
3158 /*
3159 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3160 */
3161 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003162 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003164#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3165 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3166#endif
3167 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003169 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003170 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171#else
3172# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003173 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003174 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003176 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177# endif
3178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003180 opt_idx = findoption((char_u *)"maxmem");
3181 if (opt_idx >= 0)
3182 {
3183#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3184 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3185 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3186#endif
3187 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3188 }
3189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 }
3191
3192#ifdef FEAT_GUI_W32
3193 /* force 'shortname' for Win32s */
3194 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003195 {
3196 opt_idx = findoption((char_u *)"shortname");
3197 if (opt_idx >= 0)
3198 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200#endif
3201
3202#ifdef FEAT_SEARCHPATH
3203 {
3204 char_u *cdpath;
3205 char_u *buf;
3206 int i;
3207 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003208 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209
3210 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003211 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 if (cdpath != NULL)
3213 {
3214 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3215 if (buf != NULL)
3216 {
3217 buf[0] = ','; /* start with ",", current dir first */
3218 j = 1;
3219 for (i = 0; cdpath[i] != NUL; ++i)
3220 {
3221 if (vim_ispathlistsep(cdpath[i]))
3222 buf[j++] = ',';
3223 else
3224 {
3225 if (cdpath[i] == ' ' || cdpath[i] == ',')
3226 buf[j++] = '\\';
3227 buf[j++] = cdpath[i];
3228 }
3229 }
3230 buf[j] = NUL;
3231 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003232 if (opt_idx >= 0)
3233 {
3234 options[opt_idx].def_val[VI_DEFAULT] = buf;
3235 options[opt_idx].flags |= P_DEF_ALLOCED;
3236 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003237 else
3238 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003240 if (mustfree)
3241 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 }
3243 }
3244#endif
3245
3246#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3247 /* Set print encoding on platforms that don't default to latin1 */
3248 set_string_default("penc",
3249# if defined(MSWIN) || defined(OS2)
3250 (char_u *)"cp1252"
3251# else
3252# ifdef VMS
3253 (char_u *)"dec-mcs"
3254# else
3255# ifdef EBCDIC
3256 (char_u *)"ebcdic-uk"
3257# else
3258# ifdef MAC
3259 (char_u *)"mac-roman"
3260# else /* HPUX */
3261 (char_u *)"hp-roman8"
3262# endif
3263# endif
3264# endif
3265# endif
3266 );
3267#endif
3268
3269#ifdef FEAT_POSTSCRIPT
3270 /* 'printexpr' must be allocated to be able to evaluate it. */
3271 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003272# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3273 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274# else
3275# ifdef VMS
3276 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3277
3278# else
3279 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3280# endif
3281# endif
3282 );
3283#endif
3284
3285 /*
3286 * Set all the options (except the terminal options) to their default
3287 * value. Also set the global value for local options.
3288 */
3289 set_options_default(0);
3290
3291#ifdef FEAT_GUI
3292 if (found_reverse_arg)
3293 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3294#endif
3295
3296 curbuf->b_p_initialized = TRUE;
3297 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3298 check_buf_options(curbuf);
3299 check_win_options(curwin);
3300 check_options();
3301
3302 /* Must be before option_expand(), because that one needs vim_isIDc() */
3303 didset_options();
3304
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003305#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003306 /* Use the current chartab for the generic chartab. */
3307 init_spell_chartab();
3308#endif
3309
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#ifdef FEAT_LINEBREAK
3311 /*
3312 * initialize the table for 'breakat'.
3313 */
3314 fill_breakat_flags();
3315#endif
3316
3317 /*
3318 * Expand environment variables and things like "~" for the defaults.
3319 * If option_expand() returns non-NULL the variable is expanded. This can
3320 * only happen for non-indirect options.
3321 * Also set the default to the expanded value, so ":set" does not list
3322 * them.
3323 * Don't set the P_ALLOCED flag, because we don't want to free the
3324 * default.
3325 */
3326 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3327 {
3328 if ((options[opt_idx].flags & P_GETTEXT)
3329 && options[opt_idx].var != NULL)
3330 p = (char_u *)_(*(char **)options[opt_idx].var);
3331 else
3332 p = option_expand(opt_idx, NULL);
3333 if (p != NULL && (p = vim_strsave(p)) != NULL)
3334 {
3335 *(char_u **)options[opt_idx].var = p;
3336 /* VIMEXP
3337 * Defaults for all expanded options are currently the same for Vi
3338 * and Vim. When this changes, add some code here! Also need to
3339 * split P_DEF_ALLOCED in two.
3340 */
3341 if (options[opt_idx].flags & P_DEF_ALLOCED)
3342 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3343 options[opt_idx].def_val[VI_DEFAULT] = p;
3344 options[opt_idx].flags |= P_DEF_ALLOCED;
3345 }
3346 }
3347
3348 /* Initialize the highlight_attr[] table. */
3349 highlight_changed();
3350
3351 save_file_ff(curbuf); /* Buffer is unchanged */
3352
3353 /* Parse default for 'wildmode' */
3354 check_opt_wim();
3355
3356#if defined(FEAT_ARABIC)
3357 /* Detect use of mlterm.
3358 * Mlterm is a terminal emulator akin to xterm that has some special
3359 * abilities (bidi namely).
3360 * NOTE: mlterm's author is being asked to 'set' a variable
3361 * instead of an environment variable due to inheritance.
3362 */
3363 if (mch_getenv((char_u *)"MLTERM") != NULL)
3364 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3365#endif
3366
3367#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3368 /* Parse default for 'fillchars'. */
3369 (void)set_chars_option(&p_fcs);
3370#endif
3371
3372#ifdef FEAT_CLIPBOARD
3373 /* Parse default for 'clipboard' */
3374 (void)check_clipboard_option();
3375#endif
3376
3377#ifdef FEAT_MBYTE
3378# if defined(WIN3264) && defined(FEAT_GETTEXT)
3379 /*
3380 * If $LANG isn't set, try to get a good value for it. This makes the
3381 * right language be used automatically. Don't do this for English.
3382 */
3383 if (mch_getenv((char_u *)"LANG") == NULL)
3384 {
3385 char buf[20];
3386
3387 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3388 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3389 * only the first two. */
3390 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3391 (LPTSTR)buf, 20);
3392 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3393 {
3394 /* There are a few exceptions (probably more) */
3395 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3396 STRCPY(buf, "zh_TW");
3397 else if (STRNICMP(buf, "chs", 3) == 0
3398 || STRNICMP(buf, "zhc", 3) == 0)
3399 STRCPY(buf, "zh_CN");
3400 else if (STRNICMP(buf, "jp", 2) == 0)
3401 STRCPY(buf, "ja");
3402 else
3403 buf[2] = NUL; /* truncate to two-letter code */
3404 vim_setenv("LANG", buf);
3405 }
3406 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003407# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003408# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003409 /* Moved to os_mac_conv.c to avoid dependency problems. */
3410 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003411# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412# endif
3413
3414 /* enc_locale() will try to find the encoding of the current locale. */
3415 p = enc_locale();
3416 if (p != NULL)
3417 {
3418 char_u *save_enc;
3419
3420 /* Try setting 'encoding' and check if the value is valid.
3421 * If not, go back to the default "latin1". */
3422 save_enc = p_enc;
3423 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003424 if (STRCMP(p_enc, "gb18030") == 0)
3425 {
3426 /* We don't support "gb18030", but "cp936" is a good substitute
3427 * for practical purposes, thus use that. It's not an alias to
3428 * still support conversion between gb18030 and utf-8. */
3429 p_enc = vim_strsave((char_u *)"cp936");
3430 vim_free(p);
3431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 if (mb_init() == NULL)
3433 {
3434 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003435 if (opt_idx >= 0)
3436 {
3437 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3438 options[opt_idx].flags |= P_DEF_ALLOCED;
3439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003441#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3442 || defined(VMS)
3443 if (STRCMP(p_enc, "latin1") == 0
3444# ifdef FEAT_MBYTE
3445 || enc_utf8
3446# endif
3447 )
3448 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003449 /* Adjust the default for 'isprint' and 'iskeyword' to match
3450 * latin1. Also set the defaults for when 'nocompatible' is
3451 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003452 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003453 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003454 set_string_option_direct((char_u *)"isk", -1,
3455 ISK_LATIN1, OPT_FREE, SID_NONE);
3456 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 if (opt_idx >= 0)
3458 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003459 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003460 if (opt_idx >= 0)
3461 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003462 (void)init_chartab();
3463 }
3464#endif
3465
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466# if defined(WIN3264) && !defined(FEAT_GUI)
3467 /* Win32 console: When GetACP() returns a different value from
3468 * GetConsoleCP() set 'termencoding'. */
3469 if (GetACP() != GetConsoleCP())
3470 {
3471 char buf[50];
3472
3473 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3474 p_tenc = vim_strsave((char_u *)buf);
3475 if (p_tenc != NULL)
3476 {
3477 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003478 if (opt_idx >= 0)
3479 {
3480 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3481 options[opt_idx].flags |= P_DEF_ALLOCED;
3482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 convert_setup(&input_conv, p_tenc, p_enc);
3484 convert_setup(&output_conv, p_enc, p_tenc);
3485 }
3486 else
3487 p_tenc = empty_option;
3488 }
3489# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003490# if defined(WIN3264) && defined(FEAT_MBYTE)
3491 /* $HOME may have characters in active code page. */
3492 init_homedir();
3493# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494 }
3495 else
3496 {
3497 vim_free(p_enc);
3498 p_enc = save_enc;
3499 }
3500 }
3501#endif
3502
3503#ifdef FEAT_MULTI_LANG
3504 /* Set the default for 'helplang'. */
3505 set_helplang_default(get_mess_lang());
3506#endif
3507}
3508
3509/*
3510 * Set an option to its default value.
3511 * This does not take care of side effects!
3512 */
3513 static void
3514set_option_default(opt_idx, opt_flags, compatible)
3515 int opt_idx;
3516 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3517 int compatible; /* use Vi default value */
3518{
3519 char_u *varp; /* pointer to variable for current option */
3520 int dvi; /* index in def_val[] */
3521 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003522 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3524
3525 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3526 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003527 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 {
3529 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3530 if (flags & P_STRING)
3531 {
3532 /* Use set_string_option_direct() for local options to handle
3533 * freeing and allocating the value. */
3534 if (options[opt_idx].indir != PV_NONE)
3535 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003536 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 else
3538 {
3539 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3540 free_string_option(*(char_u **)(varp));
3541 *(char_u **)varp = options[opt_idx].def_val[dvi];
3542 options[opt_idx].flags &= ~P_ALLOCED;
3543 }
3544 }
3545 else if (flags & P_NUM)
3546 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003547 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548 win_comp_scroll(curwin);
3549 else
3550 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003551 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552 /* May also set global value for local option. */
3553 if (both)
3554 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3555 *(long *)varp;
3556 }
3557 }
3558 else /* P_BOOL */
3559 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003560 /* the cast to long is required for Manx C, long_i is needed for
3561 * MSVC */
3562 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003563#ifdef UNIX
3564 /* 'modeline' defaults to off for root */
3565 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3566 *(int *)varp = FALSE;
3567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568 /* May also set global value for local option. */
3569 if (both)
3570 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3571 *(int *)varp;
3572 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003573
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003574 /* The default value is not insecure. */
3575 flagsp = insecure_flag(opt_idx, opt_flags);
3576 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577 }
3578
3579#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003580 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581#endif
3582}
3583
3584/*
3585 * Set all options (except terminal options) to their default value.
3586 */
3587 static void
3588set_options_default(opt_flags)
3589 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3590{
3591 int i;
3592#ifdef FEAT_WINDOWS
3593 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003594 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595#endif
3596
3597 for (i = 0; !istermoption(&options[i]); i++)
3598 if (!(options[i].flags & P_NODEFAULT))
3599 set_option_default(i, opt_flags, p_cp);
3600
3601#ifdef FEAT_WINDOWS
3602 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003603 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 win_comp_scroll(wp);
3605#else
3606 win_comp_scroll(curwin);
3607#endif
3608}
3609
3610/*
3611 * Set the Vi-default value of a string option.
3612 * Used for 'sh', 'backupskip' and 'term'.
3613 */
3614 void
3615set_string_default(name, val)
3616 char *name;
3617 char_u *val;
3618{
3619 char_u *p;
3620 int opt_idx;
3621
3622 p = vim_strsave(val);
3623 if (p != NULL) /* we don't want a NULL */
3624 {
3625 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003626 if (opt_idx >= 0)
3627 {
3628 if (options[opt_idx].flags & P_DEF_ALLOCED)
3629 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3630 options[opt_idx].def_val[VI_DEFAULT] = p;
3631 options[opt_idx].flags |= P_DEF_ALLOCED;
3632 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633 }
3634}
3635
3636/*
3637 * Set the Vi-default value of a number option.
3638 * Used for 'lines' and 'columns'.
3639 */
3640 void
3641set_number_default(name, val)
3642 char *name;
3643 long val;
3644{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003645 int opt_idx;
3646
3647 opt_idx = findoption((char_u *)name);
3648 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003649 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650}
3651
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003652#if defined(EXITFREE) || defined(PROTO)
3653/*
3654 * Free all options.
3655 */
3656 void
3657free_all_options()
3658{
3659 int i;
3660
3661 for (i = 0; !istermoption(&options[i]); i++)
3662 {
3663 if (options[i].indir == PV_NONE)
3664 {
3665 /* global option: free value and default value. */
3666 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3667 free_string_option(*(char_u **)options[i].var);
3668 if (options[i].flags & P_DEF_ALLOCED)
3669 free_string_option(options[i].def_val[VI_DEFAULT]);
3670 }
3671 else if (options[i].var != VAR_WIN
3672 && (options[i].flags & P_STRING))
3673 /* buffer-local option: free global value */
3674 free_string_option(*(char_u **)options[i].var);
3675 }
3676}
3677#endif
3678
3679
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680/*
3681 * Initialize the options, part two: After getting Rows and Columns and
3682 * setting 'term'.
3683 */
3684 void
3685set_init_2()
3686{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003687 int idx;
3688
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689 /*
3690 * 'scroll' defaults to half the window height. Note that this default is
3691 * wrong when the window height changes.
3692 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003693 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003694 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003695 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003696 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697 comp_col();
3698
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003699 /*
3700 * 'window' is only for backwards compatibility with Vi.
3701 * Default is Rows - 1.
3702 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003703 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003704 p_window = Rows - 1;
3705 set_number_default("window", Rows - 1);
3706
Bram Moolenaarf740b292006-02-16 22:11:02 +00003707 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003709 /*
3710 * If 'background' wasn't set by the user, try guessing the value,
3711 * depending on the terminal name. Only need to check for terminals
3712 * with a dark background, that can handle color.
3713 */
3714 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003715 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3716 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003718 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003719 /* don't mark it as set, when starting the GUI it may be
3720 * changed again */
3721 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 }
3723#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003724
3725#ifdef CURSOR_SHAPE
3726 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3727#endif
3728#ifdef FEAT_MOUSESHAPE
3729 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3730#endif
3731#ifdef FEAT_PRINTER
3732 (void)parse_printoptions(); /* parse 'printoptions' default value */
3733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734}
3735
3736/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003737 * Return "dark" or "light" depending on the kind of terminal.
3738 * This is just guessing! Recognized are:
3739 * "linux" Linux console
3740 * "screen.linux" Linux console with screen
3741 * "cygwin" Cygwin shell
3742 * "putty" Putty program
3743 * We also check the COLORFGBG environment variable, which is set by
3744 * rxvt and derivatives. This variable contains either two or three
3745 * values separated by semicolons; we want the last value in either
3746 * case. If this value is 0-6 or 8, our background is dark.
3747 */
3748 static char_u *
3749term_bg_default()
3750{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003751#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3752 /* DOS console nearly always black */
3753 return (char_u *)"dark";
3754#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003755 char_u *p;
3756
Bram Moolenaarf740b292006-02-16 22:11:02 +00003757 if (STRCMP(T_NAME, "linux") == 0
3758 || STRCMP(T_NAME, "screen.linux") == 0
3759 || STRCMP(T_NAME, "cygwin") == 0
3760 || STRCMP(T_NAME, "putty") == 0
3761 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3762 && (p = vim_strrchr(p, ';')) != NULL
3763 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3764 && p[2] == NUL))
3765 return (char_u *)"dark";
3766 return (char_u *)"light";
3767#endif
3768}
3769
3770/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 * Initialize the options, part three: After reading the .vimrc
3772 */
3773 void
3774set_init_3()
3775{
3776#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3777/*
3778 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3779 * This is done after other initializations, where 'shell' might have been
3780 * set, but only if they have not been set before.
3781 */
3782 char_u *p;
3783 int idx_srr;
3784 int do_srr;
3785#ifdef FEAT_QUICKFIX
3786 int idx_sp;
3787 int do_sp;
3788#endif
3789
3790 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003791 if (idx_srr < 0)
3792 do_srr = FALSE;
3793 else
3794 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795#ifdef FEAT_QUICKFIX
3796 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003797 if (idx_sp < 0)
3798 do_sp = FALSE;
3799 else
3800 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801#endif
3802
3803 /*
3804 * Isolate the name of the shell:
3805 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3806 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003807 * But don't allow a space in the path, so that this works:
3808 * "/usr/bin/csh --rcfile ~/.cshrc"
3809 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003811#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 p = gettail(p_sh);
3813 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003814#else
3815 p = skiptowhite(p_sh);
3816 if (*p == NUL)
3817 {
3818 /* No white space, use the tail. */
3819 p = vim_strsave(gettail(p_sh));
3820 }
3821 else
3822 {
3823 char_u *p1, *p2;
3824
3825 /* Find the last path separator before the space. */
3826 p1 = p_sh;
3827 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3828 if (vim_ispathsep(*p2))
3829 p1 = p2 + 1;
3830 p = vim_strnsave(p1, (int)(p - p1));
3831 }
3832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 if (p != NULL)
3834 {
3835 /*
3836 * Default for p_sp is "| tee", for p_srr is ">".
3837 * For known shells it is changed here to include stderr.
3838 */
3839 if ( fnamecmp(p, "csh") == 0
3840 || fnamecmp(p, "tcsh") == 0
3841# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3842 || fnamecmp(p, "csh.exe") == 0
3843 || fnamecmp(p, "tcsh.exe") == 0
3844# endif
3845 )
3846 {
3847#if defined(FEAT_QUICKFIX)
3848 if (do_sp)
3849 {
3850# ifdef WIN3264
3851 p_sp = (char_u *)">&";
3852# else
3853 p_sp = (char_u *)"|& tee";
3854# endif
3855 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3856 }
3857#endif
3858 if (do_srr)
3859 {
3860 p_srr = (char_u *)">&";
3861 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3862 }
3863 }
3864 else
3865# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3866 if ( fnamecmp(p, "sh") == 0
3867 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003868 || fnamecmp(p, "mksh") == 0
3869 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003871 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 || fnamecmp(p, "bash") == 0
3873# ifdef WIN3264
3874 || fnamecmp(p, "cmd") == 0
3875 || fnamecmp(p, "sh.exe") == 0
3876 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003877 || fnamecmp(p, "mksh.exe") == 0
3878 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003880 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881 || fnamecmp(p, "bash.exe") == 0
3882 || fnamecmp(p, "cmd.exe") == 0
3883# endif
3884 )
3885# endif
3886 {
3887#if defined(FEAT_QUICKFIX)
3888 if (do_sp)
3889 {
3890# ifdef WIN3264
3891 p_sp = (char_u *)">%s 2>&1";
3892# else
3893 p_sp = (char_u *)"2>&1| tee";
3894# endif
3895 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3896 }
3897#endif
3898 if (do_srr)
3899 {
3900 p_srr = (char_u *)">%s 2>&1";
3901 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3902 }
3903 }
3904 vim_free(p);
3905 }
3906#endif
3907
3908#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3909 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003910 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3911 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 * This is done after other initializations, where 'shell' might have been
3913 * set, but only if they have not been set before. Default for p_shcf is
3914 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3915 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3916 * command.com. And for Win32 we need to set p_sxq instead.
3917 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003918 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 {
3920 int idx3;
3921
3922 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003923 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 {
3925 p_shcf = (char_u *)"-c";
3926 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3927 }
3928
3929# ifndef DJGPP
3930# ifdef WIN3264
3931 /* Somehow Win32 requires the quotes around the redirection too */
3932 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003933 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 {
3935 p_sxq = (char_u *)"\"";
3936 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3937 }
3938# else
3939 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003940 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 {
3942 p_shq = (char_u *)"\"";
3943 options[idx3].def_val[VI_DEFAULT] = p_shq;
3944 }
3945# endif
3946# endif
3947 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003948 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3949 {
3950 int idx3;
3951
3952 /*
3953 * cmd.exe on Windows will strip the first and last double quote given
3954 * on the command line, e.g. most of the time things like:
3955 * cmd /c "my path/to/echo" "my args to echo"
3956 * become:
3957 * my path/to/echo" "my args to echo
3958 * when executed.
3959 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003960 * To avoid this, set shellxquote to surround the command in
3961 * parenthesis. This appears to make most commands work, without
3962 * breaking commands that worked previously, such as
3963 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003964 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003965 idx3 = findoption((char_u *)"sxq");
3966 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3967 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003968 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003969 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3970 }
3971
Bram Moolenaara64ba222012-02-12 23:23:31 +01003972 idx3 = findoption((char_u *)"shcf");
3973 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3974 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003975 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003976 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3977 }
3978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979#endif
3980
3981#ifdef FEAT_TITLE
3982 set_title_defaults();
3983#endif
3984}
3985
3986#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3987/*
3988 * When 'helplang' is still at its default value, set it to "lang".
3989 * Only the first two characters of "lang" are used.
3990 */
3991 void
3992set_helplang_default(lang)
3993 char_u *lang;
3994{
3995 int idx;
3996
3997 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3998 return;
3999 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004000 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001 {
4002 if (options[idx].flags & P_ALLOCED)
4003 free_string_option(p_hlg);
4004 p_hlg = vim_strsave(lang);
4005 if (p_hlg == NULL)
4006 p_hlg = empty_option;
4007 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004008 {
4009 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4010 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4011 {
4012 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4013 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004016 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 options[idx].flags |= P_ALLOCED;
4018 }
4019}
4020#endif
4021
4022#ifdef FEAT_GUI
4023static char_u *gui_bg_default __ARGS((void));
4024
4025 static char_u *
4026gui_bg_default()
4027{
4028 if (gui_get_lightness(gui.back_pixel) < 127)
4029 return (char_u *)"dark";
4030 return (char_u *)"light";
4031}
4032
4033/*
4034 * Option initializations that can only be done after opening the GUI window.
4035 */
4036 void
4037init_gui_options()
4038{
4039 /* Set the 'background' option according to the lightness of the
4040 * background color, unless the user has set it already. */
4041 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4042 {
4043 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4044 highlight_changed();
4045 }
4046}
4047#endif
4048
4049#ifdef FEAT_TITLE
4050/*
4051 * 'title' and 'icon' only default to true if they have not been set or reset
4052 * in .vimrc and we can read the old value.
4053 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4054 * they can be reset. This reduces startup time when using X on a remote
4055 * machine.
4056 */
4057 void
4058set_title_defaults()
4059{
4060 int idx1;
4061 long val;
4062
4063 /*
4064 * If GUI is (going to be) used, we can always set the window title and
4065 * icon name. Saves a bit of time, because the X11 display server does
4066 * not need to be contacted.
4067 */
4068 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004069 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 {
4071#ifdef FEAT_GUI
4072 if (gui.starting || gui.in_use)
4073 val = TRUE;
4074 else
4075#endif
4076 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004077 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 p_title = val;
4079 }
4080 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004081 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 {
4083#ifdef FEAT_GUI
4084 if (gui.starting || gui.in_use)
4085 val = TRUE;
4086 else
4087#endif
4088 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004089 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 p_icon = val;
4091 }
4092}
4093#endif
4094
4095/*
4096 * Parse 'arg' for option settings.
4097 *
4098 * 'arg' may be IObuff, but only when no errors can be present and option
4099 * does not need to be expanded with option_expand().
4100 * "opt_flags":
4101 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004102 * OPT_GLOBAL for ":setglobal"
4103 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004105 * OPT_WINONLY to only set window-local options
4106 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 *
4108 * returns FAIL if an error is detected, OK otherwise
4109 */
4110 int
4111do_set(arg, opt_flags)
4112 char_u *arg; /* option string (may be written to!) */
4113 int opt_flags;
4114{
4115 int opt_idx;
4116 char_u *errmsg;
4117 char_u errbuf[80];
4118 char_u *startarg;
4119 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4120 int nextchar; /* next non-white char after option name */
4121 int afterchar; /* character just after option name */
4122 int len;
4123 int i;
4124 long value;
4125 int key;
4126 long_u flags; /* flags for current option */
4127 char_u *varp = NULL; /* pointer to variable for current option */
4128 int did_show = FALSE; /* already showed one value */
4129 int adding; /* "opt+=arg" */
4130 int prepending; /* "opt^=arg" */
4131 int removing; /* "opt-=arg" */
4132 int cp_val = 0;
4133 char_u key_name[2];
4134
4135 if (*arg == NUL)
4136 {
4137 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004138 did_show = TRUE;
4139 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 }
4141
4142 while (*arg != NUL) /* loop to process all options */
4143 {
4144 errmsg = NULL;
4145 startarg = arg; /* remember for error message */
4146
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004147 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4148 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 {
4150 /*
4151 * ":set all" show all options.
4152 * ":set all&" set all options to their default value.
4153 */
4154 arg += 3;
4155 if (*arg == '&')
4156 {
4157 ++arg;
4158 /* Only for :set command set global value of local options. */
4159 set_options_default(OPT_FREE | opt_flags);
4160 }
4161 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004162 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004164 did_show = TRUE;
4165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004167 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 {
4169 showoptions(2, opt_flags);
4170 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004171 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 arg += 7;
4173 }
4174 else
4175 {
4176 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004177 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 {
4179 prefix = 0;
4180 arg += 2;
4181 }
4182 else if (STRNCMP(arg, "inv", 3) == 0)
4183 {
4184 prefix = 2;
4185 arg += 3;
4186 }
4187
4188 /* find end of name */
4189 key = 0;
4190 if (*arg == '<')
4191 {
4192 nextchar = 0;
4193 opt_idx = -1;
4194 /* look out for <t_>;> */
4195 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4196 len = 5;
4197 else
4198 {
4199 len = 1;
4200 while (arg[len] != NUL && arg[len] != '>')
4201 ++len;
4202 }
4203 if (arg[len] != '>')
4204 {
4205 errmsg = e_invarg;
4206 goto skip;
4207 }
4208 arg[len] = NUL; /* put NUL after name */
4209 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4210 opt_idx = findoption(arg + 1);
4211 arg[len++] = '>'; /* restore '>' */
4212 if (opt_idx == -1)
4213 key = find_key_option(arg + 1);
4214 }
4215 else
4216 {
4217 len = 0;
4218 /*
4219 * The two characters after "t_" may not be alphanumeric.
4220 */
4221 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4222 len = 4;
4223 else
4224 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4225 ++len;
4226 nextchar = arg[len];
4227 arg[len] = NUL; /* put NUL after name */
4228 opt_idx = findoption(arg);
4229 arg[len] = nextchar; /* restore nextchar */
4230 if (opt_idx == -1)
4231 key = find_key_option(arg);
4232 }
4233
4234 /* remember character after option name */
4235 afterchar = arg[len];
4236
4237 /* skip white space, allow ":set ai ?" */
4238 while (vim_iswhite(arg[len]))
4239 ++len;
4240
4241 adding = FALSE;
4242 prepending = FALSE;
4243 removing = FALSE;
4244 if (arg[len] != NUL && arg[len + 1] == '=')
4245 {
4246 if (arg[len] == '+')
4247 {
4248 adding = TRUE; /* "+=" */
4249 ++len;
4250 }
4251 else if (arg[len] == '^')
4252 {
4253 prepending = TRUE; /* "^=" */
4254 ++len;
4255 }
4256 else if (arg[len] == '-')
4257 {
4258 removing = TRUE; /* "-=" */
4259 ++len;
4260 }
4261 }
4262 nextchar = arg[len];
4263
4264 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4265 {
4266 errmsg = (char_u *)N_("E518: Unknown option");
4267 goto skip;
4268 }
4269
4270 if (opt_idx >= 0)
4271 {
4272 if (options[opt_idx].var == NULL) /* hidden option: skip */
4273 {
4274 /* Only give an error message when requesting the value of
4275 * a hidden option, ignore setting it. */
4276 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4277 && (!(options[opt_idx].flags & P_BOOL)
4278 || nextchar == '?'))
4279 errmsg = (char_u *)N_("E519: Option not supported");
4280 goto skip;
4281 }
4282
4283 flags = options[opt_idx].flags;
4284 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4285 }
4286 else
4287 {
4288 flags = P_STRING;
4289 if (key < 0)
4290 {
4291 key_name[0] = KEY2TERMCAP0(key);
4292 key_name[1] = KEY2TERMCAP1(key);
4293 }
4294 else
4295 {
4296 key_name[0] = KS_KEY;
4297 key_name[1] = (key & 0xff);
4298 }
4299 }
4300
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004301 /* Skip all options that are not window-local (used when showing
4302 * an already loaded buffer in a window). */
4303 if ((opt_flags & OPT_WINONLY)
4304 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4305 goto skip;
4306
Bram Moolenaara3227e22006-03-08 21:32:40 +00004307 /* Skip all options that are window-local (used for :vimgrep). */
4308 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4309 && options[opt_idx].var == VAR_WIN)
4310 goto skip;
4311
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004312 /* Disallow changing some options from modelines. */
4313 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004315 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004316 {
4317 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4318 goto skip;
4319 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004320#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004321 /* In diff mode some options are overruled. This avoids that
4322 * 'foldmethod' becomes "marker" instead of "diff" and that
4323 * "wrap" gets set. */
4324 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004325 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004326 && (options[opt_idx].indir == PV_FDM
4327 || options[opt_idx].indir == PV_WRAP))
4328 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330 }
4331
4332#ifdef HAVE_SANDBOX
4333 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004334 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335 {
4336 errmsg = (char_u *)_(e_sandbox);
4337 goto skip;
4338 }
4339#endif
4340
4341 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4342 {
4343 arg += len;
4344 cp_val = p_cp;
4345 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4346 {
4347 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4348 {
4349 cp_val = FALSE;
4350 arg += 3;
4351 }
4352 else /* "opt&vi": set to Vi default */
4353 {
4354 cp_val = TRUE;
4355 arg += 2;
4356 }
4357 }
4358 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4359 && arg[1] != NUL && !vim_iswhite(arg[1]))
4360 {
4361 errmsg = e_trailing;
4362 goto skip;
4363 }
4364 }
4365
4366 /*
4367 * allow '=' and ':' as MSDOS command.com allows only one
4368 * '=' character per "set" command line. grrr. (jw)
4369 */
4370 if (nextchar == '?'
4371 || (prefix == 1
4372 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4373 && !(flags & P_BOOL)))
4374 {
4375 /*
4376 * print value
4377 */
4378 if (did_show)
4379 msg_putchar('\n'); /* cursor below last one */
4380 else
4381 {
4382 gotocmdline(TRUE); /* cursor at status line */
4383 did_show = TRUE; /* remember that we did a line */
4384 }
4385 if (opt_idx >= 0)
4386 {
4387 showoneopt(&options[opt_idx], opt_flags);
4388#ifdef FEAT_EVAL
4389 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004390 {
4391 /* Mention where the option was last set. */
4392 if (varp == options[opt_idx].var)
4393 last_set_msg(options[opt_idx].scriptID);
4394 else if ((int)options[opt_idx].indir & PV_WIN)
4395 last_set_msg(curwin->w_p_scriptID[
4396 (int)options[opt_idx].indir & PV_MASK]);
4397 else if ((int)options[opt_idx].indir & PV_BUF)
4398 last_set_msg(curbuf->b_p_scriptID[
4399 (int)options[opt_idx].indir & PV_MASK]);
4400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401#endif
4402 }
4403 else
4404 {
4405 char_u *p;
4406
4407 p = find_termcode(key_name);
4408 if (p == NULL)
4409 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004410 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 goto skip;
4412 }
4413 else
4414 (void)show_one_termcode(key_name, p, TRUE);
4415 }
4416 if (nextchar != '?'
4417 && nextchar != NUL && !vim_iswhite(afterchar))
4418 errmsg = e_trailing;
4419 }
4420 else
4421 {
4422 if (flags & P_BOOL) /* boolean */
4423 {
4424 if (nextchar == '=' || nextchar == ':')
4425 {
4426 errmsg = e_invarg;
4427 goto skip;
4428 }
4429
4430 /*
4431 * ":set opt!": invert
4432 * ":set opt&": reset to default value
4433 * ":set opt<": reset to global value
4434 */
4435 if (nextchar == '!')
4436 value = *(int *)(varp) ^ 1;
4437 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004438 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 ((flags & P_VI_DEF) || cp_val)
4440 ? VI_DEFAULT : VIM_DEFAULT];
4441 else if (nextchar == '<')
4442 {
4443 /* For 'autoread' -1 means to use global value. */
4444 if ((int *)varp == &curbuf->b_p_ar
4445 && opt_flags == OPT_LOCAL)
4446 value = -1;
4447 else
4448 value = *(int *)get_varp_scope(&(options[opt_idx]),
4449 OPT_GLOBAL);
4450 }
4451 else
4452 {
4453 /*
4454 * ":set invopt": invert
4455 * ":set opt" or ":set noopt": set or reset
4456 */
4457 if (nextchar != NUL && !vim_iswhite(afterchar))
4458 {
4459 errmsg = e_trailing;
4460 goto skip;
4461 }
4462 if (prefix == 2) /* inv */
4463 value = *(int *)(varp) ^ 1;
4464 else
4465 value = prefix;
4466 }
4467
4468 errmsg = set_bool_option(opt_idx, varp, (int)value,
4469 opt_flags);
4470 }
4471 else /* numeric or string */
4472 {
4473 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4474 || prefix != 1)
4475 {
4476 errmsg = e_invarg;
4477 goto skip;
4478 }
4479
4480 if (flags & P_NUM) /* numeric */
4481 {
4482 /*
4483 * Different ways to set a number option:
4484 * & set to default value
4485 * < set to global value
4486 * <xx> accept special key codes for 'wildchar'
4487 * c accept any non-digit for 'wildchar'
4488 * [-]0-9 set number
4489 * other error
4490 */
4491 ++arg;
4492 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004493 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 ((flags & P_VI_DEF) || cp_val)
4495 ? VI_DEFAULT : VIM_DEFAULT];
4496 else if (nextchar == '<')
4497 value = *(long *)get_varp_scope(&(options[opt_idx]),
4498 OPT_GLOBAL);
4499 else if (((long *)varp == &p_wc
4500 || (long *)varp == &p_wcm)
4501 && (*arg == '<'
4502 || *arg == '^'
4503 || ((!arg[1] || vim_iswhite(arg[1]))
4504 && !VIM_ISDIGIT(*arg))))
4505 {
4506 value = string_to_key(arg);
4507 if (value == 0 && (long *)varp != &p_wcm)
4508 {
4509 errmsg = e_invarg;
4510 goto skip;
4511 }
4512 }
4513 /* allow negative numbers (for 'undolevels') */
4514 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4515 {
4516 i = 0;
4517 if (*arg == '-')
4518 i = 1;
4519#ifdef HAVE_STRTOL
4520 value = strtol((char *)arg, NULL, 0);
4521 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4522 i += 2;
4523#else
4524 value = atol((char *)arg);
4525#endif
4526 while (VIM_ISDIGIT(arg[i]))
4527 ++i;
4528 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4529 {
4530 errmsg = e_invarg;
4531 goto skip;
4532 }
4533 }
4534 else
4535 {
4536 errmsg = (char_u *)N_("E521: Number required after =");
4537 goto skip;
4538 }
4539
4540 if (adding)
4541 value = *(long *)varp + value;
4542 if (prepending)
4543 value = *(long *)varp * value;
4544 if (removing)
4545 value = *(long *)varp - value;
4546 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004547 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 }
4549 else if (opt_idx >= 0) /* string */
4550 {
4551 char_u *save_arg = NULL;
4552 char_u *s = NULL;
4553 char_u *oldval; /* previous value if *varp */
4554 char_u *newval;
4555 char_u *origval;
4556 unsigned newlen;
4557 int comma;
4558 int bs;
4559 int new_value_alloced; /* new string option
4560 was allocated */
4561
4562 /* When using ":set opt=val" for a global option
4563 * with a local value the local value will be
4564 * reset, use the global value here. */
4565 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004566 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004567 varp = options[opt_idx].var;
4568
4569 /* The old value is kept until we are sure that the
4570 * new value is valid. */
4571 oldval = *(char_u **)varp;
4572 if (nextchar == '&') /* set to default val */
4573 {
4574 newval = options[opt_idx].def_val[
4575 ((flags & P_VI_DEF) || cp_val)
4576 ? VI_DEFAULT : VIM_DEFAULT];
4577 if ((char_u **)varp == &p_bg)
4578 {
4579 /* guess the value of 'background' */
4580#ifdef FEAT_GUI
4581 if (gui.in_use)
4582 newval = gui_bg_default();
4583 else
4584#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004585 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 }
4587
4588 /* expand environment variables and ~ (since the
4589 * default value was already expanded, only
4590 * required when an environment variable was set
4591 * later */
4592 if (newval == NULL)
4593 newval = empty_option;
4594 else
4595 {
4596 s = option_expand(opt_idx, newval);
4597 if (s == NULL)
4598 s = newval;
4599 newval = vim_strsave(s);
4600 }
4601 new_value_alloced = TRUE;
4602 }
4603 else if (nextchar == '<') /* set to global val */
4604 {
4605 newval = vim_strsave(*(char_u **)get_varp_scope(
4606 &(options[opt_idx]), OPT_GLOBAL));
4607 new_value_alloced = TRUE;
4608 }
4609 else
4610 {
4611 ++arg; /* jump to after the '=' or ':' */
4612
4613 /*
4614 * Set 'keywordprg' to ":help" if an empty
4615 * value was passed to :set by the user.
4616 * Misuse errbuf[] for the resulting string.
4617 */
4618 if (varp == (char_u *)&p_kp
4619 && (*arg == NUL || *arg == ' '))
4620 {
4621 STRCPY(errbuf, ":help");
4622 save_arg = arg;
4623 arg = errbuf;
4624 }
4625 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004626 * Convert 'backspace' number to string, for
4627 * adding, prepending and removing string.
4628 */
4629 else if (varp == (char_u *)&p_bs
4630 && VIM_ISDIGIT(**(char_u **)varp))
4631 {
4632 i = getdigits((char_u **)varp);
4633 switch (i)
4634 {
4635 case 0:
4636 *(char_u **)varp = empty_option;
4637 break;
4638 case 1:
4639 *(char_u **)varp = vim_strsave(
4640 (char_u *)"indent,eol");
4641 break;
4642 case 2:
4643 *(char_u **)varp = vim_strsave(
4644 (char_u *)"indent,eol,start");
4645 break;
4646 }
4647 vim_free(oldval);
4648 oldval = *(char_u **)varp;
4649 }
4650 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 * Convert 'whichwrap' number to string, for
4652 * backwards compatibility with Vim 3.0.
4653 * Misuse errbuf[] for the resulting string.
4654 */
4655 else if (varp == (char_u *)&p_ww
4656 && VIM_ISDIGIT(*arg))
4657 {
4658 *errbuf = NUL;
4659 i = getdigits(&arg);
4660 if (i & 1)
4661 STRCAT(errbuf, "b,");
4662 if (i & 2)
4663 STRCAT(errbuf, "s,");
4664 if (i & 4)
4665 STRCAT(errbuf, "h,l,");
4666 if (i & 8)
4667 STRCAT(errbuf, "<,>,");
4668 if (i & 16)
4669 STRCAT(errbuf, "[,],");
4670 if (*errbuf != NUL) /* remove trailing , */
4671 errbuf[STRLEN(errbuf) - 1] = NUL;
4672 save_arg = arg;
4673 arg = errbuf;
4674 }
4675 /*
4676 * Remove '>' before 'dir' and 'bdir', for
4677 * backwards compatibility with version 3.0
4678 */
4679 else if ( *arg == '>'
4680 && (varp == (char_u *)&p_dir
4681 || varp == (char_u *)&p_bdir))
4682 {
4683 ++arg;
4684 }
4685
4686 /* When setting the local value of a global
4687 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004688 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004689 && (opt_flags & OPT_LOCAL))
4690 origval = *(char_u **)get_varp(
4691 &options[opt_idx]);
4692 else
4693 origval = oldval;
4694
4695 /*
4696 * Copy the new string into allocated memory.
4697 * Can't use set_string_option_direct(), because
4698 * we need to remove the backslashes.
4699 */
4700 /* get a bit too much */
4701 newlen = (unsigned)STRLEN(arg) + 1;
4702 if (adding || prepending || removing)
4703 newlen += (unsigned)STRLEN(origval) + 1;
4704 newval = alloc(newlen);
4705 if (newval == NULL) /* out of mem, don't change */
4706 break;
4707 s = newval;
4708
4709 /*
4710 * Copy the string, skip over escaped chars.
4711 * For MS-DOS and WIN32 backslashes before normal
4712 * file name characters are not removed, and keep
4713 * backslash at start, for "\\machine\path", but
4714 * do remove it for "\\\\machine\\path".
4715 * The reverse is found in ExpandOldSetting().
4716 */
4717 while (*arg && !vim_iswhite(*arg))
4718 {
4719 if (*arg == '\\' && arg[1] != NUL
4720#ifdef BACKSLASH_IN_FILENAME
4721 && !((flags & P_EXPAND)
4722 && vim_isfilec(arg[1])
4723 && (arg[1] != '\\'
4724 || (s == newval
4725 && arg[2] != '\\')))
4726#endif
4727 )
4728 ++arg; /* remove backslash */
4729#ifdef FEAT_MBYTE
4730 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004731 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 {
4733 /* copy multibyte char */
4734 mch_memmove(s, arg, (size_t)i);
4735 arg += i;
4736 s += i;
4737 }
4738 else
4739#endif
4740 *s++ = *arg++;
4741 }
4742 *s = NUL;
4743
4744 /*
4745 * Expand environment variables and ~.
4746 * Don't do it when adding without inserting a
4747 * comma.
4748 */
4749 if (!(adding || prepending || removing)
4750 || (flags & P_COMMA))
4751 {
4752 s = option_expand(opt_idx, newval);
4753 if (s != NULL)
4754 {
4755 vim_free(newval);
4756 newlen = (unsigned)STRLEN(s) + 1;
4757 if (adding || prepending || removing)
4758 newlen += (unsigned)STRLEN(origval) + 1;
4759 newval = alloc(newlen);
4760 if (newval == NULL)
4761 break;
4762 STRCPY(newval, s);
4763 }
4764 }
4765
4766 /* locate newval[] in origval[] when removing it
4767 * and when adding to avoid duplicates */
4768 i = 0; /* init for GCC */
4769 if (removing || (flags & P_NODUP))
4770 {
4771 i = (int)STRLEN(newval);
4772 bs = 0;
4773 for (s = origval; *s; ++s)
4774 {
4775 if ((!(flags & P_COMMA)
4776 || s == origval
4777 || (s[-1] == ',' && !(bs & 1)))
4778 && STRNCMP(s, newval, i) == 0
4779 && (!(flags & P_COMMA)
4780 || s[i] == ','
4781 || s[i] == NUL))
4782 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004783 /* Count backslashes. Only a comma with an
4784 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004785 * recognized as a separator */
4786 if (s > origval && s[-1] == '\\')
4787 ++bs;
4788 else
4789 bs = 0;
4790 }
4791
4792 /* do not add if already there */
4793 if ((adding || prepending) && *s)
4794 {
4795 prepending = FALSE;
4796 adding = FALSE;
4797 STRCPY(newval, origval);
4798 }
4799 }
4800
4801 /* concatenate the two strings; add a ',' if
4802 * needed */
4803 if (adding || prepending)
4804 {
4805 comma = ((flags & P_COMMA) && *origval != NUL
4806 && *newval != NUL);
4807 if (adding)
4808 {
4809 i = (int)STRLEN(origval);
4810 mch_memmove(newval + i + comma, newval,
4811 STRLEN(newval) + 1);
4812 mch_memmove(newval, origval, (size_t)i);
4813 }
4814 else
4815 {
4816 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004817 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004818 }
4819 if (comma)
4820 newval[i] = ',';
4821 }
4822
4823 /* Remove newval[] from origval[]. (Note: "i" has
4824 * been set above and is used here). */
4825 if (removing)
4826 {
4827 STRCPY(newval, origval);
4828 if (*s)
4829 {
4830 /* may need to remove a comma */
4831 if (flags & P_COMMA)
4832 {
4833 if (s == origval)
4834 {
4835 /* include comma after string */
4836 if (s[i] == ',')
4837 ++i;
4838 }
4839 else
4840 {
4841 /* include comma before string */
4842 --s;
4843 ++i;
4844 }
4845 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004846 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 }
4848 }
4849
4850 if (flags & P_FLAGLIST)
4851 {
4852 /* Remove flags that appear twice. */
4853 for (s = newval; *s; ++s)
4854 if ((!(flags & P_COMMA) || *s != ',')
4855 && vim_strchr(s + 1, *s) != NULL)
4856 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004857 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004858 --s;
4859 }
4860 }
4861
4862 if (save_arg != NULL) /* number for 'whichwrap' */
4863 arg = save_arg;
4864 new_value_alloced = TRUE;
4865 }
4866
4867 /* Set the new value. */
4868 *(char_u **)(varp) = newval;
4869
4870 /* Handle side effects, and set the global value for
4871 * ":set" on local options. */
4872 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4873 new_value_alloced, oldval, errbuf, opt_flags);
4874
4875 /* If error detected, print the error message. */
4876 if (errmsg != NULL)
4877 goto skip;
4878 }
4879 else /* key code option */
4880 {
4881 char_u *p;
4882
4883 if (nextchar == '&')
4884 {
4885 if (add_termcap_entry(key_name, TRUE) == FAIL)
4886 errmsg = (char_u *)N_("E522: Not found in termcap");
4887 }
4888 else
4889 {
4890 ++arg; /* jump to after the '=' or ':' */
4891 for (p = arg; *p && !vim_iswhite(*p); ++p)
4892 if (*p == '\\' && p[1] != NUL)
4893 ++p;
4894 nextchar = *p;
4895 *p = NUL;
4896 add_termcode(key_name, arg, FALSE);
4897 *p = nextchar;
4898 }
4899 if (full_screen)
4900 ttest(FALSE);
4901 redraw_all_later(CLEAR);
4902 }
4903 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004904
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004906 did_set_option(opt_idx, opt_flags,
4907 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 }
4909
4910skip:
4911 /*
4912 * Advance to next argument.
4913 * - skip until a blank found, taking care of backslashes
4914 * - skip blanks
4915 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4916 */
4917 for (i = 0; i < 2 ; ++i)
4918 {
4919 while (*arg != NUL && !vim_iswhite(*arg))
4920 if (*arg++ == '\\' && *arg != NUL)
4921 ++arg;
4922 arg = skipwhite(arg);
4923 if (*arg != '=')
4924 break;
4925 }
4926 }
4927
4928 if (errmsg != NULL)
4929 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004930 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004931 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 if (i + (arg - startarg) < IOSIZE)
4933 {
4934 /* append the argument with the error */
4935 STRCAT(IObuff, ": ");
4936 mch_memmove(IObuff + i, startarg, (arg - startarg));
4937 IObuff[i + (arg - startarg)] = NUL;
4938 }
4939 /* make sure all characters are printable */
4940 trans_characters(IObuff, IOSIZE);
4941
4942 ++no_wait_return; /* wait_return done later */
4943 emsg(IObuff); /* show error highlighted */
4944 --no_wait_return;
4945
4946 return FAIL;
4947 }
4948
4949 arg = skipwhite(arg);
4950 }
4951
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004952theend:
4953 if (silent_mode && did_show)
4954 {
4955 /* After displaying option values in silent mode. */
4956 silent_mode = FALSE;
4957 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4958 msg_putchar('\n');
4959 cursor_on(); /* msg_start() switches it off */
4960 out_flush();
4961 silent_mode = TRUE;
4962 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4963 }
4964
Bram Moolenaar071d4272004-06-13 20:20:40 +00004965 return OK;
4966}
4967
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004968/*
4969 * Call this when an option has been given a new value through a user command.
4970 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4971 */
4972 static void
4973did_set_option(opt_idx, opt_flags, new_value)
4974 int opt_idx;
4975 int opt_flags; /* possibly with OPT_MODELINE */
4976 int new_value; /* value was replaced completely */
4977{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004978 long_u *p;
4979
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004980 options[opt_idx].flags |= P_WAS_SET;
4981
4982 /* When an option is set in the sandbox, from a modeline or in secure mode
4983 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004984 * flag. */
4985 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004986 if (secure
4987#ifdef HAVE_SANDBOX
4988 || sandbox != 0
4989#endif
4990 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004991 *p = *p | P_INSECURE;
4992 else if (new_value)
4993 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004994}
4995
Bram Moolenaar071d4272004-06-13 20:20:40 +00004996 static char_u *
4997illegal_char(errbuf, c)
4998 char_u *errbuf;
4999 int c;
5000{
5001 if (errbuf == NULL)
5002 return (char_u *)"";
5003 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005004 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005005 return errbuf;
5006}
5007
5008/*
5009 * Convert a key name or string into a key value.
5010 * Used for 'wildchar' and 'cedit' options.
5011 */
5012 static int
5013string_to_key(arg)
5014 char_u *arg;
5015{
5016 if (*arg == '<')
5017 return find_key_option(arg + 1);
5018 if (*arg == '^')
5019 return Ctrl_chr(arg[1]);
5020 return *arg;
5021}
5022
5023#ifdef FEAT_CMDWIN
5024/*
5025 * Check value of 'cedit' and set cedit_key.
5026 * Returns NULL if value is OK, error message otherwise.
5027 */
5028 static char_u *
5029check_cedit()
5030{
5031 int n;
5032
5033 if (*p_cedit == NUL)
5034 cedit_key = -1;
5035 else
5036 {
5037 n = string_to_key(p_cedit);
5038 if (vim_isprintc(n))
5039 return e_invarg;
5040 cedit_key = n;
5041 }
5042 return NULL;
5043}
5044#endif
5045
5046#ifdef FEAT_TITLE
5047/*
5048 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5049 * maketitle() to create and display it.
5050 * When switching the title or icon off, call mch_restore_title() to get
5051 * the old value back.
5052 */
5053 static void
5054did_set_title(icon)
5055 int icon; /* Did set icon instead of title */
5056{
5057 if (starting != NO_SCREEN
5058#ifdef FEAT_GUI
5059 && !gui.starting
5060#endif
5061 )
5062 {
5063 maketitle();
5064 if (icon)
5065 {
5066 if (!p_icon)
5067 mch_restore_title(2);
5068 }
5069 else
5070 {
5071 if (!p_title)
5072 mch_restore_title(1);
5073 }
5074 }
5075}
5076#endif
5077
5078/*
5079 * set_options_bin - called when 'bin' changes value.
5080 */
5081 void
5082set_options_bin(oldval, newval, opt_flags)
5083 int oldval;
5084 int newval;
5085 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5086{
5087 /*
5088 * The option values that are changed when 'bin' changes are
5089 * copied when 'bin is set and restored when 'bin' is reset.
5090 */
5091 if (newval)
5092 {
5093 if (!oldval) /* switched on */
5094 {
5095 if (!(opt_flags & OPT_GLOBAL))
5096 {
5097 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5098 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5099 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5100 curbuf->b_p_et_nobin = curbuf->b_p_et;
5101 }
5102 if (!(opt_flags & OPT_LOCAL))
5103 {
5104 p_tw_nobin = p_tw;
5105 p_wm_nobin = p_wm;
5106 p_ml_nobin = p_ml;
5107 p_et_nobin = p_et;
5108 }
5109 }
5110
5111 if (!(opt_flags & OPT_GLOBAL))
5112 {
5113 curbuf->b_p_tw = 0; /* no automatic line wrap */
5114 curbuf->b_p_wm = 0; /* no automatic line wrap */
5115 curbuf->b_p_ml = 0; /* no modelines */
5116 curbuf->b_p_et = 0; /* no expandtab */
5117 }
5118 if (!(opt_flags & OPT_LOCAL))
5119 {
5120 p_tw = 0;
5121 p_wm = 0;
5122 p_ml = FALSE;
5123 p_et = FALSE;
5124 p_bin = TRUE; /* needed when called for the "-b" argument */
5125 }
5126 }
5127 else if (oldval) /* switched off */
5128 {
5129 if (!(opt_flags & OPT_GLOBAL))
5130 {
5131 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5132 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5133 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5134 curbuf->b_p_et = curbuf->b_p_et_nobin;
5135 }
5136 if (!(opt_flags & OPT_LOCAL))
5137 {
5138 p_tw = p_tw_nobin;
5139 p_wm = p_wm_nobin;
5140 p_ml = p_ml_nobin;
5141 p_et = p_et_nobin;
5142 }
5143 }
5144}
5145
5146#ifdef FEAT_VIMINFO
5147/*
5148 * Find the parameter represented by the given character (eg ', :, ", or /),
5149 * and return its associated value in the 'viminfo' string.
5150 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005151 * If the parameter is not specified in the string or there is no following
5152 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 */
5154 int
5155get_viminfo_parameter(type)
5156 int type;
5157{
5158 char_u *p;
5159
5160 p = find_viminfo_parameter(type);
5161 if (p != NULL && VIM_ISDIGIT(*p))
5162 return atoi((char *)p);
5163 return -1;
5164}
5165
5166/*
5167 * Find the parameter represented by the given character (eg ''', ':', '"', or
5168 * '/') in the 'viminfo' option and return a pointer to the string after it.
5169 * Return NULL if the parameter is not specified in the string.
5170 */
5171 char_u *
5172find_viminfo_parameter(type)
5173 int type;
5174{
5175 char_u *p;
5176
5177 for (p = p_viminfo; *p; ++p)
5178 {
5179 if (*p == type)
5180 return p + 1;
5181 if (*p == 'n') /* 'n' is always the last one */
5182 break;
5183 p = vim_strchr(p, ','); /* skip until next ',' */
5184 if (p == NULL) /* hit the end without finding parameter */
5185 break;
5186 }
5187 return NULL;
5188}
5189#endif
5190
5191/*
5192 * Expand environment variables for some string options.
5193 * These string options cannot be indirect!
5194 * If "val" is NULL expand the current value of the option.
5195 * Return pointer to NameBuff, or NULL when not expanded.
5196 */
5197 static char_u *
5198option_expand(opt_idx, val)
5199 int opt_idx;
5200 char_u *val;
5201{
5202 /* if option doesn't need expansion nothing to do */
5203 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5204 return NULL;
5205
5206 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5207 * expand_env() would truncate the string. */
5208 if (val != NULL && STRLEN(val) > MAXPATHL)
5209 return NULL;
5210
5211 if (val == NULL)
5212 val = *(char_u **)options[opt_idx].var;
5213
5214 /*
5215 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5216 * Escape spaces when expanding 'tags', they are used to separate file
5217 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005218 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 */
5220 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005221 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005222#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005223 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5224#endif
5225 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5227 return NULL;
5228
5229 return NameBuff;
5230}
5231
5232/*
5233 * After setting various option values: recompute variables that depend on
5234 * option values.
5235 */
5236 static void
5237didset_options()
5238{
5239 /* initialize the table for 'iskeyword' et.al. */
5240 (void)init_chartab();
5241
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005242#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5246#ifdef FEAT_SESSION
5247 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5248 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5249#endif
5250#ifdef FEAT_FOLDING
5251 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5252#endif
5253 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5254#ifdef FEAT_VIRTUALEDIT
5255 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5256#endif
5257#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5258 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5259#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005260#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005261 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005262 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005263 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005265#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5266 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5267#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005268#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005269 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5270#endif
5271#ifdef FEAT_CMDWIN
5272 /* set cedit_key */
5273 (void)check_cedit();
5274#endif
5275}
5276
5277/*
5278 * Check for string options that are NULL (normally only termcap options).
5279 */
5280 void
5281check_options()
5282{
5283 int opt_idx;
5284
5285 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5286 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5287 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5288}
5289
5290/*
5291 * Check string options in a buffer for NULL value.
5292 */
5293 void
5294check_buf_options(buf)
5295 buf_T *buf;
5296{
5297#if defined(FEAT_QUICKFIX)
5298 check_string_option(&buf->b_p_bh);
5299 check_string_option(&buf->b_p_bt);
5300#endif
5301#ifdef FEAT_MBYTE
5302 check_string_option(&buf->b_p_fenc);
5303#endif
5304 check_string_option(&buf->b_p_ff);
5305#ifdef FEAT_FIND_ID
5306 check_string_option(&buf->b_p_def);
5307 check_string_option(&buf->b_p_inc);
5308# ifdef FEAT_EVAL
5309 check_string_option(&buf->b_p_inex);
5310# endif
5311#endif
5312#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5313 check_string_option(&buf->b_p_inde);
5314 check_string_option(&buf->b_p_indk);
5315#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005316#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5317 check_string_option(&buf->b_p_bexpr);
5318#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005319#if defined(FEAT_CRYPT)
5320 check_string_option(&buf->b_p_cm);
5321#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005322#if defined(FEAT_EVAL)
5323 check_string_option(&buf->b_p_fex);
5324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325#ifdef FEAT_CRYPT
5326 check_string_option(&buf->b_p_key);
5327#endif
5328 check_string_option(&buf->b_p_kp);
5329 check_string_option(&buf->b_p_mps);
5330 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005331 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332 check_string_option(&buf->b_p_isk);
5333#ifdef FEAT_COMMENTS
5334 check_string_option(&buf->b_p_com);
5335#endif
5336#ifdef FEAT_FOLDING
5337 check_string_option(&buf->b_p_cms);
5338#endif
5339 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005340#ifdef FEAT_TEXTOBJ
5341 check_string_option(&buf->b_p_qe);
5342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343#ifdef FEAT_SYN_HL
5344 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005345#endif
5346#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005347 check_string_option(&buf->b_s.b_p_spc);
5348 check_string_option(&buf->b_s.b_p_spf);
5349 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350#endif
5351#ifdef FEAT_SEARCHPATH
5352 check_string_option(&buf->b_p_sua);
5353#endif
5354#ifdef FEAT_CINDENT
5355 check_string_option(&buf->b_p_cink);
5356 check_string_option(&buf->b_p_cino);
5357#endif
5358#ifdef FEAT_AUTOCMD
5359 check_string_option(&buf->b_p_ft);
5360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5362 check_string_option(&buf->b_p_cinw);
5363#endif
5364#ifdef FEAT_INS_EXPAND
5365 check_string_option(&buf->b_p_cpt);
5366#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005367#ifdef FEAT_COMPL_FUNC
5368 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005369 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371#ifdef FEAT_KEYMAP
5372 check_string_option(&buf->b_p_keymap);
5373#endif
5374#ifdef FEAT_QUICKFIX
5375 check_string_option(&buf->b_p_gp);
5376 check_string_option(&buf->b_p_mp);
5377 check_string_option(&buf->b_p_efm);
5378#endif
5379 check_string_option(&buf->b_p_ep);
5380 check_string_option(&buf->b_p_path);
5381 check_string_option(&buf->b_p_tags);
5382#ifdef FEAT_INS_EXPAND
5383 check_string_option(&buf->b_p_dict);
5384 check_string_option(&buf->b_p_tsr);
5385#endif
5386}
5387
5388/*
5389 * Free the string allocated for an option.
5390 * Checks for the string being empty_option. This may happen if we're out of
5391 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5392 * check_options().
5393 * Does NOT check for P_ALLOCED flag!
5394 */
5395 void
5396free_string_option(p)
5397 char_u *p;
5398{
5399 if (p != empty_option)
5400 vim_free(p);
5401}
5402
5403 void
5404clear_string_option(pp)
5405 char_u **pp;
5406{
5407 if (*pp != empty_option)
5408 vim_free(*pp);
5409 *pp = empty_option;
5410}
5411
5412 static void
5413check_string_option(pp)
5414 char_u **pp;
5415{
5416 if (*pp == NULL)
5417 *pp = empty_option;
5418}
5419
5420/*
5421 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5422 */
5423 void
5424set_term_option_alloced(p)
5425 char_u **p;
5426{
5427 int opt_idx;
5428
5429 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5430 if (options[opt_idx].var == (char_u *)p)
5431 {
5432 options[opt_idx].flags |= P_ALLOCED;
5433 return;
5434 }
5435 return; /* cannot happen: didn't find it! */
5436}
5437
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005438#if defined(FEAT_EVAL) || defined(PROTO)
5439/*
5440 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5441 * Return FALSE when it wasn't.
5442 * Return -1 for an unknown option.
5443 */
5444 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005445was_set_insecurely(opt, opt_flags)
5446 char_u *opt;
5447 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005448{
5449 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005450 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005451
5452 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005453 {
5454 flagp = insecure_flag(idx, opt_flags);
5455 return (*flagp & P_INSECURE) != 0;
5456 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005457 EMSG2(_(e_intern2), "was_set_insecurely()");
5458 return -1;
5459}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005460
5461/*
5462 * Get a pointer to the flags used for the P_INSECURE flag of option
5463 * "opt_idx". For some local options a local flags field is used.
5464 */
5465 static long_u *
5466insecure_flag(opt_idx, opt_flags)
5467 int opt_idx;
5468 int opt_flags;
5469{
5470 if (opt_flags & OPT_LOCAL)
5471 switch ((int)options[opt_idx].indir)
5472 {
5473#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005474 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005475#endif
5476#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005477# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005478 case PV_FDE: return &curwin->w_p_fde_flags;
5479 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005480# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005481# ifdef FEAT_BEVAL
5482 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5483# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005484# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005485 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005486# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005487 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005488# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005489 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005490# endif
5491#endif
5492 }
5493
5494 /* Nothing special, return global flags field. */
5495 return &options[opt_idx].flags;
5496}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005497#endif
5498
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005499#ifdef FEAT_TITLE
5500static void redraw_titles __ARGS((void));
5501
5502/*
5503 * Redraw the window title and/or tab page text later.
5504 */
5505static void redraw_titles()
5506{
5507 need_maketitle = TRUE;
5508# ifdef FEAT_WINDOWS
5509 redraw_tabline = TRUE;
5510# endif
5511}
5512#endif
5513
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514/*
5515 * Set a string option to a new value (without checking the effect).
5516 * The string is copied into allocated memory.
5517 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005518 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005519 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520 */
5521 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005522set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523 char_u *name;
5524 int opt_idx;
5525 char_u *val;
5526 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005527 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528{
5529 char_u *s;
5530 char_u **varp;
5531 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005532 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533
Bram Moolenaar89d40322006-08-29 15:30:07 +00005534 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005536 idx = findoption(name);
5537 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005538 {
5539 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542 }
5543
Bram Moolenaar89d40322006-08-29 15:30:07 +00005544 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 return;
5546
5547 s = vim_strsave(val);
5548 if (s != NULL)
5549 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005550 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005552 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 free_string_option(*varp);
5554 *varp = s;
5555
5556 /* For buffer/window local option may also set the global value. */
5557 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005558 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559
Bram Moolenaar89d40322006-08-29 15:30:07 +00005560 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561
5562 /* When setting both values of a global option with a local value,
5563 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005564 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565 {
5566 free_string_option(*varp);
5567 *varp = empty_option;
5568 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005569# ifdef FEAT_EVAL
5570 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005571 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005572 set_sid == 0 ? current_SID : set_sid);
5573# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574 }
5575}
5576
5577/*
5578 * Set global value for string option when it's a local option.
5579 */
5580 static void
5581set_string_option_global(opt_idx, varp)
5582 int opt_idx; /* option index */
5583 char_u **varp; /* pointer to option variable */
5584{
5585 char_u **p, *s;
5586
5587 /* the global value is always allocated */
5588 if (options[opt_idx].var == VAR_WIN)
5589 p = (char_u **)GLOBAL_WO(varp);
5590 else
5591 p = (char_u **)options[opt_idx].var;
5592 if (options[opt_idx].indir != PV_NONE
5593 && p != varp
5594 && (s = vim_strsave(*varp)) != NULL)
5595 {
5596 free_string_option(*p);
5597 *p = s;
5598 }
5599}
5600
5601/*
5602 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005603 *
5604 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005606 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607set_string_option(opt_idx, value, opt_flags)
5608 int opt_idx;
5609 char_u *value;
5610 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5611{
5612 char_u *s;
5613 char_u **varp;
5614 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005615 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005616
5617 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005618 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619
5620 s = vim_strsave(value);
5621 if (s != NULL)
5622 {
5623 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5624 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005625 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005626 ? OPT_GLOBAL : OPT_LOCAL)
5627 : opt_flags);
5628 oldval = *varp;
5629 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005630 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5631 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005632 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005634 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635}
5636
5637/*
5638 * Handle string options that need some action to perform when changed.
5639 * Returns NULL for success, or an error message for an error.
5640 */
5641 static char_u *
5642did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5643 opt_flags)
5644 int opt_idx; /* index in options[] table */
5645 char_u **varp; /* pointer to the option variable */
5646 int new_value_alloced; /* new value was allocated */
5647 char_u *oldval; /* previous value of the option */
5648 char_u *errbuf; /* buffer for errors, or NULL */
5649 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5650{
5651 char_u *errmsg = NULL;
5652 char_u *s, *p;
5653 int did_chartab = FALSE;
5654 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005655 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005656#ifdef FEAT_GUI
5657 /* set when changing an option that only requires a redraw in the GUI */
5658 int redraw_gui_only = FALSE;
5659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660
5661 /* Get the global option to compare with, otherwise we would have to check
5662 * two values for all local options. */
5663 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5664
5665 /* Disallow changing some options from secure mode */
5666 if ((secure
5667#ifdef HAVE_SANDBOX
5668 || sandbox != 0
5669#endif
5670 ) && (options[opt_idx].flags & P_SECURE))
5671 {
5672 errmsg = e_secure;
5673 }
5674
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005675 /* Check for a "normal" file name in some options. Disallow a path
5676 * separator (slash and/or backslash), wildcards and characters that are
5677 * often illegal in a file name. */
5678 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005679 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005680 {
5681 errmsg = e_invarg;
5682 }
5683
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 /* 'term' */
5685 else if (varp == &T_NAME)
5686 {
5687 if (T_NAME[0] == NUL)
5688 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5689#ifdef FEAT_GUI
5690 if (gui.in_use)
5691 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5692 else if (term_is_gui(T_NAME))
5693 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5694#endif
5695 else if (set_termname(T_NAME) == FAIL)
5696 errmsg = (char_u *)N_("E522: Not found in termcap");
5697 else
5698 /* Screen colors may have changed. */
5699 redraw_later_clear();
5700 }
5701
5702 /* 'backupcopy' */
5703 else if (varp == &p_bkc)
5704 {
5705 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5706 errmsg = e_invarg;
5707 if (((bkc_flags & BKC_AUTO) != 0)
5708 + ((bkc_flags & BKC_YES) != 0)
5709 + ((bkc_flags & BKC_NO) != 0) != 1)
5710 {
5711 /* Must have exactly one of "auto", "yes" and "no". */
5712 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5713 errmsg = e_invarg;
5714 }
5715 }
5716
5717 /* 'backupext' and 'patchmode' */
5718 else if (varp == &p_bex || varp == &p_pm)
5719 {
5720 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5721 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5722 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5723 }
5724
5725 /*
5726 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5727 * If the new option is invalid, use old value. 'lisp' option: refill
5728 * chartab[] for '-' char
5729 */
5730 else if ( varp == &p_isi
5731 || varp == &(curbuf->b_p_isk)
5732 || varp == &p_isp
5733 || varp == &p_isf)
5734 {
5735 if (init_chartab() == FAIL)
5736 {
5737 did_chartab = TRUE; /* need to restore it below */
5738 errmsg = e_invarg; /* error in value */
5739 }
5740 }
5741
5742 /* 'helpfile' */
5743 else if (varp == &p_hf)
5744 {
5745 /* May compute new values for $VIM and $VIMRUNTIME */
5746 if (didset_vim)
5747 {
5748 vim_setenv((char_u *)"VIM", (char_u *)"");
5749 didset_vim = FALSE;
5750 }
5751 if (didset_vimruntime)
5752 {
5753 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5754 didset_vimruntime = FALSE;
5755 }
5756 }
5757
Bram Moolenaar1a384422010-07-14 19:53:30 +02005758#ifdef FEAT_SYN_HL
5759 /* 'colorcolumn' */
5760 else if (varp == &curwin->w_p_cc)
5761 errmsg = check_colorcolumn(curwin);
5762#endif
5763
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764#ifdef FEAT_MULTI_LANG
5765 /* 'helplang' */
5766 else if (varp == &p_hlg)
5767 {
5768 /* Check for "", "ab", "ab,cd", etc. */
5769 for (s = p_hlg; *s != NUL; s += 3)
5770 {
5771 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5772 {
5773 errmsg = e_invarg;
5774 break;
5775 }
5776 if (s[2] == NUL)
5777 break;
5778 }
5779 }
5780#endif
5781
5782 /* 'highlight' */
5783 else if (varp == &p_hl)
5784 {
5785 if (highlight_changed() == FAIL)
5786 errmsg = e_invarg; /* invalid flags */
5787 }
5788
5789 /* 'nrformats' */
5790 else if (gvarp == &p_nf)
5791 {
5792 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5793 errmsg = e_invarg;
5794 }
5795
5796#ifdef FEAT_SESSION
5797 /* 'sessionoptions' */
5798 else if (varp == &p_ssop)
5799 {
5800 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5801 errmsg = e_invarg;
5802 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5803 {
5804 /* Don't allow both "sesdir" and "curdir". */
5805 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5806 errmsg = e_invarg;
5807 }
5808 }
5809 /* 'viewoptions' */
5810 else if (varp == &p_vop)
5811 {
5812 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5813 errmsg = e_invarg;
5814 }
5815#endif
5816
5817 /* 'scrollopt' */
5818#ifdef FEAT_SCROLLBIND
5819 else if (varp == &p_sbo)
5820 {
5821 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5822 errmsg = e_invarg;
5823 }
5824#endif
5825
5826 /* 'ambiwidth' */
5827#ifdef FEAT_MBYTE
5828 else if (varp == &p_ambw)
5829 {
5830 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5831 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005832 else if (set_chars_option(&p_lcs) != NULL)
5833 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5834# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5835 else if (set_chars_option(&p_fcs) != NULL)
5836 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5837# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838 }
5839#endif
5840
5841 /* 'background' */
5842 else if (varp == &p_bg)
5843 {
5844 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5845 {
5846#ifdef FEAT_EVAL
5847 int dark = (*p_bg == 'd');
5848#endif
5849
5850 init_highlight(FALSE, FALSE);
5851
5852#ifdef FEAT_EVAL
5853 if (dark != (*p_bg == 'd')
5854 && get_var_value((char_u *)"g:colors_name") != NULL)
5855 {
5856 /* The color scheme must have set 'background' back to another
5857 * value, that's not what we want here. Disable the color
5858 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005859 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 free_string_option(p_bg);
5861 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5862 check_string_option(&p_bg);
5863 init_highlight(FALSE, FALSE);
5864 }
5865#endif
5866 }
5867 else
5868 errmsg = e_invarg;
5869 }
5870
5871 /* 'wildmode' */
5872 else if (varp == &p_wim)
5873 {
5874 if (check_opt_wim() == FAIL)
5875 errmsg = e_invarg;
5876 }
5877
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005878#ifdef FEAT_CMDL_COMPL
5879 /* 'wildoptions' */
5880 else if (varp == &p_wop)
5881 {
5882 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5883 errmsg = e_invarg;
5884 }
5885#endif
5886
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887#ifdef FEAT_WAK
5888 /* 'winaltkeys' */
5889 else if (varp == &p_wak)
5890 {
5891 if (*p_wak == NUL
5892 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5893 errmsg = e_invarg;
5894# ifdef FEAT_MENU
5895# ifdef FEAT_GUI_MOTIF
5896 else if (gui.in_use)
5897 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5898# else
5899# ifdef FEAT_GUI_GTK
5900 else if (gui.in_use)
5901 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5902# endif
5903# endif
5904# endif
5905 }
5906#endif
5907
5908#ifdef FEAT_AUTOCMD
5909 /* 'eventignore' */
5910 else if (varp == &p_ei)
5911 {
5912 if (check_ei() == FAIL)
5913 errmsg = e_invarg;
5914 }
5915#endif
5916
5917#ifdef FEAT_MBYTE
5918 /* 'encoding' and 'fileencoding' */
5919 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5920 {
5921 if (gvarp == &p_fenc)
5922 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005923 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 errmsg = e_modifiable;
5925 else if (vim_strchr(*varp, ',') != NULL)
5926 /* No comma allowed in 'fileencoding'; catches confusing it
5927 * with 'fileencodings'. */
5928 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005930 {
5931# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005933 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005935 /* Add 'fileencoding' to the swap file. */
5936 ml_setflags(curbuf);
5937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 }
5939 if (errmsg == NULL)
5940 {
5941 /* canonize the value, so that STRCMP() can be used on it */
5942 p = enc_canonize(*varp);
5943 if (p != NULL)
5944 {
5945 vim_free(*varp);
5946 *varp = p;
5947 }
5948 if (varp == &p_enc)
5949 {
5950 errmsg = mb_init();
5951# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005952 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953# endif
5954 }
5955 }
5956
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005957# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5959 {
5960 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5961 if (STRCMP(p_tenc, "utf-8") != 0)
5962 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5963 }
5964# endif
5965
5966 if (errmsg == NULL)
5967 {
5968# ifdef FEAT_KEYMAP
5969 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5970 * (with another encoding). */
5971 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5972 (void)keymap_init();
5973# endif
5974
5975 /* When 'termencoding' is not empty and 'encoding' changes or when
5976 * 'termencoding' changes, need to setup for keyboard input and
5977 * display output conversion. */
5978 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5979 {
5980 convert_setup(&input_conv, p_tenc, p_enc);
5981 convert_setup(&output_conv, p_enc, p_tenc);
5982 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005983
5984# if defined(WIN3264) && defined(FEAT_MBYTE)
5985 /* $HOME may have characters in active code page. */
5986 if (varp == &p_enc)
5987 init_homedir();
5988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989 }
5990 }
5991#endif
5992
5993#if defined(FEAT_POSTSCRIPT)
5994 else if (varp == &p_penc)
5995 {
5996 /* Canonize printencoding if VIM standard one */
5997 p = enc_canonize(p_penc);
5998 if (p != NULL)
5999 {
6000 vim_free(p_penc);
6001 p_penc = p;
6002 }
6003 else
6004 {
6005 /* Ensure lower case and '-' for '_' */
6006 for (s = p_penc; *s != NUL; s++)
6007 {
6008 if (*s == '_')
6009 *s = '-';
6010 else
6011 *s = TOLOWER_ASC(*s);
6012 }
6013 }
6014 }
6015#endif
6016
Bram Moolenaar9372a112005-12-06 19:59:18 +00006017#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006018 else if (varp == &p_imak)
6019 {
6020 if (gui.in_use && !im_xim_isvalid_imactivate())
6021 errmsg = e_invarg;
6022 }
6023#endif
6024
6025#ifdef FEAT_KEYMAP
6026 else if (varp == &curbuf->b_p_keymap)
6027 {
6028 /* load or unload key mapping tables */
6029 errmsg = keymap_init();
6030
Bram Moolenaarfab06232009-03-04 03:13:35 +00006031 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006033 if (*curbuf->b_p_keymap != NUL)
6034 {
6035 /* Installed a new keymap, switch on using it. */
6036 curbuf->b_p_iminsert = B_IMODE_LMAP;
6037 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6038 curbuf->b_p_imsearch = B_IMODE_LMAP;
6039 }
6040 else
6041 {
6042 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6043 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6044 curbuf->b_p_iminsert = B_IMODE_NONE;
6045 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6046 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6047 }
6048 if ((opt_flags & OPT_LOCAL) == 0)
6049 {
6050 set_iminsert_global();
6051 set_imsearch_global();
6052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006053# ifdef FEAT_WINDOWS
6054 status_redraw_curbuf();
6055# endif
6056 }
6057 }
6058#endif
6059
6060 /* 'fileformat' */
6061 else if (gvarp == &p_ff)
6062 {
6063 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6064 errmsg = e_modifiable;
6065 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6066 errmsg = e_invarg;
6067 else
6068 {
6069 /* may also change 'textmode' */
6070 if (get_fileformat(curbuf) == EOL_DOS)
6071 curbuf->b_p_tx = TRUE;
6072 else
6073 curbuf->b_p_tx = FALSE;
6074#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006075 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006076#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006077 /* update flag in swap file */
6078 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006079 /* Redraw needed when switching to/from "mac": a CR in the text
6080 * will be displayed differently. */
6081 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6082 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083 }
6084 }
6085
6086 /* 'fileformats' */
6087 else if (varp == &p_ffs)
6088 {
6089 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6090 errmsg = e_invarg;
6091 else
6092 {
6093 /* also change 'textauto' */
6094 if (*p_ffs == NUL)
6095 p_ta = FALSE;
6096 else
6097 p_ta = TRUE;
6098 }
6099 }
6100
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006101#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 /* 'cryptkey' */
6103 else if (gvarp == &p_key)
6104 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006105# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 /* Make sure the ":set" command doesn't show the new value in the
6107 * history. */
6108 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006109# endif
6110 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6111 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006112 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6113 }
6114
6115 else if (gvarp == &p_cm)
6116 {
6117 if (opt_flags & OPT_LOCAL)
6118 p = curbuf->b_p_cm;
6119 else
6120 p = p_cm;
6121 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6122 errmsg = e_invarg;
6123 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6124 errmsg = e_invarg;
6125 else
6126 {
6127 /* When setting the global value to empty, make it "zip". */
6128 if (*p_cm == NUL)
6129 {
6130 if (new_value_alloced)
6131 free_string_option(p_cm);
6132 p_cm = vim_strsave((char_u *)"zip");
6133 new_value_alloced = TRUE;
6134 }
6135
6136 /* Need to update the swapfile when the effective method changed.
6137 * Set "s" to the effective old value, "p" to the effective new
6138 * method and compare. */
6139 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6140 s = p_cm; /* was previously using the global value */
6141 else
6142 s = oldval;
6143 if (*curbuf->b_p_cm == NUL)
6144 p = p_cm; /* is now using the global value */
6145 else
6146 p = curbuf->b_p_cm;
6147 if (STRCMP(s, p) != 0)
6148 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6149 crypt_method_from_string(s));
6150
6151 /* If the global value changes need to update the swapfile for all
6152 * buffers using that value. */
6153 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6154 {
6155 buf_T *buf;
6156
6157 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6158 if (buf != curbuf && *buf->b_p_cm == NUL)
6159 ml_set_crypt_key(buf, buf->b_p_key,
6160 crypt_method_from_string(oldval));
6161 }
6162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 }
6164#endif
6165
6166 /* 'matchpairs' */
6167 else if (gvarp == &p_mps)
6168 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006169#ifdef FEAT_MBYTE
6170 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006172 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006173 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006174 int x2 = -1;
6175 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006176
6177 if (*p != NUL)
6178 p += mb_ptr2len(p);
6179 if (*p != NUL)
6180 x2 = *p++;
6181 if (*p != NUL)
6182 {
6183 x3 = mb_ptr2char(p);
6184 p += mb_ptr2len(p);
6185 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006186 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006187 {
6188 errmsg = e_invarg;
6189 break;
6190 }
6191 if (*p == NUL)
6192 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006194 }
6195 else
6196#endif
6197 {
6198 /* Check for "x:y,x:y" */
6199 for (p = *varp; *p != NUL; p += 4)
6200 {
6201 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6202 {
6203 errmsg = e_invarg;
6204 break;
6205 }
6206 if (p[3] == NUL)
6207 break;
6208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006209 }
6210 }
6211
6212#ifdef FEAT_COMMENTS
6213 /* 'comments' */
6214 else if (gvarp == &p_com)
6215 {
6216 for (s = *varp; *s; )
6217 {
6218 while (*s && *s != ':')
6219 {
6220 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6221 && !VIM_ISDIGIT(*s) && *s != '-')
6222 {
6223 errmsg = illegal_char(errbuf, *s);
6224 break;
6225 }
6226 ++s;
6227 }
6228 if (*s++ == NUL)
6229 errmsg = (char_u *)N_("E524: Missing colon");
6230 else if (*s == ',' || *s == NUL)
6231 errmsg = (char_u *)N_("E525: Zero length string");
6232 if (errmsg != NULL)
6233 break;
6234 while (*s && *s != ',')
6235 {
6236 if (*s == '\\' && s[1] != NUL)
6237 ++s;
6238 ++s;
6239 }
6240 s = skip_to_option_part(s);
6241 }
6242 }
6243#endif
6244
6245 /* 'listchars' */
6246 else if (varp == &p_lcs)
6247 {
6248 errmsg = set_chars_option(varp);
6249 }
6250
6251#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6252 /* 'fillchars' */
6253 else if (varp == &p_fcs)
6254 {
6255 errmsg = set_chars_option(varp);
6256 }
6257#endif
6258
6259#ifdef FEAT_CMDWIN
6260 /* 'cedit' */
6261 else if (varp == &p_cedit)
6262 {
6263 errmsg = check_cedit();
6264 }
6265#endif
6266
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006267 /* 'verbosefile' */
6268 else if (varp == &p_vfile)
6269 {
6270 verbose_stop();
6271 if (*p_vfile != NUL && verbose_open() == FAIL)
6272 errmsg = e_invarg;
6273 }
6274
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275#ifdef FEAT_VIMINFO
6276 /* 'viminfo' */
6277 else if (varp == &p_viminfo)
6278 {
6279 for (s = p_viminfo; *s;)
6280 {
6281 /* Check it's a valid character */
6282 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6283 {
6284 errmsg = illegal_char(errbuf, *s);
6285 break;
6286 }
6287 if (*s == 'n') /* name is always last one */
6288 {
6289 break;
6290 }
6291 else if (*s == 'r') /* skip until next ',' */
6292 {
6293 while (*++s && *s != ',')
6294 ;
6295 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006296 else if (*s == '%')
6297 {
6298 /* optional number */
6299 while (vim_isdigit(*++s))
6300 ;
6301 }
6302 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 ++s; /* no extra chars */
6304 else /* must have a number */
6305 {
6306 while (vim_isdigit(*++s))
6307 ;
6308
6309 if (!VIM_ISDIGIT(*(s - 1)))
6310 {
6311 if (errbuf != NULL)
6312 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006313 sprintf((char *)errbuf,
6314 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 transchar_byte(*(s - 1)));
6316 errmsg = errbuf;
6317 }
6318 else
6319 errmsg = (char_u *)"";
6320 break;
6321 }
6322 }
6323 if (*s == ',')
6324 ++s;
6325 else if (*s)
6326 {
6327 if (errbuf != NULL)
6328 errmsg = (char_u *)N_("E527: Missing comma");
6329 else
6330 errmsg = (char_u *)"";
6331 break;
6332 }
6333 }
6334 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6335 errmsg = (char_u *)N_("E528: Must specify a ' value");
6336 }
6337#endif /* FEAT_VIMINFO */
6338
6339 /* terminal options */
6340 else if (istermoption(&options[opt_idx]) && full_screen)
6341 {
6342 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6343 if (varp == &T_CCO)
6344 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006345 int colors = atoi((char *)T_CCO);
6346
6347 /* Only reinitialize colors if t_Co value has really changed to
6348 * avoid expensive reload of colorscheme if t_Co is set to the
6349 * same value multiple times. */
6350 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006352 t_colors = colors;
6353 if (t_colors <= 1)
6354 {
6355 if (new_value_alloced)
6356 vim_free(T_CCO);
6357 T_CCO = empty_option;
6358 }
6359 /* We now have a different color setup, initialize it again. */
6360 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 }
6363 ttest(FALSE);
6364 if (varp == &T_ME)
6365 {
6366 out_str(T_ME);
6367 redraw_later(CLEAR);
6368#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6369 /* Since t_me has been set, this probably means that the user
6370 * wants to use this as default colors. Need to reset default
6371 * background/foreground colors. */
6372 mch_set_normal_colors();
6373#endif
6374 }
6375 }
6376
6377#ifdef FEAT_LINEBREAK
6378 /* 'showbreak' */
6379 else if (varp == &p_sbr)
6380 {
6381 for (s = p_sbr; *s; )
6382 {
6383 if (ptr2cells(s) != 1)
6384 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006385 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
6387 }
6388#endif
6389
6390#ifdef FEAT_GUI
6391 /* 'guifont' */
6392 else if (varp == &p_guifont)
6393 {
6394 if (gui.in_use)
6395 {
6396 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006397# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398 /*
6399 * Put up a font dialog and let the user select a new value.
6400 * If this is cancelled go back to the old value but don't
6401 * give an error message.
6402 */
6403 if (STRCMP(p, "*") == 0)
6404 {
6405 p = gui_mch_font_dialog(oldval);
6406
6407 if (new_value_alloced)
6408 free_string_option(p_guifont);
6409
6410 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6411 new_value_alloced = TRUE;
6412 }
6413# endif
6414 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6415 {
6416# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6417 if (STRCMP(p_guifont, "*") == 0)
6418 {
6419 /* Dialog was cancelled: Keep the old value without giving
6420 * an error message. */
6421 if (new_value_alloced)
6422 free_string_option(p_guifont);
6423 p_guifont = vim_strsave(oldval);
6424 new_value_alloced = TRUE;
6425 }
6426 else
6427# endif
6428 errmsg = (char_u *)N_("E596: Invalid font(s)");
6429 }
6430 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006431 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432 }
6433# ifdef FEAT_XFONTSET
6434 else if (varp == &p_guifontset)
6435 {
6436 if (STRCMP(p_guifontset, "*") == 0)
6437 errmsg = (char_u *)N_("E597: can't select fontset");
6438 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6439 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006440 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
6442# endif
6443# ifdef FEAT_MBYTE
6444 else if (varp == &p_guifontwide)
6445 {
6446 if (STRCMP(p_guifontwide, "*") == 0)
6447 errmsg = (char_u *)N_("E533: can't select wide font");
6448 else if (gui_get_wide_font() == FAIL)
6449 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006450 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006451 }
6452# endif
6453#endif
6454
6455#ifdef CURSOR_SHAPE
6456 /* 'guicursor' */
6457 else if (varp == &p_guicursor)
6458 errmsg = parse_shape_opt(SHAPE_CURSOR);
6459#endif
6460
6461#ifdef FEAT_MOUSESHAPE
6462 /* 'mouseshape' */
6463 else if (varp == &p_mouseshape)
6464 {
6465 errmsg = parse_shape_opt(SHAPE_MOUSE);
6466 update_mouseshape(-1);
6467 }
6468#endif
6469
6470#ifdef FEAT_PRINTER
6471 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006472 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006473# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006474 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006475 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006476# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477#endif
6478
6479#ifdef FEAT_LANGMAP
6480 /* 'langmap' */
6481 else if (varp == &p_langmap)
6482 langmap_set();
6483#endif
6484
6485#ifdef FEAT_LINEBREAK
6486 /* 'breakat' */
6487 else if (varp == &p_breakat)
6488 fill_breakat_flags();
6489#endif
6490
6491#ifdef FEAT_TITLE
6492 /* 'titlestring' and 'iconstring' */
6493 else if (varp == &p_titlestring || varp == &p_iconstring)
6494 {
6495# ifdef FEAT_STL_OPT
6496 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6497
6498 /* NULL => statusline syntax */
6499 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6500 stl_syntax |= flagval;
6501 else
6502 stl_syntax &= ~flagval;
6503# endif
6504 did_set_title(varp == &p_iconstring);
6505
6506 }
6507#endif
6508
6509#ifdef FEAT_GUI
6510 /* 'guioptions' */
6511 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006512 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006514 redraw_gui_only = TRUE;
6515 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516#endif
6517
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006518#if defined(FEAT_GUI_TABLINE)
6519 /* 'guitablabel' */
6520 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006521 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006522 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006523 redraw_gui_only = TRUE;
6524 }
6525 /* 'guitabtooltip' */
6526 else if (varp == &p_gtt)
6527 {
6528 redraw_gui_only = TRUE;
6529 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006530#endif
6531
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6533 /* 'ttymouse' */
6534 else if (varp == &p_ttym)
6535 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006536 /* Switch the mouse off before changing the escape sequences used for
6537 * that. */
6538 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6540 errmsg = e_invarg;
6541 else
6542 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006543 if (termcap_active)
6544 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006545 }
6546#endif
6547
6548#ifdef FEAT_VISUAL
6549 /* 'selection' */
6550 else if (varp == &p_sel)
6551 {
6552 if (*p_sel == NUL
6553 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6554 errmsg = e_invarg;
6555 }
6556
6557 /* 'selectmode' */
6558 else if (varp == &p_slm)
6559 {
6560 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6561 errmsg = e_invarg;
6562 }
6563#endif
6564
6565#ifdef FEAT_BROWSE
6566 /* 'browsedir' */
6567 else if (varp == &p_bsdir)
6568 {
6569 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6570 && !mch_isdir(p_bsdir))
6571 errmsg = e_invarg;
6572 }
6573#endif
6574
6575#ifdef FEAT_VISUAL
6576 /* 'keymodel' */
6577 else if (varp == &p_km)
6578 {
6579 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6580 errmsg = e_invarg;
6581 else
6582 {
6583 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6584 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6585 }
6586 }
6587#endif
6588
6589 /* 'mousemodel' */
6590 else if (varp == &p_mousem)
6591 {
6592 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6593 errmsg = e_invarg;
6594#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6595 else if (*p_mousem != *oldval)
6596 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6597 * to create or delete the popup menus. */
6598 gui_motif_update_mousemodel(root_menu);
6599#endif
6600 }
6601
6602 /* 'switchbuf' */
6603 else if (varp == &p_swb)
6604 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006605 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 errmsg = e_invarg;
6607 }
6608
6609 /* 'debug' */
6610 else if (varp == &p_debug)
6611 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006612 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 errmsg = e_invarg;
6614 }
6615
6616 /* 'display' */
6617 else if (varp == &p_dy)
6618 {
6619 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6620 errmsg = e_invarg;
6621 else
6622 (void)init_chartab();
6623
6624 }
6625
6626#ifdef FEAT_VERTSPLIT
6627 /* 'eadirection' */
6628 else if (varp == &p_ead)
6629 {
6630 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6631 errmsg = e_invarg;
6632 }
6633#endif
6634
6635#ifdef FEAT_CLIPBOARD
6636 /* 'clipboard' */
6637 else if (varp == &p_cb)
6638 errmsg = check_clipboard_option();
6639#endif
6640
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006641#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006642 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6643 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006644 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006645 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006646 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006647 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006648
Bram Moolenaar860cae12010-06-05 23:22:07 +02006649 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006650 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006651 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6652 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006653 ".add") != 0))
6654 errmsg = e_invarg;
6655 }
6656
6657 if (errmsg == NULL)
6658 {
6659 FOR_ALL_WINDOWS(wp)
6660 if (wp->w_buffer == curbuf && wp->w_p_spell)
6661 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006662 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006663# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006664 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006665# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006666 }
6667 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006668 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006669 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006670 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006671 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006672 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006673 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006674 /* 'spellsuggest' */
6675 else if (varp == &p_sps)
6676 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006677 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006678 errmsg = e_invarg;
6679 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006680 /* 'mkspellmem' */
6681 else if (varp == &p_msm)
6682 {
6683 if (spell_check_msm() != OK)
6684 errmsg = e_invarg;
6685 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006686#endif
6687
Bram Moolenaar071d4272004-06-13 20:20:40 +00006688#ifdef FEAT_QUICKFIX
6689 /* When 'bufhidden' is set, check for valid value. */
6690 else if (gvarp == &p_bh)
6691 {
6692 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6693 errmsg = e_invarg;
6694 }
6695
6696 /* When 'buftype' is set, check for valid value. */
6697 else if (gvarp == &p_bt)
6698 {
6699 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6700 errmsg = e_invarg;
6701 else
6702 {
6703# ifdef FEAT_WINDOWS
6704 if (curwin->w_status_height)
6705 {
6706 curwin->w_redr_status = TRUE;
6707 redraw_later(VALID);
6708 }
6709# endif
6710 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006711# ifdef FEAT_TITLE
6712 redraw_titles();
6713# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006714 }
6715 }
6716#endif
6717
6718#ifdef FEAT_STL_OPT
6719 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006720 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 {
6722 int wid;
6723
6724 if (varp == &p_ruf) /* reset ru_wid first */
6725 ru_wid = 0;
6726 s = *varp;
6727 if (varp == &p_ruf && *s == '%')
6728 {
6729 /* set ru_wid if 'ruf' starts with "%99(" */
6730 if (*++s == '-') /* ignore a '-' */
6731 s++;
6732 wid = getdigits(&s);
6733 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6734 ru_wid = wid;
6735 else
6736 errmsg = check_stl_option(p_ruf);
6737 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006738 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006739 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006741 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742 comp_col();
6743 }
6744#endif
6745
6746#ifdef FEAT_INS_EXPAND
6747 /* check if it is a valid value for 'complete' -- Acevedo */
6748 else if (gvarp == &p_cpt)
6749 {
6750 for (s = *varp; *s;)
6751 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006752 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 s++;
6754 if (!*s)
6755 break;
6756 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6757 {
6758 errmsg = illegal_char(errbuf, *s);
6759 break;
6760 }
6761 if (*++s != NUL && *s != ',' && *s != ' ')
6762 {
6763 if (s[-1] == 'k' || s[-1] == 's')
6764 {
6765 /* skip optional filename after 'k' and 's' */
6766 while (*s && *s != ',' && *s != ' ')
6767 {
6768 if (*s == '\\')
6769 ++s;
6770 ++s;
6771 }
6772 }
6773 else
6774 {
6775 if (errbuf != NULL)
6776 {
6777 sprintf((char *)errbuf,
6778 _("E535: Illegal character after <%c>"),
6779 *--s);
6780 errmsg = errbuf;
6781 }
6782 else
6783 errmsg = (char_u *)"";
6784 break;
6785 }
6786 }
6787 }
6788 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006789
6790 /* 'completeopt' */
6791 else if (varp == &p_cot)
6792 {
6793 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6794 errmsg = e_invarg;
6795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796#endif /* FEAT_INS_EXPAND */
6797
6798
6799#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6800 else if (varp == &p_toolbar)
6801 {
6802 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6803 &toolbar_flags, TRUE) != OK)
6804 errmsg = e_invarg;
6805 else
6806 {
6807 out_flush();
6808 gui_mch_show_toolbar((toolbar_flags &
6809 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6810 }
6811 }
6812#endif
6813
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006814#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 /* 'toolbariconsize': GTK+ 2 only */
6816 else if (varp == &p_tbis)
6817 {
6818 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6819 errmsg = e_invarg;
6820 else
6821 {
6822 out_flush();
6823 gui_mch_show_toolbar((toolbar_flags &
6824 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6825 }
6826 }
6827#endif
6828
6829 /* 'pastetoggle': translate key codes like in a mapping */
6830 else if (varp == &p_pt)
6831 {
6832 if (*p_pt)
6833 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006834 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 if (p != NULL)
6836 {
6837 if (new_value_alloced)
6838 free_string_option(p_pt);
6839 p_pt = p;
6840 new_value_alloced = TRUE;
6841 }
6842 }
6843 }
6844
6845 /* 'backspace' */
6846 else if (varp == &p_bs)
6847 {
6848 if (VIM_ISDIGIT(*p_bs))
6849 {
6850 if (*p_bs >'2' || p_bs[1] != NUL)
6851 errmsg = e_invarg;
6852 }
6853 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6854 errmsg = e_invarg;
6855 }
6856
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006857#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858 /* 'casemap' */
6859 else if (varp == &p_cmp)
6860 {
6861 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6862 errmsg = e_invarg;
6863 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865
6866#ifdef FEAT_DIFF
6867 /* 'diffopt' */
6868 else if (varp == &p_dip)
6869 {
6870 if (diffopt_changed() == FAIL)
6871 errmsg = e_invarg;
6872 }
6873#endif
6874
6875#ifdef FEAT_FOLDING
6876 /* 'foldmethod' */
6877 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6878 {
6879 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6880 || *curwin->w_p_fdm == NUL)
6881 errmsg = e_invarg;
6882 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006883 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006885 if (foldmethodIsDiff(curwin))
6886 newFoldLevel();
6887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006888 }
6889# ifdef FEAT_EVAL
6890 /* 'foldexpr' */
6891 else if (varp == &curwin->w_p_fde)
6892 {
6893 if (foldmethodIsExpr(curwin))
6894 foldUpdateAll(curwin);
6895 }
6896# endif
6897 /* 'foldmarker' */
6898 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6899 {
6900 p = vim_strchr(*varp, ',');
6901 if (p == NULL)
6902 errmsg = (char_u *)N_("E536: comma required");
6903 else if (p == *varp || p[1] == NUL)
6904 errmsg = e_invarg;
6905 else if (foldmethodIsMarker(curwin))
6906 foldUpdateAll(curwin);
6907 }
6908 /* 'commentstring' */
6909 else if (gvarp == &p_cms)
6910 {
6911 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6912 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6913 }
6914 /* 'foldopen' */
6915 else if (varp == &p_fdo)
6916 {
6917 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6918 errmsg = e_invarg;
6919 }
6920 /* 'foldclose' */
6921 else if (varp == &p_fcl)
6922 {
6923 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6924 errmsg = e_invarg;
6925 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006926 /* 'foldignore' */
6927 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6928 {
6929 if (foldmethodIsIndent(curwin))
6930 foldUpdateAll(curwin);
6931 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006932#endif
6933
6934#ifdef FEAT_VIRTUALEDIT
6935 /* 'virtualedit' */
6936 else if (varp == &p_ve)
6937 {
6938 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6939 errmsg = e_invarg;
6940 else if (STRCMP(p_ve, oldval) != 0)
6941 {
6942 /* Recompute cursor position in case the new 've' setting
6943 * changes something. */
6944 validate_virtcol();
6945 coladvance(curwin->w_virtcol);
6946 }
6947 }
6948#endif
6949
6950#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6951 else if (varp == &p_csqf)
6952 {
6953 if (p_csqf != NULL)
6954 {
6955 p = p_csqf;
6956 while (*p != NUL)
6957 {
6958 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6959 || p[1] == NUL
6960 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6961 || (p[2] != NUL && p[2] != ','))
6962 {
6963 errmsg = e_invarg;
6964 break;
6965 }
6966 else if (p[2] == NUL)
6967 break;
6968 else
6969 p += 3;
6970 }
6971 }
6972 }
6973#endif
6974
6975 /* Options that are a list of flags. */
6976 else
6977 {
6978 p = NULL;
6979 if (varp == &p_ww)
6980 p = (char_u *)WW_ALL;
6981 if (varp == &p_shm)
6982 p = (char_u *)SHM_ALL;
6983 else if (varp == &(p_cpo))
6984 p = (char_u *)CPO_ALL;
6985 else if (varp == &(curbuf->b_p_fo))
6986 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006987#ifdef FEAT_CONCEAL
6988 else if (varp == &curwin->w_p_cocu)
6989 p = (char_u *)COCU_ALL;
6990#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991 else if (varp == &p_mouse)
6992 {
6993#ifdef FEAT_MOUSE
6994 p = (char_u *)MOUSE_ALL;
6995#else
6996 if (*p_mouse != NUL)
6997 errmsg = (char_u *)N_("E538: No mouse support");
6998#endif
6999 }
7000#if defined(FEAT_GUI)
7001 else if (varp == &p_go)
7002 p = (char_u *)GO_ALL;
7003#endif
7004 if (p != NULL)
7005 {
7006 for (s = *varp; *s; ++s)
7007 if (vim_strchr(p, *s) == NULL)
7008 {
7009 errmsg = illegal_char(errbuf, *s);
7010 break;
7011 }
7012 }
7013 }
7014
7015 /*
7016 * If error detected, restore the previous value.
7017 */
7018 if (errmsg != NULL)
7019 {
7020 if (new_value_alloced)
7021 free_string_option(*varp);
7022 *varp = oldval;
7023 /*
7024 * When resetting some values, need to act on it.
7025 */
7026 if (did_chartab)
7027 (void)init_chartab();
7028 if (varp == &p_hl)
7029 (void)highlight_changed();
7030 }
7031 else
7032 {
7033#ifdef FEAT_EVAL
7034 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007035 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036#endif
7037 /*
7038 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007039 * Use "free_oldval", because recursiveness may change the flags under
7040 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007042 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 free_string_option(oldval);
7044 if (new_value_alloced)
7045 options[opt_idx].flags |= P_ALLOCED;
7046 else
7047 options[opt_idx].flags &= ~P_ALLOCED;
7048
7049 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007050 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 {
7052 /* global option with local value set to use global value; free
7053 * the local value and make it empty */
7054 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7055 free_string_option(*(char_u **)p);
7056 *(char_u **)p = empty_option;
7057 }
7058
7059 /* May set global value for local option. */
7060 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7061 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007062
7063#ifdef FEAT_AUTOCMD
7064 /*
7065 * Trigger the autocommand only after setting the flags.
7066 */
7067# ifdef FEAT_SYN_HL
7068 /* When 'syntax' is set, load the syntax of that name */
7069 if (varp == &(curbuf->b_p_syn))
7070 {
7071 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7072 curbuf->b_fname, TRUE, curbuf);
7073 }
7074# endif
7075 else if (varp == &(curbuf->b_p_ft))
7076 {
7077 /* 'filetype' is set, trigger the FileType autocommand */
7078 did_filetype = TRUE;
7079 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7080 curbuf->b_fname, TRUE, curbuf);
7081 }
7082#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007083#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007084 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007085 {
7086 char_u fname[200];
7087
7088 /*
7089 * Source the spell/LANG.vim in 'runtimepath'.
7090 * They could set 'spellcapcheck' depending on the language.
7091 * Use the first name in 'spelllang' up to '_region' or
7092 * '.encoding'.
7093 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007094 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007095 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7096 break;
7097 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02007098 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007099 source_runtime(fname, TRUE);
7100 }
7101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 }
7103
7104#ifdef FEAT_MOUSE
7105 if (varp == &p_mouse)
7106 {
7107# ifdef FEAT_MOUSE_TTY
7108 if (*p_mouse == NUL)
7109 mch_setmouse(FALSE); /* switch mouse off */
7110 else
7111# endif
7112 setmouse(); /* in case 'mouse' changed */
7113 }
7114#endif
7115
Bram Moolenaar913077c2012-03-28 19:59:04 +02007116 if (curwin->w_curswant != MAXCOL
7117 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7118 curwin->w_set_curswant = TRUE;
7119
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007120#ifdef FEAT_GUI
7121 /* check redraw when it's not a GUI option or the GUI is active. */
7122 if (!redraw_gui_only || gui.in_use)
7123#endif
7124 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125
7126 return errmsg;
7127}
7128
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007129#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007130/*
7131 * Simple int comparison function for use with qsort()
7132 */
7133 static int
7134int_cmp(a, b)
7135 const void *a;
7136 const void *b;
7137{
7138 return *(const int *)a - *(const int *)b;
7139}
7140
7141/*
7142 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7143 * Returns error message, NULL if it's OK.
7144 */
7145 char_u *
7146check_colorcolumn(wp)
7147 win_T *wp;
7148{
7149 char_u *s;
7150 int col;
7151 int count = 0;
7152 int color_cols[256];
7153 int i;
7154 int j = 0;
7155
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007156 if (wp->w_buffer == NULL)
7157 return NULL; /* buffer was closed */
7158
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007159 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007160 {
7161 if (*s == '-' || *s == '+')
7162 {
7163 /* -N and +N: add to 'textwidth' */
7164 col = (*s == '-') ? -1 : 1;
7165 ++s;
7166 if (!VIM_ISDIGIT(*s))
7167 return e_invarg;
7168 col = col * getdigits(&s);
7169 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007170 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007171 col += wp->w_buffer->b_p_tw;
7172 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007173 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007174 }
7175 else if (VIM_ISDIGIT(*s))
7176 col = getdigits(&s);
7177 else
7178 return e_invarg;
7179 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007180skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007181 if (*s == NUL)
7182 break;
7183 if (*s != ',')
7184 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007185 if (*++s == NUL)
7186 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007187 }
7188
7189 vim_free(wp->w_p_cc_cols);
7190 if (count == 0)
7191 wp->w_p_cc_cols = NULL;
7192 else
7193 {
7194 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7195 if (wp->w_p_cc_cols != NULL)
7196 {
7197 /* sort the columns for faster usage on screen redraw inside
7198 * win_line() */
7199 qsort(color_cols, count, sizeof(int), int_cmp);
7200
7201 for (i = 0; i < count; ++i)
7202 /* skip duplicates */
7203 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7204 wp->w_p_cc_cols[j++] = color_cols[i];
7205 wp->w_p_cc_cols[j] = -1; /* end marker */
7206 }
7207 }
7208
7209 return NULL; /* no error */
7210}
7211#endif
7212
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213/*
7214 * Handle setting 'listchars' or 'fillchars'.
7215 * Returns error message, NULL if it's OK.
7216 */
7217 static char_u *
7218set_chars_option(varp)
7219 char_u **varp;
7220{
7221 int round, i, len, entries;
7222 char_u *p, *s;
7223 int c1, c2 = 0;
7224 struct charstab
7225 {
7226 int *cp;
7227 char *name;
7228 };
7229#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7230 static struct charstab filltab[] =
7231 {
7232 {&fill_stl, "stl"},
7233 {&fill_stlnc, "stlnc"},
7234 {&fill_vert, "vert"},
7235 {&fill_fold, "fold"},
7236 {&fill_diff, "diff"},
7237 };
7238#endif
7239 static struct charstab lcstab[] =
7240 {
7241 {&lcs_eol, "eol"},
7242 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007243 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007244 {&lcs_prec, "precedes"},
7245 {&lcs_tab2, "tab"},
7246 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007247#ifdef FEAT_CONCEAL
7248 {&lcs_conceal, "conceal"},
7249#else
7250 {NULL, "conceal"},
7251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007252 };
7253 struct charstab *tab;
7254
7255#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7256 if (varp == &p_lcs)
7257#endif
7258 {
7259 tab = lcstab;
7260 entries = sizeof(lcstab) / sizeof(struct charstab);
7261 }
7262#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7263 else
7264 {
7265 tab = filltab;
7266 entries = sizeof(filltab) / sizeof(struct charstab);
7267 }
7268#endif
7269
7270 /* first round: check for valid value, second round: assign values */
7271 for (round = 0; round <= 1; ++round)
7272 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007273 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 {
7275 /* After checking that the value is valid: set defaults: space for
7276 * 'fillchars', NUL for 'listchars' */
7277 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007278 if (tab[i].cp != NULL)
7279 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 if (varp == &p_lcs)
7281 lcs_tab1 = NUL;
7282#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7283 else
7284 fill_diff = '-';
7285#endif
7286 }
7287 p = *varp;
7288 while (*p)
7289 {
7290 for (i = 0; i < entries; ++i)
7291 {
7292 len = (int)STRLEN(tab[i].name);
7293 if (STRNCMP(p, tab[i].name, len) == 0
7294 && p[len] == ':'
7295 && p[len + 1] != NUL)
7296 {
7297 s = p + len + 1;
7298#ifdef FEAT_MBYTE
7299 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007300 if (mb_char2cells(c1) > 1)
7301 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302#else
7303 c1 = *s++;
7304#endif
7305 if (tab[i].cp == &lcs_tab2)
7306 {
7307 if (*s == NUL)
7308 continue;
7309#ifdef FEAT_MBYTE
7310 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007311 if (mb_char2cells(c2) > 1)
7312 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313#else
7314 c2 = *s++;
7315#endif
7316 }
7317 if (*s == ',' || *s == NUL)
7318 {
7319 if (round)
7320 {
7321 if (tab[i].cp == &lcs_tab2)
7322 {
7323 lcs_tab1 = c1;
7324 lcs_tab2 = c2;
7325 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007326 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327 *(tab[i].cp) = c1;
7328
7329 }
7330 p = s;
7331 break;
7332 }
7333 }
7334 }
7335
7336 if (i == entries)
7337 return e_invarg;
7338 if (*p == ',')
7339 ++p;
7340 }
7341 }
7342
7343 return NULL; /* no error */
7344}
7345
7346#ifdef FEAT_STL_OPT
7347/*
7348 * Check validity of options with the 'statusline' format.
7349 * Return error message or NULL.
7350 */
7351 char_u *
7352check_stl_option(s)
7353 char_u *s;
7354{
7355 int itemcnt = 0;
7356 int groupdepth = 0;
7357 static char_u errbuf[80];
7358
7359 while (*s && itemcnt < STL_MAX_ITEM)
7360 {
7361 /* Check for valid keys after % sequences */
7362 while (*s && *s != '%')
7363 s++;
7364 if (!*s)
7365 break;
7366 s++;
7367 if (*s != '%' && *s != ')')
7368 ++itemcnt;
7369 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7370 {
7371 s++;
7372 continue;
7373 }
7374 if (*s == ')')
7375 {
7376 s++;
7377 if (--groupdepth < 0)
7378 break;
7379 continue;
7380 }
7381 if (*s == '-')
7382 s++;
7383 while (VIM_ISDIGIT(*s))
7384 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007385 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386 continue;
7387 if (*s == '.')
7388 {
7389 s++;
7390 while (*s && VIM_ISDIGIT(*s))
7391 s++;
7392 }
7393 if (*s == '(')
7394 {
7395 groupdepth++;
7396 continue;
7397 }
7398 if (vim_strchr(STL_ALL, *s) == NULL)
7399 {
7400 return illegal_char(errbuf, *s);
7401 }
7402 if (*s == '{')
7403 {
7404 s++;
7405 while (*s != '}' && *s)
7406 s++;
7407 if (*s != '}')
7408 return (char_u *)N_("E540: Unclosed expression sequence");
7409 }
7410 }
7411 if (itemcnt >= STL_MAX_ITEM)
7412 return (char_u *)N_("E541: too many items");
7413 if (groupdepth != 0)
7414 return (char_u *)N_("E542: unbalanced groups");
7415 return NULL;
7416}
7417#endif
7418
7419#ifdef FEAT_CLIPBOARD
7420/*
7421 * Extract the items in the 'clipboard' option and set global values.
7422 */
7423 static char_u *
7424check_clipboard_option()
7425{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007426 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007427 int new_autoselect_star = FALSE;
7428 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007430 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007431 regprog_T *new_exclude_prog = NULL;
7432 char_u *errmsg = NULL;
7433 char_u *p;
7434
7435 for (p = p_cb; *p != NUL; )
7436 {
7437 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7438 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007439 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 p += 7;
7441 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007442 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007443 && (p[11] == ',' || p[11] == NUL))
7444 {
7445 new_unnamed |= CLIP_UNNAMED_PLUS;
7446 p += 11;
7447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007449 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007450 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007451 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 p += 10;
7453 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007454 else if (STRNCMP(p, "autoselectplus", 14) == 0
7455 && (p[14] == ',' || p[14] == NUL))
7456 {
7457 new_autoselect_plus = TRUE;
7458 p += 14;
7459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007461 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 {
7463 new_autoselectml = TRUE;
7464 p += 12;
7465 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007466 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7467 {
7468 new_html = TRUE;
7469 p += 4;
7470 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7472 {
7473 p += 8;
7474 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7475 if (new_exclude_prog == NULL)
7476 errmsg = e_invarg;
7477 break;
7478 }
7479 else
7480 {
7481 errmsg = e_invarg;
7482 break;
7483 }
7484 if (*p == ',')
7485 ++p;
7486 }
7487 if (errmsg == NULL)
7488 {
7489 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007490 clip_autoselect_star = new_autoselect_star;
7491 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007493 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 vim_free(clip_exclude_prog);
7495 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007496#ifdef FEAT_GUI_GTK
7497 if (gui.in_use)
7498 {
7499 gui_gtk_set_selection_targets();
7500 gui_gtk_set_dnd_targets();
7501 }
7502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503 }
7504 else
7505 vim_free(new_exclude_prog);
7506
7507 return errmsg;
7508}
7509#endif
7510
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007511#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007512/*
7513 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7514 * Return error message when failed, NULL when OK.
7515 */
7516 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007517compile_cap_prog(synblock)
7518 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007519{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007520 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007521 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007522
Bram Moolenaar860cae12010-06-05 23:22:07 +02007523 if (*synblock->b_p_spc == NUL)
7524 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007525 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007526 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007527 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007528 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007529 if (re != NULL)
7530 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007531 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7532 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007533 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007534 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007535 return e_invarg;
7536 }
7537 vim_free(re);
7538 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007539 }
7540
7541 vim_free(rp);
7542 return NULL;
7543}
7544#endif
7545
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007546#if defined(FEAT_EVAL) || defined(PROTO)
7547/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007548 * Set the scriptID for an option, taking care of setting the buffer- or
7549 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007550 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007551 static void
7552set_option_scriptID_idx(opt_idx, opt_flags, id)
7553 int opt_idx;
7554 int opt_flags;
7555 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007556{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007557 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7558 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007559
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007560 /* Remember where the option was set. For local options need to do that
7561 * in the buffer or window structure. */
7562 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007563 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007564 if (both || (opt_flags & OPT_LOCAL))
7565 {
7566 if (indir & PV_BUF)
7567 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7568 else if (indir & PV_WIN)
7569 curwin->w_p_scriptID[indir & PV_MASK] = id;
7570 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007571}
7572#endif
7573
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574/*
7575 * Set the value of a boolean option, and take care of side effects.
7576 * Returns NULL for success, or an error message for an error.
7577 */
7578 static char_u *
7579set_bool_option(opt_idx, varp, value, opt_flags)
7580 int opt_idx; /* index in options[] table */
7581 char_u *varp; /* pointer to the option variable */
7582 int value; /* new value */
7583 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7584{
7585 int old_value = *(int *)varp;
7586
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587 /* Disallow changing some options from secure mode */
7588 if ((secure
7589#ifdef HAVE_SANDBOX
7590 || sandbox != 0
7591#endif
7592 ) && (options[opt_idx].flags & P_SECURE))
7593 return e_secure;
7594
7595 *(int *)varp = value; /* set the new value */
7596#ifdef FEAT_EVAL
7597 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007598 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007599#endif
7600
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007601#ifdef FEAT_GUI
7602 need_mouse_correct = TRUE;
7603#endif
7604
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605 /* May set global value for local option. */
7606 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7607 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7608
7609 /*
7610 * Handle side effects of changing a bool option.
7611 */
7612
7613 /* 'compatible' */
7614 if ((int *)varp == &p_cp)
7615 {
7616 compatible_set();
7617 }
7618
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007619#ifdef FEAT_PERSISTENT_UNDO
7620 /* 'undofile' */
7621 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7622 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007623 /* Only take action when the option was set. When reset we do not
7624 * delete the undo file, the option may be set again without making
7625 * any changes in between. */
7626 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007627 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007628 char_u hash[UNDO_HASH_SIZE];
7629 buf_T *save_curbuf = curbuf;
7630
7631 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007632 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007633 /* When 'undofile' is set globally: for every buffer, otherwise
7634 * only for the current buffer: Try to read in the undofile,
7635 * if one exists, the buffer wasn't changed and the buffer was
7636 * loaded */
7637 if ((curbuf == save_curbuf
7638 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7639 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7640 {
7641 u_compute_hash(hash);
7642 u_read_undo(NULL, hash, curbuf->b_fname);
7643 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007644 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007645 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007646 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007647 }
7648#endif
7649
Bram Moolenaar20754022013-03-13 20:42:32 +01007650 /* If 'number' is set, reset 'relativenumber'. */
7651 /* If 'relativenumber' is set, reset 'number'. */
7652 else if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007653 {
Bram Moolenaar20754022013-03-13 20:42:32 +01007654 curwin->w_p_rnu = FALSE;
7655
7656 /* Only reset the global value if the own value is set globally. */
7657 if (((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0))
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007658 curwin->w_allbuf_opt.wo_rnu = FALSE;
Bram Moolenaar20754022013-03-13 20:42:32 +01007659 }
7660 else if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7661 {
7662 curwin->w_p_nu = FALSE;
7663
7664 /* Only reset the global value if the own value is set globally. */
7665 if (((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0))
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007666 curwin->w_allbuf_opt.wo_nu = FALSE;
Bram Moolenaar20754022013-03-13 20:42:32 +01007667 }
7668 else if ((int *)varp == &curwin->w_allbuf_opt.wo_nu
7669 && curwin->w_allbuf_opt.wo_nu)
7670 {
7671 curwin->w_allbuf_opt.wo_rnu = FALSE;
7672 }
7673 else if ((int *)varp == &curwin->w_allbuf_opt.wo_rnu
7674 && curwin->w_allbuf_opt.wo_rnu)
7675 {
7676 curwin->w_allbuf_opt.wo_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007677 }
7678
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679 else if ((int *)varp == &curbuf->b_p_ro)
7680 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007681 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7683 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007684
7685 /* when 'readonly' is set may give W10 again */
7686 if (curbuf->b_p_ro)
7687 curbuf->b_did_warn = FALSE;
7688
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007690 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691#endif
7692 }
7693
Bram Moolenaar9c449722010-07-20 18:44:27 +02007694#ifdef FEAT_GUI
7695 else if ((int *)varp == &p_mh)
7696 {
7697 if (!p_mh)
7698 gui_mch_mousehide(FALSE);
7699 }
7700#endif
7701
Bram Moolenaara539df02010-08-01 14:35:05 +02007702#ifdef FEAT_TITLE
7703 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007705 {
7706 redraw_titles();
7707 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 /* when 'endofline' is changed, redraw the window title */
7709 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007710 {
7711 redraw_titles();
7712 }
7713# ifdef FEAT_MBYTE
7714 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007715 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007716 {
7717 redraw_titles();
7718 }
7719# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720#endif
7721
7722 /* when 'bin' is set also set some other options */
7723 else if ((int *)varp == &curbuf->b_p_bin)
7724 {
7725 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7726#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007727 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007728#endif
7729 }
7730
7731#ifdef FEAT_AUTOCMD
7732 /* when 'buflisted' changes, trigger autocommands */
7733 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7734 {
7735 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7736 NULL, NULL, TRUE, curbuf);
7737 }
7738#endif
7739
7740 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7741 else if ((int *)varp == &curbuf->b_p_swf)
7742 {
7743 if (curbuf->b_p_swf && p_uc)
7744 ml_open_file(curbuf); /* create the swap file */
7745 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007746 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7747 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 mf_close_file(curbuf, TRUE); /* remove the swap file */
7749 }
7750
7751 /* when 'terse' is set change 'shortmess' */
7752 else if ((int *)varp == &p_terse)
7753 {
7754 char_u *p;
7755
7756 p = vim_strchr(p_shm, SHM_SEARCH);
7757
7758 /* insert 's' in p_shm */
7759 if (p_terse && p == NULL)
7760 {
7761 STRCPY(IObuff, p_shm);
7762 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007763 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 }
7765 /* remove 's' from p_shm */
7766 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007767 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768 }
7769
7770 /* when 'paste' is set or reset also change other options */
7771 else if ((int *)varp == &p_paste)
7772 {
7773 paste_option_changed();
7774 }
7775
7776 /* when 'insertmode' is set from an autocommand need to do work here */
7777 else if ((int *)varp == &p_im)
7778 {
7779 if (p_im)
7780 {
7781 if ((State & INSERT) == 0)
7782 need_start_insertmode = TRUE;
7783 stop_insert_mode = FALSE;
7784 }
7785 else
7786 {
7787 need_start_insertmode = FALSE;
7788 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007789 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 clear_cmdline = TRUE; /* remove "(insert)" */
7791 restart_edit = 0;
7792 }
7793 }
7794
7795 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7796 else if ((int *)varp == &p_ic && p_hls)
7797 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007798 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 }
7800
7801#ifdef FEAT_SEARCH_EXTRA
7802 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7803 else if ((int *)varp == &p_hls)
7804 {
7805 no_hlsearch = FALSE;
7806 }
7807#endif
7808
7809#ifdef FEAT_SCROLLBIND
7810 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7811 * at the end of normal_cmd() */
7812 else if ((int *)varp == &curwin->w_p_scb)
7813 {
7814 if (curwin->w_p_scb)
7815 do_check_scrollbind(FALSE);
7816 }
7817#endif
7818
7819#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7820 /* There can be only one window with 'previewwindow' set. */
7821 else if ((int *)varp == &curwin->w_p_pvw)
7822 {
7823 if (curwin->w_p_pvw)
7824 {
7825 win_T *win;
7826
7827 for (win = firstwin; win != NULL; win = win->w_next)
7828 if (win->w_p_pvw && win != curwin)
7829 {
7830 curwin->w_p_pvw = FALSE;
7831 return (char_u *)N_("E590: A preview window already exists");
7832 }
7833 }
7834 }
7835#endif
7836
7837 /* when 'textmode' is set or reset also change 'fileformat' */
7838 else if ((int *)varp == &curbuf->b_p_tx)
7839 {
7840 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7841 }
7842
7843 /* when 'textauto' is set or reset also change 'fileformats' */
7844 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845 set_string_option_direct((char_u *)"ffs", -1,
7846 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007847 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848
7849 /*
7850 * When 'lisp' option changes include/exclude '-' in
7851 * keyword characters.
7852 */
7853#ifdef FEAT_LISP
7854 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7855 {
7856 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7857 }
7858#endif
7859
7860#ifdef FEAT_TITLE
7861 /* when 'title' changed, may need to change the title; same for 'icon' */
7862 else if ((int *)varp == &p_title)
7863 {
7864 did_set_title(FALSE);
7865 }
7866
7867 else if ((int *)varp == &p_icon)
7868 {
7869 did_set_title(TRUE);
7870 }
7871#endif
7872
7873 else if ((int *)varp == &curbuf->b_changed)
7874 {
7875 if (!value)
7876 save_file_ff(curbuf); /* Buffer is unchanged */
7877#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007878 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879#endif
7880#ifdef FEAT_AUTOCMD
7881 modified_was_set = value;
7882#endif
7883 }
7884
7885#ifdef BACKSLASH_IN_FILENAME
7886 else if ((int *)varp == &p_ssl)
7887 {
7888 if (p_ssl)
7889 {
7890 psepc = '/';
7891 psepcN = '\\';
7892 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 }
7894 else
7895 {
7896 psepc = '\\';
7897 psepcN = '/';
7898 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 }
7900
7901 /* need to adjust the file name arguments and buffer names. */
7902 buflist_slash_adjust();
7903 alist_slash_adjust();
7904# ifdef FEAT_EVAL
7905 scriptnames_slash_adjust();
7906# endif
7907 }
7908#endif
7909
7910 /* If 'wrap' is set, set w_leftcol to zero. */
7911 else if ((int *)varp == &curwin->w_p_wrap)
7912 {
7913 if (curwin->w_p_wrap)
7914 curwin->w_leftcol = 0;
7915 }
7916
7917#ifdef FEAT_WINDOWS
7918 else if ((int *)varp == &p_ea)
7919 {
7920 if (p_ea && !old_value)
7921 win_equal(curwin, FALSE, 0);
7922 }
7923#endif
7924
7925 else if ((int *)varp == &p_wiv)
7926 {
7927 /*
7928 * When 'weirdinvert' changed, set/reset 't_xs'.
7929 * Then set 'weirdinvert' according to value of 't_xs'.
7930 */
7931 if (p_wiv && !old_value)
7932 T_XS = (char_u *)"y";
7933 else if (!p_wiv && old_value)
7934 T_XS = empty_option;
7935 p_wiv = (*T_XS != NUL);
7936 }
7937
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007938#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 else if ((int *)varp == &p_beval)
7940 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007941 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007943 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 gui_mch_disable_beval_area(balloonEval);
7945 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007948#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 else if ((int *)varp == &p_acd)
7950 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007951 /* Change directories when the 'acd' option is set now. */
7952 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954#endif
7955
7956#ifdef FEAT_DIFF
7957 /* 'diff' */
7958 else if ((int *)varp == &curwin->w_p_diff)
7959 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007960 /* May add or remove the buffer from the list of diff buffers. */
7961 diff_buf_adjust(curwin);
7962# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 if (foldmethodIsDiff(curwin))
7964 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967#endif
7968
7969#ifdef USE_IM_CONTROL
7970 /* 'imdisable' */
7971 else if ((int *)varp == &p_imdisable)
7972 {
7973 /* Only de-activate it here, it will be enabled when changing mode. */
7974 if (p_imdisable)
7975 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007976 else if (State & INSERT)
7977 /* When the option is set from an autocommand, it may need to take
7978 * effect right away. */
7979 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 }
7981#endif
7982
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007983#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007984 /* 'spell' */
7985 else if ((int *)varp == &curwin->w_p_spell)
7986 {
7987 if (curwin->w_p_spell)
7988 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007989 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007990 if (errmsg != NULL)
7991 EMSG(_(errmsg));
7992 }
7993 }
7994#endif
7995
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996#ifdef FEAT_FKMAP
7997 else if ((int *)varp == &p_altkeymap)
7998 {
7999 if (old_value != p_altkeymap)
8000 {
8001 if (!p_altkeymap)
8002 {
8003 p_hkmap = p_fkmap;
8004 p_fkmap = 0;
8005 }
8006 else
8007 {
8008 p_fkmap = p_hkmap;
8009 p_hkmap = 0;
8010 }
8011 (void)init_chartab();
8012 }
8013 }
8014
8015 /*
8016 * In case some second language keymapping options have changed, check
8017 * and correct the setting in a consistent way.
8018 */
8019
8020 /*
8021 * If hkmap or fkmap are set, reset Arabic keymapping.
8022 */
8023 if ((p_hkmap || p_fkmap) && p_altkeymap)
8024 {
8025 p_altkeymap = p_fkmap;
8026# ifdef FEAT_ARABIC
8027 curwin->w_p_arab = FALSE;
8028# endif
8029 (void)init_chartab();
8030 }
8031
8032 /*
8033 * If hkmap set, reset Farsi keymapping.
8034 */
8035 if (p_hkmap && p_altkeymap)
8036 {
8037 p_altkeymap = 0;
8038 p_fkmap = 0;
8039# ifdef FEAT_ARABIC
8040 curwin->w_p_arab = FALSE;
8041# endif
8042 (void)init_chartab();
8043 }
8044
8045 /*
8046 * If fkmap set, reset Hebrew keymapping.
8047 */
8048 if (p_fkmap && !p_altkeymap)
8049 {
8050 p_altkeymap = 1;
8051 p_hkmap = 0;
8052# ifdef FEAT_ARABIC
8053 curwin->w_p_arab = FALSE;
8054# endif
8055 (void)init_chartab();
8056 }
8057#endif
8058
8059#ifdef FEAT_ARABIC
8060 if ((int *)varp == &curwin->w_p_arab)
8061 {
8062 if (curwin->w_p_arab)
8063 {
8064 /*
8065 * 'arabic' is set, handle various sub-settings.
8066 */
8067 if (!p_tbidi)
8068 {
8069 /* set rightleft mode */
8070 if (!curwin->w_p_rl)
8071 {
8072 curwin->w_p_rl = TRUE;
8073 changed_window_setting();
8074 }
8075
8076 /* Enable Arabic shaping (major part of what Arabic requires) */
8077 if (!p_arshape)
8078 {
8079 p_arshape = TRUE;
8080 redraw_later_clear();
8081 }
8082 }
8083
8084 /* Arabic requires a utf-8 encoding, inform the user if its not
8085 * set. */
8086 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008087 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008088 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8089
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008090 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008091 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8092#ifdef FEAT_EVAL
8093 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8094#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096
8097# ifdef FEAT_MBYTE
8098 /* set 'delcombine' */
8099 p_deco = TRUE;
8100# endif
8101
8102# ifdef FEAT_KEYMAP
8103 /* Force-set the necessary keymap for arabic */
8104 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8105 OPT_LOCAL);
8106# endif
8107# ifdef FEAT_FKMAP
8108 p_altkeymap = 0;
8109 p_hkmap = 0;
8110 p_fkmap = 0;
8111 (void)init_chartab();
8112# endif
8113 }
8114 else
8115 {
8116 /*
8117 * 'arabic' is reset, handle various sub-settings.
8118 */
8119 if (!p_tbidi)
8120 {
8121 /* reset rightleft mode */
8122 if (curwin->w_p_rl)
8123 {
8124 curwin->w_p_rl = FALSE;
8125 changed_window_setting();
8126 }
8127
8128 /* 'arabicshape' isn't reset, it is a global option and
8129 * another window may still need it "on". */
8130 }
8131
8132 /* 'delcombine' isn't reset, it is a global option and another
8133 * window may still want it "on". */
8134
8135# ifdef FEAT_KEYMAP
8136 /* Revert to the default keymap */
8137 curbuf->b_p_iminsert = B_IMODE_NONE;
8138 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8139# endif
8140 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008141 }
8142
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008143#endif
8144
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 /*
8146 * End of handling side effects for bool options.
8147 */
8148
8149 options[opt_idx].flags |= P_WAS_SET;
8150
8151 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008152 if (curwin->w_curswant != MAXCOL
8153 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8154 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 check_redraw(options[opt_idx].flags);
8156
8157 return NULL;
8158}
8159
8160/*
8161 * Set the value of a number option, and take care of side effects.
8162 * Returns NULL for success, or an error message for an error.
8163 */
8164 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008165set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 int opt_idx; /* index in options[] table */
8167 char_u *varp; /* pointer to the option variable */
8168 long value; /* new value */
8169 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008170 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8172 OPT_MODELINE */
8173{
8174 char_u *errmsg = NULL;
8175 long old_value = *(long *)varp;
8176 long old_Rows = Rows; /* remember old Rows */
8177 long old_Columns = Columns; /* remember old Columns */
8178 long *pp = (long *)varp;
8179
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008180 /* Disallow changing some options from secure mode. */
8181 if ((secure
8182#ifdef HAVE_SANDBOX
8183 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008185 ) && (options[opt_idx].flags & P_SECURE))
8186 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187
8188 *pp = value;
8189#ifdef FEAT_EVAL
8190 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008191 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008193#ifdef FEAT_GUI
8194 need_mouse_correct = TRUE;
8195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196
Bram Moolenaar14f24742012-08-08 18:01:05 +02008197 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 {
8199 errmsg = e_positive;
8200 curbuf->b_p_sw = curbuf->b_p_ts;
8201 }
8202
8203 /*
8204 * Number options that need some action when changed
8205 */
8206#ifdef FEAT_WINDOWS
8207 if (pp == &p_wh || pp == &p_hh)
8208 {
8209 if (p_wh < 1)
8210 {
8211 errmsg = e_positive;
8212 p_wh = 1;
8213 }
8214 if (p_wmh > p_wh)
8215 {
8216 errmsg = e_winheight;
8217 p_wh = p_wmh;
8218 }
8219 if (p_hh < 0)
8220 {
8221 errmsg = e_positive;
8222 p_hh = 0;
8223 }
8224
8225 /* Change window height NOW */
8226 if (lastwin != firstwin)
8227 {
8228 if (pp == &p_wh && curwin->w_height < p_wh)
8229 win_setheight((int)p_wh);
8230 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8231 win_setheight((int)p_hh);
8232 }
8233 }
8234
8235 /* 'winminheight' */
8236 else if (pp == &p_wmh)
8237 {
8238 if (p_wmh < 0)
8239 {
8240 errmsg = e_positive;
8241 p_wmh = 0;
8242 }
8243 if (p_wmh > p_wh)
8244 {
8245 errmsg = e_winheight;
8246 p_wmh = p_wh;
8247 }
8248 win_setminheight();
8249 }
8250
8251# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008252 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253 {
8254 if (p_wiw < 1)
8255 {
8256 errmsg = e_positive;
8257 p_wiw = 1;
8258 }
8259 if (p_wmw > p_wiw)
8260 {
8261 errmsg = e_winwidth;
8262 p_wiw = p_wmw;
8263 }
8264
8265 /* Change window width NOW */
8266 if (lastwin != firstwin && curwin->w_width < p_wiw)
8267 win_setwidth((int)p_wiw);
8268 }
8269
8270 /* 'winminwidth' */
8271 else if (pp == &p_wmw)
8272 {
8273 if (p_wmw < 0)
8274 {
8275 errmsg = e_positive;
8276 p_wmw = 0;
8277 }
8278 if (p_wmw > p_wiw)
8279 {
8280 errmsg = e_winwidth;
8281 p_wmw = p_wiw;
8282 }
8283 win_setminheight();
8284 }
8285# endif
8286
8287#endif
8288
8289#ifdef FEAT_WINDOWS
8290 /* (re)set last window status line */
8291 else if (pp == &p_ls)
8292 {
8293 last_status(FALSE);
8294 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008295
8296 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008297 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008298 {
8299 shell_new_rows(); /* recompute window positions and heights */
8300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301#endif
8302
8303#ifdef FEAT_GUI
8304 else if (pp == &p_linespace)
8305 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008306 /* Recompute gui.char_height and resize the Vim window to keep the
8307 * same number of lines. */
8308 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008309 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 }
8311#endif
8312
8313#ifdef FEAT_FOLDING
8314 /* 'foldlevel' */
8315 else if (pp == &curwin->w_p_fdl)
8316 {
8317 if (curwin->w_p_fdl < 0)
8318 curwin->w_p_fdl = 0;
8319 newFoldLevel();
8320 }
8321
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008322 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 else if (pp == &curwin->w_p_fml)
8324 {
8325 foldUpdateAll(curwin);
8326 }
8327
8328 /* 'foldnestmax' */
8329 else if (pp == &curwin->w_p_fdn)
8330 {
8331 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8332 foldUpdateAll(curwin);
8333 }
8334
8335 /* 'foldcolumn' */
8336 else if (pp == &curwin->w_p_fdc)
8337 {
8338 if (curwin->w_p_fdc < 0)
8339 {
8340 errmsg = e_positive;
8341 curwin->w_p_fdc = 0;
8342 }
8343 else if (curwin->w_p_fdc > 12)
8344 {
8345 errmsg = e_invarg;
8346 curwin->w_p_fdc = 12;
8347 }
8348 }
8349
8350 /* 'shiftwidth' or 'tabstop' */
8351 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8352 {
8353 if (foldmethodIsIndent(curwin))
8354 foldUpdateAll(curwin);
8355 }
8356#endif /* FEAT_FOLDING */
8357
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008358#ifdef FEAT_MBYTE
8359 /* 'maxcombine' */
8360 else if (pp == &p_mco)
8361 {
8362 if (p_mco > MAX_MCO)
8363 p_mco = MAX_MCO;
8364 else if (p_mco < 0)
8365 p_mco = 0;
8366 screenclear(); /* will re-allocate the screen */
8367 }
8368#endif
8369
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 else if (pp == &curbuf->b_p_iminsert)
8371 {
8372 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8373 {
8374 errmsg = e_invarg;
8375 curbuf->b_p_iminsert = B_IMODE_NONE;
8376 }
8377 p_iminsert = curbuf->b_p_iminsert;
8378 if (termcap_active) /* don't do this in the alternate screen */
8379 showmode();
8380#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8381 /* Show/unshow value of 'keymap' in status lines. */
8382 status_redraw_curbuf();
8383#endif
8384 }
8385
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008386 else if (pp == &p_window)
8387 {
8388 if (p_window < 1)
8389 p_window = 1;
8390 else if (p_window >= Rows)
8391 p_window = Rows - 1;
8392 }
8393
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 else if (pp == &curbuf->b_p_imsearch)
8395 {
8396 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8397 {
8398 errmsg = e_invarg;
8399 curbuf->b_p_imsearch = B_IMODE_NONE;
8400 }
8401 p_imsearch = curbuf->b_p_imsearch;
8402 }
8403
8404#ifdef FEAT_TITLE
8405 /* if 'titlelen' has changed, redraw the title */
8406 else if (pp == &p_titlelen)
8407 {
8408 if (p_titlelen < 0)
8409 {
8410 errmsg = e_positive;
8411 p_titlelen = 85;
8412 }
8413 if (starting != NO_SCREEN && old_value != p_titlelen)
8414 need_maketitle = TRUE;
8415 }
8416#endif
8417
8418 /* if p_ch changed value, change the command line height */
8419 else if (pp == &p_ch)
8420 {
8421 if (p_ch < 1)
8422 {
8423 errmsg = e_positive;
8424 p_ch = 1;
8425 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008426 if (p_ch > Rows - min_rows() + 1)
8427 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428
8429 /* Only compute the new window layout when startup has been
8430 * completed. Otherwise the frame sizes may be wrong. */
8431 if (p_ch != old_value && full_screen
8432#ifdef FEAT_GUI
8433 && !gui.starting
8434#endif
8435 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008436 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 }
8438
8439 /* when 'updatecount' changes from zero to non-zero, open swap files */
8440 else if (pp == &p_uc)
8441 {
8442 if (p_uc < 0)
8443 {
8444 errmsg = e_positive;
8445 p_uc = 100;
8446 }
8447 if (p_uc && !old_value)
8448 ml_open_files();
8449 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008450#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008451 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008452 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008453 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008454 {
8455 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008456 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008457 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008458 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008459 {
8460 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008461 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008462 }
8463 }
8464#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008465#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008466 else if (pp == &p_mzq)
8467 mzvim_reset_timer();
8468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469
8470 /* sync undo before 'undolevels' changes */
8471 else if (pp == &p_ul)
8472 {
8473 /* use the old value, otherwise u_sync() may not work properly */
8474 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008475 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 p_ul = value;
8477 }
8478
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008479#ifdef FEAT_LINEBREAK
8480 /* 'numberwidth' must be positive */
8481 else if (pp == &curwin->w_p_nuw)
8482 {
8483 if (curwin->w_p_nuw < 1)
8484 {
8485 errmsg = e_positive;
8486 curwin->w_p_nuw = 1;
8487 }
8488 if (curwin->w_p_nuw > 10)
8489 {
8490 errmsg = e_invarg;
8491 curwin->w_p_nuw = 10;
8492 }
8493 curwin->w_nrwidth_line_count = 0;
8494 }
8495#endif
8496
Bram Moolenaar1a384422010-07-14 19:53:30 +02008497 else if (pp == &curbuf->b_p_tw)
8498 {
8499 if (curbuf->b_p_tw < 0)
8500 {
8501 errmsg = e_positive;
8502 curbuf->b_p_tw = 0;
8503 }
8504#ifdef FEAT_SYN_HL
8505# ifdef FEAT_WINDOWS
8506 {
8507 win_T *wp;
8508 tabpage_T *tp;
8509
8510 FOR_ALL_TAB_WINDOWS(tp, wp)
8511 check_colorcolumn(wp);
8512 }
8513# else
8514 check_colorcolumn(curwin);
8515# endif
8516#endif
8517 }
8518
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 /*
8520 * Check the bounds for numeric options here
8521 */
8522 if (Rows < min_rows() && full_screen)
8523 {
8524 if (errbuf != NULL)
8525 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008526 vim_snprintf((char *)errbuf, errbuflen,
8527 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008528 errmsg = errbuf;
8529 }
8530 Rows = min_rows();
8531 }
8532 if (Columns < MIN_COLUMNS && full_screen)
8533 {
8534 if (errbuf != NULL)
8535 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008536 vim_snprintf((char *)errbuf, errbuflen,
8537 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 errmsg = errbuf;
8539 }
8540 Columns = MIN_COLUMNS;
8541 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008542 /* Limit the values to avoid an overflow in Rows * Columns. */
8543 if (Columns > 10000)
8544 Columns = 10000;
8545 if (Rows > 1000)
8546 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547
8548#ifdef DJGPP
8549 /* avoid a crash by checking for a too large value of 'columns' */
8550 if (old_Columns != Columns && full_screen && term_console)
8551 mch_check_columns();
8552#endif
8553
8554 /*
8555 * If the screen (shell) height has been changed, assume it is the
8556 * physical screenheight.
8557 */
8558 if (old_Rows != Rows || old_Columns != Columns)
8559 {
8560 /* Changing the screen size is not allowed while updating the screen. */
8561 if (updating_screen)
8562 *pp = old_value;
8563 else if (full_screen
8564#ifdef FEAT_GUI
8565 && !gui.starting
8566#endif
8567 )
8568 set_shellsize((int)Columns, (int)Rows, TRUE);
8569 else
8570 {
8571 /* Postpone the resizing; check the size and cmdline position for
8572 * messages. */
8573 check_shellsize();
8574 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8575 cmdline_row = Rows - p_ch;
8576 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008577 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008578 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008579 }
8580
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581 if (curbuf->b_p_ts <= 0)
8582 {
8583 errmsg = e_positive;
8584 curbuf->b_p_ts = 8;
8585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586 if (p_tm < 0)
8587 {
8588 errmsg = e_positive;
8589 p_tm = 0;
8590 }
8591 if ((curwin->w_p_scr <= 0
8592 || (curwin->w_p_scr > curwin->w_height
8593 && curwin->w_height > 0))
8594 && full_screen)
8595 {
8596 if (pp == &(curwin->w_p_scr))
8597 {
8598 if (curwin->w_p_scr != 0)
8599 errmsg = e_scroll;
8600 win_comp_scroll(curwin);
8601 }
8602 /* If 'scroll' became invalid because of a side effect silently adjust
8603 * it. */
8604 else if (curwin->w_p_scr <= 0)
8605 curwin->w_p_scr = 1;
8606 else /* curwin->w_p_scr > curwin->w_height */
8607 curwin->w_p_scr = curwin->w_height;
8608 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008609 if (p_hi < 0)
8610 {
8611 errmsg = e_positive;
8612 p_hi = 0;
8613 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008614 if (p_re < 0 || p_re > 2)
8615 {
8616 errmsg = e_invarg;
8617 p_re = 0;
8618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008619 if (p_report < 0)
8620 {
8621 errmsg = e_positive;
8622 p_report = 1;
8623 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008624 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 {
8626 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8627 p_sj = Rows / 2;
8628 else
8629 {
8630 errmsg = e_scroll;
8631 p_sj = 1;
8632 }
8633 }
8634 if (p_so < 0 && full_screen)
8635 {
8636 errmsg = e_scroll;
8637 p_so = 0;
8638 }
8639 if (p_siso < 0 && full_screen)
8640 {
8641 errmsg = e_positive;
8642 p_siso = 0;
8643 }
8644#ifdef FEAT_CMDWIN
8645 if (p_cwh < 1)
8646 {
8647 errmsg = e_positive;
8648 p_cwh = 1;
8649 }
8650#endif
8651 if (p_ut < 0)
8652 {
8653 errmsg = e_positive;
8654 p_ut = 2000;
8655 }
8656 if (p_ss < 0)
8657 {
8658 errmsg = e_positive;
8659 p_ss = 0;
8660 }
8661
8662 /* May set global value for local option. */
8663 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8664 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8665
8666 options[opt_idx].flags |= P_WAS_SET;
8667
8668 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008669 if (curwin->w_curswant != MAXCOL
8670 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8671 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 check_redraw(options[opt_idx].flags);
8673
8674 return errmsg;
8675}
8676
8677/*
8678 * Called after an option changed: check if something needs to be redrawn.
8679 */
8680 static void
8681check_redraw(flags)
8682 long_u flags;
8683{
8684 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008685 int doclear = (flags & P_RCLR) == P_RCLR;
8686 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687
8688#ifdef FEAT_WINDOWS
8689 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8690 status_redraw_all();
8691#endif
8692
8693 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8694 changed_window_setting();
8695 if (flags & P_RBUF)
8696 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008697 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698 redraw_all_later(CLEAR);
8699 else if (all)
8700 redraw_all_later(NOT_VALID);
8701}
8702
8703/*
8704 * Find index for option 'arg'.
8705 * Return -1 if not found.
8706 */
8707 static int
8708findoption(arg)
8709 char_u *arg;
8710{
8711 int opt_idx;
8712 char *s, *p;
8713 static short quick_tab[27] = {0, 0}; /* quick access table */
8714 int is_term_opt;
8715
8716 /*
8717 * For first call: Initialize the quick-access table.
8718 * It contains the index for the first option that starts with a certain
8719 * letter. There are 26 letters, plus the first "t_" option.
8720 */
8721 if (quick_tab[1] == 0)
8722 {
8723 p = options[0].fullname;
8724 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8725 {
8726 if (s[0] != p[0])
8727 {
8728 if (s[0] == 't' && s[1] == '_')
8729 quick_tab[26] = opt_idx;
8730 else
8731 quick_tab[CharOrdLow(s[0])] = opt_idx;
8732 }
8733 p = s;
8734 }
8735 }
8736
8737 /*
8738 * Check for name starting with an illegal character.
8739 */
8740#ifdef EBCDIC
8741 if (!islower(arg[0]))
8742#else
8743 if (arg[0] < 'a' || arg[0] > 'z')
8744#endif
8745 return -1;
8746
8747 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8748 if (is_term_opt)
8749 opt_idx = quick_tab[26];
8750 else
8751 opt_idx = quick_tab[CharOrdLow(arg[0])];
8752 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8753 {
8754 if (STRCMP(arg, s) == 0) /* match full name */
8755 break;
8756 }
8757 if (s == NULL && !is_term_opt)
8758 {
8759 opt_idx = quick_tab[CharOrdLow(arg[0])];
8760 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8761 {
8762 s = options[opt_idx].shortname;
8763 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8764 break;
8765 s = NULL;
8766 }
8767 }
8768 if (s == NULL)
8769 opt_idx = -1;
8770 return opt_idx;
8771}
8772
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008773#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774/*
8775 * Get the value for an option.
8776 *
8777 * Returns:
8778 * Number or Toggle option: 1, *numval gets value.
8779 * String option: 0, *stringval gets allocated string.
8780 * Hidden Number or Toggle option: -1.
8781 * hidden String option: -2.
8782 * unknown option: -3.
8783 */
8784 int
8785get_option_value(name, numval, stringval, opt_flags)
8786 char_u *name;
8787 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008788 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 int opt_flags;
8790{
8791 int opt_idx;
8792 char_u *varp;
8793
8794 opt_idx = findoption(name);
8795 if (opt_idx < 0) /* unknown option */
8796 return -3;
8797
8798 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8799
8800 if (options[opt_idx].flags & P_STRING)
8801 {
8802 if (varp == NULL) /* hidden option */
8803 return -2;
8804 if (stringval != NULL)
8805 {
8806#ifdef FEAT_CRYPT
8807 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008808 if ((char_u **)varp == &curbuf->b_p_key
8809 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 *stringval = vim_strsave((char_u *)"*****");
8811 else
8812#endif
8813 *stringval = vim_strsave(*(char_u **)(varp));
8814 }
8815 return 0;
8816 }
8817
8818 if (varp == NULL) /* hidden option */
8819 return -1;
8820 if (options[opt_idx].flags & P_NUM)
8821 *numval = *(long *)varp;
8822 else
8823 {
8824 /* Special case: 'modified' is b_changed, but we also want to consider
8825 * it set when 'ff' or 'fenc' changed. */
8826 if ((int *)varp == &curbuf->b_changed)
8827 *numval = curbufIsChanged();
8828 else
8829 *numval = *(int *)varp;
8830 }
8831 return 1;
8832}
8833#endif
8834
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008835#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8836/*
8837 * Returns the option attributes and its value. Unlike the above function it
8838 * will return either global value or local value of the option depending on
8839 * what was requested, but it will never return global value if it was
8840 * requested to return local one and vice versa. Neither it will return
8841 * buffer-local value if it was requested to return window-local one.
8842 *
8843 * Pretends that option is absent if it is not present in the requested scope
8844 * (i.e. has no global, window-local or buffer-local value depending on
8845 * opt_type). Uses
8846 *
8847 * Returned flags:
8848 * 0 hidden or unknown option
8849 * see SOPT_* in vim.h for other flags
8850 *
8851 * Possible opt_type values: see SREQ_* in vim.h
8852 */
8853 int
8854get_option_value_strict(name, numval, stringval, opt_type, from)
8855 char_u *name;
8856 long *numval;
8857 char_u **stringval; /* NULL when only obtaining attributes */
8858 int opt_type;
8859 void *from;
8860{
8861 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008862 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008863 struct vimoption *p;
8864 int r = 0;
8865
8866 opt_idx = findoption(name);
8867 if (opt_idx < 0)
8868 return 0;
8869
8870 p = &(options[opt_idx]);
8871
8872 /* Hidden option */
8873 if (p->var == NULL)
8874 return 0;
8875
8876 if (p->flags & P_BOOL)
8877 r |= SOPT_BOOL;
8878 else if (p->flags & P_NUM)
8879 r |= SOPT_NUM;
8880 else if (p->flags & P_STRING)
8881 r |= SOPT_STRING;
8882
8883 if (p->indir == PV_NONE)
8884 {
8885 if (opt_type == SREQ_GLOBAL)
8886 r |= SOPT_GLOBAL;
8887 else
8888 return 0; /* Did not request global-only option */
8889 }
8890 else
8891 {
8892 if (p->indir & PV_BOTH)
8893 r |= SOPT_GLOBAL;
8894 else if (opt_type == SREQ_GLOBAL)
8895 return 0; /* Requested global option */
8896
8897 if (p->indir & PV_WIN)
8898 {
8899 if (opt_type == SREQ_BUF)
8900 return 0; /* Did not request window-local option */
8901 else
8902 r |= SOPT_WIN;
8903 }
8904 else if (p->indir & PV_BUF)
8905 {
8906 if (opt_type == SREQ_WIN)
8907 return 0; /* Did not request buffer-local option */
8908 else
8909 r |= SOPT_BUF;
8910 }
8911 }
8912
8913 if (stringval == NULL)
8914 return r;
8915
8916 if (opt_type == SREQ_GLOBAL)
8917 varp = p->var;
8918 else
8919 {
8920 if (opt_type == SREQ_BUF)
8921 {
8922 /* Special case: 'modified' is b_changed, but we also want to
8923 * consider it set when 'ff' or 'fenc' changed. */
8924 if (p->indir == PV_MOD)
8925 {
8926 *numval = bufIsChanged((buf_T *) from);
8927 varp = NULL;
8928 }
8929#ifdef FEAT_CRYPT
8930 else if (p->indir == PV_KEY)
8931 {
8932 /* never return the value of the crypt key */
8933 *stringval = NULL;
8934 varp = NULL;
8935 }
8936#endif
8937 else
8938 {
8939 aco_save_T aco;
8940 aucmd_prepbuf(&aco, (buf_T *) from);
8941 varp = get_varp(p);
8942 aucmd_restbuf(&aco);
8943 }
8944 }
8945 else if (opt_type == SREQ_WIN)
8946 {
8947 win_T *save_curwin;
8948 save_curwin = curwin;
8949 curwin = (win_T *) from;
8950 curbuf = curwin->w_buffer;
8951 varp = get_varp(p);
8952 curwin = save_curwin;
8953 curbuf = curwin->w_buffer;
8954 }
8955 if (varp == p->var)
8956 return (r | SOPT_UNSET);
8957 }
8958
8959 if (varp != NULL)
8960 {
8961 if (p->flags & P_STRING)
8962 *stringval = vim_strsave(*(char_u **)(varp));
8963 else if (p->flags & P_NUM)
8964 *numval = *(long *) varp;
8965 else
8966 *numval = *(int *)varp;
8967 }
8968
8969 return r;
8970}
8971#endif
8972
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973/*
8974 * Set the value of option "name".
8975 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02008976 *
8977 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02008979 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980set_option_value(name, number, string, opt_flags)
8981 char_u *name;
8982 long number;
8983 char_u *string;
8984 int opt_flags; /* OPT_LOCAL or 0 (both) */
8985{
8986 int opt_idx;
8987 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008988 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989
8990 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008991 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 EMSG2(_("E355: Unknown option: %s"), name);
8993 else
8994 {
8995 flags = options[opt_idx].flags;
8996#ifdef HAVE_SANDBOX
8997 /* Disallow changing some options in the sandbox */
8998 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008999 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009001 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009004 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009005 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006 else
9007 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009008 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 if (varp != NULL) /* hidden option is not changed */
9010 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009011 if (number == 0 && string != NULL)
9012 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009013 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009014
9015 /* Either we are given a string or we are setting option
9016 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009017 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009018 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009019 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009020 {
9021 /* There's another character after zeros or the string
9022 * is empty. In both cases, we are trying to set a
9023 * num option using a string. */
9024 EMSG3(_("E521: Number required: &%s = '%s'"),
9025 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009026 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009027
9028 }
9029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009030 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009031 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009032 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009034 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009035 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036 }
9037 }
9038 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009039 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009040}
9041
9042/*
9043 * Get the terminal code for a terminal option.
9044 * Returns NULL when not found.
9045 */
9046 char_u *
9047get_term_code(tname)
9048 char_u *tname;
9049{
9050 int opt_idx;
9051 char_u *varp;
9052
9053 if (tname[0] != 't' || tname[1] != '_' ||
9054 tname[2] == NUL || tname[3] == NUL)
9055 return NULL;
9056 if ((opt_idx = findoption(tname)) >= 0)
9057 {
9058 varp = get_varp(&(options[opt_idx]));
9059 if (varp != NULL)
9060 varp = *(char_u **)(varp);
9061 return varp;
9062 }
9063 return find_termcode(tname + 2);
9064}
9065
9066 char_u *
9067get_highlight_default()
9068{
9069 int i;
9070
9071 i = findoption((char_u *)"hl");
9072 if (i >= 0)
9073 return options[i].def_val[VI_DEFAULT];
9074 return (char_u *)NULL;
9075}
9076
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009077#if defined(FEAT_MBYTE) || defined(PROTO)
9078 char_u *
9079get_encoding_default()
9080{
9081 int i;
9082
9083 i = findoption((char_u *)"enc");
9084 if (i >= 0)
9085 return options[i].def_val[VI_DEFAULT];
9086 return (char_u *)NULL;
9087}
9088#endif
9089
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090/*
9091 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9092 */
9093 static int
9094find_key_option(arg)
9095 char_u *arg;
9096{
9097 int key;
9098 int modifiers;
9099
9100 /*
9101 * Don't use get_special_key_code() for t_xx, we don't want it to call
9102 * add_termcap_entry().
9103 */
9104 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9105 key = TERMCAP2KEY(arg[2], arg[3]);
9106 else
9107 {
9108 --arg; /* put arg at the '<' */
9109 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009110 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 if (modifiers) /* can't handle modifiers here */
9112 key = 0;
9113 }
9114 return key;
9115}
9116
9117/*
9118 * if 'all' == 0: show changed options
9119 * if 'all' == 1: show all normal options
9120 * if 'all' == 2: show all terminal options
9121 */
9122 static void
9123showoptions(all, opt_flags)
9124 int all;
9125 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9126{
9127 struct vimoption *p;
9128 int col;
9129 int isterm;
9130 char_u *varp;
9131 struct vimoption **items;
9132 int item_count;
9133 int run;
9134 int row, rows;
9135 int cols;
9136 int i;
9137 int len;
9138
9139#define INC 20
9140#define GAP 3
9141
9142 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9143 PARAM_COUNT));
9144 if (items == NULL)
9145 return;
9146
9147 /* Highlight title */
9148 if (all == 2)
9149 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9150 else if (opt_flags & OPT_GLOBAL)
9151 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9152 else if (opt_flags & OPT_LOCAL)
9153 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9154 else
9155 MSG_PUTS_TITLE(_("\n--- Options ---"));
9156
9157 /*
9158 * do the loop two times:
9159 * 1. display the short items
9160 * 2. display the long items (only strings and numbers)
9161 */
9162 for (run = 1; run <= 2 && !got_int; ++run)
9163 {
9164 /*
9165 * collect the items in items[]
9166 */
9167 item_count = 0;
9168 for (p = &options[0]; p->fullname != NULL; p++)
9169 {
9170 varp = NULL;
9171 isterm = istermoption(p);
9172 if (opt_flags != 0)
9173 {
9174 if (p->indir != PV_NONE && !isterm)
9175 varp = get_varp_scope(p, opt_flags);
9176 }
9177 else
9178 varp = get_varp(p);
9179 if (varp != NULL
9180 && ((all == 2 && isterm)
9181 || (all == 1 && !isterm)
9182 || (all == 0 && !optval_default(p, varp))))
9183 {
9184 if (p->flags & P_BOOL)
9185 len = 1; /* a toggle option fits always */
9186 else
9187 {
9188 option_value2string(p, opt_flags);
9189 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9190 }
9191 if ((len <= INC - GAP && run == 1) ||
9192 (len > INC - GAP && run == 2))
9193 items[item_count++] = p;
9194 }
9195 }
9196
9197 /*
9198 * display the items
9199 */
9200 if (run == 1)
9201 {
9202 cols = (Columns + GAP - 3) / INC;
9203 if (cols == 0)
9204 cols = 1;
9205 rows = (item_count + cols - 1) / cols;
9206 }
9207 else /* run == 2 */
9208 rows = item_count;
9209 for (row = 0; row < rows && !got_int; ++row)
9210 {
9211 msg_putchar('\n'); /* go to next line */
9212 if (got_int) /* 'q' typed in more */
9213 break;
9214 col = 0;
9215 for (i = row; i < item_count; i += rows)
9216 {
9217 msg_col = col; /* make columns */
9218 showoneopt(items[i], opt_flags);
9219 col += INC;
9220 }
9221 out_flush();
9222 ui_breakcheck();
9223 }
9224 }
9225 vim_free(items);
9226}
9227
9228/*
9229 * Return TRUE if option "p" has its default value.
9230 */
9231 static int
9232optval_default(p, varp)
9233 struct vimoption *p;
9234 char_u *varp;
9235{
9236 int dvi;
9237
9238 if (varp == NULL)
9239 return TRUE; /* hidden option is always at default */
9240 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9241 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009242 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009244 /* the cast to long is required for Manx C, long_i is
9245 * needed for MSVC */
9246 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009247 /* P_STRING */
9248 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9249}
9250
9251/*
9252 * showoneopt: show the value of one option
9253 * must not be called with a hidden option!
9254 */
9255 static void
9256showoneopt(p, opt_flags)
9257 struct vimoption *p;
9258 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9259{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009260 char_u *varp;
9261 int save_silent = silent_mode;
9262
9263 silent_mode = FALSE;
9264 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009265
9266 varp = get_varp_scope(p, opt_flags);
9267
9268 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9269 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9270 ? !curbufIsChanged() : !*(int *)varp))
9271 MSG_PUTS("no");
9272 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9273 MSG_PUTS("--");
9274 else
9275 MSG_PUTS(" ");
9276 MSG_PUTS(p->fullname);
9277 if (!(p->flags & P_BOOL))
9278 {
9279 msg_putchar('=');
9280 /* put value string in NameBuff */
9281 option_value2string(p, opt_flags);
9282 msg_outtrans(NameBuff);
9283 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009284
9285 silent_mode = save_silent;
9286 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287}
9288
9289/*
9290 * Write modified options as ":set" commands to a file.
9291 *
9292 * There are three values for "opt_flags":
9293 * OPT_GLOBAL: Write global option values and fresh values of
9294 * buffer-local options (used for start of a session
9295 * file).
9296 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9297 * curwin (used for a vimrc file).
9298 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9299 * and local values for window-local options of
9300 * curwin. Local values are also written when at the
9301 * default value, because a modeline or autocommand
9302 * may have set them when doing ":edit file" and the
9303 * user has set them back at the default or fresh
9304 * value.
9305 * When "local_only" is TRUE, don't write fresh
9306 * values, only local values (for ":mkview").
9307 * (fresh value = value used for a new buffer or window for a local option).
9308 *
9309 * Return FAIL on error, OK otherwise.
9310 */
9311 int
9312makeset(fd, opt_flags, local_only)
9313 FILE *fd;
9314 int opt_flags;
9315 int local_only;
9316{
9317 struct vimoption *p;
9318 char_u *varp; /* currently used value */
9319 char_u *varp_fresh; /* local value */
9320 char_u *varp_local = NULL; /* fresh value */
9321 char *cmd;
9322 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009323 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324
9325 /*
9326 * The options that don't have a default (terminal name, columns, lines)
9327 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009328 * Do the loop over "options[]" twice: once for options with the
9329 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009331 for (pri = 1; pri >= 0; --pri)
9332 {
9333 for (p = &options[0]; !istermoption(p); p++)
9334 if (!(p->flags & P_NO_MKRC)
9335 && !istermoption(p)
9336 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 {
9338 /* skip global option when only doing locals */
9339 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9340 continue;
9341
9342 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9343 * file, they are always buffer-specific. */
9344 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9345 continue;
9346
9347 /* Global values are only written when not at the default value. */
9348 varp = get_varp_scope(p, opt_flags);
9349 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9350 continue;
9351
9352 round = 2;
9353 if (p->indir != PV_NONE)
9354 {
9355 if (p->var == VAR_WIN)
9356 {
9357 /* skip window-local option when only doing globals */
9358 if (!(opt_flags & OPT_LOCAL))
9359 continue;
9360 /* When fresh value of window-local option is not at the
9361 * default, need to write it too. */
9362 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9363 {
9364 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9365 if (!optval_default(p, varp_fresh))
9366 {
9367 round = 1;
9368 varp_local = varp;
9369 varp = varp_fresh;
9370 }
9371 }
9372 }
9373 }
9374
9375 /* Round 1: fresh value for window-local options.
9376 * Round 2: other values */
9377 for ( ; round <= 2; varp = varp_local, ++round)
9378 {
9379 if (round == 1 || (opt_flags & OPT_GLOBAL))
9380 cmd = "set";
9381 else
9382 cmd = "setlocal";
9383
9384 if (p->flags & P_BOOL)
9385 {
9386 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9387 return FAIL;
9388 }
9389 else if (p->flags & P_NUM)
9390 {
9391 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9392 return FAIL;
9393 }
9394 else /* P_STRING */
9395 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009396#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9397 int do_endif = FALSE;
9398
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399 /* Don't set 'syntax' and 'filetype' again if the value is
9400 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009401 if (
9402# if defined(FEAT_SYN_HL)
9403 p->indir == PV_SYN
9404# if defined(FEAT_AUTOCMD)
9405 ||
9406# endif
9407# endif
9408# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009409 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009410# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009411 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412 {
9413 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9414 *(char_u **)(varp)) < 0
9415 || put_eol(fd) < 0)
9416 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009417 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9421 (p->flags & P_EXPAND) != 0) == FAIL)
9422 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009423#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9424 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 {
9426 if (put_line(fd, "endif") == FAIL)
9427 return FAIL;
9428 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430 }
9431 }
9432 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009433 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434 return OK;
9435}
9436
9437#if defined(FEAT_FOLDING) || defined(PROTO)
9438/*
9439 * Generate set commands for the local fold options only. Used when
9440 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9441 */
9442 int
9443makefoldset(fd)
9444 FILE *fd;
9445{
9446 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9447# ifdef FEAT_EVAL
9448 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9449 == FAIL
9450# endif
9451 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9452 == FAIL
9453 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9454 == FAIL
9455 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9456 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9457 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9458 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9459 )
9460 return FAIL;
9461
9462 return OK;
9463}
9464#endif
9465
9466 static int
9467put_setstring(fd, cmd, name, valuep, expand)
9468 FILE *fd;
9469 char *cmd;
9470 char *name;
9471 char_u **valuep;
9472 int expand;
9473{
9474 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009475 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476
9477 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9478 return FAIL;
9479 if (*valuep != NULL)
9480 {
9481 /* Output 'pastetoggle' as key names. For other
9482 * options some characters have to be escaped with
9483 * CTRL-V or backslash */
9484 if (valuep == &p_pt)
9485 {
9486 s = *valuep;
9487 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009488 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489 return FAIL;
9490 }
9491 else if (expand)
9492 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009493 buf = alloc(MAXPATHL);
9494 if (buf == NULL)
9495 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9497 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009498 {
9499 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009500 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009501 }
9502 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009503 }
9504 else if (put_escstr(fd, *valuep, 2) == FAIL)
9505 return FAIL;
9506 }
9507 if (put_eol(fd) < 0)
9508 return FAIL;
9509 return OK;
9510}
9511
9512 static int
9513put_setnum(fd, cmd, name, valuep)
9514 FILE *fd;
9515 char *cmd;
9516 char *name;
9517 long *valuep;
9518{
9519 long wc;
9520
9521 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9522 return FAIL;
9523 if (wc_use_keyname((char_u *)valuep, &wc))
9524 {
9525 /* print 'wildchar' and 'wildcharm' as a key name */
9526 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9527 return FAIL;
9528 }
9529 else if (fprintf(fd, "%ld", *valuep) < 0)
9530 return FAIL;
9531 if (put_eol(fd) < 0)
9532 return FAIL;
9533 return OK;
9534}
9535
9536 static int
9537put_setbool(fd, cmd, name, value)
9538 FILE *fd;
9539 char *cmd;
9540 char *name;
9541 int value;
9542{
Bram Moolenaar893de922007-10-02 18:40:57 +00009543 if (value < 0) /* global/local option using global value */
9544 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009545 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9546 || put_eol(fd) < 0)
9547 return FAIL;
9548 return OK;
9549}
9550
9551/*
9552 * Clear all the terminal options.
9553 * If the option has been allocated, free the memory.
9554 * Terminal options are never hidden or indirect.
9555 */
9556 void
9557clear_termoptions()
9558{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559 /*
9560 * Reset a few things before clearing the old options. This may cause
9561 * outputting a few things that the terminal doesn't understand, but the
9562 * screen will be cleared later, so this is OK.
9563 */
9564#ifdef FEAT_MOUSE_TTY
9565 mch_setmouse(FALSE); /* switch mouse off */
9566#endif
9567#ifdef FEAT_TITLE
9568 mch_restore_title(3); /* restore window titles */
9569#endif
9570#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9571 /* When starting the GUI close the display opened for the clipboard.
9572 * After restoring the title, because that will need the display. */
9573 if (gui.starting)
9574 clear_xterm_clip();
9575#endif
9576#ifdef WIN3264
9577 /*
9578 * Check if this is allowed now.
9579 */
9580 if (can_end_termcap_mode(FALSE) == TRUE)
9581#endif
9582 stoptermcap(); /* stop termcap mode */
9583
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009584 free_termoptions();
9585}
9586
9587 void
9588free_termoptions()
9589{
9590 struct vimoption *p;
9591
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 for (p = &options[0]; p->fullname != NULL; p++)
9593 if (istermoption(p))
9594 {
9595 if (p->flags & P_ALLOCED)
9596 free_string_option(*(char_u **)(p->var));
9597 if (p->flags & P_DEF_ALLOCED)
9598 free_string_option(p->def_val[VI_DEFAULT]);
9599 *(char_u **)(p->var) = empty_option;
9600 p->def_val[VI_DEFAULT] = empty_option;
9601 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9602 }
9603 clear_termcodes();
9604}
9605
9606/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009607 * Free the string for one term option, if it was allocated.
9608 * Set the string to empty_option and clear allocated flag.
9609 * "var" points to the option value.
9610 */
9611 void
9612free_one_termoption(var)
9613 char_u *var;
9614{
9615 struct vimoption *p;
9616
9617 for (p = &options[0]; p->fullname != NULL; p++)
9618 if (p->var == var)
9619 {
9620 if (p->flags & P_ALLOCED)
9621 free_string_option(*(char_u **)(p->var));
9622 *(char_u **)(p->var) = empty_option;
9623 p->flags &= ~P_ALLOCED;
9624 break;
9625 }
9626}
9627
9628/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 * Set the terminal option defaults to the current value.
9630 * Used after setting the terminal name.
9631 */
9632 void
9633set_term_defaults()
9634{
9635 struct vimoption *p;
9636
9637 for (p = &options[0]; p->fullname != NULL; p++)
9638 {
9639 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9640 {
9641 if (p->flags & P_DEF_ALLOCED)
9642 {
9643 free_string_option(p->def_val[VI_DEFAULT]);
9644 p->flags &= ~P_DEF_ALLOCED;
9645 }
9646 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9647 if (p->flags & P_ALLOCED)
9648 {
9649 p->flags |= P_DEF_ALLOCED;
9650 p->flags &= ~P_ALLOCED; /* don't free the value now */
9651 }
9652 }
9653 }
9654}
9655
9656/*
9657 * return TRUE if 'p' starts with 't_'
9658 */
9659 static int
9660istermoption(p)
9661 struct vimoption *p;
9662{
9663 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9664}
9665
9666/*
9667 * Compute columns for ruler and shown command. 'sc_col' is also used to
9668 * decide what the maximum length of a message on the status line can be.
9669 * If there is a status line for the last window, 'sc_col' is independent
9670 * of 'ru_col'.
9671 */
9672
9673#define COL_RULER 17 /* columns needed by standard ruler */
9674
9675 void
9676comp_col()
9677{
9678#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9679 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9680
9681 sc_col = 0;
9682 ru_col = 0;
9683 if (p_ru)
9684 {
9685#ifdef FEAT_STL_OPT
9686 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9687#else
9688 ru_col = COL_RULER + 1;
9689#endif
9690 /* no last status line, adjust sc_col */
9691 if (!last_has_status)
9692 sc_col = ru_col;
9693 }
9694 if (p_sc)
9695 {
9696 sc_col += SHOWCMD_COLS;
9697 if (!p_ru || last_has_status) /* no need for separating space */
9698 ++sc_col;
9699 }
9700 sc_col = Columns - sc_col;
9701 ru_col = Columns - ru_col;
9702 if (sc_col <= 0) /* screen too narrow, will become a mess */
9703 sc_col = 1;
9704 if (ru_col <= 0)
9705 ru_col = 1;
9706#else
9707 sc_col = Columns;
9708 ru_col = Columns;
9709#endif
9710}
9711
9712/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009713 * Unset local option value, similar to ":set opt<".
9714 */
9715
9716 void
9717unset_global_local_option(name, from)
9718 char_u *name;
9719 void *from;
9720{
9721 struct vimoption *p;
9722 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009723 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009724
9725 opt_idx = findoption(name);
9726 p = &(options[opt_idx]);
9727
9728 switch ((int)p->indir)
9729 {
9730 /* global option with local value: use local value if it's been set */
9731 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009732 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009733 break;
9734 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009735 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009736 break;
9737 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009738 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009739 break;
9740 case PV_AR:
9741 buf->b_p_ar = -1;
9742 break;
9743 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009744 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009745 break;
9746#ifdef FEAT_FIND_ID
9747 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009748 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009749 break;
9750 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009751 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009752 break;
9753#endif
9754#ifdef FEAT_INS_EXPAND
9755 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009756 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009757 break;
9758 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009759 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009760 break;
9761#endif
9762#ifdef FEAT_QUICKFIX
9763 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009764 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009765 break;
9766 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009767 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009768 break;
9769 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009770 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009771 break;
9772#endif
9773#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9774 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009775 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009776 break;
9777#endif
9778#if defined(FEAT_CRYPT)
9779 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009780 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009781 break;
9782#endif
9783#ifdef FEAT_STL_OPT
9784 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009785 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009786 break;
9787#endif
9788 }
9789}
9790
9791/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792 * Get pointer to option variable, depending on local or global scope.
9793 */
9794 static char_u *
9795get_varp_scope(p, opt_flags)
9796 struct vimoption *p;
9797 int opt_flags;
9798{
9799 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9800 {
9801 if (p->var == VAR_WIN)
9802 return (char_u *)GLOBAL_WO(get_varp(p));
9803 return p->var;
9804 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009805 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009806 {
9807 switch ((int)p->indir)
9808 {
9809#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009810 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9811 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9812 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009813#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009814 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9815 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9816 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009817 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009818 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009819#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009820 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9821 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009822#endif
9823#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009824 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9825 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009827#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9828 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9829#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009830#if defined(FEAT_CRYPT)
9831 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9832#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009833#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009834 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836 }
9837 return NULL; /* "cannot happen" */
9838 }
9839 return get_varp(p);
9840}
9841
9842/*
9843 * Get pointer to option variable.
9844 */
9845 static char_u *
9846get_varp(p)
9847 struct vimoption *p;
9848{
9849 /* hidden option, always return NULL */
9850 if (p->var == NULL)
9851 return NULL;
9852
9853 switch ((int)p->indir)
9854 {
9855 case PV_NONE: return p->var;
9856
9857 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009858 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009860 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009862 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009864 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009866 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9868#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009869 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009871 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9873#endif
9874#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009875 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009877 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9879#endif
9880#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009881 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009883 case PV_GP: return *curbuf->b_p_gp != NUL
9884 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9885 case PV_MP: return *curbuf->b_p_mp != NUL
9886 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009887#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009888#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9889 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9890 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9891#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009892#if defined(FEAT_CRYPT)
9893 case PV_CM: return *curbuf->b_p_cm != NUL
9894 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9895#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009896#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009897 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009898 ? (char_u *)&(curwin->w_p_stl) : p->var;
9899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900
9901#ifdef FEAT_ARABIC
9902 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9903#endif
9904 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009905#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009906 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9907#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009908#ifdef FEAT_SYN_HL
9909 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9910 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009911 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913#ifdef FEAT_DIFF
9914 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9915#endif
9916#ifdef FEAT_FOLDING
9917 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9918 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9919 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9920 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9921 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9922 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9923 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9924# ifdef FEAT_EVAL
9925 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9926 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9927# endif
9928 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9929#endif
9930 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009931 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009932#ifdef FEAT_LINEBREAK
9933 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9934#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009935#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9937#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009938#ifdef FEAT_VERTSPLIT
9939 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009941#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9942 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9943#endif
9944#ifdef FEAT_RIGHTLEFT
9945 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9946 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9947#endif
9948 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9949 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9950#ifdef FEAT_LINEBREAK
9951 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9952#endif
9953#ifdef FEAT_SCROLLBIND
9954 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9955#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009956#ifdef FEAT_CURSORBIND
9957 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9958#endif
9959#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009960 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
9961 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963
9964 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9965 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9966#ifdef FEAT_MBYTE
9967 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9968#endif
9969#if defined(FEAT_QUICKFIX)
9970 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9971 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9972#endif
9973 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9974 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9975#ifdef FEAT_CINDENT
9976 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9977 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9978 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9979#endif
9980#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9981 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9982#endif
9983#ifdef FEAT_COMMENTS
9984 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9985#endif
9986#ifdef FEAT_FOLDING
9987 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9988#endif
9989#ifdef FEAT_INS_EXPAND
9990 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9991#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009992#ifdef FEAT_COMPL_FUNC
9993 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009994 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9997 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9998#ifdef FEAT_MBYTE
9999 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10000#endif
10001 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10002#ifdef FEAT_AUTOCMD
10003 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10004#endif
10005 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010006 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10008 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10009 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10010 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10011#ifdef FEAT_FIND_ID
10012# ifdef FEAT_EVAL
10013 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10014# endif
10015#endif
10016#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10017 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10018 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10019#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010020#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010021 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10022#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023#ifdef FEAT_CRYPT
10024 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10025#endif
10026#ifdef FEAT_LISP
10027 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10028#endif
10029 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10030 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10031 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10032 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10033 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010035#ifdef FEAT_TEXTOBJ
10036 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10039#ifdef FEAT_SMARTINDENT
10040 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10041#endif
10042#ifndef SHORT_FNAME
10043 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10044#endif
10045 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10046#ifdef FEAT_SEARCHPATH
10047 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10048#endif
10049 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10050#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010051 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010052 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10053#endif
10054#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010055 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10056 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10057 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010058#endif
10059 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10060 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10061 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10062 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010063#ifdef FEAT_PERSISTENT_UNDO
10064 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10067#ifdef FEAT_KEYMAP
10068 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10069#endif
10070 default: EMSG(_("E356: get_varp ERROR"));
10071 }
10072 /* always return a valid pointer to avoid a crash! */
10073 return (char_u *)&(curbuf->b_p_wm);
10074}
10075
10076/*
10077 * Get the value of 'equalprg', either the buffer-local one or the global one.
10078 */
10079 char_u *
10080get_equalprg()
10081{
10082 if (*curbuf->b_p_ep == NUL)
10083 return p_ep;
10084 return curbuf->b_p_ep;
10085}
10086
10087#if defined(FEAT_WINDOWS) || defined(PROTO)
10088/*
10089 * Copy options from one window to another.
10090 * Used when splitting a window.
10091 */
10092 void
10093win_copy_options(wp_from, wp_to)
10094 win_T *wp_from;
10095 win_T *wp_to;
10096{
10097 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10098 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10099# ifdef FEAT_RIGHTLEFT
10100# ifdef FEAT_FKMAP
10101 /* Is this right? */
10102 wp_to->w_farsi = wp_from->w_farsi;
10103# endif
10104# endif
10105}
10106#endif
10107
10108/*
10109 * Copy the options from one winopt_T to another.
10110 * Doesn't free the old option values in "to", use clear_winopt() for that.
10111 * The 'scroll' option is not copied, because it depends on the window height.
10112 * The 'previewwindow' option is reset, there can be only one preview window.
10113 */
10114 void
10115copy_winopt(from, to)
10116 winopt_T *from;
10117 winopt_T *to;
10118{
10119#ifdef FEAT_ARABIC
10120 to->wo_arab = from->wo_arab;
10121#endif
10122 to->wo_list = from->wo_list;
10123 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010124 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010125#ifdef FEAT_LINEBREAK
10126 to->wo_nuw = from->wo_nuw;
10127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128#ifdef FEAT_RIGHTLEFT
10129 to->wo_rl = from->wo_rl;
10130 to->wo_rlc = vim_strsave(from->wo_rlc);
10131#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010132#ifdef FEAT_STL_OPT
10133 to->wo_stl = vim_strsave(from->wo_stl);
10134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135 to->wo_wrap = from->wo_wrap;
10136#ifdef FEAT_LINEBREAK
10137 to->wo_lbr = from->wo_lbr;
10138#endif
10139#ifdef FEAT_SCROLLBIND
10140 to->wo_scb = from->wo_scb;
10141#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010142#ifdef FEAT_CURSORBIND
10143 to->wo_crb = from->wo_crb;
10144#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010145#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010146 to->wo_spell = from->wo_spell;
10147#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010148#ifdef FEAT_SYN_HL
10149 to->wo_cuc = from->wo_cuc;
10150 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010151 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153#ifdef FEAT_DIFF
10154 to->wo_diff = from->wo_diff;
10155#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010156#ifdef FEAT_CONCEAL
10157 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010158 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160#ifdef FEAT_FOLDING
10161 to->wo_fdc = from->wo_fdc;
10162 to->wo_fen = from->wo_fen;
10163 to->wo_fdi = vim_strsave(from->wo_fdi);
10164 to->wo_fml = from->wo_fml;
10165 to->wo_fdl = from->wo_fdl;
10166 to->wo_fdm = vim_strsave(from->wo_fdm);
10167 to->wo_fdn = from->wo_fdn;
10168# ifdef FEAT_EVAL
10169 to->wo_fde = vim_strsave(from->wo_fde);
10170 to->wo_fdt = vim_strsave(from->wo_fdt);
10171# endif
10172 to->wo_fmr = vim_strsave(from->wo_fmr);
10173#endif
10174 check_winopt(to); /* don't want NULL pointers */
10175}
10176
10177/*
10178 * Check string options in a window for a NULL value.
10179 */
10180 void
10181check_win_options(win)
10182 win_T *win;
10183{
10184 check_winopt(&win->w_onebuf_opt);
10185 check_winopt(&win->w_allbuf_opt);
10186}
10187
10188/*
10189 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10190 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 void
10192check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010193 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194{
10195#ifdef FEAT_FOLDING
10196 check_string_option(&wop->wo_fdi);
10197 check_string_option(&wop->wo_fdm);
10198# ifdef FEAT_EVAL
10199 check_string_option(&wop->wo_fde);
10200 check_string_option(&wop->wo_fdt);
10201# endif
10202 check_string_option(&wop->wo_fmr);
10203#endif
10204#ifdef FEAT_RIGHTLEFT
10205 check_string_option(&wop->wo_rlc);
10206#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010207#ifdef FEAT_STL_OPT
10208 check_string_option(&wop->wo_stl);
10209#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010210#ifdef FEAT_SYN_HL
10211 check_string_option(&wop->wo_cc);
10212#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010213#ifdef FEAT_CONCEAL
10214 check_string_option(&wop->wo_cocu);
10215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216}
10217
10218/*
10219 * Free the allocated memory inside a winopt_T.
10220 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 void
10222clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010223 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224{
10225#ifdef FEAT_FOLDING
10226 clear_string_option(&wop->wo_fdi);
10227 clear_string_option(&wop->wo_fdm);
10228# ifdef FEAT_EVAL
10229 clear_string_option(&wop->wo_fde);
10230 clear_string_option(&wop->wo_fdt);
10231# endif
10232 clear_string_option(&wop->wo_fmr);
10233#endif
10234#ifdef FEAT_RIGHTLEFT
10235 clear_string_option(&wop->wo_rlc);
10236#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010237#ifdef FEAT_STL_OPT
10238 clear_string_option(&wop->wo_stl);
10239#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010240#ifdef FEAT_SYN_HL
10241 clear_string_option(&wop->wo_cc);
10242#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010243#ifdef FEAT_CONCEAL
10244 clear_string_option(&wop->wo_cocu);
10245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246}
10247
10248/*
10249 * Copy global option values to local options for one buffer.
10250 * Used when creating a new buffer and sometimes when entering a buffer.
10251 * flags:
10252 * BCO_ENTER We will enter the buf buffer.
10253 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10254 * appropriate.
10255 * BCO_NOHELP Don't copy the values to a help buffer.
10256 */
10257 void
10258buf_copy_options(buf, flags)
10259 buf_T *buf;
10260 int flags;
10261{
10262 int should_copy = TRUE;
10263 char_u *save_p_isk = NULL; /* init for GCC */
10264 int dont_do_help;
10265 int did_isk = FALSE;
10266
10267 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010268 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 */
10270 if (buf == NULL || !buf_valid(buf))
10271 return;
10272
10273 /*
10274 * Skip this when the option defaults have not been set yet. Happens when
10275 * main() allocates the first buffer.
10276 */
10277 if (p_cpo != NULL)
10278 {
10279 /*
10280 * Always copy when entering and 'cpo' contains 'S'.
10281 * Don't copy when already initialized.
10282 * Don't copy when 'cpo' contains 's' and not entering.
10283 * 'S' BCO_ENTER initialized 's' should_copy
10284 * yes yes X X TRUE
10285 * yes no yes X FALSE
10286 * no X yes X FALSE
10287 * X no no yes FALSE
10288 * X no no no TRUE
10289 * no yes no X TRUE
10290 */
10291 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10292 && (buf->b_p_initialized
10293 || (!(flags & BCO_ENTER)
10294 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10295 should_copy = FALSE;
10296
10297 if (should_copy || (flags & BCO_ALWAYS))
10298 {
10299 /* Don't copy the options specific to a help buffer when
10300 * BCO_NOHELP is given or the options were initialized already
10301 * (jumping back to a help file with CTRL-T or CTRL-O) */
10302 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10303 || buf->b_p_initialized;
10304 if (dont_do_help) /* don't free b_p_isk */
10305 {
10306 save_p_isk = buf->b_p_isk;
10307 buf->b_p_isk = NULL;
10308 }
10309 /*
10310 * Always free the allocated strings.
10311 * If not already initialized, set 'readonly' and copy 'fileformat'.
10312 */
10313 if (!buf->b_p_initialized)
10314 {
10315 free_buf_options(buf, TRUE);
10316 buf->b_p_ro = FALSE; /* don't copy readonly */
10317 buf->b_p_tx = p_tx;
10318#ifdef FEAT_MBYTE
10319 buf->b_p_fenc = vim_strsave(p_fenc);
10320#endif
10321 buf->b_p_ff = vim_strsave(p_ff);
10322#if defined(FEAT_QUICKFIX)
10323 buf->b_p_bh = empty_option;
10324 buf->b_p_bt = empty_option;
10325#endif
10326 }
10327 else
10328 free_buf_options(buf, FALSE);
10329
10330 buf->b_p_ai = p_ai;
10331 buf->b_p_ai_nopaste = p_ai_nopaste;
10332 buf->b_p_sw = p_sw;
10333 buf->b_p_tw = p_tw;
10334 buf->b_p_tw_nopaste = p_tw_nopaste;
10335 buf->b_p_tw_nobin = p_tw_nobin;
10336 buf->b_p_wm = p_wm;
10337 buf->b_p_wm_nopaste = p_wm_nopaste;
10338 buf->b_p_wm_nobin = p_wm_nobin;
10339 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010340#ifdef FEAT_MBYTE
10341 buf->b_p_bomb = p_bomb;
10342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343 buf->b_p_et = p_et;
10344 buf->b_p_et_nobin = p_et_nobin;
10345 buf->b_p_ml = p_ml;
10346 buf->b_p_ml_nobin = p_ml_nobin;
10347 buf->b_p_inf = p_inf;
10348 buf->b_p_swf = p_swf;
10349#ifdef FEAT_INS_EXPAND
10350 buf->b_p_cpt = vim_strsave(p_cpt);
10351#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010352#ifdef FEAT_COMPL_FUNC
10353 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010354 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 buf->b_p_sts = p_sts;
10357 buf->b_p_sts_nopaste = p_sts_nopaste;
10358#ifndef SHORT_FNAME
10359 buf->b_p_sn = p_sn;
10360#endif
10361#ifdef FEAT_COMMENTS
10362 buf->b_p_com = vim_strsave(p_com);
10363#endif
10364#ifdef FEAT_FOLDING
10365 buf->b_p_cms = vim_strsave(p_cms);
10366#endif
10367 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010368 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369 buf->b_p_nf = vim_strsave(p_nf);
10370 buf->b_p_mps = vim_strsave(p_mps);
10371#ifdef FEAT_SMARTINDENT
10372 buf->b_p_si = p_si;
10373#endif
10374 buf->b_p_ci = p_ci;
10375#ifdef FEAT_CINDENT
10376 buf->b_p_cin = p_cin;
10377 buf->b_p_cink = vim_strsave(p_cink);
10378 buf->b_p_cino = vim_strsave(p_cino);
10379#endif
10380#ifdef FEAT_AUTOCMD
10381 /* Don't copy 'filetype', it must be detected */
10382 buf->b_p_ft = empty_option;
10383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 buf->b_p_pi = p_pi;
10385#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10386 buf->b_p_cinw = vim_strsave(p_cinw);
10387#endif
10388#ifdef FEAT_LISP
10389 buf->b_p_lisp = p_lisp;
10390#endif
10391#ifdef FEAT_SYN_HL
10392 /* Don't copy 'syntax', it must be set */
10393 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010394 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010395#endif
10396#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010397 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010398 (void)compile_cap_prog(&buf->b_s);
10399 buf->b_s.b_p_spf = vim_strsave(p_spf);
10400 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401#endif
10402#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10403 buf->b_p_inde = vim_strsave(p_inde);
10404 buf->b_p_indk = vim_strsave(p_indk);
10405#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010406#if defined(FEAT_EVAL)
10407 buf->b_p_fex = vim_strsave(p_fex);
10408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409#ifdef FEAT_CRYPT
10410 buf->b_p_key = vim_strsave(p_key);
10411#endif
10412#ifdef FEAT_SEARCHPATH
10413 buf->b_p_sua = vim_strsave(p_sua);
10414#endif
10415#ifdef FEAT_KEYMAP
10416 buf->b_p_keymap = vim_strsave(p_keymap);
10417 buf->b_kmap_state |= KEYMAP_INIT;
10418#endif
10419 /* This isn't really an option, but copying the langmap and IME
10420 * state from the current buffer is better than resetting it. */
10421 buf->b_p_iminsert = p_iminsert;
10422 buf->b_p_imsearch = p_imsearch;
10423
10424 /* options that are normally global but also have a local value
10425 * are not copied, start using the global value */
10426 buf->b_p_ar = -1;
10427#ifdef FEAT_QUICKFIX
10428 buf->b_p_gp = empty_option;
10429 buf->b_p_mp = empty_option;
10430 buf->b_p_efm = empty_option;
10431#endif
10432 buf->b_p_ep = empty_option;
10433 buf->b_p_kp = empty_option;
10434 buf->b_p_path = empty_option;
10435 buf->b_p_tags = empty_option;
10436#ifdef FEAT_FIND_ID
10437 buf->b_p_def = empty_option;
10438 buf->b_p_inc = empty_option;
10439# ifdef FEAT_EVAL
10440 buf->b_p_inex = vim_strsave(p_inex);
10441# endif
10442#endif
10443#ifdef FEAT_INS_EXPAND
10444 buf->b_p_dict = empty_option;
10445 buf->b_p_tsr = empty_option;
10446#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010447#ifdef FEAT_TEXTOBJ
10448 buf->b_p_qe = vim_strsave(p_qe);
10449#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010450#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10451 buf->b_p_bexpr = empty_option;
10452#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010453#if defined(FEAT_CRYPT)
10454 buf->b_p_cm = empty_option;
10455#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010456#ifdef FEAT_PERSISTENT_UNDO
10457 buf->b_p_udf = p_udf;
10458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459
10460 /*
10461 * Don't copy the options set by ex_help(), use the saved values,
10462 * when going from a help buffer to a non-help buffer.
10463 * Don't touch these at all when BCO_NOHELP is used and going from
10464 * or to a help buffer.
10465 */
10466 if (dont_do_help)
10467 buf->b_p_isk = save_p_isk;
10468 else
10469 {
10470 buf->b_p_isk = vim_strsave(p_isk);
10471 did_isk = TRUE;
10472 buf->b_p_ts = p_ts;
10473 buf->b_help = FALSE;
10474#ifdef FEAT_QUICKFIX
10475 if (buf->b_p_bt[0] == 'h')
10476 clear_string_option(&buf->b_p_bt);
10477#endif
10478 buf->b_p_ma = p_ma;
10479 }
10480 }
10481
10482 /*
10483 * When the options should be copied (ignoring BCO_ALWAYS), set the
10484 * flag that indicates that the options have been initialized.
10485 */
10486 if (should_copy)
10487 buf->b_p_initialized = TRUE;
10488 }
10489
10490 check_buf_options(buf); /* make sure we don't have NULLs */
10491 if (did_isk)
10492 (void)buf_init_chartab(buf, FALSE);
10493}
10494
10495/*
10496 * Reset the 'modifiable' option and its default value.
10497 */
10498 void
10499reset_modifiable()
10500{
10501 int opt_idx;
10502
10503 curbuf->b_p_ma = FALSE;
10504 p_ma = FALSE;
10505 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010506 if (opt_idx >= 0)
10507 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508}
10509
10510/*
10511 * Set the global value for 'iminsert' to the local value.
10512 */
10513 void
10514set_iminsert_global()
10515{
10516 p_iminsert = curbuf->b_p_iminsert;
10517}
10518
10519/*
10520 * Set the global value for 'imsearch' to the local value.
10521 */
10522 void
10523set_imsearch_global()
10524{
10525 p_imsearch = curbuf->b_p_imsearch;
10526}
10527
10528#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10529static int expand_option_idx = -1;
10530static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10531static int expand_option_flags = 0;
10532
10533 void
10534set_context_in_set_cmd(xp, arg, opt_flags)
10535 expand_T *xp;
10536 char_u *arg;
10537 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10538{
10539 int nextchar;
10540 long_u flags = 0; /* init for GCC */
10541 int opt_idx = 0; /* init for GCC */
10542 char_u *p;
10543 char_u *s;
10544 int is_term_option = FALSE;
10545 int key;
10546
10547 expand_option_flags = opt_flags;
10548
10549 xp->xp_context = EXPAND_SETTINGS;
10550 if (*arg == NUL)
10551 {
10552 xp->xp_pattern = arg;
10553 return;
10554 }
10555 p = arg + STRLEN(arg) - 1;
10556 if (*p == ' ' && *(p - 1) != '\\')
10557 {
10558 xp->xp_pattern = p + 1;
10559 return;
10560 }
10561 while (p > arg)
10562 {
10563 s = p;
10564 /* count number of backslashes before ' ' or ',' */
10565 if (*p == ' ' || *p == ',')
10566 {
10567 while (s > arg && *(s - 1) == '\\')
10568 --s;
10569 }
10570 /* break at a space with an even number of backslashes */
10571 if (*p == ' ' && ((p - s) & 1) == 0)
10572 {
10573 ++p;
10574 break;
10575 }
10576 --p;
10577 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010578 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 {
10580 xp->xp_context = EXPAND_BOOL_SETTINGS;
10581 p += 2;
10582 }
10583 if (STRNCMP(p, "inv", 3) == 0)
10584 {
10585 xp->xp_context = EXPAND_BOOL_SETTINGS;
10586 p += 3;
10587 }
10588 xp->xp_pattern = arg = p;
10589 if (*arg == '<')
10590 {
10591 while (*p != '>')
10592 if (*p++ == NUL) /* expand terminal option name */
10593 return;
10594 key = get_special_key_code(arg + 1);
10595 if (key == 0) /* unknown name */
10596 {
10597 xp->xp_context = EXPAND_NOTHING;
10598 return;
10599 }
10600 nextchar = *++p;
10601 is_term_option = TRUE;
10602 expand_option_name[2] = KEY2TERMCAP0(key);
10603 expand_option_name[3] = KEY2TERMCAP1(key);
10604 }
10605 else
10606 {
10607 if (p[0] == 't' && p[1] == '_')
10608 {
10609 p += 2;
10610 if (*p != NUL)
10611 ++p;
10612 if (*p == NUL)
10613 return; /* expand option name */
10614 nextchar = *++p;
10615 is_term_option = TRUE;
10616 expand_option_name[2] = p[-2];
10617 expand_option_name[3] = p[-1];
10618 }
10619 else
10620 {
10621 /* Allow * wildcard */
10622 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10623 p++;
10624 if (*p == NUL)
10625 return;
10626 nextchar = *p;
10627 *p = NUL;
10628 opt_idx = findoption(arg);
10629 *p = nextchar;
10630 if (opt_idx == -1 || options[opt_idx].var == NULL)
10631 {
10632 xp->xp_context = EXPAND_NOTHING;
10633 return;
10634 }
10635 flags = options[opt_idx].flags;
10636 if (flags & P_BOOL)
10637 {
10638 xp->xp_context = EXPAND_NOTHING;
10639 return;
10640 }
10641 }
10642 }
10643 /* handle "-=" and "+=" */
10644 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10645 {
10646 ++p;
10647 nextchar = '=';
10648 }
10649 if ((nextchar != '=' && nextchar != ':')
10650 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10651 {
10652 xp->xp_context = EXPAND_UNSUCCESSFUL;
10653 return;
10654 }
10655 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10656 {
10657 xp->xp_context = EXPAND_OLD_SETTING;
10658 if (is_term_option)
10659 expand_option_idx = -1;
10660 else
10661 expand_option_idx = opt_idx;
10662 xp->xp_pattern = p + 1;
10663 return;
10664 }
10665 xp->xp_context = EXPAND_NOTHING;
10666 if (is_term_option || (flags & P_NUM))
10667 return;
10668
10669 xp->xp_pattern = p + 1;
10670
10671 if (flags & P_EXPAND)
10672 {
10673 p = options[opt_idx].var;
10674 if (p == (char_u *)&p_bdir
10675 || p == (char_u *)&p_dir
10676 || p == (char_u *)&p_path
10677 || p == (char_u *)&p_rtp
10678#ifdef FEAT_SEARCHPATH
10679 || p == (char_u *)&p_cdpath
10680#endif
10681#ifdef FEAT_SESSION
10682 || p == (char_u *)&p_vdir
10683#endif
10684 )
10685 {
10686 xp->xp_context = EXPAND_DIRECTORIES;
10687 if (p == (char_u *)&p_path
10688#ifdef FEAT_SEARCHPATH
10689 || p == (char_u *)&p_cdpath
10690#endif
10691 )
10692 xp->xp_backslash = XP_BS_THREE;
10693 else
10694 xp->xp_backslash = XP_BS_ONE;
10695 }
10696 else
10697 {
10698 xp->xp_context = EXPAND_FILES;
10699 /* for 'tags' need three backslashes for a space */
10700 if (p == (char_u *)&p_tags)
10701 xp->xp_backslash = XP_BS_THREE;
10702 else
10703 xp->xp_backslash = XP_BS_ONE;
10704 }
10705 }
10706
10707 /* For an option that is a list of file names, find the start of the
10708 * last file name. */
10709 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10710 {
10711 /* count number of backslashes before ' ' or ',' */
10712 if (*p == ' ' || *p == ',')
10713 {
10714 s = p;
10715 while (s > xp->xp_pattern && *(s - 1) == '\\')
10716 --s;
10717 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10718 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10719 {
10720 xp->xp_pattern = p + 1;
10721 break;
10722 }
10723 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010724
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010725#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010726 /* for 'spellsuggest' start at "file:" */
10727 if (options[opt_idx].var == (char_u *)&p_sps
10728 && STRNCMP(p, "file:", 5) == 0)
10729 {
10730 xp->xp_pattern = p + 5;
10731 break;
10732 }
10733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 }
10735
10736 return;
10737}
10738
10739 int
10740ExpandSettings(xp, regmatch, num_file, file)
10741 expand_T *xp;
10742 regmatch_T *regmatch;
10743 int *num_file;
10744 char_u ***file;
10745{
10746 int num_normal = 0; /* Nr of matching non-term-code settings */
10747 int num_term = 0; /* Nr of matching terminal code settings */
10748 int opt_idx;
10749 int match;
10750 int count = 0;
10751 char_u *str;
10752 int loop;
10753 int is_term_opt;
10754 char_u name_buf[MAX_KEY_NAME_LEN];
10755 static char *(names[]) = {"all", "termcap"};
10756 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10757
10758 /* do this loop twice:
10759 * loop == 0: count the number of matching options
10760 * loop == 1: copy the matching options into allocated memory
10761 */
10762 for (loop = 0; loop <= 1; ++loop)
10763 {
10764 regmatch->rm_ic = ic;
10765 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10766 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010767 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10768 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10770 {
10771 if (loop == 0)
10772 num_normal++;
10773 else
10774 (*file)[count++] = vim_strsave((char_u *)names[match]);
10775 }
10776 }
10777 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10778 opt_idx++)
10779 {
10780 if (options[opt_idx].var == NULL)
10781 continue;
10782 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10783 && !(options[opt_idx].flags & P_BOOL))
10784 continue;
10785 is_term_opt = istermoption(&options[opt_idx]);
10786 if (is_term_opt && num_normal > 0)
10787 continue;
10788 match = FALSE;
10789 if (vim_regexec(regmatch, str, (colnr_T)0)
10790 || (options[opt_idx].shortname != NULL
10791 && vim_regexec(regmatch,
10792 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10793 match = TRUE;
10794 else if (is_term_opt)
10795 {
10796 name_buf[0] = '<';
10797 name_buf[1] = 't';
10798 name_buf[2] = '_';
10799 name_buf[3] = str[2];
10800 name_buf[4] = str[3];
10801 name_buf[5] = '>';
10802 name_buf[6] = NUL;
10803 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10804 {
10805 match = TRUE;
10806 str = name_buf;
10807 }
10808 }
10809 if (match)
10810 {
10811 if (loop == 0)
10812 {
10813 if (is_term_opt)
10814 num_term++;
10815 else
10816 num_normal++;
10817 }
10818 else
10819 (*file)[count++] = vim_strsave(str);
10820 }
10821 }
10822 /*
10823 * Check terminal key codes, these are not in the option table
10824 */
10825 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10826 {
10827 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10828 {
10829 if (!isprint(str[0]) || !isprint(str[1]))
10830 continue;
10831
10832 name_buf[0] = 't';
10833 name_buf[1] = '_';
10834 name_buf[2] = str[0];
10835 name_buf[3] = str[1];
10836 name_buf[4] = NUL;
10837
10838 match = FALSE;
10839 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10840 match = TRUE;
10841 else
10842 {
10843 name_buf[0] = '<';
10844 name_buf[1] = 't';
10845 name_buf[2] = '_';
10846 name_buf[3] = str[0];
10847 name_buf[4] = str[1];
10848 name_buf[5] = '>';
10849 name_buf[6] = NUL;
10850
10851 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10852 match = TRUE;
10853 }
10854 if (match)
10855 {
10856 if (loop == 0)
10857 num_term++;
10858 else
10859 (*file)[count++] = vim_strsave(name_buf);
10860 }
10861 }
10862
10863 /*
10864 * Check special key names.
10865 */
10866 regmatch->rm_ic = TRUE; /* ignore case here */
10867 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10868 {
10869 name_buf[0] = '<';
10870 STRCPY(name_buf + 1, str);
10871 STRCAT(name_buf, ">");
10872
10873 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10874 {
10875 if (loop == 0)
10876 num_term++;
10877 else
10878 (*file)[count++] = vim_strsave(name_buf);
10879 }
10880 }
10881 }
10882 if (loop == 0)
10883 {
10884 if (num_normal > 0)
10885 *num_file = num_normal;
10886 else if (num_term > 0)
10887 *num_file = num_term;
10888 else
10889 return OK;
10890 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10891 if (*file == NULL)
10892 {
10893 *file = (char_u **)"";
10894 return FAIL;
10895 }
10896 }
10897 }
10898 return OK;
10899}
10900
10901 int
10902ExpandOldSetting(num_file, file)
10903 int *num_file;
10904 char_u ***file;
10905{
10906 char_u *var = NULL; /* init for GCC */
10907 char_u *buf;
10908
10909 *num_file = 0;
10910 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10911 if (*file == NULL)
10912 return FAIL;
10913
10914 /*
10915 * For a terminal key code expand_option_idx is < 0.
10916 */
10917 if (expand_option_idx < 0)
10918 {
10919 var = find_termcode(expand_option_name + 2);
10920 if (var == NULL)
10921 expand_option_idx = findoption(expand_option_name);
10922 }
10923
10924 if (expand_option_idx >= 0)
10925 {
10926 /* put string of option value in NameBuff */
10927 option_value2string(&options[expand_option_idx], expand_option_flags);
10928 var = NameBuff;
10929 }
10930 else if (var == NULL)
10931 var = (char_u *)"";
10932
10933 /* A backslash is required before some characters. This is the reverse of
10934 * what happens in do_set(). */
10935 buf = vim_strsave_escaped(var, escape_chars);
10936
10937 if (buf == NULL)
10938 {
10939 vim_free(*file);
10940 *file = NULL;
10941 return FAIL;
10942 }
10943
10944#ifdef BACKSLASH_IN_FILENAME
10945 /* For MS-Windows et al. we don't double backslashes at the start and
10946 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010947 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948 if (var[0] == '\\' && var[1] == '\\'
10949 && expand_option_idx >= 0
10950 && (options[expand_option_idx].flags & P_EXPAND)
10951 && vim_isfilec(var[2])
10952 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010953 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954#endif
10955
10956 *file[0] = buf;
10957 *num_file = 1;
10958 return OK;
10959}
10960#endif
10961
10962/*
10963 * Get the value for the numeric or string option *opp in a nice format into
10964 * NameBuff[]. Must not be called with a hidden option!
10965 */
10966 static void
10967option_value2string(opp, opt_flags)
10968 struct vimoption *opp;
10969 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10970{
10971 char_u *varp;
10972
10973 varp = get_varp_scope(opp, opt_flags);
10974
10975 if (opp->flags & P_NUM)
10976 {
10977 long wc = 0;
10978
10979 if (wc_use_keyname(varp, &wc))
10980 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10981 else if (wc != 0)
10982 STRCPY(NameBuff, transchar((int)wc));
10983 else
10984 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10985 }
10986 else /* P_STRING */
10987 {
10988 varp = *(char_u **)(varp);
10989 if (varp == NULL) /* just in case */
10990 NameBuff[0] = NUL;
10991#ifdef FEAT_CRYPT
10992 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010993 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 STRCPY(NameBuff, "*****");
10995#endif
10996 else if (opp->flags & P_EXPAND)
10997 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10998 /* Translate 'pastetoggle' into special key names */
10999 else if ((char_u **)opp->var == &p_pt)
11000 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11001 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011002 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003 }
11004}
11005
11006/*
11007 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11008 * printed as a keyname.
11009 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11010 */
11011 static int
11012wc_use_keyname(varp, wcp)
11013 char_u *varp;
11014 long *wcp;
11015{
11016 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11017 {
11018 *wcp = *(long *)varp;
11019 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11020 return TRUE;
11021 }
11022 return FALSE;
11023}
11024
11025#ifdef FEAT_LANGMAP
11026/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011027 * Any character has an equivalent 'langmap' character. This is used for
11028 * keyboards that have a special language mode that sends characters above
11029 * 128 (although other characters can be translated too). The "to" field is a
11030 * Vim command character. This avoids having to switch the keyboard back to
11031 * ASCII mode when leaving Insert mode.
11032 *
11033 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11034 * commands.
11035 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11036 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11037 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011039# ifdef FEAT_MBYTE
11040/*
11041 * With multi-byte support use growarray for 'langmap' chars >= 256
11042 */
11043typedef struct
11044{
11045 int from;
11046 int to;
11047} langmap_entry_T;
11048
11049static garray_T langmap_mapga;
11050static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051
11052/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011053 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11054 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011056 static void
11057langmap_set_entry(from, to)
11058 int from;
11059 int to;
11060{
11061 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011062 int a = 0;
11063 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011064
11065 /* Do a binary search for an existing entry. */
11066 while (a != b)
11067 {
11068 int i = (a + b) / 2;
11069 int d = entries[i].from - from;
11070
11071 if (d == 0)
11072 {
11073 entries[i].to = to;
11074 return;
11075 }
11076 if (d < 0)
11077 a = i + 1;
11078 else
11079 b = i;
11080 }
11081
11082 if (ga_grow(&langmap_mapga, 1) != OK)
11083 return; /* out of memory */
11084
11085 /* insert new entry at position "a" */
11086 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11087 mch_memmove(entries + 1, entries,
11088 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11089 ++langmap_mapga.ga_len;
11090 entries[0].from = from;
11091 entries[0].to = to;
11092}
11093
11094/*
11095 * Apply 'langmap' to multi-byte character "c" and return the result.
11096 */
11097 int
11098langmap_adjust_mb(c)
11099 int c;
11100{
11101 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11102 int a = 0;
11103 int b = langmap_mapga.ga_len;
11104
11105 while (a != b)
11106 {
11107 int i = (a + b) / 2;
11108 int d = entries[i].from - c;
11109
11110 if (d == 0)
11111 return entries[i].to; /* found matching entry */
11112 if (d < 0)
11113 a = i + 1;
11114 else
11115 b = i;
11116 }
11117 return c; /* no entry found, return "c" unmodified */
11118}
11119# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120
11121 static void
11122langmap_init()
11123{
11124 int i;
11125
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011126 for (i = 0; i < 256; i++)
11127 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11128# ifdef FEAT_MBYTE
11129 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11130# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131}
11132
11133/*
11134 * Called when langmap option is set; the language map can be
11135 * changed at any time!
11136 */
11137 static void
11138langmap_set()
11139{
11140 char_u *p;
11141 char_u *p2;
11142 int from, to;
11143
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011144#ifdef FEAT_MBYTE
11145 ga_clear(&langmap_mapga); /* clear the previous map first */
11146#endif
11147 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148
11149 for (p = p_langmap; p[0] != NUL; )
11150 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011151 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11152 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011153 {
11154 if (p2[0] == '\\' && p2[1] != NUL)
11155 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 }
11157 if (p2[0] == ';')
11158 ++p2; /* abcd;ABCD form, p2 points to A */
11159 else
11160 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11161 while (p[0])
11162 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011163 if (p[0] == ',')
11164 {
11165 ++p;
11166 break;
11167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011168 if (p[0] == '\\' && p[1] != NUL)
11169 ++p;
11170#ifdef FEAT_MBYTE
11171 from = (*mb_ptr2char)(p);
11172#else
11173 from = p[0];
11174#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011175 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176 if (p2 == NULL)
11177 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011178 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011179 if (p[0] != ',')
11180 {
11181 if (p[0] == '\\')
11182 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011184 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011186 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189 }
11190 else
11191 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011192 if (p2[0] != ',')
11193 {
11194 if (p2[0] == '\\')
11195 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011197 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011199 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011200#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 }
11203 if (to == NUL)
11204 {
11205 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11206 transchar(from));
11207 return;
11208 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011209
11210#ifdef FEAT_MBYTE
11211 if (from >= 256)
11212 langmap_set_entry(from, to);
11213 else
11214#endif
11215 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011216
11217 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011218 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011219 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011221 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 if (*p == ';')
11223 {
11224 p = p2;
11225 if (p[0] != NUL)
11226 {
11227 if (p[0] != ',')
11228 {
11229 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11230 return;
11231 }
11232 ++p;
11233 }
11234 break;
11235 }
11236 }
11237 }
11238 }
11239}
11240#endif
11241
11242/*
11243 * Return TRUE if format option 'x' is in effect.
11244 * Take care of no formatting when 'paste' is set.
11245 */
11246 int
11247has_format_option(x)
11248 int x;
11249{
11250 if (p_paste)
11251 return FALSE;
11252 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11253}
11254
11255/*
11256 * Return TRUE if "x" is present in 'shortmess' option, or
11257 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11258 */
11259 int
11260shortmess(x)
11261 int x;
11262{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011263 return p_shm != NULL &&
11264 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 || (vim_strchr(p_shm, 'a') != NULL
11266 && vim_strchr((char_u *)SHM_A, x) != NULL));
11267}
11268
11269/*
11270 * paste_option_changed() - Called after p_paste was set or reset.
11271 */
11272 static void
11273paste_option_changed()
11274{
11275 static int old_p_paste = FALSE;
11276 static int save_sm = 0;
11277#ifdef FEAT_CMDL_INFO
11278 static int save_ru = 0;
11279#endif
11280#ifdef FEAT_RIGHTLEFT
11281 static int save_ri = 0;
11282 static int save_hkmap = 0;
11283#endif
11284 buf_T *buf;
11285
11286 if (p_paste)
11287 {
11288 /*
11289 * Paste switched from off to on.
11290 * Save the current values, so they can be restored later.
11291 */
11292 if (!old_p_paste)
11293 {
11294 /* save options for each buffer */
11295 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11296 {
11297 buf->b_p_tw_nopaste = buf->b_p_tw;
11298 buf->b_p_wm_nopaste = buf->b_p_wm;
11299 buf->b_p_sts_nopaste = buf->b_p_sts;
11300 buf->b_p_ai_nopaste = buf->b_p_ai;
11301 }
11302
11303 /* save global options */
11304 save_sm = p_sm;
11305#ifdef FEAT_CMDL_INFO
11306 save_ru = p_ru;
11307#endif
11308#ifdef FEAT_RIGHTLEFT
11309 save_ri = p_ri;
11310 save_hkmap = p_hkmap;
11311#endif
11312 /* save global values for local buffer options */
11313 p_tw_nopaste = p_tw;
11314 p_wm_nopaste = p_wm;
11315 p_sts_nopaste = p_sts;
11316 p_ai_nopaste = p_ai;
11317 }
11318
11319 /*
11320 * Always set the option values, also when 'paste' is set when it is
11321 * already on.
11322 */
11323 /* set options for each buffer */
11324 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11325 {
11326 buf->b_p_tw = 0; /* textwidth is 0 */
11327 buf->b_p_wm = 0; /* wrapmargin is 0 */
11328 buf->b_p_sts = 0; /* softtabstop is 0 */
11329 buf->b_p_ai = 0; /* no auto-indent */
11330 }
11331
11332 /* set global options */
11333 p_sm = 0; /* no showmatch */
11334#ifdef FEAT_CMDL_INFO
11335# ifdef FEAT_WINDOWS
11336 if (p_ru)
11337 status_redraw_all(); /* redraw to remove the ruler */
11338# endif
11339 p_ru = 0; /* no ruler */
11340#endif
11341#ifdef FEAT_RIGHTLEFT
11342 p_ri = 0; /* no reverse insert */
11343 p_hkmap = 0; /* no Hebrew keyboard */
11344#endif
11345 /* set global values for local buffer options */
11346 p_tw = 0;
11347 p_wm = 0;
11348 p_sts = 0;
11349 p_ai = 0;
11350 }
11351
11352 /*
11353 * Paste switched from on to off: Restore saved values.
11354 */
11355 else if (old_p_paste)
11356 {
11357 /* restore options for each buffer */
11358 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11359 {
11360 buf->b_p_tw = buf->b_p_tw_nopaste;
11361 buf->b_p_wm = buf->b_p_wm_nopaste;
11362 buf->b_p_sts = buf->b_p_sts_nopaste;
11363 buf->b_p_ai = buf->b_p_ai_nopaste;
11364 }
11365
11366 /* restore global options */
11367 p_sm = save_sm;
11368#ifdef FEAT_CMDL_INFO
11369# ifdef FEAT_WINDOWS
11370 if (p_ru != save_ru)
11371 status_redraw_all(); /* redraw to draw the ruler */
11372# endif
11373 p_ru = save_ru;
11374#endif
11375#ifdef FEAT_RIGHTLEFT
11376 p_ri = save_ri;
11377 p_hkmap = save_hkmap;
11378#endif
11379 /* set global values for local buffer options */
11380 p_tw = p_tw_nopaste;
11381 p_wm = p_wm_nopaste;
11382 p_sts = p_sts_nopaste;
11383 p_ai = p_ai_nopaste;
11384 }
11385
11386 old_p_paste = p_paste;
11387}
11388
11389/*
11390 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11391 *
11392 * Reset 'compatible' and set the values for options that didn't get set yet
11393 * to the Vim defaults.
11394 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011395 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396 */
11397 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011398vimrc_found(fname, envname)
11399 char_u *fname;
11400 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011402 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011403 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011404 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405
11406 if (!option_was_set((char_u *)"cp"))
11407 {
11408 p_cp = FALSE;
11409 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11410 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11411 set_option_default(opt_idx, OPT_FREE, FALSE);
11412 didset_options();
11413 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011414
11415 if (fname != NULL)
11416 {
11417 p = vim_getenv(envname, &dofree);
11418 if (p == NULL)
11419 {
11420 /* Set $MYVIMRC to the first vimrc file found. */
11421 p = FullName_save(fname, FALSE);
11422 if (p != NULL)
11423 {
11424 vim_setenv(envname, p);
11425 vim_free(p);
11426 }
11427 }
11428 else if (dofree)
11429 vim_free(p);
11430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431}
11432
11433/*
11434 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11435 */
11436 void
11437change_compatible(on)
11438 int on;
11439{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011440 int opt_idx;
11441
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442 if (p_cp != on)
11443 {
11444 p_cp = on;
11445 compatible_set();
11446 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011447 opt_idx = findoption((char_u *)"cp");
11448 if (opt_idx >= 0)
11449 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450}
11451
11452/*
11453 * Return TRUE when option "name" has been set.
11454 */
11455 int
11456option_was_set(name)
11457 char_u *name;
11458{
11459 int idx;
11460
11461 idx = findoption(name);
11462 if (idx < 0) /* unknown option */
11463 return FALSE;
11464 if (options[idx].flags & P_WAS_SET)
11465 return TRUE;
11466 return FALSE;
11467}
11468
11469/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011470 * Reset the flag indicating option "name" was set.
11471 */
11472 void
11473reset_option_was_set(name)
11474 char_u *name;
11475{
11476 int idx = findoption(name);
11477
11478 if (idx >= 0)
11479 options[idx].flags &= ~P_WAS_SET;
11480}
11481
11482/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483 * compatible_set() - Called when 'compatible' has been set or unset.
11484 *
11485 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11486 * flag) to a Vi compatible value.
11487 * When 'compatible' is unset: Set all options that have a different default
11488 * for Vim (without the P_VI_DEF flag) to that default.
11489 */
11490 static void
11491compatible_set()
11492{
11493 int opt_idx;
11494
11495 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11496 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11497 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11498 set_option_default(opt_idx, OPT_FREE, p_cp);
11499 didset_options();
11500}
11501
11502#ifdef FEAT_LINEBREAK
11503
11504# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11505 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011506 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011507# endif
11508
11509/*
11510 * fill_breakat_flags() -- called when 'breakat' changes value.
11511 */
11512 static void
11513fill_breakat_flags()
11514{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011515 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516 int i;
11517
11518 for (i = 0; i < 256; i++)
11519 breakat_flags[i] = FALSE;
11520
11521 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011522 for (p = p_breakat; *p; p++)
11523 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524}
11525
11526# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011527 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528# endif
11529
11530#endif
11531
11532/*
11533 * Check an option that can be a range of string values.
11534 *
11535 * Return OK for correct value, FAIL otherwise.
11536 * Empty is always OK.
11537 */
11538 static int
11539check_opt_strings(val, values, list)
11540 char_u *val;
11541 char **values;
11542 int list; /* when TRUE: accept a list of values */
11543{
11544 return opt_strings_flags(val, values, NULL, list);
11545}
11546
11547/*
11548 * Handle an option that can be a range of string values.
11549 * Set a flag in "*flagp" for each string present.
11550 *
11551 * Return OK for correct value, FAIL otherwise.
11552 * Empty is always OK.
11553 */
11554 static int
11555opt_strings_flags(val, values, flagp, list)
11556 char_u *val; /* new value */
11557 char **values; /* array of valid string values */
11558 unsigned *flagp;
11559 int list; /* when TRUE: accept a list of values */
11560{
11561 int i;
11562 int len;
11563 unsigned new_flags = 0;
11564
11565 while (*val)
11566 {
11567 for (i = 0; ; ++i)
11568 {
11569 if (values[i] == NULL) /* val not found in values[] */
11570 return FAIL;
11571
11572 len = (int)STRLEN(values[i]);
11573 if (STRNCMP(values[i], val, len) == 0
11574 && ((list && val[len] == ',') || val[len] == NUL))
11575 {
11576 val += len + (val[len] == ',');
11577 new_flags |= (1 << i);
11578 break; /* check next item in val list */
11579 }
11580 }
11581 }
11582 if (flagp != NULL)
11583 *flagp = new_flags;
11584
11585 return OK;
11586}
11587
11588/*
11589 * Read the 'wildmode' option, fill wim_flags[].
11590 */
11591 static int
11592check_opt_wim()
11593{
11594 char_u new_wim_flags[4];
11595 char_u *p;
11596 int i;
11597 int idx = 0;
11598
11599 for (i = 0; i < 4; ++i)
11600 new_wim_flags[i] = 0;
11601
11602 for (p = p_wim; *p; ++p)
11603 {
11604 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11605 ;
11606 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11607 return FAIL;
11608 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11609 new_wim_flags[idx] |= WIM_LONGEST;
11610 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11611 new_wim_flags[idx] |= WIM_FULL;
11612 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11613 new_wim_flags[idx] |= WIM_LIST;
11614 else
11615 return FAIL;
11616 p += i;
11617 if (*p == NUL)
11618 break;
11619 if (*p == ',')
11620 {
11621 if (idx == 3)
11622 return FAIL;
11623 ++idx;
11624 }
11625 }
11626
11627 /* fill remaining entries with last flag */
11628 while (idx < 3)
11629 {
11630 new_wim_flags[idx + 1] = new_wim_flags[idx];
11631 ++idx;
11632 }
11633
11634 /* only when there are no errors, wim_flags[] is changed */
11635 for (i = 0; i < 4; ++i)
11636 wim_flags[i] = new_wim_flags[i];
11637 return OK;
11638}
11639
11640/*
11641 * Check if backspacing over something is allowed.
11642 */
11643 int
11644can_bs(what)
11645 int what; /* BS_INDENT, BS_EOL or BS_START */
11646{
11647 switch (*p_bs)
11648 {
11649 case '2': return TRUE;
11650 case '1': return (what != BS_START);
11651 case '0': return FALSE;
11652 }
11653 return vim_strchr(p_bs, what) != NULL;
11654}
11655
11656/*
11657 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11658 * the file must be considered changed when the value is different.
11659 */
11660 void
11661save_file_ff(buf)
11662 buf_T *buf;
11663{
11664 buf->b_start_ffc = *buf->b_p_ff;
11665 buf->b_start_eol = buf->b_p_eol;
11666#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011667 buf->b_start_bomb = buf->b_p_bomb;
11668
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669 /* Only use free/alloc when necessary, they take time. */
11670 if (buf->b_start_fenc == NULL
11671 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11672 {
11673 vim_free(buf->b_start_fenc);
11674 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11675 }
11676#endif
11677}
11678
11679/*
11680 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11681 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011682 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11683 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011684 * When "ignore_empty" is true don't consider a new, empty buffer to be
11685 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011686 */
11687 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011688file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011690 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011692 /* In a buffer that was never loaded the options are not valid. */
11693 if (buf->b_flags & BF_NEVERLOADED)
11694 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011695 if (ignore_empty
11696 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697 && buf->b_ml.ml_line_count == 1
11698 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11699 return FALSE;
11700 if (buf->b_start_ffc != *buf->b_p_ff)
11701 return TRUE;
11702 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11703 return TRUE;
11704#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011705 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11706 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011707 if (buf->b_start_fenc == NULL)
11708 return (*buf->b_p_fenc != NUL);
11709 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11710#else
11711 return FALSE;
11712#endif
11713}
11714
11715/*
11716 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11717 */
11718 int
11719check_ff_value(p)
11720 char_u *p;
11721{
11722 return check_opt_strings(p, p_ff_values, FALSE);
11723}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011724
11725/*
11726 * Return the effective shiftwidth value for current buffer, using the
11727 * 'tabstop' value when 'shiftwidth' is zero.
11728 */
11729 long
11730get_sw_value()
11731{
11732 return curbuf->b_p_sw ? curbuf->b_p_sw : curbuf->b_p_ts;
11733}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011734
11735/*
11736 * Return the effective softtabstop value for the current buffer, using the
11737 * 'tabstop' value when 'softtabstop' is negative.
11738 */
11739 long
11740get_sts_value()
11741{
11742 return curbuf->b_p_sts < 0 ? get_sw_value() : curbuf->b_p_sts;
11743}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011744
11745/*
11746 * Check matchpairs option for "*initc".
11747 * If there is a match set "*initc" to the matching character and "*findc" to
11748 * the opposite character. Set "*backwards" to the direction.
11749 * When "switchit" is TRUE swap the direction.
11750 */
11751 void
11752find_mps_values(initc, findc, backwards, switchit)
11753 int *initc;
11754 int *findc;
11755 int *backwards;
11756 int switchit;
11757{
11758 char_u *ptr;
11759
11760 ptr = curbuf->b_p_mps;
11761 while (*ptr != NUL)
11762 {
11763#ifdef FEAT_MBYTE
11764 if (has_mbyte)
11765 {
11766 char_u *prev;
11767
11768 if (mb_ptr2char(ptr) == *initc)
11769 {
11770 if (switchit)
11771 {
11772 *findc = *initc;
11773 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11774 *backwards = TRUE;
11775 }
11776 else
11777 {
11778 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11779 *backwards = FALSE;
11780 }
11781 return;
11782 }
11783 prev = ptr;
11784 ptr += mb_ptr2len(ptr) + 1;
11785 if (mb_ptr2char(ptr) == *initc)
11786 {
11787 if (switchit)
11788 {
11789 *findc = *initc;
11790 *initc = mb_ptr2char(prev);
11791 *backwards = FALSE;
11792 }
11793 else
11794 {
11795 *findc = mb_ptr2char(prev);
11796 *backwards = TRUE;
11797 }
11798 return;
11799 }
11800 ptr += mb_ptr2len(ptr);
11801 }
11802 else
11803#endif
11804 {
11805 if (*ptr == *initc)
11806 {
11807 if (switchit)
11808 {
11809 *backwards = TRUE;
11810 *findc = *initc;
11811 *initc = ptr[2];
11812 }
11813 else
11814 {
11815 *backwards = FALSE;
11816 *findc = ptr[2];
11817 }
11818 return;
11819 }
11820 ptr += 2;
11821 if (*ptr == *initc)
11822 {
11823 if (switchit)
11824 {
11825 *backwards = FALSE;
11826 *findc = *initc;
11827 *initc = ptr[-2];
11828 }
11829 else
11830 {
11831 *backwards = TRUE;
11832 *findc = ptr[-2];
11833 }
11834 return;
11835 }
11836 ++ptr;
11837 }
11838 if (*ptr == ',')
11839 ++ptr;
11840 }
11841}