blob: 2dfb6d967ce48e3bd40a54e9661b3a3ef190afda [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 Moolenaar40e6a712010-05-16 22:32:54 +020080#define PV_CM 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)
143#ifdef FEAT_OSFILETYPE
144# define PV_OFT OPT_BUF(BV_OFT)
145#endif
146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000193#ifdef FEAT_DIFF
194# define PV_DIFF OPT_WIN(WV_DIFF)
195#endif
196#ifdef FEAT_FOLDING
197# define PV_FDC OPT_WIN(WV_FDC)
198# define PV_FEN OPT_WIN(WV_FEN)
199# define PV_FDI OPT_WIN(WV_FDI)
200# define PV_FDL OPT_WIN(WV_FDL)
201# define PV_FDM OPT_WIN(WV_FDM)
202# define PV_FML OPT_WIN(WV_FML)
203# define PV_FDN OPT_WIN(WV_FDN)
204# ifdef FEAT_EVAL
205# define PV_FDE OPT_WIN(WV_FDE)
206# define PV_FDT OPT_WIN(WV_FDT)
207# endif
208# define PV_FMR OPT_WIN(WV_FMR)
209#endif
210#ifdef FEAT_LINEBREAK
211# define PV_LBR OPT_WIN(WV_LBR)
212#endif
213#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200214#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000215#ifdef FEAT_LINEBREAK
216# define PV_NUW OPT_WIN(WV_NUW)
217#endif
218#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
219# define PV_PVW OPT_WIN(WV_PVW)
220#endif
221#ifdef FEAT_RIGHTLEFT
222# define PV_RL OPT_WIN(WV_RL)
223# define PV_RLC OPT_WIN(WV_RLC)
224#endif
225#ifdef FEAT_SCROLLBIND
226# define PV_SCBIND OPT_WIN(WV_SCBIND)
227#endif
228#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000230# define PV_SPELL OPT_WIN(WV_SPELL)
231#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SYN_HL
233# define PV_CUC OPT_WIN(WV_CUC)
234# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200235# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237#ifdef FEAT_STL_OPT
238# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
239#endif
240#ifdef FEAT_WINDOWS
241# define PV_WFH OPT_WIN(WV_WFH)
242#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000243#ifdef FEAT_VERTSPLIT
244# define PV_WFW OPT_WIN(WV_WFW)
245#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200247#ifdef FEAT_CURSORBIND
248# define PV_CRBIND OPT_WIN(WV_CRBIND)
249#endif
250#ifdef FEAT_CONCEAL
251# define PV_CONCEAL OPT_WIN(WV_CONCEAL)
252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000253
254/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255typedef enum
256{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000257 PV_NONE = 0,
258 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259} idopt_T;
260
261/*
262 * Options local to a window have a value local to a buffer and global to all
263 * buffers. Indicate this by setting "var" to VAR_WIN.
264 */
265#define VAR_WIN ((char_u *)-1)
266
267/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000268 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269 * Only to be used in option.c!
270 */
271static int p_ai;
272static int p_bin;
273#ifdef FEAT_MBYTE
274static int p_bomb;
275#endif
276#if defined(FEAT_QUICKFIX)
277static char_u *p_bh;
278static char_u *p_bt;
279#endif
280static int p_bl;
281static int p_ci;
282#ifdef FEAT_CINDENT
283static int p_cin;
284static char_u *p_cink;
285static char_u *p_cino;
286#endif
287#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
288static char_u *p_cinw;
289#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200290#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200291static long p_cm;
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
307static int p_et;
308#ifdef FEAT_MBYTE
309static char_u *p_fenc;
310#endif
311static char_u *p_ff;
312static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000313static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314#ifdef FEAT_AUTOCMD
315static char_u *p_ft;
316#endif
317static long p_iminsert;
318static long p_imsearch;
319#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
320static char_u *p_inex;
321#endif
322#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
323static char_u *p_inde;
324static char_u *p_indk;
325#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000326#if defined(FEAT_EVAL)
327static char_u *p_fex;
328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000329static int p_inf;
330static char_u *p_isk;
331#ifdef FEAT_CRYPT
332static char_u *p_key;
333#endif
334#ifdef FEAT_LISP
335static int p_lisp;
336#endif
337static int p_ml;
338static int p_ma;
339static int p_mod;
340static char_u *p_mps;
341static char_u *p_nf;
342#ifdef FEAT_OSFILETYPE
343static char_u *p_oft;
344#endif
345static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000346#ifdef FEAT_TEXTOBJ
347static char_u *p_qe;
348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static int p_ro;
350#ifdef FEAT_SMARTINDENT
351static int p_si;
352#endif
353#ifndef SHORT_FNAME
354static int p_sn;
355#endif
356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
378#ifdef FEAT_KEYMAP
379static char_u *p_keymap;
380#endif
381
382/* Saved values for when 'bin' is set. */
383static int p_et_nobin;
384static int p_ml_nobin;
385static long p_tw_nobin;
386static long p_wm_nobin;
387
388/* Saved values for when 'paste' is set */
389static long p_tw_nopaste;
390static long p_wm_nopaste;
391static long p_sts_nopaste;
392static int p_ai_nopaste;
393
394struct vimoption
395{
396 char *fullname; /* full option name */
397 char *shortname; /* permissible abbreviation */
398 long_u flags; /* see below */
399 char_u *var; /* global option: pointer to variable;
400 * window-local option: VAR_WIN;
401 * buffer-local option: global value */
402 idopt_T indir; /* global option: PV_NONE;
403 * local option: indirect option index */
404 char_u *def_val[2]; /* default values for variable (vi and vim) */
405#ifdef FEAT_EVAL
406 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000407# define SCRIPTID_INIT , 0
408#else
409# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#endif
411};
412
413#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
414#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
415
416/*
417 * Flags
418 */
419#define P_BOOL 0x01 /* the option is boolean */
420#define P_NUM 0x02 /* the option is numeric */
421#define P_STRING 0x04 /* the option is a string */
422#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000423 must use free_string_option() when
424 assigning new value. Not set if default is
425 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
427 never be used for local or hidden options! */
428#define P_NODEFAULT 0x40 /* don't set to default value */
429#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
430 use vim_free() when assigning new value */
431#define P_WAS_SET 0x100 /* option has been set/reset */
432#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
433#define P_VI_DEF 0x400 /* Use Vi default for Vim */
434#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
435
436 /* when option changed, what to display: */
437#define P_RSTAT 0x1000 /* redraw status lines */
438#define P_RWIN 0x2000 /* redraw current window */
439#define P_RBUF 0x4000 /* redraw current buffer */
440#define P_RALL 0x6000 /* redraw all windows */
441#define P_RCLR 0x7000 /* clear and redraw all */
442
443#define P_COMMA 0x8000 /* comma separated list */
444#define P_NODUP 0x10000L/* don't allow duplicate strings */
445#define P_FLAGLIST 0x20000L/* list of single-char flags */
446
447#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
448#define P_GETTEXT 0x80000L/* expand default value with _() */
449#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000450#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000451#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
453 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000455#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
456
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000457/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
458 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000459#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000460# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000461#else
462# define ISP_LATIN1 (char_u *)"@,161-255"
463#endif
464
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000465/* The 16 bit MS-DOS version is low on space, make the string as short as
466 * possible when compiling with few features. */
467#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
468 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200469 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200470# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,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 +0000471#else
472# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
473#endif
474
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475/*
476 * options[] is initialized here.
477 * The order of the options MUST be alphabetic for ":set all" and findoption().
478 * All option names MUST start with a lowercase letter (for findoption()).
479 * Exception: "t_" options are at the end.
480 * The options with a NULL variable are 'hidden': a set command for them is
481 * ignored and they are not printed.
482 */
483static struct vimoption
484#ifdef FEAT_GUI_W16
485 _far
486#endif
487 options[] =
488{
489 {"aleph", "al", P_NUM|P_VI_DEF,
490#ifdef FEAT_RIGHTLEFT
491 (char_u *)&p_aleph, PV_NONE,
492#else
493 (char_u *)NULL, PV_NONE,
494#endif
495 {
496#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
497 (char_u *)128L,
498#else
499 (char_u *)224L,
500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
503#if defined(FEAT_GUI) && defined(MACOS_X)
504 (char_u *)&p_antialias, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#else
507 (char_u *)NULL, PV_NONE,
508 {(char_u *)FALSE, (char_u *)FALSE}
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
512#ifdef FEAT_ARABIC
513 (char_u *)VAR_WIN, PV_ARAB,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
519#ifdef FEAT_ARABIC
520 (char_u *)&p_arshape, PV_NONE,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
526#ifdef FEAT_RIGHTLEFT
527 (char_u *)&p_ari, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
533#ifdef FEAT_FKMAP
534 (char_u *)&p_altkeymap, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
540#if defined(FEAT_MBYTE)
541 (char_u *)&p_ambw, PV_NONE,
542 {(char_u *)"single", (char_u *)0L}
543#else
544 (char_u *)NULL, PV_NONE,
545 {(char_u *)0L, (char_u *)0L}
546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000547 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000548#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autochdir", "acd", P_BOOL|P_VI_DEF,
550 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552#endif
553 {"autoindent", "ai", P_BOOL|P_VI_DEF,
554 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoprint", "ap", P_BOOL|P_VI_DEF,
557 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000560 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowrite", "aw", P_BOOL|P_VI_DEF,
563 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autowriteall","awa", P_BOOL|P_VI_DEF,
566 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
569 (char_u *)&p_bg, PV_NONE,
570 {
571#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
572 (char_u *)"dark",
573#else
574 (char_u *)"light",
575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
578 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
581 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
584 (char_u *)&p_bkc, PV_NONE,
585#ifdef UNIX
586 {(char_u *)"yes", (char_u *)"auto"}
587#else
588 {(char_u *)"auto", (char_u *)"auto"}
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
592 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000594 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595 (char_u *)&p_bex, PV_NONE,
596 {
597#ifdef VMS
598 (char_u *)"_",
599#else
600 (char_u *)"~",
601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
604#ifdef FEAT_WILDIGN
605 (char_u *)&p_bsk, PV_NONE,
606 {(char_u *)"", (char_u *)0L}
607#else
608 (char_u *)NULL, PV_NONE,
609 {(char_u *)0L, (char_u *)0L}
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612#ifdef FEAT_BEVAL
613 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
614 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
617 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000619# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000620 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000621 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000623# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624#endif
625 {"beautify", "bf", P_BOOL|P_VI_DEF,
626 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
629 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
632#ifdef MSDOS
633 (char_u *)&p_biosk, PV_NONE,
634#else
635 (char_u *)NULL, PV_NONE,
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
639#ifdef FEAT_MBYTE
640 (char_u *)&p_bomb, PV_BOMB,
641#else
642 (char_u *)NULL, PV_NONE,
643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
646#ifdef FEAT_LINEBREAK
647 (char_u *)&p_breakat, PV_NONE,
648 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
655#ifdef FEAT_BROWSE
656 (char_u *)&p_bsdir, PV_NONE,
657 {(char_u *)"last", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
664#if defined(FEAT_QUICKFIX)
665 (char_u *)&p_bh, PV_BH,
666 {(char_u *)"", (char_u *)0L}
667#else
668 (char_u *)NULL, PV_NONE,
669 {(char_u *)0L, (char_u *)0L}
670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
673 (char_u *)&p_bl, PV_BL,
674 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000675 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
677#if defined(FEAT_QUICKFIX)
678 (char_u *)&p_bt, PV_BT,
679 {(char_u *)"", (char_u *)0L}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)0L, (char_u *)0L}
683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000686#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 (char_u *)&p_cmp, PV_NONE,
688 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000694 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
695#ifdef FEAT_SEARCHPATH
696 (char_u *)&p_cdpath, PV_NONE,
697 {(char_u *)",,", (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"cedit", NULL, P_STRING,
704#ifdef FEAT_CMDWIN
705 (char_u *)&p_cedit, PV_NONE,
706 {(char_u *)"", (char_u *)CTRL_F_STR}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)0L, (char_u *)0L}
710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
713#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
714 (char_u *)&p_ccv, PV_NONE,
715 {(char_u *)"", (char_u *)0L}
716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
722#ifdef FEAT_CINDENT
723 (char_u *)&p_cin, PV_CIN,
724#else
725 (char_u *)NULL, PV_NONE,
726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
729#ifdef FEAT_CINDENT
730 (char_u *)&p_cink, PV_CINK,
731 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
732#else
733 (char_u *)NULL, PV_NONE,
734 {(char_u *)0L, (char_u *)0L}
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
738#ifdef FEAT_CINDENT
739 (char_u *)&p_cino, PV_CINO,
740#else
741 (char_u *)NULL, PV_NONE,
742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000744 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
745#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
746 (char_u *)&p_cinw, PV_CINW,
747 {(char_u *)"if,else,while,do,for,switch",
748 (char_u *)0L}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
755#ifdef FEAT_CLIPBOARD
756 (char_u *)&p_cb, PV_NONE,
757# ifdef FEAT_XCLIPBOARD
758 {(char_u *)"autoselect,exclude:cons\\|linux",
759 (char_u *)0L}
760# else
761 {(char_u *)"", (char_u *)0L}
762# endif
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)"", (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
769 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
772#ifdef FEAT_CMDWIN
773 (char_u *)&p_cwh, PV_NONE,
774#else
775 (char_u *)NULL, PV_NONE,
776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000777 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200778 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
779#ifdef FEAT_SYN_HL
780 (char_u *)VAR_WIN, PV_CC,
781#else
782 (char_u *)NULL, PV_NONE,
783#endif
784 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
786 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000787 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
789#ifdef FEAT_COMMENTS
790 (char_u *)&p_com, PV_COM,
791 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
792 (char_u *)0L}
793#else
794 (char_u *)NULL, PV_NONE,
795 {(char_u *)0L, (char_u *)0L}
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
799#ifdef FEAT_FOLDING
800 (char_u *)&p_cms, PV_CMS,
801 {(char_u *)"/*%s*/", (char_u *)0L}
802#else
803 (char_u *)NULL, PV_NONE,
804 {(char_u *)0L, (char_u *)0L}
805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000807 /* P_PRI_MKRC isn't needed here, optval_default()
808 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"compatible", "cp", P_BOOL|P_RALL,
810 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000811 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
813#ifdef FEAT_INS_EXPAND
814 (char_u *)&p_cpt, PV_CPT,
815 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
816#else
817 (char_u *)NULL, PV_NONE,
818 {(char_u *)0L, (char_u *)0L}
819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000820 SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200821 {"conceallevel","conc", P_NUM|P_RWIN|P_VI_DEF,
822#ifdef FEAT_CONCEAL
823 (char_u *)VAR_WIN, PV_CONCEAL,
824#else
825 (char_u *)NULL, PV_NONE,
826#endif
827 {(char_u *)0L, (char_u *)0L}
828 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000829 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
830#ifdef FEAT_COMPL_FUNC
831 (char_u *)&p_cfu, PV_CFU,
832 {(char_u *)"", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000838 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
839#ifdef FEAT_INS_EXPAND
840 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000841 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"confirm", "cf", P_BOOL|P_VI_DEF,
848#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
849 (char_u *)&p_confirm, PV_NONE,
850#else
851 (char_u *)NULL, PV_NONE,
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854 {"conskey", "consk",P_BOOL|P_VI_DEF,
855#ifdef MSDOS
856 (char_u *)&p_consk, PV_NONE,
857#else
858 (char_u *)NULL, PV_NONE,
859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
862 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
865 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
867 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200868 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200869#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200870 (char_u *)&p_cm, PV_CM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200874 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
876#ifdef FEAT_CSCOPE
877 (char_u *)&p_cspc, PV_NONE,
878#else
879 (char_u *)NULL, PV_NONE,
880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
883#ifdef FEAT_CSCOPE
884 (char_u *)&p_csprg, PV_NONE,
885 {(char_u *)"cscope", (char_u *)0L}
886#else
887 (char_u *)NULL, PV_NONE,
888 {(char_u *)0L, (char_u *)0L}
889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000890 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
892#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
893 (char_u *)&p_csqf, PV_NONE,
894 {(char_u *)"", (char_u *)0L}
895#else
896 (char_u *)NULL, PV_NONE,
897 {(char_u *)0L, (char_u *)0L}
898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
901#ifdef FEAT_CSCOPE
902 (char_u *)&p_cst, PV_NONE,
903#else
904 (char_u *)NULL, PV_NONE,
905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
908#ifdef FEAT_CSCOPE
909 (char_u *)&p_csto, PV_NONE,
910#else
911 (char_u *)NULL, PV_NONE,
912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
915#ifdef FEAT_CSCOPE
916 (char_u *)&p_csverbose, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200921 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
922#ifdef FEAT_CURSORBIND
923 (char_u *)VAR_WIN, PV_CRBIND,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000928 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
929#ifdef FEAT_SYN_HL
930 (char_u *)VAR_WIN, PV_CUC,
931#else
932 (char_u *)NULL, PV_NONE,
933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000934 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000935 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
936#ifdef FEAT_SYN_HL
937 (char_u *)VAR_WIN, PV_CUL,
938#else
939 (char_u *)NULL, PV_NONE,
940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000941 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942 {"debug", NULL, P_STRING|P_VI_DEF,
943 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
946#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000947 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000948 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)NULL, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_MBYTE
956 (char_u *)&p_deco, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
962#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000963 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
969#ifdef FEAT_DIFF
970 (char_u *)VAR_WIN, PV_DIFF,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
976#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
977 (char_u *)&p_dex, PV_NONE,
978 {(char_u *)"", (char_u *)0L}
979#else
980 (char_u *)NULL, PV_NONE,
981 {(char_u *)0L, (char_u *)0L}
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
985#ifdef FEAT_DIFF
986 (char_u *)&p_dip, PV_NONE,
987 {(char_u *)"filler", (char_u *)NULL}
988#else
989 (char_u *)NULL, PV_NONE,
990 {(char_u *)"", (char_u *)NULL}
991#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
994#ifdef FEAT_DIGRAPHS
995 (char_u *)&p_dg, PV_NONE,
996#else
997 (char_u *)NULL, PV_NONE,
998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1001 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1004 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"eadirection", "ead", P_STRING|P_VI_DEF,
1007#ifdef FEAT_VERTSPLIT
1008 (char_u *)&p_ead, PV_NONE,
1009 {(char_u *)"both", (char_u *)0L}
1010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1016 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
1019#ifdef FEAT_MBYTE
1020 (char_u *)&p_enc, PV_NONE,
1021 {(char_u *)ENC_DFLT, (char_u *)0L}
1022#else
1023 (char_u *)NULL, PV_NONE,
1024 {(char_u *)0L, (char_u *)0L}
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1028 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1031 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001034 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1037 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1040#ifdef FEAT_QUICKFIX
1041 (char_u *)&p_ef, PV_NONE,
1042 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)NULL, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1049#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001050 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)NULL, (char_u *)0L}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"esckeys", "ek", P_BOOL|P_VIM,
1058 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1061#ifdef FEAT_AUTOCMD
1062 (char_u *)&p_ei, PV_NONE,
1063#else
1064 (char_u *)NULL, PV_NONE,
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1068 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1071 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1074#ifdef FEAT_MBYTE
1075 (char_u *)&p_fenc, PV_FENC,
1076 {(char_u *)"", (char_u *)0L}
1077#else
1078 (char_u *)NULL, PV_NONE,
1079 {(char_u *)0L, (char_u *)0L}
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1083#ifdef FEAT_MBYTE
1084 (char_u *)&p_fencs, PV_NONE,
1085 {(char_u *)"ucs-bom", (char_u *)0L}
1086#else
1087 (char_u *)NULL, PV_NONE,
1088 {(char_u *)0L, (char_u *)0L}
1089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1092 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1095 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1097 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001098 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_AUTOCMD
1100 (char_u *)&p_ft, PV_FT,
1101 {(char_u *)"", (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)0L, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1108#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1109 (char_u *)&p_fcs, PV_NONE,
1110 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)"", (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1117#ifdef FEAT_FKMAP
1118 (char_u *)&p_fkmap, PV_NONE,
1119#else
1120 (char_u *)NULL, PV_NONE,
1121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"flash", "fl", P_BOOL|P_VI_DEF,
1124 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_FOLDING
1127 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1128 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1131 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1134 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001135 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1137# ifdef FEAT_EVAL
1138 (char_u *)VAR_WIN, PV_FDE,
1139 {(char_u *)"0", (char_u *)NULL}
1140# else
1141 (char_u *)NULL, PV_NONE,
1142 {(char_u *)NULL, (char_u *)0L}
1143# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1146 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1149 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1152 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1155 P_RWIN|P_COMMA|P_NODUP,
1156 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)"{{{,}}}", (char_u *)NULL}
1158 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1160 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1163 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1166 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1169 (char_u *)&p_fdo, PV_NONE,
1170 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1173# ifdef FEAT_EVAL
1174 (char_u *)VAR_WIN, PV_FDT,
1175 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001176# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001179# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001182 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001183#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001184 (char_u *)&p_fex, PV_FEX,
1185 {(char_u *)"", (char_u *)0L}
1186#else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)0L, (char_u *)0L}
1189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1192 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1194 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001195 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1196 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1198 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1200 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001202 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1203#ifdef HAVE_FSYNC
1204 (char_u *)&p_fs, PV_NONE,
1205 {(char_u *)TRUE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)FALSE, (char_u *)0L}
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1212 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"graphic", "gr", P_BOOL|P_VI_DEF,
1215 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1218#ifdef FEAT_QUICKFIX
1219 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1227#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001228 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {
1230# ifdef WIN3264
1231 /* may be changed to "grep -n" in os_win32.c */
1232 (char_u *)"findstr /n",
1233# else
1234# ifdef UNIX
1235 /* Add an extra file name so that grep will always
1236 * insert a file name in the match line. */
1237 (char_u *)"grep -n $* /dev/null",
1238# else
1239# ifdef VMS
1240 (char_u *)"SEARCH/NUMBERS ",
1241# else
1242 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243# endif
1244# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)NULL, (char_u *)0L}
1250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001251 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1253#ifdef CURSOR_SHAPE
1254 (char_u *)&p_guicursor, PV_NONE,
1255 {
1256# ifdef FEAT_GUI
1257 (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",
1258# else /* MSDOS or Win32 console */
1259 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1260# endif
1261 (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1268#ifdef FEAT_GUI
1269 (char_u *)&p_guifont, PV_NONE,
1270 {(char_u *)"", (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1277#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1278 (char_u *)&p_guifontset, PV_NONE,
1279 {(char_u *)"", (char_u *)0L}
1280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1286#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1287 (char_u *)&p_guifontwide, PV_NONE,
1288 {(char_u *)"", (char_u *)0L}
1289#else
1290 (char_u *)NULL, PV_NONE,
1291 {(char_u *)NULL, (char_u *)0L}
1292#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001295#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 (char_u *)&p_ghr, PV_NONE,
1297#else
1298 (char_u *)NULL, PV_NONE,
1299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001300 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001302#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303 (char_u *)&p_go, PV_NONE,
1304# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001305 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001307 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308# endif
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"guipty", NULL, P_BOOL|P_VI_DEF,
1315#if defined(FEAT_GUI)
1316 (char_u *)&p_guipty, PV_NONE,
1317#else
1318 (char_u *)NULL, PV_NONE,
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001321 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001322#if defined(FEAT_GUI_TABLINE)
1323 (char_u *)&p_gtl, PV_NONE,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)NULL, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001330 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001331#if defined(FEAT_GUI_TABLINE)
1332 (char_u *)&p_gtt, PV_NONE,
1333 {(char_u *)"", (char_u *)0L}
1334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1340 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1343 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1345 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 {"helpheight", "hh", P_NUM|P_VI_DEF,
1347#ifdef FEAT_WINDOWS
1348 (char_u *)&p_hh, PV_NONE,
1349#else
1350 (char_u *)NULL, PV_NONE,
1351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1354#ifdef FEAT_MULTI_LANG
1355 (char_u *)&p_hlg, PV_NONE,
1356 {(char_u *)"", (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)0L, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"hidden", "hid", P_BOOL|P_VI_DEF,
1363 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1366 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 {"history", "hi", P_NUM|P_VIM,
1370 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1373#ifdef FEAT_RIGHTLEFT
1374 (char_u *)&p_hkmap, PV_NONE,
1375#else
1376 (char_u *)NULL, PV_NONE,
1377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1380#ifdef FEAT_RIGHTLEFT
1381 (char_u *)&p_hkmapp, PV_NONE,
1382#else
1383 (char_u *)NULL, PV_NONE,
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1387 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"icon", NULL, P_BOOL|P_VI_DEF,
1390#ifdef FEAT_TITLE
1391 (char_u *)&p_icon, PV_NONE,
1392#else
1393 (char_u *)NULL, PV_NONE,
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"iconstring", NULL, P_STRING|P_VI_DEF,
1397#ifdef FEAT_TITLE
1398 (char_u *)&p_iconstring, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1404 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001407#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 (char_u *)&p_imak, PV_NONE,
1409#else
1410 (char_u *)NULL, PV_NONE,
1411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001412 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1414#ifdef USE_IM_CONTROL
1415 (char_u *)&p_imcmdline, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1421#ifdef USE_IM_CONTROL
1422 (char_u *)&p_imdisable, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
1426#ifdef __sgi
1427 {(char_u *)TRUE, (char_u *)0L}
1428#else
1429 {(char_u *)FALSE, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"iminsert", "imi", P_NUM|P_VI_DEF,
1433 (char_u *)&p_iminsert, PV_IMI,
1434#ifdef B_IMODE_IM
1435 {(char_u *)B_IMODE_IM, (char_u *)0L}
1436#else
1437 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"imsearch", "ims", P_NUM|P_VI_DEF,
1441 (char_u *)&p_imsearch, PV_IMS,
1442#ifdef B_IMODE_IM
1443 {(char_u *)B_IMODE_IM, (char_u *)0L}
1444#else
1445 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1449#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001450 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1452#else
1453 (char_u *)NULL, PV_NONE,
1454 {(char_u *)0L, (char_u *)0L}
1455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001456 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1458#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1459 (char_u *)&p_inex, PV_INEX,
1460 {(char_u *)"", (char_u *)0L}
1461#else
1462 (char_u *)NULL, PV_NONE,
1463 {(char_u *)0L, (char_u *)0L}
1464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001465 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1467 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1470#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1471 (char_u *)&p_inde, PV_INDE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)0L, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1479#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1480 (char_u *)&p_indk, PV_INDK,
1481 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1482#else
1483 (char_u *)NULL, PV_NONE,
1484 {(char_u *)0L, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"infercase", "inf", P_BOOL|P_VI_DEF,
1488 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1491 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1494 (char_u *)&p_isf, PV_NONE,
1495 {
1496#ifdef BACKSLASH_IN_FILENAME
1497 /* Excluded are: & and ^ are special in cmd.exe
1498 * ( and ) are used in text separating fnames */
1499 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1500#else
1501# ifdef AMIGA
1502 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1503# else
1504# ifdef VMS
1505 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1506# else /* UNIX et al. */
1507# ifdef EBCDIC
1508 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1509# else
1510 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1511# endif
1512# endif
1513# endif
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1517 (char_u *)&p_isi, PV_NONE,
1518 {
1519#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1520 (char_u *)"@,48-57,_,128-167,224-235",
1521#else
1522# ifdef EBCDIC
1523 /* TODO: EBCDIC Check this! @ == isalpha()*/
1524 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1525 "112-120,128,140-142,156,158,172,"
1526 "174,186,191,203-207,219-225,235-239,"
1527 "251-254",
1528# else
1529 (char_u *)"@,48-57,_,192-255",
1530# endif
1531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1534 (char_u *)&p_isk, PV_ISK,
1535 {
1536#ifdef EBCDIC
1537 (char_u *)"@,240-249,_",
1538 /* TODO: EBCDIC Check this! @ == isalpha()*/
1539 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1540 "112-120,128,140-142,156,158,172,"
1541 "174,186,191,203-207,219-225,235-239,"
1542 "251-254",
1543#else
1544 (char_u *)"@,48-57,_",
1545# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1546 (char_u *)"@,48-57,_,128-167,224-235"
1547# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001548 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549# endif
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1553 (char_u *)&p_isp, PV_NONE,
1554 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001555#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1556 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 || defined(VMS)
1558 (char_u *)"@,~-255",
1559#else
1560# ifdef EBCDIC
1561 /* all chars above 63 are printable */
1562 (char_u *)"63-255",
1563# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001564 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565# endif
1566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001567 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1569 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1572#ifdef FEAT_CRYPT
1573 (char_u *)&p_key, PV_KEY,
1574 {(char_u *)"", (char_u *)0L}
1575#else
1576 (char_u *)NULL, PV_NONE,
1577 {(char_u *)0L, (char_u *)0L}
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001580 {"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 +00001581#ifdef FEAT_KEYMAP
1582 (char_u *)&p_keymap, PV_KMAP,
1583 {(char_u *)"", (char_u *)0L}
1584#else
1585 (char_u *)NULL, PV_NONE,
1586 {(char_u *)"", (char_u *)0L}
1587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001588 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1590#ifdef FEAT_VISUAL
1591 (char_u *)&p_km, PV_NONE,
1592#else
1593 (char_u *)NULL, PV_NONE,
1594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001597 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {
1599#if defined(MSDOS) || defined(MSWIN)
1600 (char_u *)":help",
1601#else
1602#ifdef VMS
1603 (char_u *)"help",
1604#else
1605# if defined(OS2)
1606 (char_u *)"view /",
1607# else
1608# ifdef USEMAN_S
1609 (char_u *)"man -s",
1610# else
1611 (char_u *)"man",
1612# endif
1613# endif
1614#endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1618#ifdef FEAT_LANGMAP
1619 (char_u *)&p_langmap, PV_NONE,
1620 {(char_u *)"", /* unmatched } */
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)NULL,
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001626 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1628 (char_u *)&p_lm, PV_NONE,
1629#else
1630 (char_u *)NULL, PV_NONE,
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1634#ifdef FEAT_WINDOWS
1635 (char_u *)&p_ls, PV_NONE,
1636#else
1637 (char_u *)NULL, PV_NONE,
1638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001639 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1641 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1644#ifdef FEAT_LINEBREAK
1645 (char_u *)VAR_WIN, PV_LBR,
1646#else
1647 (char_u *)NULL, PV_NONE,
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1651 (char_u *)&Rows, PV_NONE,
1652 {
1653#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1654 (char_u *)25L,
1655#else
1656 (char_u *)24L,
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1660#ifdef FEAT_GUI
1661 (char_u *)&p_linespace, PV_NONE,
1662#else
1663 (char_u *)NULL, PV_NONE,
1664#endif
1665#ifdef FEAT_GUI_W32
1666 {(char_u *)1L, (char_u *)0L}
1667#else
1668 {(char_u *)0L, (char_u *)0L}
1669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"lisp", NULL, P_BOOL|P_VI_DEF,
1672#ifdef FEAT_LISP
1673 (char_u *)&p_lisp, PV_LISP,
1674#else
1675 (char_u *)NULL, PV_NONE,
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1679#ifdef FEAT_LISP
1680 (char_u *)&p_lispwords, PV_NONE,
1681 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1682#else
1683 (char_u *)NULL, PV_NONE,
1684 {(char_u *)"", (char_u *)0L}
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1688 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001689 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1691 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1694 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001696#ifdef FEAT_GUI_MAC
1697 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1698 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"magic", NULL, P_BOOL|P_VI_DEF,
1702 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001704 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#ifdef FEAT_QUICKFIX
1706 (char_u *)&p_mef, PV_NONE,
1707 {(char_u *)"", (char_u *)0L}
1708#else
1709 (char_u *)NULL, PV_NONE,
1710 {(char_u *)NULL, (char_u *)0L}
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1714#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001715 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716# ifdef VMS
1717 {(char_u *)"MMS", (char_u *)0L}
1718# else
1719 {(char_u *)"make", (char_u *)0L}
1720# endif
1721#else
1722 (char_u *)NULL, PV_NONE,
1723 {(char_u *)NULL, (char_u *)0L}
1724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1727 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"matchtime", "mat", P_NUM|P_VI_DEF,
1731 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001733 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1734#ifdef FEAT_MBYTE
1735 (char_u *)&p_mco, PV_NONE,
1736#else
1737 (char_u *)NULL, PV_NONE,
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1741#ifdef FEAT_EVAL
1742 (char_u *)&p_mfd, PV_NONE,
1743#else
1744 (char_u *)NULL, PV_NONE,
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1748 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"maxmem", "mm", P_NUM|P_VI_DEF,
1751 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1753 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001754 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1755 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1758 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1760 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"menuitems", "mis", P_NUM|P_VI_DEF,
1762#ifdef FEAT_MENU
1763 (char_u *)&p_mis, PV_NONE,
1764#else
1765 (char_u *)NULL, PV_NONE,
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"mesg", NULL, P_BOOL|P_VI_DEF,
1769 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001771 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001772#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001773 (char_u *)&p_msm, PV_NONE,
1774 {(char_u *)"460000,2000,500", (char_u *)0L}
1775#else
1776 (char_u *)NULL, PV_NONE,
1777 {(char_u *)0L, (char_u *)0L}
1778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"modeline", "ml", P_BOOL|P_VIM,
1781 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"modelines", "mls", P_NUM|P_VI_DEF,
1784 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1787 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1790 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"more", NULL, P_BOOL|P_VIM,
1793 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1796 (char_u *)&p_mouse, PV_NONE,
1797 {
1798#if defined(MSDOS) || defined(WIN3264)
1799 (char_u *)"a",
1800#else
1801 (char_u *)"",
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1805#ifdef FEAT_GUI
1806 (char_u *)&p_mousef, PV_NONE,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1812#ifdef FEAT_GUI
1813 (char_u *)&p_mh, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1819 (char_u *)&p_mousem, PV_NONE,
1820 {
1821#if defined(MSDOS) || defined(MSWIN)
1822 (char_u *)"popup",
1823#else
1824# if defined(MACOS)
1825 (char_u *)"popup_setpos",
1826# else
1827 (char_u *)"extend",
1828# endif
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1832#ifdef FEAT_MOUSESHAPE
1833 (char_u *)&p_mouseshape, PV_NONE,
1834 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)NULL, (char_u *)0L}
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1841 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001843 {"mzquantum", "mzq", P_NUM,
1844#ifdef FEAT_MZSCHEME
1845 (char_u *)&p_mzq, PV_NONE,
1846#else
1847 (char_u *)NULL, PV_NONE,
1848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"novice", NULL, P_BOOL|P_VI_DEF,
1851 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1854 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)"octal,hex", (char_u *)0L}
1856 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1858 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001860 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1861#ifdef FEAT_LINEBREAK
1862 (char_u *)VAR_WIN, PV_NUW,
1863#else
1864 (char_u *)NULL, PV_NONE,
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001867 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001868#ifdef FEAT_COMPL_FUNC
1869 (char_u *)&p_ofu, PV_OFU,
1870 {(char_u *)"", (char_u *)0L}
1871#else
1872 (char_u *)NULL, PV_NONE,
1873 {(char_u *)0L, (char_u *)0L}
1874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"open", NULL, P_BOOL|P_VI_DEF,
1877 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001879 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1880#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1881 (char_u *)&p_odev, PV_NONE,
1882#else
1883 (char_u *)NULL, PV_NONE,
1884#endif
1885 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001887 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1888 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"optimize", "opt", P_BOOL|P_VI_DEF,
1891 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1894#ifdef FEAT_OSFILETYPE
1895 (char_u *)&p_oft, PV_OFT,
1896 {(char_u *)DFLT_OFT, (char_u *)0L}
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)0L, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"paragraphs", "para", P_STRING|P_VI_DEF,
1903 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001904 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001906 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1910 (char_u *)&p_pt, 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 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1913#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1914 (char_u *)&p_pex, PV_NONE,
1915 {(char_u *)"", (char_u *)0L}
1916#else
1917 (char_u *)NULL, PV_NONE,
1918 {(char_u *)0L, (char_u *)0L}
1919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001921 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001925 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {
1927#if defined AMIGA || defined MSDOS || defined MSWIN
1928 (char_u *)".,,",
1929#else
1930# if defined(__EMX__)
1931 (char_u *)".,/emx/include,,",
1932# else /* Unix, probably */
1933 (char_u *)".,/usr/include,,",
1934# endif
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1938 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001940 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1942 (char_u *)&p_pvh, PV_NONE,
1943#else
1944 (char_u *)NULL, PV_NONE,
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1948#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1949 (char_u *)VAR_WIN, PV_PVW,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001954 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955#ifdef FEAT_PRINTER
1956 (char_u *)&p_pdev, PV_NONE,
1957 {(char_u *)"", (char_u *)0L}
1958#else
1959 (char_u *)NULL, PV_NONE,
1960 {(char_u *)NULL, (char_u *)0L}
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"printencoding", "penc", P_STRING|P_VI_DEF,
1964#ifdef FEAT_POSTSCRIPT
1965 (char_u *)&p_penc, PV_NONE,
1966 {(char_u *)"", (char_u *)0L}
1967#else
1968 (char_u *)NULL, PV_NONE,
1969 {(char_u *)NULL, (char_u *)0L}
1970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1973#ifdef FEAT_POSTSCRIPT
1974 (char_u *)&p_pexpr, PV_NONE,
1975 {(char_u *)"", (char_u *)0L}
1976#else
1977 (char_u *)NULL, PV_NONE,
1978 {(char_u *)NULL, (char_u *)0L}
1979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"printfont", "pfn", P_STRING|P_VI_DEF,
1982#ifdef FEAT_PRINTER
1983 (char_u *)&p_pfn, PV_NONE,
1984 {
1985# ifdef MSWIN
1986 (char_u *)"Courier_New:h10",
1987# else
1988 (char_u *)"courier",
1989# endif
1990 (char_u *)0L}
1991#else
1992 (char_u *)NULL, PV_NONE,
1993 {(char_u *)NULL, (char_u *)0L}
1994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1997#ifdef FEAT_PRINTER
1998 (char_u *)&p_header, PV_NONE,
1999 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2000#else
2001 (char_u *)NULL, PV_NONE,
2002 {(char_u *)NULL, (char_u *)0L}
2003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002004 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002005 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2006#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2007 (char_u *)&p_pmcs, PV_NONE,
2008 {(char_u *)"", (char_u *)0L}
2009#else
2010 (char_u *)NULL, PV_NONE,
2011 {(char_u *)NULL, (char_u *)0L}
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002014 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2015#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2016 (char_u *)&p_pmfn, PV_NONE,
2017 {(char_u *)"", (char_u *)0L}
2018#else
2019 (char_u *)NULL, PV_NONE,
2020 {(char_u *)NULL, (char_u *)0L}
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2024#ifdef FEAT_PRINTER
2025 (char_u *)&p_popt, PV_NONE,
2026 {(char_u *)"", (char_u *)0L}
2027#else
2028 (char_u *)NULL, PV_NONE,
2029 {(char_u *)NULL, (char_u *)0L}
2030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002031 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002033 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002035 {"pumheight", "ph", P_NUM|P_VI_DEF,
2036#ifdef FEAT_INS_EXPAND
2037 (char_u *)&p_ph, PV_NONE,
2038#else
2039 (char_u *)NULL, PV_NONE,
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002042 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2043#ifdef FEAT_TEXTOBJ
2044 (char_u *)&p_qe, PV_QE,
2045 {(char_u *)"\\", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2052 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"redraw", NULL, P_BOOL|P_VI_DEF,
2055 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002057 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2058#ifdef FEAT_RELTIME
2059 (char_u *)&p_rdt, PV_NONE,
2060#else
2061 (char_u *)NULL, PV_NONE,
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002064 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2065 (char_u *)VAR_WIN, PV_RNU,
2066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"remap", NULL, P_BOOL|P_VI_DEF,
2068 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"report", NULL, P_NUM|P_VI_DEF,
2071 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2074#ifdef WIN3264
2075 (char_u *)&p_rs, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2081#ifdef FEAT_RIGHTLEFT
2082 (char_u *)&p_ri, PV_NONE,
2083#else
2084 (char_u *)NULL, PV_NONE,
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2088#ifdef FEAT_RIGHTLEFT
2089 (char_u *)VAR_WIN, PV_RL,
2090#else
2091 (char_u *)NULL, PV_NONE,
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2095#ifdef FEAT_RIGHTLEFT
2096 (char_u *)VAR_WIN, PV_RLC,
2097 {(char_u *)"search", (char_u *)NULL}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2104#ifdef FEAT_CMDL_INFO
2105 (char_u *)&p_ru, PV_NONE,
2106#else
2107 (char_u *)NULL, PV_NONE,
2108#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2111#ifdef FEAT_STL_OPT
2112 (char_u *)&p_ruf, PV_NONE,
2113#else
2114 (char_u *)NULL, PV_NONE,
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2118 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2122 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2125#ifdef FEAT_SCROLLBIND
2126 (char_u *)VAR_WIN, PV_SCBIND,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2132 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2135 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2138#ifdef FEAT_SCROLLBIND
2139 (char_u *)&p_sbo, PV_NONE,
2140 {(char_u *)"ver,jump", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)0L, (char_u *)0L}
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"sections", "sect", P_STRING|P_VI_DEF,
2147 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2149 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2151 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"selection", "sel", P_STRING|P_VI_DEF,
2154#ifdef FEAT_VISUAL
2155 (char_u *)&p_sel, PV_NONE,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)"inclusive", (char_u *)0L}
2160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2162#ifdef FEAT_VISUAL
2163 (char_u *)&p_slm, PV_NONE,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2169#ifdef FEAT_SESSION
2170 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002171 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)0L, (char_u *)0L}
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2179 (char_u *)&p_sh, PV_NONE,
2180 {
2181#ifdef VMS
2182 (char_u *)"-",
2183#else
2184# if defined(MSDOS)
2185 (char_u *)"command",
2186# else
2187# if defined(WIN16)
2188 (char_u *)"command.com",
2189# else
2190# if defined(WIN3264)
2191 (char_u *)"", /* set in set_init_1() */
2192# else
2193# if defined(OS2)
2194 (char_u *)"cmd.exe",
2195# else
2196# if defined(ARCHIE)
2197 (char_u *)"gos",
2198# else
2199 (char_u *)"sh",
2200# endif
2201# endif
2202# endif
2203# endif
2204# endif
2205#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2208 (char_u *)&p_shcf, PV_NONE,
2209 {
2210#if defined(MSDOS) || defined(MSWIN)
2211 (char_u *)"/c",
2212#else
2213# if defined(OS2)
2214 (char_u *)"/c",
2215# else
2216 (char_u *)"-c",
2217# endif
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2221#ifdef FEAT_QUICKFIX
2222 (char_u *)&p_sp, PV_NONE,
2223 {
2224#if defined(UNIX) || defined(OS2)
2225# ifdef ARCHIE
2226 (char_u *)"2>",
2227# else
2228 (char_u *)"| tee",
2229# endif
2230#else
2231 (char_u *)">",
2232#endif
2233 (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)0L, (char_u *)0L}
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2240 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2243 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2246#ifdef BACKSLASH_IN_FILENAME
2247 (char_u *)&p_ssl, PV_NONE,
2248#else
2249 (char_u *)NULL, PV_NONE,
2250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002252 {"shelltemp", "stmp", P_BOOL,
2253 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"shelltype", "st", P_NUM|P_VI_DEF,
2256#ifdef AMIGA
2257 (char_u *)&p_st, PV_NONE,
2258#else
2259 (char_u *)NULL, PV_NONE,
2260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2263 (char_u *)&p_sxq, PV_NONE,
2264 {
2265#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2266 (char_u *)"\"",
2267#else
2268 (char_u *)"",
2269#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2272 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2275 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2278 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)"", (char_u *)"filnxtToO"}
2280 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"shortname", "sn", P_BOOL|P_VI_DEF,
2282#ifdef SHORT_FNAME
2283 (char_u *)NULL, PV_NONE,
2284#else
2285 (char_u *)&p_sn, PV_SN,
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2289#ifdef FEAT_LINEBREAK
2290 (char_u *)&p_sbr, PV_NONE,
2291#else
2292 (char_u *)NULL, PV_NONE,
2293#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"showcmd", "sc", P_BOOL|P_VIM,
2296#ifdef FEAT_CMDL_INFO
2297 (char_u *)&p_sc, PV_NONE,
2298#else
2299 (char_u *)NULL, PV_NONE,
2300#endif
2301 {(char_u *)FALSE,
2302#ifdef UNIX
2303 (char_u *)FALSE
2304#else
2305 (char_u *)TRUE
2306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2309 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2312 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002313 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"showmode", "smd", P_BOOL|P_VIM,
2315 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002317 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2318#ifdef FEAT_WINDOWS
2319 (char_u *)&p_stal, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2325 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2328 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2331 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2334 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2337#ifdef FEAT_SMARTINDENT
2338 (char_u *)&p_si, PV_SI,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2344 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2347 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2350 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002352 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002353#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002354 (char_u *)VAR_WIN, PV_SPELL,
2355#else
2356 (char_u *)NULL, PV_NONE,
2357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002359 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002360#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002361 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002362 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002363#else
2364 (char_u *)NULL, PV_NONE,
2365 {(char_u *)0L, (char_u *)0L}
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002368 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002369#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002370 (char_u *)&p_spf, PV_SPF,
2371 {(char_u *)"", (char_u *)0L}
2372#else
2373 (char_u *)NULL, PV_NONE,
2374 {(char_u *)0L, (char_u *)0L}
2375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002377 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002378#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002379 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002380 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002381#else
2382 (char_u *)NULL, PV_NONE,
2383 {(char_u *)0L, (char_u *)0L}
2384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002386 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002387#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002388 (char_u *)&p_sps, PV_NONE,
2389 {(char_u *)"best", (char_u *)0L}
2390#else
2391 (char_u *)NULL, PV_NONE,
2392 {(char_u *)0L, (char_u *)0L}
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2396#ifdef FEAT_WINDOWS
2397 (char_u *)&p_sb, PV_NONE,
2398#else
2399 (char_u *)NULL, PV_NONE,
2400#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"splitright", "spr", P_BOOL|P_VI_DEF,
2403#ifdef FEAT_VERTSPLIT
2404 (char_u *)&p_spr, PV_NONE,
2405#else
2406 (char_u *)NULL, PV_NONE,
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2410 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2413#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002414 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415#else
2416 (char_u *)NULL, PV_NONE,
2417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2420 (char_u *)&p_su, PV_NONE,
2421 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002424#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 (char_u *)&p_sua, PV_SUA,
2426 {(char_u *)"", (char_u *)0L}
2427#else
2428 (char_u *)NULL, PV_NONE,
2429 {(char_u *)0L, (char_u *)0L}
2430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2433 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"swapsync", "sws", P_STRING|P_VI_DEF,
2436 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2439 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002441 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2442#ifdef FEAT_SYN_HL
2443 (char_u *)&p_smc, PV_SMC,
2444 {(char_u *)3000L, (char_u *)0L}
2445#else
2446 (char_u *)NULL, PV_NONE,
2447 {(char_u *)0L, (char_u *)0L}
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002450 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451#ifdef FEAT_SYN_HL
2452 (char_u *)&p_syn, PV_SYN,
2453 {(char_u *)"", (char_u *)0L}
2454#else
2455 (char_u *)NULL, PV_NONE,
2456 {(char_u *)0L, (char_u *)0L}
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002459 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2460#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002461 (char_u *)&p_tal, PV_NONE,
2462#else
2463 (char_u *)NULL, PV_NONE,
2464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002466 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2467#ifdef FEAT_WINDOWS
2468 (char_u *)&p_tpm, PV_NONE,
2469#else
2470 (char_u *)NULL, PV_NONE,
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2474 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2477 (char_u *)&p_tbs, PV_NONE,
2478#ifdef VMS /* binary searching doesn't appear to work on VMS */
2479 {(char_u *)0L, (char_u *)0L}
2480#else
2481 {(char_u *)TRUE, (char_u *)0L}
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"taglength", "tl", P_NUM|P_VI_DEF,
2485 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"tagrelative", "tr", P_BOOL|P_VIM,
2488 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002491 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {
2493#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2494 (char_u *)"./tags,./TAGS,tags,TAGS",
2495#else
2496 (char_u *)"./tags,tags",
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2500 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2503 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2506#ifdef FEAT_ARABIC
2507 (char_u *)&p_tbidi, PV_NONE,
2508#else
2509 (char_u *)NULL, PV_NONE,
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2513#ifdef FEAT_MBYTE
2514 (char_u *)&p_tenc, PV_NONE,
2515 {(char_u *)"", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"terse", NULL, P_BOOL|P_VI_DEF,
2522 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"textauto", "ta", P_BOOL|P_VIM,
2525 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2529 (char_u *)&p_tx, PV_TX,
2530 {
2531#ifdef USE_CRNL
2532 (char_u *)TRUE,
2533#else
2534 (char_u *)FALSE,
2535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002537 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2541#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002542 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543#else
2544 (char_u *)NULL, PV_NONE,
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2548 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"timeout", "to", P_BOOL|P_VI_DEF,
2551 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2554 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"title", NULL, P_BOOL|P_VI_DEF,
2557#ifdef FEAT_TITLE
2558 (char_u *)&p_title, PV_NONE,
2559#else
2560 (char_u *)NULL, PV_NONE,
2561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"titlelen", NULL, P_NUM|P_VI_DEF,
2564#ifdef FEAT_TITLE
2565 (char_u *)&p_titlelen, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002570 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571#ifdef FEAT_TITLE
2572 (char_u *)&p_titleold, PV_NONE,
2573 {(char_u *)N_("Thanks for flying Vim"),
2574 (char_u *)0L}
2575#else
2576 (char_u *)NULL, PV_NONE,
2577 {(char_u *)0L, (char_u *)0L}
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"titlestring", NULL, P_STRING|P_VI_DEF,
2581#ifdef FEAT_TITLE
2582 (char_u *)&p_titlestring, PV_NONE,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2588 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2589 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)"icons,tooltips", (char_u *)0L}
2591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002593#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2595 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597#endif
2598 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2599 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2602 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2605 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2608 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2611#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2612 (char_u *)&p_ttym, PV_NONE,
2613#else
2614 (char_u *)NULL, PV_NONE,
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2618 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2621 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002623 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2624#ifdef FEAT_PERSISTENT_UNDO
2625 (char_u *)&p_udir, PV_NONE,
2626 {(char_u *)".", (char_u *)0L}
2627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}
2630#endif
2631 SCRIPTID_INIT},
2632 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2633#ifdef FEAT_PERSISTENT_UNDO
2634 (char_u *)&p_udf, PV_UDF,
2635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
2638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"undolevels", "ul", P_NUM|P_VI_DEF,
2640 (char_u *)&p_ul, PV_NONE,
2641 {
2642#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2643 (char_u *)1000L,
2644#else
2645 (char_u *)100L,
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"updatecount", "uc", P_NUM|P_VI_DEF,
2649 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"updatetime", "ut", P_NUM|P_VI_DEF,
2652 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"verbose", "vbs", P_NUM|P_VI_DEF,
2655 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002657 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2658 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2661#ifdef FEAT_SESSION
2662 (char_u *)&p_vdir, PV_NONE,
2663 {(char_u *)DFLT_VDIR, (char_u *)0L}
2664#else
2665 (char_u *)NULL, PV_NONE,
2666 {(char_u *)0L, (char_u *)0L}
2667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2670#ifdef FEAT_SESSION
2671 (char_u *)&p_vop, PV_NONE,
2672 {(char_u *)"folds,options,cursor", (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2679#ifdef FEAT_VIMINFO
2680 (char_u *)&p_viminfo, PV_NONE,
2681#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002682 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#else
2684# ifdef AMIGA
2685 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002686 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002688 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689# endif
2690#endif
2691#else
2692 (char_u *)NULL, PV_NONE,
2693 {(char_u *)0L, (char_u *)0L}
2694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2697#ifdef FEAT_VIRTUALEDIT
2698 (char_u *)&p_ve, PV_NONE,
2699 {(char_u *)"", (char_u *)""}
2700#else
2701 (char_u *)NULL, PV_NONE,
2702 {(char_u *)0L, (char_u *)0L}
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2706 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"w300", NULL, P_NUM|P_VI_DEF,
2709 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"w1200", NULL, P_NUM|P_VI_DEF,
2712 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"w9600", NULL, P_NUM|P_VI_DEF,
2715 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"warn", NULL, P_BOOL|P_VI_DEF,
2718 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2721 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2724 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"wildchar", "wc", P_NUM|P_VIM,
2727 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2731 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2734#ifdef FEAT_WILDIGN
2735 (char_u *)&p_wig, PV_NONE,
2736#else
2737 (char_u *)NULL, PV_NONE,
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2741#ifdef FEAT_WILDMENU
2742 (char_u *)&p_wmnu, PV_NONE,
2743#else
2744 (char_u *)NULL, PV_NONE,
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2748 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002750 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2751#ifdef FEAT_CMDL_COMPL
2752 (char_u *)&p_wop, PV_NONE,
2753 {(char_u *)"", (char_u *)0L}
2754#else
2755 (char_u *)NULL, PV_NONE,
2756 {(char_u *)NULL, (char_u *)0L}
2757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2760#ifdef FEAT_WAK
2761 (char_u *)&p_wak, PV_NONE,
2762 {(char_u *)"menu", (char_u *)0L}
2763#else
2764 (char_u *)NULL, PV_NONE,
2765 {(char_u *)NULL, (char_u *)0L}
2766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002769 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"winheight", "wh", P_NUM|P_VI_DEF,
2772#ifdef FEAT_WINDOWS
2773 (char_u *)&p_wh, PV_NONE,
2774#else
2775 (char_u *)NULL, PV_NONE,
2776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002779#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 (char_u *)VAR_WIN, PV_WFH,
2781#else
2782 (char_u *)NULL, PV_NONE,
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002785 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2786#ifdef FEAT_VERTSPLIT
2787 (char_u *)VAR_WIN, PV_WFW,
2788#else
2789 (char_u *)NULL, PV_NONE,
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2793#ifdef FEAT_WINDOWS
2794 (char_u *)&p_wmh, PV_NONE,
2795#else
2796 (char_u *)NULL, PV_NONE,
2797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2800#ifdef FEAT_VERTSPLIT
2801 (char_u *)&p_wmw, PV_NONE,
2802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2807#ifdef FEAT_VERTSPLIT
2808 (char_u *)&p_wiw, PV_NONE,
2809#else
2810 (char_u *)NULL, PV_NONE,
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2814 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2817 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2820 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"write", NULL, P_BOOL|P_VI_DEF,
2823 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"writeany", "wa", P_BOOL|P_VI_DEF,
2826 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2829 (char_u *)&p_wb, PV_NONE,
2830 {
2831#ifdef FEAT_WRITEBACKUP
2832 (char_u *)TRUE,
2833#else
2834 (char_u *)FALSE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"writedelay", "wd", P_NUM|P_VI_DEF,
2838 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840
2841/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002842#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845
2846 p_term("t_AB", T_CAB)
2847 p_term("t_AF", T_CAF)
2848 p_term("t_AL", T_CAL)
2849 p_term("t_al", T_AL)
2850 p_term("t_bc", T_BC)
2851 p_term("t_cd", T_CD)
2852 p_term("t_ce", T_CE)
2853 p_term("t_cl", T_CL)
2854 p_term("t_cm", T_CM)
2855 p_term("t_Co", T_CCO)
2856 p_term("t_CS", T_CCS)
2857 p_term("t_cs", T_CS)
2858#ifdef FEAT_VERTSPLIT
2859 p_term("t_CV", T_CSV)
2860#endif
2861 p_term("t_ut", T_UT)
2862 p_term("t_da", T_DA)
2863 p_term("t_db", T_DB)
2864 p_term("t_DL", T_CDL)
2865 p_term("t_dl", T_DL)
2866 p_term("t_fs", T_FS)
2867 p_term("t_IE", T_CIE)
2868 p_term("t_IS", T_CIS)
2869 p_term("t_ke", T_KE)
2870 p_term("t_ks", T_KS)
2871 p_term("t_le", T_LE)
2872 p_term("t_mb", T_MB)
2873 p_term("t_md", T_MD)
2874 p_term("t_me", T_ME)
2875 p_term("t_mr", T_MR)
2876 p_term("t_ms", T_MS)
2877 p_term("t_nd", T_ND)
2878 p_term("t_op", T_OP)
2879 p_term("t_RI", T_CRI)
2880 p_term("t_RV", T_CRV)
2881 p_term("t_Sb", T_CSB)
2882 p_term("t_Sf", T_CSF)
2883 p_term("t_se", T_SE)
2884 p_term("t_so", T_SO)
2885 p_term("t_sr", T_SR)
2886 p_term("t_ts", T_TS)
2887 p_term("t_te", T_TE)
2888 p_term("t_ti", T_TI)
2889 p_term("t_ue", T_UE)
2890 p_term("t_us", T_US)
2891 p_term("t_vb", T_VB)
2892 p_term("t_ve", T_VE)
2893 p_term("t_vi", T_VI)
2894 p_term("t_vs", T_VS)
2895 p_term("t_WP", T_CWP)
2896 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002897 p_term("t_SI", T_CSI)
2898 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 p_term("t_xs", T_XS)
2900 p_term("t_ZH", T_CZH)
2901 p_term("t_ZR", T_CZR)
2902
2903/* terminal key codes are not in here */
2904
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 /* end marker */
2906 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907};
2908
2909#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2910
2911#ifdef FEAT_MBYTE
2912static char *(p_ambw_values[]) = {"single", "double", NULL};
2913#endif
2914static char *(p_bg_values[]) = {"light", "dark", NULL};
2915static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2916static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002917#ifdef FEAT_CMDL_COMPL
2918static char *(p_wop_values[]) = {"tagfile", NULL};
2919#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920#ifdef FEAT_WAK
2921static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2922#endif
2923static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2924#ifdef FEAT_VISUAL
2925static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2926static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2927#endif
2928#ifdef FEAT_VISUAL
2929static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2930#endif
2931#ifdef FEAT_BROWSE
2932static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2933#endif
2934#ifdef FEAT_SCROLLBIND
2935static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2936#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002937static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938#ifdef FEAT_VERTSPLIT
2939static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2940#endif
2941#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002942# ifdef FEAT_AUTOCMD
2943static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2944# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002946# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2948#endif
2949static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2950#ifdef FEAT_FOLDING
2951static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002952# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002954# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 NULL};
2956static char *(p_fcl_values[]) = {"all", NULL};
2957#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002958#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002959static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961
2962static void set_option_default __ARGS((int, int opt_flags, int compatible));
2963static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002964static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002965static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966static char_u *illegal_char __ARGS((char_u *, int));
2967static int string_to_key __ARGS((char_u *arg));
2968#ifdef FEAT_CMDWIN
2969static char_u *check_cedit __ARGS((void));
2970#endif
2971#ifdef FEAT_TITLE
2972static void did_set_title __ARGS((int icon));
2973#endif
2974static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2975static void didset_options __ARGS((void));
2976static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002977#if defined(FEAT_EVAL) || defined(PROTO)
2978static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2979#else
2980# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2983static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2984static 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));
2985static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02002986#ifdef FEAT_SYN_HL
2987static int int_cmp __ARGS((const void *a, const void *b));
2988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989#ifdef FEAT_CLIPBOARD
2990static char_u *check_clipboard_option __ARGS((void));
2991#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002992#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02002993static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002994#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002995#ifdef FEAT_EVAL
2996static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002999static 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 +00003000static void check_redraw __ARGS((long_u flags));
3001static int findoption __ARGS((char_u *));
3002static int find_key_option __ARGS((char_u *));
3003static void showoptions __ARGS((int all, int opt_flags));
3004static int optval_default __ARGS((struct vimoption *, char_u *varp));
3005static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3006static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3007static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3008static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3009static int istermoption __ARGS((struct vimoption *));
3010static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3011static char_u *get_varp __ARGS((struct vimoption *));
3012static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3013static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3014#ifdef FEAT_LANGMAP
3015static void langmap_init __ARGS((void));
3016static void langmap_set __ARGS((void));
3017#endif
3018static void paste_option_changed __ARGS((void));
3019static void compatible_set __ARGS((void));
3020#ifdef FEAT_LINEBREAK
3021static void fill_breakat_flags __ARGS((void));
3022#endif
3023static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3024static int check_opt_strings __ARGS((char_u *val, char **values, int));
3025static int check_opt_wim __ARGS((void));
3026
3027/*
3028 * Initialize the options, first part.
3029 *
3030 * Called only once from main(), just after creating the first buffer.
3031 */
3032 void
3033set_init_1()
3034{
3035 char_u *p;
3036 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003037 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038
3039#ifdef FEAT_LANGMAP
3040 langmap_init();
3041#endif
3042
3043 /* Be Vi compatible by default */
3044 p_cp = TRUE;
3045
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003046 /* Use POSIX compatibility when $VIM_POSIX is set. */
3047 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003048 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003049 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003050 set_string_default("shm", (char_u *)"A");
3051 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003052
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 /*
3054 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003055 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003057 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3059# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003060 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003062 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003064 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065# endif
3066#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003067 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 set_string_default("sh", p);
3069
3070#ifdef FEAT_WILDIGN
3071 /*
3072 * Set the default for 'backupskip' to include environment variables for
3073 * temp files.
3074 */
3075 {
3076# ifdef UNIX
3077 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3078# else
3079 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3080# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003081 int len;
3082 garray_T ga;
3083 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084
3085 ga_init2(&ga, 1, 100);
3086 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3087 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003088 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089# ifdef UNIX
3090 if (*names[n] == NUL)
3091 p = (char_u *)"/tmp";
3092 else
3093# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003094 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 if (p != NULL && *p != NUL)
3096 {
3097 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003098 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 if (ga_grow(&ga, len) == OK)
3100 {
3101 if (ga.ga_len > 0)
3102 STRCAT(ga.ga_data, ",");
3103 STRCAT(ga.ga_data, p);
3104 add_pathsep(ga.ga_data);
3105 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 ga.ga_len += len;
3107 }
3108 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003109 if (mustfree)
3110 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 }
3112 if (ga.ga_data != NULL)
3113 {
3114 set_string_default("bsk", ga.ga_data);
3115 vim_free(ga.ga_data);
3116 }
3117 }
3118#endif
3119
3120 /*
3121 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3122 */
3123 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003124 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003126#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3127 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3128#endif
3129 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003131 /* Use amount of memory available at this moment. */
3132 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133#else
3134# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003135 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003136 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003138 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139# endif
3140#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003142 opt_idx = findoption((char_u *)"maxmem");
3143 if (opt_idx >= 0)
3144 {
3145#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3146 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3147 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3148#endif
3149 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3150 }
3151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 }
3153
3154#ifdef FEAT_GUI_W32
3155 /* force 'shortname' for Win32s */
3156 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003157 {
3158 opt_idx = findoption((char_u *)"shortname");
3159 if (opt_idx >= 0)
3160 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3161 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162#endif
3163
3164#ifdef FEAT_SEARCHPATH
3165 {
3166 char_u *cdpath;
3167 char_u *buf;
3168 int i;
3169 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003170 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171
3172 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003173 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 if (cdpath != NULL)
3175 {
3176 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3177 if (buf != NULL)
3178 {
3179 buf[0] = ','; /* start with ",", current dir first */
3180 j = 1;
3181 for (i = 0; cdpath[i] != NUL; ++i)
3182 {
3183 if (vim_ispathlistsep(cdpath[i]))
3184 buf[j++] = ',';
3185 else
3186 {
3187 if (cdpath[i] == ' ' || cdpath[i] == ',')
3188 buf[j++] = '\\';
3189 buf[j++] = cdpath[i];
3190 }
3191 }
3192 buf[j] = NUL;
3193 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003194 if (opt_idx >= 0)
3195 {
3196 options[opt_idx].def_val[VI_DEFAULT] = buf;
3197 options[opt_idx].flags |= P_DEF_ALLOCED;
3198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003200 if (mustfree)
3201 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 }
3203 }
3204#endif
3205
3206#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3207 /* Set print encoding on platforms that don't default to latin1 */
3208 set_string_default("penc",
3209# if defined(MSWIN) || defined(OS2)
3210 (char_u *)"cp1252"
3211# else
3212# ifdef VMS
3213 (char_u *)"dec-mcs"
3214# else
3215# ifdef EBCDIC
3216 (char_u *)"ebcdic-uk"
3217# else
3218# ifdef MAC
3219 (char_u *)"mac-roman"
3220# else /* HPUX */
3221 (char_u *)"hp-roman8"
3222# endif
3223# endif
3224# endif
3225# endif
3226 );
3227#endif
3228
3229#ifdef FEAT_POSTSCRIPT
3230 /* 'printexpr' must be allocated to be able to evaluate it. */
3231 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003232# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3233 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234# else
3235# ifdef VMS
3236 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3237
3238# else
3239 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3240# endif
3241# endif
3242 );
3243#endif
3244
3245 /*
3246 * Set all the options (except the terminal options) to their default
3247 * value. Also set the global value for local options.
3248 */
3249 set_options_default(0);
3250
3251#ifdef FEAT_GUI
3252 if (found_reverse_arg)
3253 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3254#endif
3255
3256 curbuf->b_p_initialized = TRUE;
3257 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3258 check_buf_options(curbuf);
3259 check_win_options(curwin);
3260 check_options();
3261
3262 /* Must be before option_expand(), because that one needs vim_isIDc() */
3263 didset_options();
3264
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003265#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003266 /* Use the current chartab for the generic chartab. */
3267 init_spell_chartab();
3268#endif
3269
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270#ifdef FEAT_LINEBREAK
3271 /*
3272 * initialize the table for 'breakat'.
3273 */
3274 fill_breakat_flags();
3275#endif
3276
3277 /*
3278 * Expand environment variables and things like "~" for the defaults.
3279 * If option_expand() returns non-NULL the variable is expanded. This can
3280 * only happen for non-indirect options.
3281 * Also set the default to the expanded value, so ":set" does not list
3282 * them.
3283 * Don't set the P_ALLOCED flag, because we don't want to free the
3284 * default.
3285 */
3286 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3287 {
3288 if ((options[opt_idx].flags & P_GETTEXT)
3289 && options[opt_idx].var != NULL)
3290 p = (char_u *)_(*(char **)options[opt_idx].var);
3291 else
3292 p = option_expand(opt_idx, NULL);
3293 if (p != NULL && (p = vim_strsave(p)) != NULL)
3294 {
3295 *(char_u **)options[opt_idx].var = p;
3296 /* VIMEXP
3297 * Defaults for all expanded options are currently the same for Vi
3298 * and Vim. When this changes, add some code here! Also need to
3299 * split P_DEF_ALLOCED in two.
3300 */
3301 if (options[opt_idx].flags & P_DEF_ALLOCED)
3302 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3303 options[opt_idx].def_val[VI_DEFAULT] = p;
3304 options[opt_idx].flags |= P_DEF_ALLOCED;
3305 }
3306 }
3307
3308 /* Initialize the highlight_attr[] table. */
3309 highlight_changed();
3310
3311 save_file_ff(curbuf); /* Buffer is unchanged */
3312
3313 /* Parse default for 'wildmode' */
3314 check_opt_wim();
3315
3316#if defined(FEAT_ARABIC)
3317 /* Detect use of mlterm.
3318 * Mlterm is a terminal emulator akin to xterm that has some special
3319 * abilities (bidi namely).
3320 * NOTE: mlterm's author is being asked to 'set' a variable
3321 * instead of an environment variable due to inheritance.
3322 */
3323 if (mch_getenv((char_u *)"MLTERM") != NULL)
3324 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3325#endif
3326
3327#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3328 /* Parse default for 'fillchars'. */
3329 (void)set_chars_option(&p_fcs);
3330#endif
3331
3332#ifdef FEAT_CLIPBOARD
3333 /* Parse default for 'clipboard' */
3334 (void)check_clipboard_option();
3335#endif
3336
3337#ifdef FEAT_MBYTE
3338# if defined(WIN3264) && defined(FEAT_GETTEXT)
3339 /*
3340 * If $LANG isn't set, try to get a good value for it. This makes the
3341 * right language be used automatically. Don't do this for English.
3342 */
3343 if (mch_getenv((char_u *)"LANG") == NULL)
3344 {
3345 char buf[20];
3346
3347 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3348 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3349 * only the first two. */
3350 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3351 (LPTSTR)buf, 20);
3352 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3353 {
3354 /* There are a few exceptions (probably more) */
3355 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3356 STRCPY(buf, "zh_TW");
3357 else if (STRNICMP(buf, "chs", 3) == 0
3358 || STRNICMP(buf, "zhc", 3) == 0)
3359 STRCPY(buf, "zh_CN");
3360 else if (STRNICMP(buf, "jp", 2) == 0)
3361 STRCPY(buf, "ja");
3362 else
3363 buf[2] = NUL; /* truncate to two-letter code */
3364 vim_setenv("LANG", buf);
3365 }
3366 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003367# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003368# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003369 /* Moved to os_mac_conv.c to avoid dependency problems. */
3370 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003371# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372# endif
3373
3374 /* enc_locale() will try to find the encoding of the current locale. */
3375 p = enc_locale();
3376 if (p != NULL)
3377 {
3378 char_u *save_enc;
3379
3380 /* Try setting 'encoding' and check if the value is valid.
3381 * If not, go back to the default "latin1". */
3382 save_enc = p_enc;
3383 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003384 if (STRCMP(p_enc, "gb18030") == 0)
3385 {
3386 /* We don't support "gb18030", but "cp936" is a good substitute
3387 * for practical purposes, thus use that. It's not an alias to
3388 * still support conversion between gb18030 and utf-8. */
3389 p_enc = vim_strsave((char_u *)"cp936");
3390 vim_free(p);
3391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 if (mb_init() == NULL)
3393 {
3394 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003395 if (opt_idx >= 0)
3396 {
3397 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3398 options[opt_idx].flags |= P_DEF_ALLOCED;
3399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003401#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3402 || defined(VMS)
3403 if (STRCMP(p_enc, "latin1") == 0
3404# ifdef FEAT_MBYTE
3405 || enc_utf8
3406# endif
3407 )
3408 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003409 /* Adjust the default for 'isprint' and 'iskeyword' to match
3410 * latin1. Also set the defaults for when 'nocompatible' is
3411 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003412 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003413 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003414 set_string_option_direct((char_u *)"isk", -1,
3415 ISK_LATIN1, OPT_FREE, SID_NONE);
3416 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003417 if (opt_idx >= 0)
3418 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003419 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 if (opt_idx >= 0)
3421 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003422 (void)init_chartab();
3423 }
3424#endif
3425
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426# if defined(WIN3264) && !defined(FEAT_GUI)
3427 /* Win32 console: When GetACP() returns a different value from
3428 * GetConsoleCP() set 'termencoding'. */
3429 if (GetACP() != GetConsoleCP())
3430 {
3431 char buf[50];
3432
3433 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3434 p_tenc = vim_strsave((char_u *)buf);
3435 if (p_tenc != NULL)
3436 {
3437 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 if (opt_idx >= 0)
3439 {
3440 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3441 options[opt_idx].flags |= P_DEF_ALLOCED;
3442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 convert_setup(&input_conv, p_tenc, p_enc);
3444 convert_setup(&output_conv, p_enc, p_tenc);
3445 }
3446 else
3447 p_tenc = empty_option;
3448 }
3449# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003450# if defined(WIN3264) && defined(FEAT_MBYTE)
3451 /* $HOME may have characters in active code page. */
3452 init_homedir();
3453# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454 }
3455 else
3456 {
3457 vim_free(p_enc);
3458 p_enc = save_enc;
3459 }
3460 }
3461#endif
3462
3463#ifdef FEAT_MULTI_LANG
3464 /* Set the default for 'helplang'. */
3465 set_helplang_default(get_mess_lang());
3466#endif
3467}
3468
3469/*
3470 * Set an option to its default value.
3471 * This does not take care of side effects!
3472 */
3473 static void
3474set_option_default(opt_idx, opt_flags, compatible)
3475 int opt_idx;
3476 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3477 int compatible; /* use Vi default value */
3478{
3479 char_u *varp; /* pointer to variable for current option */
3480 int dvi; /* index in def_val[] */
3481 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003482 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3484
3485 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3486 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003487 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 {
3489 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3490 if (flags & P_STRING)
3491 {
3492 /* Use set_string_option_direct() for local options to handle
3493 * freeing and allocating the value. */
3494 if (options[opt_idx].indir != PV_NONE)
3495 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003496 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 else
3498 {
3499 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3500 free_string_option(*(char_u **)(varp));
3501 *(char_u **)varp = options[opt_idx].def_val[dvi];
3502 options[opt_idx].flags &= ~P_ALLOCED;
3503 }
3504 }
3505 else if (flags & P_NUM)
3506 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003507 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508 win_comp_scroll(curwin);
3509 else
3510 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003511 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003512 /* May also set global value for local option. */
3513 if (both)
3514 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3515 *(long *)varp;
3516 }
3517 }
3518 else /* P_BOOL */
3519 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003520 /* the cast to long is required for Manx C, long_i is needed for
3521 * MSVC */
3522 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003523#ifdef UNIX
3524 /* 'modeline' defaults to off for root */
3525 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3526 *(int *)varp = FALSE;
3527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 /* May also set global value for local option. */
3529 if (both)
3530 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3531 *(int *)varp;
3532 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003533
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003534 /* The default value is not insecure. */
3535 flagsp = insecure_flag(opt_idx, opt_flags);
3536 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 }
3538
3539#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003540 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541#endif
3542}
3543
3544/*
3545 * Set all options (except terminal options) to their default value.
3546 */
3547 static void
3548set_options_default(opt_flags)
3549 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3550{
3551 int i;
3552#ifdef FEAT_WINDOWS
3553 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003554 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555#endif
3556
3557 for (i = 0; !istermoption(&options[i]); i++)
3558 if (!(options[i].flags & P_NODEFAULT))
3559 set_option_default(i, opt_flags, p_cp);
3560
3561#ifdef FEAT_WINDOWS
3562 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003563 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 win_comp_scroll(wp);
3565#else
3566 win_comp_scroll(curwin);
3567#endif
3568}
3569
3570/*
3571 * Set the Vi-default value of a string option.
3572 * Used for 'sh', 'backupskip' and 'term'.
3573 */
3574 void
3575set_string_default(name, val)
3576 char *name;
3577 char_u *val;
3578{
3579 char_u *p;
3580 int opt_idx;
3581
3582 p = vim_strsave(val);
3583 if (p != NULL) /* we don't want a NULL */
3584 {
3585 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003586 if (opt_idx >= 0)
3587 {
3588 if (options[opt_idx].flags & P_DEF_ALLOCED)
3589 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3590 options[opt_idx].def_val[VI_DEFAULT] = p;
3591 options[opt_idx].flags |= P_DEF_ALLOCED;
3592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 }
3594}
3595
3596/*
3597 * Set the Vi-default value of a number option.
3598 * Used for 'lines' and 'columns'.
3599 */
3600 void
3601set_number_default(name, val)
3602 char *name;
3603 long val;
3604{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003605 int opt_idx;
3606
3607 opt_idx = findoption((char_u *)name);
3608 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003609 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610}
3611
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003612#if defined(EXITFREE) || defined(PROTO)
3613/*
3614 * Free all options.
3615 */
3616 void
3617free_all_options()
3618{
3619 int i;
3620
3621 for (i = 0; !istermoption(&options[i]); i++)
3622 {
3623 if (options[i].indir == PV_NONE)
3624 {
3625 /* global option: free value and default value. */
3626 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3627 free_string_option(*(char_u **)options[i].var);
3628 if (options[i].flags & P_DEF_ALLOCED)
3629 free_string_option(options[i].def_val[VI_DEFAULT]);
3630 }
3631 else if (options[i].var != VAR_WIN
3632 && (options[i].flags & P_STRING))
3633 /* buffer-local option: free global value */
3634 free_string_option(*(char_u **)options[i].var);
3635 }
3636}
3637#endif
3638
3639
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640/*
3641 * Initialize the options, part two: After getting Rows and Columns and
3642 * setting 'term'.
3643 */
3644 void
3645set_init_2()
3646{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003647 int idx;
3648
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 /*
3650 * 'scroll' defaults to half the window height. Note that this default is
3651 * wrong when the window height changes.
3652 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003653 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003654 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003655 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003656 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 comp_col();
3658
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003659 /*
3660 * 'window' is only for backwards compatibility with Vi.
3661 * Default is Rows - 1.
3662 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003663 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003664 p_window = Rows - 1;
3665 set_number_default("window", Rows - 1);
3666
Bram Moolenaarf740b292006-02-16 22:11:02 +00003667 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003669 /*
3670 * If 'background' wasn't set by the user, try guessing the value,
3671 * depending on the terminal name. Only need to check for terminals
3672 * with a dark background, that can handle color.
3673 */
3674 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003675 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3676 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003678 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003679 /* don't mark it as set, when starting the GUI it may be
3680 * changed again */
3681 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 }
3683#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003684
3685#ifdef CURSOR_SHAPE
3686 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3687#endif
3688#ifdef FEAT_MOUSESHAPE
3689 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3690#endif
3691#ifdef FEAT_PRINTER
3692 (void)parse_printoptions(); /* parse 'printoptions' default value */
3693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694}
3695
3696/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003697 * Return "dark" or "light" depending on the kind of terminal.
3698 * This is just guessing! Recognized are:
3699 * "linux" Linux console
3700 * "screen.linux" Linux console with screen
3701 * "cygwin" Cygwin shell
3702 * "putty" Putty program
3703 * We also check the COLORFGBG environment variable, which is set by
3704 * rxvt and derivatives. This variable contains either two or three
3705 * values separated by semicolons; we want the last value in either
3706 * case. If this value is 0-6 or 8, our background is dark.
3707 */
3708 static char_u *
3709term_bg_default()
3710{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003711#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3712 /* DOS console nearly always black */
3713 return (char_u *)"dark";
3714#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003715 char_u *p;
3716
Bram Moolenaarf740b292006-02-16 22:11:02 +00003717 if (STRCMP(T_NAME, "linux") == 0
3718 || STRCMP(T_NAME, "screen.linux") == 0
3719 || STRCMP(T_NAME, "cygwin") == 0
3720 || STRCMP(T_NAME, "putty") == 0
3721 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3722 && (p = vim_strrchr(p, ';')) != NULL
3723 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3724 && p[2] == NUL))
3725 return (char_u *)"dark";
3726 return (char_u *)"light";
3727#endif
3728}
3729
3730/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 * Initialize the options, part three: After reading the .vimrc
3732 */
3733 void
3734set_init_3()
3735{
3736#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3737/*
3738 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3739 * This is done after other initializations, where 'shell' might have been
3740 * set, but only if they have not been set before.
3741 */
3742 char_u *p;
3743 int idx_srr;
3744 int do_srr;
3745#ifdef FEAT_QUICKFIX
3746 int idx_sp;
3747 int do_sp;
3748#endif
3749
3750 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003751 if (idx_srr < 0)
3752 do_srr = FALSE;
3753 else
3754 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755#ifdef FEAT_QUICKFIX
3756 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003757 if (idx_sp < 0)
3758 do_sp = FALSE;
3759 else
3760 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761#endif
3762
3763 /*
3764 * Isolate the name of the shell:
3765 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3766 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003767 * But don't allow a space in the path, so that this works:
3768 * "/usr/bin/csh --rcfile ~/.cshrc"
3769 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003771#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 p = gettail(p_sh);
3773 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003774#else
3775 p = skiptowhite(p_sh);
3776 if (*p == NUL)
3777 {
3778 /* No white space, use the tail. */
3779 p = vim_strsave(gettail(p_sh));
3780 }
3781 else
3782 {
3783 char_u *p1, *p2;
3784
3785 /* Find the last path separator before the space. */
3786 p1 = p_sh;
3787 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3788 if (vim_ispathsep(*p2))
3789 p1 = p2 + 1;
3790 p = vim_strnsave(p1, (int)(p - p1));
3791 }
3792#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 if (p != NULL)
3794 {
3795 /*
3796 * Default for p_sp is "| tee", for p_srr is ">".
3797 * For known shells it is changed here to include stderr.
3798 */
3799 if ( fnamecmp(p, "csh") == 0
3800 || fnamecmp(p, "tcsh") == 0
3801# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3802 || fnamecmp(p, "csh.exe") == 0
3803 || fnamecmp(p, "tcsh.exe") == 0
3804# endif
3805 )
3806 {
3807#if defined(FEAT_QUICKFIX)
3808 if (do_sp)
3809 {
3810# ifdef WIN3264
3811 p_sp = (char_u *)">&";
3812# else
3813 p_sp = (char_u *)"|& tee";
3814# endif
3815 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3816 }
3817#endif
3818 if (do_srr)
3819 {
3820 p_srr = (char_u *)">&";
3821 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3822 }
3823 }
3824 else
3825# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3826 if ( fnamecmp(p, "sh") == 0
3827 || fnamecmp(p, "ksh") == 0
3828 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003829 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 || fnamecmp(p, "bash") == 0
3831# ifdef WIN3264
3832 || fnamecmp(p, "cmd") == 0
3833 || fnamecmp(p, "sh.exe") == 0
3834 || fnamecmp(p, "ksh.exe") == 0
3835 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003836 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 || fnamecmp(p, "bash.exe") == 0
3838 || fnamecmp(p, "cmd.exe") == 0
3839# endif
3840 )
3841# endif
3842 {
3843#if defined(FEAT_QUICKFIX)
3844 if (do_sp)
3845 {
3846# ifdef WIN3264
3847 p_sp = (char_u *)">%s 2>&1";
3848# else
3849 p_sp = (char_u *)"2>&1| tee";
3850# endif
3851 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3852 }
3853#endif
3854 if (do_srr)
3855 {
3856 p_srr = (char_u *)">%s 2>&1";
3857 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3858 }
3859 }
3860 vim_free(p);
3861 }
3862#endif
3863
3864#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3865 /*
3866 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3867 * This is done after other initializations, where 'shell' might have been
3868 * set, but only if they have not been set before. Default for p_shcf is
3869 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3870 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3871 * command.com. And for Win32 we need to set p_sxq instead.
3872 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003873 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874 {
3875 int idx3;
3876
3877 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003878 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 {
3880 p_shcf = (char_u *)"-c";
3881 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3882 }
3883
3884# ifndef DJGPP
3885# ifdef WIN3264
3886 /* Somehow Win32 requires the quotes around the redirection too */
3887 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003888 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 {
3890 p_sxq = (char_u *)"\"";
3891 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3892 }
3893# else
3894 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 {
3897 p_shq = (char_u *)"\"";
3898 options[idx3].def_val[VI_DEFAULT] = p_shq;
3899 }
3900# endif
3901# endif
3902 }
3903#endif
3904
3905#ifdef FEAT_TITLE
3906 set_title_defaults();
3907#endif
3908}
3909
3910#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3911/*
3912 * When 'helplang' is still at its default value, set it to "lang".
3913 * Only the first two characters of "lang" are used.
3914 */
3915 void
3916set_helplang_default(lang)
3917 char_u *lang;
3918{
3919 int idx;
3920
3921 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3922 return;
3923 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003924 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 {
3926 if (options[idx].flags & P_ALLOCED)
3927 free_string_option(p_hlg);
3928 p_hlg = vim_strsave(lang);
3929 if (p_hlg == NULL)
3930 p_hlg = empty_option;
3931 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003932 {
3933 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3934 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3935 {
3936 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3937 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3938 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 options[idx].flags |= P_ALLOCED;
3942 }
3943}
3944#endif
3945
3946#ifdef FEAT_GUI
3947static char_u *gui_bg_default __ARGS((void));
3948
3949 static char_u *
3950gui_bg_default()
3951{
3952 if (gui_get_lightness(gui.back_pixel) < 127)
3953 return (char_u *)"dark";
3954 return (char_u *)"light";
3955}
3956
3957/*
3958 * Option initializations that can only be done after opening the GUI window.
3959 */
3960 void
3961init_gui_options()
3962{
3963 /* Set the 'background' option according to the lightness of the
3964 * background color, unless the user has set it already. */
3965 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3966 {
3967 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3968 highlight_changed();
3969 }
3970}
3971#endif
3972
3973#ifdef FEAT_TITLE
3974/*
3975 * 'title' and 'icon' only default to true if they have not been set or reset
3976 * in .vimrc and we can read the old value.
3977 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3978 * they can be reset. This reduces startup time when using X on a remote
3979 * machine.
3980 */
3981 void
3982set_title_defaults()
3983{
3984 int idx1;
3985 long val;
3986
3987 /*
3988 * If GUI is (going to be) used, we can always set the window title and
3989 * icon name. Saves a bit of time, because the X11 display server does
3990 * not need to be contacted.
3991 */
3992 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003993 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 {
3995#ifdef FEAT_GUI
3996 if (gui.starting || gui.in_use)
3997 val = TRUE;
3998 else
3999#endif
4000 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004001 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 p_title = val;
4003 }
4004 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004005 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006 {
4007#ifdef FEAT_GUI
4008 if (gui.starting || gui.in_use)
4009 val = TRUE;
4010 else
4011#endif
4012 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004013 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 p_icon = val;
4015 }
4016}
4017#endif
4018
4019/*
4020 * Parse 'arg' for option settings.
4021 *
4022 * 'arg' may be IObuff, but only when no errors can be present and option
4023 * does not need to be expanded with option_expand().
4024 * "opt_flags":
4025 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004026 * OPT_GLOBAL for ":setglobal"
4027 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004029 * OPT_WINONLY to only set window-local options
4030 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 *
4032 * returns FAIL if an error is detected, OK otherwise
4033 */
4034 int
4035do_set(arg, opt_flags)
4036 char_u *arg; /* option string (may be written to!) */
4037 int opt_flags;
4038{
4039 int opt_idx;
4040 char_u *errmsg;
4041 char_u errbuf[80];
4042 char_u *startarg;
4043 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4044 int nextchar; /* next non-white char after option name */
4045 int afterchar; /* character just after option name */
4046 int len;
4047 int i;
4048 long value;
4049 int key;
4050 long_u flags; /* flags for current option */
4051 char_u *varp = NULL; /* pointer to variable for current option */
4052 int did_show = FALSE; /* already showed one value */
4053 int adding; /* "opt+=arg" */
4054 int prepending; /* "opt^=arg" */
4055 int removing; /* "opt-=arg" */
4056 int cp_val = 0;
4057 char_u key_name[2];
4058
4059 if (*arg == NUL)
4060 {
4061 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004062 did_show = TRUE;
4063 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 }
4065
4066 while (*arg != NUL) /* loop to process all options */
4067 {
4068 errmsg = NULL;
4069 startarg = arg; /* remember for error message */
4070
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004071 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4072 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 {
4074 /*
4075 * ":set all" show all options.
4076 * ":set all&" set all options to their default value.
4077 */
4078 arg += 3;
4079 if (*arg == '&')
4080 {
4081 ++arg;
4082 /* Only for :set command set global value of local options. */
4083 set_options_default(OPT_FREE | opt_flags);
4084 }
4085 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004086 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004088 did_show = TRUE;
4089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004091 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 {
4093 showoptions(2, opt_flags);
4094 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004095 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 arg += 7;
4097 }
4098 else
4099 {
4100 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004101 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 {
4103 prefix = 0;
4104 arg += 2;
4105 }
4106 else if (STRNCMP(arg, "inv", 3) == 0)
4107 {
4108 prefix = 2;
4109 arg += 3;
4110 }
4111
4112 /* find end of name */
4113 key = 0;
4114 if (*arg == '<')
4115 {
4116 nextchar = 0;
4117 opt_idx = -1;
4118 /* look out for <t_>;> */
4119 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4120 len = 5;
4121 else
4122 {
4123 len = 1;
4124 while (arg[len] != NUL && arg[len] != '>')
4125 ++len;
4126 }
4127 if (arg[len] != '>')
4128 {
4129 errmsg = e_invarg;
4130 goto skip;
4131 }
4132 arg[len] = NUL; /* put NUL after name */
4133 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4134 opt_idx = findoption(arg + 1);
4135 arg[len++] = '>'; /* restore '>' */
4136 if (opt_idx == -1)
4137 key = find_key_option(arg + 1);
4138 }
4139 else
4140 {
4141 len = 0;
4142 /*
4143 * The two characters after "t_" may not be alphanumeric.
4144 */
4145 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4146 len = 4;
4147 else
4148 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4149 ++len;
4150 nextchar = arg[len];
4151 arg[len] = NUL; /* put NUL after name */
4152 opt_idx = findoption(arg);
4153 arg[len] = nextchar; /* restore nextchar */
4154 if (opt_idx == -1)
4155 key = find_key_option(arg);
4156 }
4157
4158 /* remember character after option name */
4159 afterchar = arg[len];
4160
4161 /* skip white space, allow ":set ai ?" */
4162 while (vim_iswhite(arg[len]))
4163 ++len;
4164
4165 adding = FALSE;
4166 prepending = FALSE;
4167 removing = FALSE;
4168 if (arg[len] != NUL && arg[len + 1] == '=')
4169 {
4170 if (arg[len] == '+')
4171 {
4172 adding = TRUE; /* "+=" */
4173 ++len;
4174 }
4175 else if (arg[len] == '^')
4176 {
4177 prepending = TRUE; /* "^=" */
4178 ++len;
4179 }
4180 else if (arg[len] == '-')
4181 {
4182 removing = TRUE; /* "-=" */
4183 ++len;
4184 }
4185 }
4186 nextchar = arg[len];
4187
4188 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4189 {
4190 errmsg = (char_u *)N_("E518: Unknown option");
4191 goto skip;
4192 }
4193
4194 if (opt_idx >= 0)
4195 {
4196 if (options[opt_idx].var == NULL) /* hidden option: skip */
4197 {
4198 /* Only give an error message when requesting the value of
4199 * a hidden option, ignore setting it. */
4200 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4201 && (!(options[opt_idx].flags & P_BOOL)
4202 || nextchar == '?'))
4203 errmsg = (char_u *)N_("E519: Option not supported");
4204 goto skip;
4205 }
4206
4207 flags = options[opt_idx].flags;
4208 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4209 }
4210 else
4211 {
4212 flags = P_STRING;
4213 if (key < 0)
4214 {
4215 key_name[0] = KEY2TERMCAP0(key);
4216 key_name[1] = KEY2TERMCAP1(key);
4217 }
4218 else
4219 {
4220 key_name[0] = KS_KEY;
4221 key_name[1] = (key & 0xff);
4222 }
4223 }
4224
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004225 /* Skip all options that are not window-local (used when showing
4226 * an already loaded buffer in a window). */
4227 if ((opt_flags & OPT_WINONLY)
4228 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4229 goto skip;
4230
Bram Moolenaara3227e22006-03-08 21:32:40 +00004231 /* Skip all options that are window-local (used for :vimgrep). */
4232 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4233 && options[opt_idx].var == VAR_WIN)
4234 goto skip;
4235
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004236 /* Disallow changing some options from modelines. */
4237 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004239 if (flags & P_SECURE)
4240 {
4241 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4242 goto skip;
4243 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004244#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004245 /* In diff mode some options are overruled. This avoids that
4246 * 'foldmethod' becomes "marker" instead of "diff" and that
4247 * "wrap" gets set. */
4248 if (curwin->w_p_diff
4249 && (options[opt_idx].indir == PV_FDM
4250 || options[opt_idx].indir == PV_WRAP))
4251 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004252#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 }
4254
4255#ifdef HAVE_SANDBOX
4256 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004257 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 {
4259 errmsg = (char_u *)_(e_sandbox);
4260 goto skip;
4261 }
4262#endif
4263
4264 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4265 {
4266 arg += len;
4267 cp_val = p_cp;
4268 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4269 {
4270 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4271 {
4272 cp_val = FALSE;
4273 arg += 3;
4274 }
4275 else /* "opt&vi": set to Vi default */
4276 {
4277 cp_val = TRUE;
4278 arg += 2;
4279 }
4280 }
4281 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4282 && arg[1] != NUL && !vim_iswhite(arg[1]))
4283 {
4284 errmsg = e_trailing;
4285 goto skip;
4286 }
4287 }
4288
4289 /*
4290 * allow '=' and ':' as MSDOS command.com allows only one
4291 * '=' character per "set" command line. grrr. (jw)
4292 */
4293 if (nextchar == '?'
4294 || (prefix == 1
4295 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4296 && !(flags & P_BOOL)))
4297 {
4298 /*
4299 * print value
4300 */
4301 if (did_show)
4302 msg_putchar('\n'); /* cursor below last one */
4303 else
4304 {
4305 gotocmdline(TRUE); /* cursor at status line */
4306 did_show = TRUE; /* remember that we did a line */
4307 }
4308 if (opt_idx >= 0)
4309 {
4310 showoneopt(&options[opt_idx], opt_flags);
4311#ifdef FEAT_EVAL
4312 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004313 {
4314 /* Mention where the option was last set. */
4315 if (varp == options[opt_idx].var)
4316 last_set_msg(options[opt_idx].scriptID);
4317 else if ((int)options[opt_idx].indir & PV_WIN)
4318 last_set_msg(curwin->w_p_scriptID[
4319 (int)options[opt_idx].indir & PV_MASK]);
4320 else if ((int)options[opt_idx].indir & PV_BUF)
4321 last_set_msg(curbuf->b_p_scriptID[
4322 (int)options[opt_idx].indir & PV_MASK]);
4323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004324#endif
4325 }
4326 else
4327 {
4328 char_u *p;
4329
4330 p = find_termcode(key_name);
4331 if (p == NULL)
4332 {
4333 errmsg = (char_u *)N_("E518: Unknown option");
4334 goto skip;
4335 }
4336 else
4337 (void)show_one_termcode(key_name, p, TRUE);
4338 }
4339 if (nextchar != '?'
4340 && nextchar != NUL && !vim_iswhite(afterchar))
4341 errmsg = e_trailing;
4342 }
4343 else
4344 {
4345 if (flags & P_BOOL) /* boolean */
4346 {
4347 if (nextchar == '=' || nextchar == ':')
4348 {
4349 errmsg = e_invarg;
4350 goto skip;
4351 }
4352
4353 /*
4354 * ":set opt!": invert
4355 * ":set opt&": reset to default value
4356 * ":set opt<": reset to global value
4357 */
4358 if (nextchar == '!')
4359 value = *(int *)(varp) ^ 1;
4360 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004361 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362 ((flags & P_VI_DEF) || cp_val)
4363 ? VI_DEFAULT : VIM_DEFAULT];
4364 else if (nextchar == '<')
4365 {
4366 /* For 'autoread' -1 means to use global value. */
4367 if ((int *)varp == &curbuf->b_p_ar
4368 && opt_flags == OPT_LOCAL)
4369 value = -1;
4370 else
4371 value = *(int *)get_varp_scope(&(options[opt_idx]),
4372 OPT_GLOBAL);
4373 }
4374 else
4375 {
4376 /*
4377 * ":set invopt": invert
4378 * ":set opt" or ":set noopt": set or reset
4379 */
4380 if (nextchar != NUL && !vim_iswhite(afterchar))
4381 {
4382 errmsg = e_trailing;
4383 goto skip;
4384 }
4385 if (prefix == 2) /* inv */
4386 value = *(int *)(varp) ^ 1;
4387 else
4388 value = prefix;
4389 }
4390
4391 errmsg = set_bool_option(opt_idx, varp, (int)value,
4392 opt_flags);
4393 }
4394 else /* numeric or string */
4395 {
4396 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4397 || prefix != 1)
4398 {
4399 errmsg = e_invarg;
4400 goto skip;
4401 }
4402
4403 if (flags & P_NUM) /* numeric */
4404 {
4405 /*
4406 * Different ways to set a number option:
4407 * & set to default value
4408 * < set to global value
4409 * <xx> accept special key codes for 'wildchar'
4410 * c accept any non-digit for 'wildchar'
4411 * [-]0-9 set number
4412 * other error
4413 */
4414 ++arg;
4415 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004416 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 ((flags & P_VI_DEF) || cp_val)
4418 ? VI_DEFAULT : VIM_DEFAULT];
4419 else if (nextchar == '<')
4420 value = *(long *)get_varp_scope(&(options[opt_idx]),
4421 OPT_GLOBAL);
4422 else if (((long *)varp == &p_wc
4423 || (long *)varp == &p_wcm)
4424 && (*arg == '<'
4425 || *arg == '^'
4426 || ((!arg[1] || vim_iswhite(arg[1]))
4427 && !VIM_ISDIGIT(*arg))))
4428 {
4429 value = string_to_key(arg);
4430 if (value == 0 && (long *)varp != &p_wcm)
4431 {
4432 errmsg = e_invarg;
4433 goto skip;
4434 }
4435 }
4436 /* allow negative numbers (for 'undolevels') */
4437 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4438 {
4439 i = 0;
4440 if (*arg == '-')
4441 i = 1;
4442#ifdef HAVE_STRTOL
4443 value = strtol((char *)arg, NULL, 0);
4444 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4445 i += 2;
4446#else
4447 value = atol((char *)arg);
4448#endif
4449 while (VIM_ISDIGIT(arg[i]))
4450 ++i;
4451 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4452 {
4453 errmsg = e_invarg;
4454 goto skip;
4455 }
4456 }
4457 else
4458 {
4459 errmsg = (char_u *)N_("E521: Number required after =");
4460 goto skip;
4461 }
4462
4463 if (adding)
4464 value = *(long *)varp + value;
4465 if (prepending)
4466 value = *(long *)varp * value;
4467 if (removing)
4468 value = *(long *)varp - value;
4469 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004470 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471 }
4472 else if (opt_idx >= 0) /* string */
4473 {
4474 char_u *save_arg = NULL;
4475 char_u *s = NULL;
4476 char_u *oldval; /* previous value if *varp */
4477 char_u *newval;
4478 char_u *origval;
4479 unsigned newlen;
4480 int comma;
4481 int bs;
4482 int new_value_alloced; /* new string option
4483 was allocated */
4484
4485 /* When using ":set opt=val" for a global option
4486 * with a local value the local value will be
4487 * reset, use the global value here. */
4488 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004489 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004490 varp = options[opt_idx].var;
4491
4492 /* The old value is kept until we are sure that the
4493 * new value is valid. */
4494 oldval = *(char_u **)varp;
4495 if (nextchar == '&') /* set to default val */
4496 {
4497 newval = options[opt_idx].def_val[
4498 ((flags & P_VI_DEF) || cp_val)
4499 ? VI_DEFAULT : VIM_DEFAULT];
4500 if ((char_u **)varp == &p_bg)
4501 {
4502 /* guess the value of 'background' */
4503#ifdef FEAT_GUI
4504 if (gui.in_use)
4505 newval = gui_bg_default();
4506 else
4507#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004508 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004509 }
4510
4511 /* expand environment variables and ~ (since the
4512 * default value was already expanded, only
4513 * required when an environment variable was set
4514 * later */
4515 if (newval == NULL)
4516 newval = empty_option;
4517 else
4518 {
4519 s = option_expand(opt_idx, newval);
4520 if (s == NULL)
4521 s = newval;
4522 newval = vim_strsave(s);
4523 }
4524 new_value_alloced = TRUE;
4525 }
4526 else if (nextchar == '<') /* set to global val */
4527 {
4528 newval = vim_strsave(*(char_u **)get_varp_scope(
4529 &(options[opt_idx]), OPT_GLOBAL));
4530 new_value_alloced = TRUE;
4531 }
4532 else
4533 {
4534 ++arg; /* jump to after the '=' or ':' */
4535
4536 /*
4537 * Set 'keywordprg' to ":help" if an empty
4538 * value was passed to :set by the user.
4539 * Misuse errbuf[] for the resulting string.
4540 */
4541 if (varp == (char_u *)&p_kp
4542 && (*arg == NUL || *arg == ' '))
4543 {
4544 STRCPY(errbuf, ":help");
4545 save_arg = arg;
4546 arg = errbuf;
4547 }
4548 /*
4549 * Convert 'whichwrap' number to string, for
4550 * backwards compatibility with Vim 3.0.
4551 * Misuse errbuf[] for the resulting string.
4552 */
4553 else if (varp == (char_u *)&p_ww
4554 && VIM_ISDIGIT(*arg))
4555 {
4556 *errbuf = NUL;
4557 i = getdigits(&arg);
4558 if (i & 1)
4559 STRCAT(errbuf, "b,");
4560 if (i & 2)
4561 STRCAT(errbuf, "s,");
4562 if (i & 4)
4563 STRCAT(errbuf, "h,l,");
4564 if (i & 8)
4565 STRCAT(errbuf, "<,>,");
4566 if (i & 16)
4567 STRCAT(errbuf, "[,],");
4568 if (*errbuf != NUL) /* remove trailing , */
4569 errbuf[STRLEN(errbuf) - 1] = NUL;
4570 save_arg = arg;
4571 arg = errbuf;
4572 }
4573 /*
4574 * Remove '>' before 'dir' and 'bdir', for
4575 * backwards compatibility with version 3.0
4576 */
4577 else if ( *arg == '>'
4578 && (varp == (char_u *)&p_dir
4579 || varp == (char_u *)&p_bdir))
4580 {
4581 ++arg;
4582 }
4583
4584 /* When setting the local value of a global
4585 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004586 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004587 && (opt_flags & OPT_LOCAL))
4588 origval = *(char_u **)get_varp(
4589 &options[opt_idx]);
4590 else
4591 origval = oldval;
4592
4593 /*
4594 * Copy the new string into allocated memory.
4595 * Can't use set_string_option_direct(), because
4596 * we need to remove the backslashes.
4597 */
4598 /* get a bit too much */
4599 newlen = (unsigned)STRLEN(arg) + 1;
4600 if (adding || prepending || removing)
4601 newlen += (unsigned)STRLEN(origval) + 1;
4602 newval = alloc(newlen);
4603 if (newval == NULL) /* out of mem, don't change */
4604 break;
4605 s = newval;
4606
4607 /*
4608 * Copy the string, skip over escaped chars.
4609 * For MS-DOS and WIN32 backslashes before normal
4610 * file name characters are not removed, and keep
4611 * backslash at start, for "\\machine\path", but
4612 * do remove it for "\\\\machine\\path".
4613 * The reverse is found in ExpandOldSetting().
4614 */
4615 while (*arg && !vim_iswhite(*arg))
4616 {
4617 if (*arg == '\\' && arg[1] != NUL
4618#ifdef BACKSLASH_IN_FILENAME
4619 && !((flags & P_EXPAND)
4620 && vim_isfilec(arg[1])
4621 && (arg[1] != '\\'
4622 || (s == newval
4623 && arg[2] != '\\')))
4624#endif
4625 )
4626 ++arg; /* remove backslash */
4627#ifdef FEAT_MBYTE
4628 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004629 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004630 {
4631 /* copy multibyte char */
4632 mch_memmove(s, arg, (size_t)i);
4633 arg += i;
4634 s += i;
4635 }
4636 else
4637#endif
4638 *s++ = *arg++;
4639 }
4640 *s = NUL;
4641
4642 /*
4643 * Expand environment variables and ~.
4644 * Don't do it when adding without inserting a
4645 * comma.
4646 */
4647 if (!(adding || prepending || removing)
4648 || (flags & P_COMMA))
4649 {
4650 s = option_expand(opt_idx, newval);
4651 if (s != NULL)
4652 {
4653 vim_free(newval);
4654 newlen = (unsigned)STRLEN(s) + 1;
4655 if (adding || prepending || removing)
4656 newlen += (unsigned)STRLEN(origval) + 1;
4657 newval = alloc(newlen);
4658 if (newval == NULL)
4659 break;
4660 STRCPY(newval, s);
4661 }
4662 }
4663
4664 /* locate newval[] in origval[] when removing it
4665 * and when adding to avoid duplicates */
4666 i = 0; /* init for GCC */
4667 if (removing || (flags & P_NODUP))
4668 {
4669 i = (int)STRLEN(newval);
4670 bs = 0;
4671 for (s = origval; *s; ++s)
4672 {
4673 if ((!(flags & P_COMMA)
4674 || s == origval
4675 || (s[-1] == ',' && !(bs & 1)))
4676 && STRNCMP(s, newval, i) == 0
4677 && (!(flags & P_COMMA)
4678 || s[i] == ','
4679 || s[i] == NUL))
4680 break;
4681 /* Count backspaces. Only a comma with an
4682 * even number of backspaces before it is
4683 * recognized as a separator */
4684 if (s > origval && s[-1] == '\\')
4685 ++bs;
4686 else
4687 bs = 0;
4688 }
4689
4690 /* do not add if already there */
4691 if ((adding || prepending) && *s)
4692 {
4693 prepending = FALSE;
4694 adding = FALSE;
4695 STRCPY(newval, origval);
4696 }
4697 }
4698
4699 /* concatenate the two strings; add a ',' if
4700 * needed */
4701 if (adding || prepending)
4702 {
4703 comma = ((flags & P_COMMA) && *origval != NUL
4704 && *newval != NUL);
4705 if (adding)
4706 {
4707 i = (int)STRLEN(origval);
4708 mch_memmove(newval + i + comma, newval,
4709 STRLEN(newval) + 1);
4710 mch_memmove(newval, origval, (size_t)i);
4711 }
4712 else
4713 {
4714 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004715 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 }
4717 if (comma)
4718 newval[i] = ',';
4719 }
4720
4721 /* Remove newval[] from origval[]. (Note: "i" has
4722 * been set above and is used here). */
4723 if (removing)
4724 {
4725 STRCPY(newval, origval);
4726 if (*s)
4727 {
4728 /* may need to remove a comma */
4729 if (flags & P_COMMA)
4730 {
4731 if (s == origval)
4732 {
4733 /* include comma after string */
4734 if (s[i] == ',')
4735 ++i;
4736 }
4737 else
4738 {
4739 /* include comma before string */
4740 --s;
4741 ++i;
4742 }
4743 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004744 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 }
4746 }
4747
4748 if (flags & P_FLAGLIST)
4749 {
4750 /* Remove flags that appear twice. */
4751 for (s = newval; *s; ++s)
4752 if ((!(flags & P_COMMA) || *s != ',')
4753 && vim_strchr(s + 1, *s) != NULL)
4754 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004755 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004756 --s;
4757 }
4758 }
4759
4760 if (save_arg != NULL) /* number for 'whichwrap' */
4761 arg = save_arg;
4762 new_value_alloced = TRUE;
4763 }
4764
4765 /* Set the new value. */
4766 *(char_u **)(varp) = newval;
4767
4768 /* Handle side effects, and set the global value for
4769 * ":set" on local options. */
4770 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4771 new_value_alloced, oldval, errbuf, opt_flags);
4772
4773 /* If error detected, print the error message. */
4774 if (errmsg != NULL)
4775 goto skip;
4776 }
4777 else /* key code option */
4778 {
4779 char_u *p;
4780
4781 if (nextchar == '&')
4782 {
4783 if (add_termcap_entry(key_name, TRUE) == FAIL)
4784 errmsg = (char_u *)N_("E522: Not found in termcap");
4785 }
4786 else
4787 {
4788 ++arg; /* jump to after the '=' or ':' */
4789 for (p = arg; *p && !vim_iswhite(*p); ++p)
4790 if (*p == '\\' && p[1] != NUL)
4791 ++p;
4792 nextchar = *p;
4793 *p = NUL;
4794 add_termcode(key_name, arg, FALSE);
4795 *p = nextchar;
4796 }
4797 if (full_screen)
4798 ttest(FALSE);
4799 redraw_all_later(CLEAR);
4800 }
4801 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004802
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004804 did_set_option(opt_idx, opt_flags,
4805 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 }
4807
4808skip:
4809 /*
4810 * Advance to next argument.
4811 * - skip until a blank found, taking care of backslashes
4812 * - skip blanks
4813 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4814 */
4815 for (i = 0; i < 2 ; ++i)
4816 {
4817 while (*arg != NUL && !vim_iswhite(*arg))
4818 if (*arg++ == '\\' && *arg != NUL)
4819 ++arg;
4820 arg = skipwhite(arg);
4821 if (*arg != '=')
4822 break;
4823 }
4824 }
4825
4826 if (errmsg != NULL)
4827 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004828 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004829 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 if (i + (arg - startarg) < IOSIZE)
4831 {
4832 /* append the argument with the error */
4833 STRCAT(IObuff, ": ");
4834 mch_memmove(IObuff + i, startarg, (arg - startarg));
4835 IObuff[i + (arg - startarg)] = NUL;
4836 }
4837 /* make sure all characters are printable */
4838 trans_characters(IObuff, IOSIZE);
4839
4840 ++no_wait_return; /* wait_return done later */
4841 emsg(IObuff); /* show error highlighted */
4842 --no_wait_return;
4843
4844 return FAIL;
4845 }
4846
4847 arg = skipwhite(arg);
4848 }
4849
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004850theend:
4851 if (silent_mode && did_show)
4852 {
4853 /* After displaying option values in silent mode. */
4854 silent_mode = FALSE;
4855 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4856 msg_putchar('\n');
4857 cursor_on(); /* msg_start() switches it off */
4858 out_flush();
4859 silent_mode = TRUE;
4860 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4861 }
4862
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 return OK;
4864}
4865
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004866/*
4867 * Call this when an option has been given a new value through a user command.
4868 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4869 */
4870 static void
4871did_set_option(opt_idx, opt_flags, new_value)
4872 int opt_idx;
4873 int opt_flags; /* possibly with OPT_MODELINE */
4874 int new_value; /* value was replaced completely */
4875{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004876 long_u *p;
4877
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004878 options[opt_idx].flags |= P_WAS_SET;
4879
4880 /* When an option is set in the sandbox, from a modeline or in secure mode
4881 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004882 * flag. */
4883 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004884 if (secure
4885#ifdef HAVE_SANDBOX
4886 || sandbox != 0
4887#endif
4888 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004889 *p = *p | P_INSECURE;
4890 else if (new_value)
4891 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004892}
4893
Bram Moolenaar071d4272004-06-13 20:20:40 +00004894 static char_u *
4895illegal_char(errbuf, c)
4896 char_u *errbuf;
4897 int c;
4898{
4899 if (errbuf == NULL)
4900 return (char_u *)"";
4901 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004902 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 return errbuf;
4904}
4905
4906/*
4907 * Convert a key name or string into a key value.
4908 * Used for 'wildchar' and 'cedit' options.
4909 */
4910 static int
4911string_to_key(arg)
4912 char_u *arg;
4913{
4914 if (*arg == '<')
4915 return find_key_option(arg + 1);
4916 if (*arg == '^')
4917 return Ctrl_chr(arg[1]);
4918 return *arg;
4919}
4920
4921#ifdef FEAT_CMDWIN
4922/*
4923 * Check value of 'cedit' and set cedit_key.
4924 * Returns NULL if value is OK, error message otherwise.
4925 */
4926 static char_u *
4927check_cedit()
4928{
4929 int n;
4930
4931 if (*p_cedit == NUL)
4932 cedit_key = -1;
4933 else
4934 {
4935 n = string_to_key(p_cedit);
4936 if (vim_isprintc(n))
4937 return e_invarg;
4938 cedit_key = n;
4939 }
4940 return NULL;
4941}
4942#endif
4943
4944#ifdef FEAT_TITLE
4945/*
4946 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4947 * maketitle() to create and display it.
4948 * When switching the title or icon off, call mch_restore_title() to get
4949 * the old value back.
4950 */
4951 static void
4952did_set_title(icon)
4953 int icon; /* Did set icon instead of title */
4954{
4955 if (starting != NO_SCREEN
4956#ifdef FEAT_GUI
4957 && !gui.starting
4958#endif
4959 )
4960 {
4961 maketitle();
4962 if (icon)
4963 {
4964 if (!p_icon)
4965 mch_restore_title(2);
4966 }
4967 else
4968 {
4969 if (!p_title)
4970 mch_restore_title(1);
4971 }
4972 }
4973}
4974#endif
4975
4976/*
4977 * set_options_bin - called when 'bin' changes value.
4978 */
4979 void
4980set_options_bin(oldval, newval, opt_flags)
4981 int oldval;
4982 int newval;
4983 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4984{
4985 /*
4986 * The option values that are changed when 'bin' changes are
4987 * copied when 'bin is set and restored when 'bin' is reset.
4988 */
4989 if (newval)
4990 {
4991 if (!oldval) /* switched on */
4992 {
4993 if (!(opt_flags & OPT_GLOBAL))
4994 {
4995 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4996 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4997 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4998 curbuf->b_p_et_nobin = curbuf->b_p_et;
4999 }
5000 if (!(opt_flags & OPT_LOCAL))
5001 {
5002 p_tw_nobin = p_tw;
5003 p_wm_nobin = p_wm;
5004 p_ml_nobin = p_ml;
5005 p_et_nobin = p_et;
5006 }
5007 }
5008
5009 if (!(opt_flags & OPT_GLOBAL))
5010 {
5011 curbuf->b_p_tw = 0; /* no automatic line wrap */
5012 curbuf->b_p_wm = 0; /* no automatic line wrap */
5013 curbuf->b_p_ml = 0; /* no modelines */
5014 curbuf->b_p_et = 0; /* no expandtab */
5015 }
5016 if (!(opt_flags & OPT_LOCAL))
5017 {
5018 p_tw = 0;
5019 p_wm = 0;
5020 p_ml = FALSE;
5021 p_et = FALSE;
5022 p_bin = TRUE; /* needed when called for the "-b" argument */
5023 }
5024 }
5025 else if (oldval) /* switched off */
5026 {
5027 if (!(opt_flags & OPT_GLOBAL))
5028 {
5029 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5030 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5031 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5032 curbuf->b_p_et = curbuf->b_p_et_nobin;
5033 }
5034 if (!(opt_flags & OPT_LOCAL))
5035 {
5036 p_tw = p_tw_nobin;
5037 p_wm = p_wm_nobin;
5038 p_ml = p_ml_nobin;
5039 p_et = p_et_nobin;
5040 }
5041 }
5042}
5043
5044#ifdef FEAT_VIMINFO
5045/*
5046 * Find the parameter represented by the given character (eg ', :, ", or /),
5047 * and return its associated value in the 'viminfo' string.
5048 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005049 * If the parameter is not specified in the string or there is no following
5050 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 */
5052 int
5053get_viminfo_parameter(type)
5054 int type;
5055{
5056 char_u *p;
5057
5058 p = find_viminfo_parameter(type);
5059 if (p != NULL && VIM_ISDIGIT(*p))
5060 return atoi((char *)p);
5061 return -1;
5062}
5063
5064/*
5065 * Find the parameter represented by the given character (eg ''', ':', '"', or
5066 * '/') in the 'viminfo' option and return a pointer to the string after it.
5067 * Return NULL if the parameter is not specified in the string.
5068 */
5069 char_u *
5070find_viminfo_parameter(type)
5071 int type;
5072{
5073 char_u *p;
5074
5075 for (p = p_viminfo; *p; ++p)
5076 {
5077 if (*p == type)
5078 return p + 1;
5079 if (*p == 'n') /* 'n' is always the last one */
5080 break;
5081 p = vim_strchr(p, ','); /* skip until next ',' */
5082 if (p == NULL) /* hit the end without finding parameter */
5083 break;
5084 }
5085 return NULL;
5086}
5087#endif
5088
5089/*
5090 * Expand environment variables for some string options.
5091 * These string options cannot be indirect!
5092 * If "val" is NULL expand the current value of the option.
5093 * Return pointer to NameBuff, or NULL when not expanded.
5094 */
5095 static char_u *
5096option_expand(opt_idx, val)
5097 int opt_idx;
5098 char_u *val;
5099{
5100 /* if option doesn't need expansion nothing to do */
5101 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5102 return NULL;
5103
5104 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5105 * expand_env() would truncate the string. */
5106 if (val != NULL && STRLEN(val) > MAXPATHL)
5107 return NULL;
5108
5109 if (val == NULL)
5110 val = *(char_u **)options[opt_idx].var;
5111
5112 /*
5113 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5114 * Escape spaces when expanding 'tags', they are used to separate file
5115 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005116 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 */
5118 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005119 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005120#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005121 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5122#endif
5123 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005124 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5125 return NULL;
5126
5127 return NameBuff;
5128}
5129
5130/*
5131 * After setting various option values: recompute variables that depend on
5132 * option values.
5133 */
5134 static void
5135didset_options()
5136{
5137 /* initialize the table for 'iskeyword' et.al. */
5138 (void)init_chartab();
5139
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005140#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005141 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5144#ifdef FEAT_SESSION
5145 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5146 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5147#endif
5148#ifdef FEAT_FOLDING
5149 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5150#endif
5151 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5152#ifdef FEAT_VIRTUALEDIT
5153 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5154#endif
5155#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5156 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5157#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005158#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005159 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005160 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005161 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005162#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5164 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5165#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005166#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5168#endif
5169#ifdef FEAT_CMDWIN
5170 /* set cedit_key */
5171 (void)check_cedit();
5172#endif
5173}
5174
5175/*
5176 * Check for string options that are NULL (normally only termcap options).
5177 */
5178 void
5179check_options()
5180{
5181 int opt_idx;
5182
5183 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5184 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5185 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5186}
5187
5188/*
5189 * Check string options in a buffer for NULL value.
5190 */
5191 void
5192check_buf_options(buf)
5193 buf_T *buf;
5194{
5195#if defined(FEAT_QUICKFIX)
5196 check_string_option(&buf->b_p_bh);
5197 check_string_option(&buf->b_p_bt);
5198#endif
5199#ifdef FEAT_MBYTE
5200 check_string_option(&buf->b_p_fenc);
5201#endif
5202 check_string_option(&buf->b_p_ff);
5203#ifdef FEAT_FIND_ID
5204 check_string_option(&buf->b_p_def);
5205 check_string_option(&buf->b_p_inc);
5206# ifdef FEAT_EVAL
5207 check_string_option(&buf->b_p_inex);
5208# endif
5209#endif
5210#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5211 check_string_option(&buf->b_p_inde);
5212 check_string_option(&buf->b_p_indk);
5213#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005214#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5215 check_string_option(&buf->b_p_bexpr);
5216#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005217#if defined(FEAT_EVAL)
5218 check_string_option(&buf->b_p_fex);
5219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220#ifdef FEAT_CRYPT
5221 check_string_option(&buf->b_p_key);
5222#endif
5223 check_string_option(&buf->b_p_kp);
5224 check_string_option(&buf->b_p_mps);
5225 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005226 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005227 check_string_option(&buf->b_p_isk);
5228#ifdef FEAT_COMMENTS
5229 check_string_option(&buf->b_p_com);
5230#endif
5231#ifdef FEAT_FOLDING
5232 check_string_option(&buf->b_p_cms);
5233#endif
5234 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005235#ifdef FEAT_TEXTOBJ
5236 check_string_option(&buf->b_p_qe);
5237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005238#ifdef FEAT_SYN_HL
5239 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005240#endif
5241#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005242 check_string_option(&buf->b_s.b_p_spc);
5243 check_string_option(&buf->b_s.b_p_spf);
5244 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245#endif
5246#ifdef FEAT_SEARCHPATH
5247 check_string_option(&buf->b_p_sua);
5248#endif
5249#ifdef FEAT_CINDENT
5250 check_string_option(&buf->b_p_cink);
5251 check_string_option(&buf->b_p_cino);
5252#endif
5253#ifdef FEAT_AUTOCMD
5254 check_string_option(&buf->b_p_ft);
5255#endif
5256#ifdef FEAT_OSFILETYPE
5257 check_string_option(&buf->b_p_oft);
5258#endif
5259#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5260 check_string_option(&buf->b_p_cinw);
5261#endif
5262#ifdef FEAT_INS_EXPAND
5263 check_string_option(&buf->b_p_cpt);
5264#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005265#ifdef FEAT_COMPL_FUNC
5266 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005267 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005269#ifdef FEAT_KEYMAP
5270 check_string_option(&buf->b_p_keymap);
5271#endif
5272#ifdef FEAT_QUICKFIX
5273 check_string_option(&buf->b_p_gp);
5274 check_string_option(&buf->b_p_mp);
5275 check_string_option(&buf->b_p_efm);
5276#endif
5277 check_string_option(&buf->b_p_ep);
5278 check_string_option(&buf->b_p_path);
5279 check_string_option(&buf->b_p_tags);
5280#ifdef FEAT_INS_EXPAND
5281 check_string_option(&buf->b_p_dict);
5282 check_string_option(&buf->b_p_tsr);
5283#endif
5284}
5285
5286/*
5287 * Free the string allocated for an option.
5288 * Checks for the string being empty_option. This may happen if we're out of
5289 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5290 * check_options().
5291 * Does NOT check for P_ALLOCED flag!
5292 */
5293 void
5294free_string_option(p)
5295 char_u *p;
5296{
5297 if (p != empty_option)
5298 vim_free(p);
5299}
5300
5301 void
5302clear_string_option(pp)
5303 char_u **pp;
5304{
5305 if (*pp != empty_option)
5306 vim_free(*pp);
5307 *pp = empty_option;
5308}
5309
5310 static void
5311check_string_option(pp)
5312 char_u **pp;
5313{
5314 if (*pp == NULL)
5315 *pp = empty_option;
5316}
5317
5318/*
5319 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5320 */
5321 void
5322set_term_option_alloced(p)
5323 char_u **p;
5324{
5325 int opt_idx;
5326
5327 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5328 if (options[opt_idx].var == (char_u *)p)
5329 {
5330 options[opt_idx].flags |= P_ALLOCED;
5331 return;
5332 }
5333 return; /* cannot happen: didn't find it! */
5334}
5335
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336#if defined(FEAT_EVAL) || defined(PROTO)
5337/*
5338 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5339 * Return FALSE when it wasn't.
5340 * Return -1 for an unknown option.
5341 */
5342 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005343was_set_insecurely(opt, opt_flags)
5344 char_u *opt;
5345 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005346{
5347 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005348 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005349
5350 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005351 {
5352 flagp = insecure_flag(idx, opt_flags);
5353 return (*flagp & P_INSECURE) != 0;
5354 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005355 EMSG2(_(e_intern2), "was_set_insecurely()");
5356 return -1;
5357}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005358
5359/*
5360 * Get a pointer to the flags used for the P_INSECURE flag of option
5361 * "opt_idx". For some local options a local flags field is used.
5362 */
5363 static long_u *
5364insecure_flag(opt_idx, opt_flags)
5365 int opt_idx;
5366 int opt_flags;
5367{
5368 if (opt_flags & OPT_LOCAL)
5369 switch ((int)options[opt_idx].indir)
5370 {
5371#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005372 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005373#endif
5374#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005375# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005376 case PV_FDE: return &curwin->w_p_fde_flags;
5377 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005378# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005379# ifdef FEAT_BEVAL
5380 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5381# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005382# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005383 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005384# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005385 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005386# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005387 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005388# endif
5389#endif
5390 }
5391
5392 /* Nothing special, return global flags field. */
5393 return &options[opt_idx].flags;
5394}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005395#endif
5396
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005397#ifdef FEAT_TITLE
5398static void redraw_titles __ARGS((void));
5399
5400/*
5401 * Redraw the window title and/or tab page text later.
5402 */
5403static void redraw_titles()
5404{
5405 need_maketitle = TRUE;
5406# ifdef FEAT_WINDOWS
5407 redraw_tabline = TRUE;
5408# endif
5409}
5410#endif
5411
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412/*
5413 * Set a string option to a new value (without checking the effect).
5414 * The string is copied into allocated memory.
5415 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005416 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005417 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418 */
5419 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005420set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005421 char_u *name;
5422 int opt_idx;
5423 char_u *val;
5424 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005425 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426{
5427 char_u *s;
5428 char_u **varp;
5429 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005430 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431
Bram Moolenaar89d40322006-08-29 15:30:07 +00005432 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005434 idx = findoption(name);
5435 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005436 {
5437 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005438 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 }
5441
Bram Moolenaar89d40322006-08-29 15:30:07 +00005442 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443 return;
5444
5445 s = vim_strsave(val);
5446 if (s != NULL)
5447 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005448 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005450 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005451 free_string_option(*varp);
5452 *varp = s;
5453
5454 /* For buffer/window local option may also set the global value. */
5455 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005456 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457
Bram Moolenaar89d40322006-08-29 15:30:07 +00005458 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459
5460 /* When setting both values of a global option with a local value,
5461 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005462 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 {
5464 free_string_option(*varp);
5465 *varp = empty_option;
5466 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005467# ifdef FEAT_EVAL
5468 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005469 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005470 set_sid == 0 ? current_SID : set_sid);
5471# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 }
5473}
5474
5475/*
5476 * Set global value for string option when it's a local option.
5477 */
5478 static void
5479set_string_option_global(opt_idx, varp)
5480 int opt_idx; /* option index */
5481 char_u **varp; /* pointer to option variable */
5482{
5483 char_u **p, *s;
5484
5485 /* the global value is always allocated */
5486 if (options[opt_idx].var == VAR_WIN)
5487 p = (char_u **)GLOBAL_WO(varp);
5488 else
5489 p = (char_u **)options[opt_idx].var;
5490 if (options[opt_idx].indir != PV_NONE
5491 && p != varp
5492 && (s = vim_strsave(*varp)) != NULL)
5493 {
5494 free_string_option(*p);
5495 *p = s;
5496 }
5497}
5498
5499/*
5500 * Set a string option to a new value, and handle the effects.
5501 */
5502 static void
5503set_string_option(opt_idx, value, opt_flags)
5504 int opt_idx;
5505 char_u *value;
5506 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5507{
5508 char_u *s;
5509 char_u **varp;
5510 char_u *oldval;
5511
5512 if (options[opt_idx].var == NULL) /* don't set hidden option */
5513 return;
5514
5515 s = vim_strsave(value);
5516 if (s != NULL)
5517 {
5518 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5519 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005520 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521 ? OPT_GLOBAL : OPT_LOCAL)
5522 : opt_flags);
5523 oldval = *varp;
5524 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005525 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5526 opt_flags) == NULL)
5527 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 }
5529}
5530
5531/*
5532 * Handle string options that need some action to perform when changed.
5533 * Returns NULL for success, or an error message for an error.
5534 */
5535 static char_u *
5536did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5537 opt_flags)
5538 int opt_idx; /* index in options[] table */
5539 char_u **varp; /* pointer to the option variable */
5540 int new_value_alloced; /* new value was allocated */
5541 char_u *oldval; /* previous value of the option */
5542 char_u *errbuf; /* buffer for errors, or NULL */
5543 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5544{
5545 char_u *errmsg = NULL;
5546 char_u *s, *p;
5547 int did_chartab = FALSE;
5548 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005549 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005550#ifdef FEAT_GUI
5551 /* set when changing an option that only requires a redraw in the GUI */
5552 int redraw_gui_only = FALSE;
5553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554
5555 /* Get the global option to compare with, otherwise we would have to check
5556 * two values for all local options. */
5557 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5558
5559 /* Disallow changing some options from secure mode */
5560 if ((secure
5561#ifdef HAVE_SANDBOX
5562 || sandbox != 0
5563#endif
5564 ) && (options[opt_idx].flags & P_SECURE))
5565 {
5566 errmsg = e_secure;
5567 }
5568
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005569 /* Check for a "normal" file name in some options. Disallow a path
5570 * separator (slash and/or backslash), wildcards and characters that are
5571 * often illegal in a file name. */
5572 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005573 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005574 {
5575 errmsg = e_invarg;
5576 }
5577
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 /* 'term' */
5579 else if (varp == &T_NAME)
5580 {
5581 if (T_NAME[0] == NUL)
5582 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5583#ifdef FEAT_GUI
5584 if (gui.in_use)
5585 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5586 else if (term_is_gui(T_NAME))
5587 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5588#endif
5589 else if (set_termname(T_NAME) == FAIL)
5590 errmsg = (char_u *)N_("E522: Not found in termcap");
5591 else
5592 /* Screen colors may have changed. */
5593 redraw_later_clear();
5594 }
5595
5596 /* 'backupcopy' */
5597 else if (varp == &p_bkc)
5598 {
5599 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5600 errmsg = e_invarg;
5601 if (((bkc_flags & BKC_AUTO) != 0)
5602 + ((bkc_flags & BKC_YES) != 0)
5603 + ((bkc_flags & BKC_NO) != 0) != 1)
5604 {
5605 /* Must have exactly one of "auto", "yes" and "no". */
5606 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5607 errmsg = e_invarg;
5608 }
5609 }
5610
5611 /* 'backupext' and 'patchmode' */
5612 else if (varp == &p_bex || varp == &p_pm)
5613 {
5614 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5615 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5616 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5617 }
5618
5619 /*
5620 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5621 * If the new option is invalid, use old value. 'lisp' option: refill
5622 * chartab[] for '-' char
5623 */
5624 else if ( varp == &p_isi
5625 || varp == &(curbuf->b_p_isk)
5626 || varp == &p_isp
5627 || varp == &p_isf)
5628 {
5629 if (init_chartab() == FAIL)
5630 {
5631 did_chartab = TRUE; /* need to restore it below */
5632 errmsg = e_invarg; /* error in value */
5633 }
5634 }
5635
5636 /* 'helpfile' */
5637 else if (varp == &p_hf)
5638 {
5639 /* May compute new values for $VIM and $VIMRUNTIME */
5640 if (didset_vim)
5641 {
5642 vim_setenv((char_u *)"VIM", (char_u *)"");
5643 didset_vim = FALSE;
5644 }
5645 if (didset_vimruntime)
5646 {
5647 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5648 didset_vimruntime = FALSE;
5649 }
5650 }
5651
Bram Moolenaar1a384422010-07-14 19:53:30 +02005652#ifdef FEAT_SYN_HL
5653 /* 'colorcolumn' */
5654 else if (varp == &curwin->w_p_cc)
5655 errmsg = check_colorcolumn(curwin);
5656#endif
5657
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658#ifdef FEAT_MULTI_LANG
5659 /* 'helplang' */
5660 else if (varp == &p_hlg)
5661 {
5662 /* Check for "", "ab", "ab,cd", etc. */
5663 for (s = p_hlg; *s != NUL; s += 3)
5664 {
5665 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5666 {
5667 errmsg = e_invarg;
5668 break;
5669 }
5670 if (s[2] == NUL)
5671 break;
5672 }
5673 }
5674#endif
5675
5676 /* 'highlight' */
5677 else if (varp == &p_hl)
5678 {
5679 if (highlight_changed() == FAIL)
5680 errmsg = e_invarg; /* invalid flags */
5681 }
5682
5683 /* 'nrformats' */
5684 else if (gvarp == &p_nf)
5685 {
5686 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5687 errmsg = e_invarg;
5688 }
5689
5690#ifdef FEAT_SESSION
5691 /* 'sessionoptions' */
5692 else if (varp == &p_ssop)
5693 {
5694 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5695 errmsg = e_invarg;
5696 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5697 {
5698 /* Don't allow both "sesdir" and "curdir". */
5699 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5700 errmsg = e_invarg;
5701 }
5702 }
5703 /* 'viewoptions' */
5704 else if (varp == &p_vop)
5705 {
5706 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5707 errmsg = e_invarg;
5708 }
5709#endif
5710
5711 /* 'scrollopt' */
5712#ifdef FEAT_SCROLLBIND
5713 else if (varp == &p_sbo)
5714 {
5715 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5716 errmsg = e_invarg;
5717 }
5718#endif
5719
5720 /* 'ambiwidth' */
5721#ifdef FEAT_MBYTE
5722 else if (varp == &p_ambw)
5723 {
5724 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5725 errmsg = e_invarg;
5726 }
5727#endif
5728
5729 /* 'background' */
5730 else if (varp == &p_bg)
5731 {
5732 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5733 {
5734#ifdef FEAT_EVAL
5735 int dark = (*p_bg == 'd');
5736#endif
5737
5738 init_highlight(FALSE, FALSE);
5739
5740#ifdef FEAT_EVAL
5741 if (dark != (*p_bg == 'd')
5742 && get_var_value((char_u *)"g:colors_name") != NULL)
5743 {
5744 /* The color scheme must have set 'background' back to another
5745 * value, that's not what we want here. Disable the color
5746 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005747 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748 free_string_option(p_bg);
5749 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5750 check_string_option(&p_bg);
5751 init_highlight(FALSE, FALSE);
5752 }
5753#endif
5754 }
5755 else
5756 errmsg = e_invarg;
5757 }
5758
5759 /* 'wildmode' */
5760 else if (varp == &p_wim)
5761 {
5762 if (check_opt_wim() == FAIL)
5763 errmsg = e_invarg;
5764 }
5765
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005766#ifdef FEAT_CMDL_COMPL
5767 /* 'wildoptions' */
5768 else if (varp == &p_wop)
5769 {
5770 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5771 errmsg = e_invarg;
5772 }
5773#endif
5774
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775#ifdef FEAT_WAK
5776 /* 'winaltkeys' */
5777 else if (varp == &p_wak)
5778 {
5779 if (*p_wak == NUL
5780 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5781 errmsg = e_invarg;
5782# ifdef FEAT_MENU
5783# ifdef FEAT_GUI_MOTIF
5784 else if (gui.in_use)
5785 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5786# else
5787# ifdef FEAT_GUI_GTK
5788 else if (gui.in_use)
5789 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5790# endif
5791# endif
5792# endif
5793 }
5794#endif
5795
5796#ifdef FEAT_AUTOCMD
5797 /* 'eventignore' */
5798 else if (varp == &p_ei)
5799 {
5800 if (check_ei() == FAIL)
5801 errmsg = e_invarg;
5802 }
5803#endif
5804
5805#ifdef FEAT_MBYTE
5806 /* 'encoding' and 'fileencoding' */
5807 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5808 {
5809 if (gvarp == &p_fenc)
5810 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005811 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812 errmsg = e_modifiable;
5813 else if (vim_strchr(*varp, ',') != NULL)
5814 /* No comma allowed in 'fileencoding'; catches confusing it
5815 * with 'fileencodings'. */
5816 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005817 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005818 {
5819# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005820 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005821 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005823 /* Add 'fileencoding' to the swap file. */
5824 ml_setflags(curbuf);
5825 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826 }
5827 if (errmsg == NULL)
5828 {
5829 /* canonize the value, so that STRCMP() can be used on it */
5830 p = enc_canonize(*varp);
5831 if (p != NULL)
5832 {
5833 vim_free(*varp);
5834 *varp = p;
5835 }
5836 if (varp == &p_enc)
5837 {
5838 errmsg = mb_init();
5839# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005840 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841# endif
5842 }
5843 }
5844
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005845# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5847 {
5848 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5849 if (STRCMP(p_tenc, "utf-8") != 0)
5850 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5851 }
5852# endif
5853
5854 if (errmsg == NULL)
5855 {
5856# ifdef FEAT_KEYMAP
5857 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5858 * (with another encoding). */
5859 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5860 (void)keymap_init();
5861# endif
5862
5863 /* When 'termencoding' is not empty and 'encoding' changes or when
5864 * 'termencoding' changes, need to setup for keyboard input and
5865 * display output conversion. */
5866 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5867 {
5868 convert_setup(&input_conv, p_tenc, p_enc);
5869 convert_setup(&output_conv, p_enc, p_tenc);
5870 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005871
5872# if defined(WIN3264) && defined(FEAT_MBYTE)
5873 /* $HOME may have characters in active code page. */
5874 if (varp == &p_enc)
5875 init_homedir();
5876# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877 }
5878 }
5879#endif
5880
5881#if defined(FEAT_POSTSCRIPT)
5882 else if (varp == &p_penc)
5883 {
5884 /* Canonize printencoding if VIM standard one */
5885 p = enc_canonize(p_penc);
5886 if (p != NULL)
5887 {
5888 vim_free(p_penc);
5889 p_penc = p;
5890 }
5891 else
5892 {
5893 /* Ensure lower case and '-' for '_' */
5894 for (s = p_penc; *s != NUL; s++)
5895 {
5896 if (*s == '_')
5897 *s = '-';
5898 else
5899 *s = TOLOWER_ASC(*s);
5900 }
5901 }
5902 }
5903#endif
5904
Bram Moolenaar9372a112005-12-06 19:59:18 +00005905#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 else if (varp == &p_imak)
5907 {
5908 if (gui.in_use && !im_xim_isvalid_imactivate())
5909 errmsg = e_invarg;
5910 }
5911#endif
5912
5913#ifdef FEAT_KEYMAP
5914 else if (varp == &curbuf->b_p_keymap)
5915 {
5916 /* load or unload key mapping tables */
5917 errmsg = keymap_init();
5918
Bram Moolenaarfab06232009-03-04 03:13:35 +00005919 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005921 if (*curbuf->b_p_keymap != NUL)
5922 {
5923 /* Installed a new keymap, switch on using it. */
5924 curbuf->b_p_iminsert = B_IMODE_LMAP;
5925 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5926 curbuf->b_p_imsearch = B_IMODE_LMAP;
5927 }
5928 else
5929 {
5930 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5931 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5932 curbuf->b_p_iminsert = B_IMODE_NONE;
5933 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5934 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5935 }
5936 if ((opt_flags & OPT_LOCAL) == 0)
5937 {
5938 set_iminsert_global();
5939 set_imsearch_global();
5940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941# ifdef FEAT_WINDOWS
5942 status_redraw_curbuf();
5943# endif
5944 }
5945 }
5946#endif
5947
5948 /* 'fileformat' */
5949 else if (gvarp == &p_ff)
5950 {
5951 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5952 errmsg = e_modifiable;
5953 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5954 errmsg = e_invarg;
5955 else
5956 {
5957 /* may also change 'textmode' */
5958 if (get_fileformat(curbuf) == EOL_DOS)
5959 curbuf->b_p_tx = TRUE;
5960 else
5961 curbuf->b_p_tx = FALSE;
5962#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005963 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005965 /* update flag in swap file */
5966 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005967 /* Redraw needed when switching to/from "mac": a CR in the text
5968 * will be displayed differently. */
5969 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5970 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971 }
5972 }
5973
5974 /* 'fileformats' */
5975 else if (varp == &p_ffs)
5976 {
5977 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5978 errmsg = e_invarg;
5979 else
5980 {
5981 /* also change 'textauto' */
5982 if (*p_ffs == NUL)
5983 p_ta = FALSE;
5984 else
5985 p_ta = TRUE;
5986 }
5987 }
5988
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005989#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 /* 'cryptkey' */
5991 else if (gvarp == &p_key)
5992 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005993# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994 /* Make sure the ":set" command doesn't show the new value in the
5995 * history. */
5996 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005997# endif
5998 if (STRCMP(curbuf->b_p_key, oldval) != 0)
5999 /* Need to update the swapfile. */
6000 ml_set_crypt_key(curbuf, oldval, curbuf->b_p_cm);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 }
6002#endif
6003
6004 /* 'matchpairs' */
6005 else if (gvarp == &p_mps)
6006 {
6007 /* Check for "x:y,x:y" */
6008 for (p = *varp; *p != NUL; p += 4)
6009 {
6010 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6011 {
6012 errmsg = e_invarg;
6013 break;
6014 }
6015 if (p[3] == NUL)
6016 break;
6017 }
6018 }
6019
6020#ifdef FEAT_COMMENTS
6021 /* 'comments' */
6022 else if (gvarp == &p_com)
6023 {
6024 for (s = *varp; *s; )
6025 {
6026 while (*s && *s != ':')
6027 {
6028 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6029 && !VIM_ISDIGIT(*s) && *s != '-')
6030 {
6031 errmsg = illegal_char(errbuf, *s);
6032 break;
6033 }
6034 ++s;
6035 }
6036 if (*s++ == NUL)
6037 errmsg = (char_u *)N_("E524: Missing colon");
6038 else if (*s == ',' || *s == NUL)
6039 errmsg = (char_u *)N_("E525: Zero length string");
6040 if (errmsg != NULL)
6041 break;
6042 while (*s && *s != ',')
6043 {
6044 if (*s == '\\' && s[1] != NUL)
6045 ++s;
6046 ++s;
6047 }
6048 s = skip_to_option_part(s);
6049 }
6050 }
6051#endif
6052
6053 /* 'listchars' */
6054 else if (varp == &p_lcs)
6055 {
6056 errmsg = set_chars_option(varp);
6057 }
6058
6059#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6060 /* 'fillchars' */
6061 else if (varp == &p_fcs)
6062 {
6063 errmsg = set_chars_option(varp);
6064 }
6065#endif
6066
6067#ifdef FEAT_CMDWIN
6068 /* 'cedit' */
6069 else if (varp == &p_cedit)
6070 {
6071 errmsg = check_cedit();
6072 }
6073#endif
6074
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006075 /* 'verbosefile' */
6076 else if (varp == &p_vfile)
6077 {
6078 verbose_stop();
6079 if (*p_vfile != NUL && verbose_open() == FAIL)
6080 errmsg = e_invarg;
6081 }
6082
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083#ifdef FEAT_VIMINFO
6084 /* 'viminfo' */
6085 else if (varp == &p_viminfo)
6086 {
6087 for (s = p_viminfo; *s;)
6088 {
6089 /* Check it's a valid character */
6090 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6091 {
6092 errmsg = illegal_char(errbuf, *s);
6093 break;
6094 }
6095 if (*s == 'n') /* name is always last one */
6096 {
6097 break;
6098 }
6099 else if (*s == 'r') /* skip until next ',' */
6100 {
6101 while (*++s && *s != ',')
6102 ;
6103 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006104 else if (*s == '%')
6105 {
6106 /* optional number */
6107 while (vim_isdigit(*++s))
6108 ;
6109 }
6110 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 ++s; /* no extra chars */
6112 else /* must have a number */
6113 {
6114 while (vim_isdigit(*++s))
6115 ;
6116
6117 if (!VIM_ISDIGIT(*(s - 1)))
6118 {
6119 if (errbuf != NULL)
6120 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006121 sprintf((char *)errbuf,
6122 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 transchar_byte(*(s - 1)));
6124 errmsg = errbuf;
6125 }
6126 else
6127 errmsg = (char_u *)"";
6128 break;
6129 }
6130 }
6131 if (*s == ',')
6132 ++s;
6133 else if (*s)
6134 {
6135 if (errbuf != NULL)
6136 errmsg = (char_u *)N_("E527: Missing comma");
6137 else
6138 errmsg = (char_u *)"";
6139 break;
6140 }
6141 }
6142 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6143 errmsg = (char_u *)N_("E528: Must specify a ' value");
6144 }
6145#endif /* FEAT_VIMINFO */
6146
6147 /* terminal options */
6148 else if (istermoption(&options[opt_idx]) && full_screen)
6149 {
6150 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6151 if (varp == &T_CCO)
6152 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006153 int colors = atoi((char *)T_CCO);
6154
6155 /* Only reinitialize colors if t_Co value has really changed to
6156 * avoid expensive reload of colorscheme if t_Co is set to the
6157 * same value multiple times. */
6158 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006160 t_colors = colors;
6161 if (t_colors <= 1)
6162 {
6163 if (new_value_alloced)
6164 vim_free(T_CCO);
6165 T_CCO = empty_option;
6166 }
6167 /* We now have a different color setup, initialize it again. */
6168 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 }
6171 ttest(FALSE);
6172 if (varp == &T_ME)
6173 {
6174 out_str(T_ME);
6175 redraw_later(CLEAR);
6176#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6177 /* Since t_me has been set, this probably means that the user
6178 * wants to use this as default colors. Need to reset default
6179 * background/foreground colors. */
6180 mch_set_normal_colors();
6181#endif
6182 }
6183 }
6184
6185#ifdef FEAT_LINEBREAK
6186 /* 'showbreak' */
6187 else if (varp == &p_sbr)
6188 {
6189 for (s = p_sbr; *s; )
6190 {
6191 if (ptr2cells(s) != 1)
6192 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006193 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 }
6195 }
6196#endif
6197
6198#ifdef FEAT_GUI
6199 /* 'guifont' */
6200 else if (varp == &p_guifont)
6201 {
6202 if (gui.in_use)
6203 {
6204 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006205# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006206 /*
6207 * Put up a font dialog and let the user select a new value.
6208 * If this is cancelled go back to the old value but don't
6209 * give an error message.
6210 */
6211 if (STRCMP(p, "*") == 0)
6212 {
6213 p = gui_mch_font_dialog(oldval);
6214
6215 if (new_value_alloced)
6216 free_string_option(p_guifont);
6217
6218 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6219 new_value_alloced = TRUE;
6220 }
6221# endif
6222 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6223 {
6224# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6225 if (STRCMP(p_guifont, "*") == 0)
6226 {
6227 /* Dialog was cancelled: Keep the old value without giving
6228 * an error message. */
6229 if (new_value_alloced)
6230 free_string_option(p_guifont);
6231 p_guifont = vim_strsave(oldval);
6232 new_value_alloced = TRUE;
6233 }
6234 else
6235# endif
6236 errmsg = (char_u *)N_("E596: Invalid font(s)");
6237 }
6238 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006239 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 }
6241# ifdef FEAT_XFONTSET
6242 else if (varp == &p_guifontset)
6243 {
6244 if (STRCMP(p_guifontset, "*") == 0)
6245 errmsg = (char_u *)N_("E597: can't select fontset");
6246 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6247 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006248 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 }
6250# endif
6251# ifdef FEAT_MBYTE
6252 else if (varp == &p_guifontwide)
6253 {
6254 if (STRCMP(p_guifontwide, "*") == 0)
6255 errmsg = (char_u *)N_("E533: can't select wide font");
6256 else if (gui_get_wide_font() == FAIL)
6257 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006258 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006259 }
6260# endif
6261#endif
6262
6263#ifdef CURSOR_SHAPE
6264 /* 'guicursor' */
6265 else if (varp == &p_guicursor)
6266 errmsg = parse_shape_opt(SHAPE_CURSOR);
6267#endif
6268
6269#ifdef FEAT_MOUSESHAPE
6270 /* 'mouseshape' */
6271 else if (varp == &p_mouseshape)
6272 {
6273 errmsg = parse_shape_opt(SHAPE_MOUSE);
6274 update_mouseshape(-1);
6275 }
6276#endif
6277
6278#ifdef FEAT_PRINTER
6279 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006280 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006281# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006282 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006283 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006284# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285#endif
6286
6287#ifdef FEAT_LANGMAP
6288 /* 'langmap' */
6289 else if (varp == &p_langmap)
6290 langmap_set();
6291#endif
6292
6293#ifdef FEAT_LINEBREAK
6294 /* 'breakat' */
6295 else if (varp == &p_breakat)
6296 fill_breakat_flags();
6297#endif
6298
6299#ifdef FEAT_TITLE
6300 /* 'titlestring' and 'iconstring' */
6301 else if (varp == &p_titlestring || varp == &p_iconstring)
6302 {
6303# ifdef FEAT_STL_OPT
6304 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6305
6306 /* NULL => statusline syntax */
6307 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6308 stl_syntax |= flagval;
6309 else
6310 stl_syntax &= ~flagval;
6311# endif
6312 did_set_title(varp == &p_iconstring);
6313
6314 }
6315#endif
6316
6317#ifdef FEAT_GUI
6318 /* 'guioptions' */
6319 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006320 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006322 redraw_gui_only = TRUE;
6323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324#endif
6325
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006326#if defined(FEAT_GUI_TABLINE)
6327 /* 'guitablabel' */
6328 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006329 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006330 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006331 redraw_gui_only = TRUE;
6332 }
6333 /* 'guitabtooltip' */
6334 else if (varp == &p_gtt)
6335 {
6336 redraw_gui_only = TRUE;
6337 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006338#endif
6339
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6341 /* 'ttymouse' */
6342 else if (varp == &p_ttym)
6343 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006344 /* Switch the mouse off before changing the escape sequences used for
6345 * that. */
6346 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6348 errmsg = e_invarg;
6349 else
6350 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006351 if (termcap_active)
6352 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 }
6354#endif
6355
6356#ifdef FEAT_VISUAL
6357 /* 'selection' */
6358 else if (varp == &p_sel)
6359 {
6360 if (*p_sel == NUL
6361 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6362 errmsg = e_invarg;
6363 }
6364
6365 /* 'selectmode' */
6366 else if (varp == &p_slm)
6367 {
6368 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6369 errmsg = e_invarg;
6370 }
6371#endif
6372
6373#ifdef FEAT_BROWSE
6374 /* 'browsedir' */
6375 else if (varp == &p_bsdir)
6376 {
6377 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6378 && !mch_isdir(p_bsdir))
6379 errmsg = e_invarg;
6380 }
6381#endif
6382
6383#ifdef FEAT_VISUAL
6384 /* 'keymodel' */
6385 else if (varp == &p_km)
6386 {
6387 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6388 errmsg = e_invarg;
6389 else
6390 {
6391 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6392 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6393 }
6394 }
6395#endif
6396
6397 /* 'mousemodel' */
6398 else if (varp == &p_mousem)
6399 {
6400 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6401 errmsg = e_invarg;
6402#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6403 else if (*p_mousem != *oldval)
6404 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6405 * to create or delete the popup menus. */
6406 gui_motif_update_mousemodel(root_menu);
6407#endif
6408 }
6409
6410 /* 'switchbuf' */
6411 else if (varp == &p_swb)
6412 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006413 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006414 errmsg = e_invarg;
6415 }
6416
6417 /* 'debug' */
6418 else if (varp == &p_debug)
6419 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006420 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421 errmsg = e_invarg;
6422 }
6423
6424 /* 'display' */
6425 else if (varp == &p_dy)
6426 {
6427 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6428 errmsg = e_invarg;
6429 else
6430 (void)init_chartab();
6431
6432 }
6433
6434#ifdef FEAT_VERTSPLIT
6435 /* 'eadirection' */
6436 else if (varp == &p_ead)
6437 {
6438 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6439 errmsg = e_invarg;
6440 }
6441#endif
6442
6443#ifdef FEAT_CLIPBOARD
6444 /* 'clipboard' */
6445 else if (varp == &p_cb)
6446 errmsg = check_clipboard_option();
6447#endif
6448
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006449#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006450 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6451 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006452 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006453 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006454 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006455 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006456
Bram Moolenaar860cae12010-06-05 23:22:07 +02006457 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006458 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006459 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6460 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006461 ".add") != 0))
6462 errmsg = e_invarg;
6463 }
6464
6465 if (errmsg == NULL)
6466 {
6467 FOR_ALL_WINDOWS(wp)
6468 if (wp->w_buffer == curbuf && wp->w_p_spell)
6469 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006470 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006471# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006472 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006473# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006474 }
6475 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006476 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006477 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006478 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006479 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006480 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006481 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006482 /* 'spellsuggest' */
6483 else if (varp == &p_sps)
6484 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006485 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006486 errmsg = e_invarg;
6487 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006488 /* 'mkspellmem' */
6489 else if (varp == &p_msm)
6490 {
6491 if (spell_check_msm() != OK)
6492 errmsg = e_invarg;
6493 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006494#endif
6495
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496#ifdef FEAT_QUICKFIX
6497 /* When 'bufhidden' is set, check for valid value. */
6498 else if (gvarp == &p_bh)
6499 {
6500 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6501 errmsg = e_invarg;
6502 }
6503
6504 /* When 'buftype' is set, check for valid value. */
6505 else if (gvarp == &p_bt)
6506 {
6507 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6508 errmsg = e_invarg;
6509 else
6510 {
6511# ifdef FEAT_WINDOWS
6512 if (curwin->w_status_height)
6513 {
6514 curwin->w_redr_status = TRUE;
6515 redraw_later(VALID);
6516 }
6517# endif
6518 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006519# ifdef FEAT_TITLE
6520 redraw_titles();
6521# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 }
6523 }
6524#endif
6525
6526#ifdef FEAT_STL_OPT
6527 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006528 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 {
6530 int wid;
6531
6532 if (varp == &p_ruf) /* reset ru_wid first */
6533 ru_wid = 0;
6534 s = *varp;
6535 if (varp == &p_ruf && *s == '%')
6536 {
6537 /* set ru_wid if 'ruf' starts with "%99(" */
6538 if (*++s == '-') /* ignore a '-' */
6539 s++;
6540 wid = getdigits(&s);
6541 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6542 ru_wid = wid;
6543 else
6544 errmsg = check_stl_option(p_ruf);
6545 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006546 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006547 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006549 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 comp_col();
6551 }
6552#endif
6553
6554#ifdef FEAT_INS_EXPAND
6555 /* check if it is a valid value for 'complete' -- Acevedo */
6556 else if (gvarp == &p_cpt)
6557 {
6558 for (s = *varp; *s;)
6559 {
6560 while(*s == ',' || *s == ' ')
6561 s++;
6562 if (!*s)
6563 break;
6564 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6565 {
6566 errmsg = illegal_char(errbuf, *s);
6567 break;
6568 }
6569 if (*++s != NUL && *s != ',' && *s != ' ')
6570 {
6571 if (s[-1] == 'k' || s[-1] == 's')
6572 {
6573 /* skip optional filename after 'k' and 's' */
6574 while (*s && *s != ',' && *s != ' ')
6575 {
6576 if (*s == '\\')
6577 ++s;
6578 ++s;
6579 }
6580 }
6581 else
6582 {
6583 if (errbuf != NULL)
6584 {
6585 sprintf((char *)errbuf,
6586 _("E535: Illegal character after <%c>"),
6587 *--s);
6588 errmsg = errbuf;
6589 }
6590 else
6591 errmsg = (char_u *)"";
6592 break;
6593 }
6594 }
6595 }
6596 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006597
6598 /* 'completeopt' */
6599 else if (varp == &p_cot)
6600 {
6601 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6602 errmsg = e_invarg;
6603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604#endif /* FEAT_INS_EXPAND */
6605
6606
6607#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6608 else if (varp == &p_toolbar)
6609 {
6610 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6611 &toolbar_flags, TRUE) != OK)
6612 errmsg = e_invarg;
6613 else
6614 {
6615 out_flush();
6616 gui_mch_show_toolbar((toolbar_flags &
6617 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6618 }
6619 }
6620#endif
6621
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006622#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 /* 'toolbariconsize': GTK+ 2 only */
6624 else if (varp == &p_tbis)
6625 {
6626 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6627 errmsg = e_invarg;
6628 else
6629 {
6630 out_flush();
6631 gui_mch_show_toolbar((toolbar_flags &
6632 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6633 }
6634 }
6635#endif
6636
6637 /* 'pastetoggle': translate key codes like in a mapping */
6638 else if (varp == &p_pt)
6639 {
6640 if (*p_pt)
6641 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006642 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 if (p != NULL)
6644 {
6645 if (new_value_alloced)
6646 free_string_option(p_pt);
6647 p_pt = p;
6648 new_value_alloced = TRUE;
6649 }
6650 }
6651 }
6652
6653 /* 'backspace' */
6654 else if (varp == &p_bs)
6655 {
6656 if (VIM_ISDIGIT(*p_bs))
6657 {
6658 if (*p_bs >'2' || p_bs[1] != NUL)
6659 errmsg = e_invarg;
6660 }
6661 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6662 errmsg = e_invarg;
6663 }
6664
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006665#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006666 /* 'casemap' */
6667 else if (varp == &p_cmp)
6668 {
6669 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6670 errmsg = e_invarg;
6671 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006673
6674#ifdef FEAT_DIFF
6675 /* 'diffopt' */
6676 else if (varp == &p_dip)
6677 {
6678 if (diffopt_changed() == FAIL)
6679 errmsg = e_invarg;
6680 }
6681#endif
6682
6683#ifdef FEAT_FOLDING
6684 /* 'foldmethod' */
6685 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6686 {
6687 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6688 || *curwin->w_p_fdm == NUL)
6689 errmsg = e_invarg;
6690 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006691 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006692 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006693 if (foldmethodIsDiff(curwin))
6694 newFoldLevel();
6695 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 }
6697# ifdef FEAT_EVAL
6698 /* 'foldexpr' */
6699 else if (varp == &curwin->w_p_fde)
6700 {
6701 if (foldmethodIsExpr(curwin))
6702 foldUpdateAll(curwin);
6703 }
6704# endif
6705 /* 'foldmarker' */
6706 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6707 {
6708 p = vim_strchr(*varp, ',');
6709 if (p == NULL)
6710 errmsg = (char_u *)N_("E536: comma required");
6711 else if (p == *varp || p[1] == NUL)
6712 errmsg = e_invarg;
6713 else if (foldmethodIsMarker(curwin))
6714 foldUpdateAll(curwin);
6715 }
6716 /* 'commentstring' */
6717 else if (gvarp == &p_cms)
6718 {
6719 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6720 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6721 }
6722 /* 'foldopen' */
6723 else if (varp == &p_fdo)
6724 {
6725 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6726 errmsg = e_invarg;
6727 }
6728 /* 'foldclose' */
6729 else if (varp == &p_fcl)
6730 {
6731 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6732 errmsg = e_invarg;
6733 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006734 /* 'foldignore' */
6735 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6736 {
6737 if (foldmethodIsIndent(curwin))
6738 foldUpdateAll(curwin);
6739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740#endif
6741
6742#ifdef FEAT_VIRTUALEDIT
6743 /* 'virtualedit' */
6744 else if (varp == &p_ve)
6745 {
6746 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6747 errmsg = e_invarg;
6748 else if (STRCMP(p_ve, oldval) != 0)
6749 {
6750 /* Recompute cursor position in case the new 've' setting
6751 * changes something. */
6752 validate_virtcol();
6753 coladvance(curwin->w_virtcol);
6754 }
6755 }
6756#endif
6757
6758#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6759 else if (varp == &p_csqf)
6760 {
6761 if (p_csqf != NULL)
6762 {
6763 p = p_csqf;
6764 while (*p != NUL)
6765 {
6766 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6767 || p[1] == NUL
6768 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6769 || (p[2] != NUL && p[2] != ','))
6770 {
6771 errmsg = e_invarg;
6772 break;
6773 }
6774 else if (p[2] == NUL)
6775 break;
6776 else
6777 p += 3;
6778 }
6779 }
6780 }
6781#endif
6782
6783 /* Options that are a list of flags. */
6784 else
6785 {
6786 p = NULL;
6787 if (varp == &p_ww)
6788 p = (char_u *)WW_ALL;
6789 if (varp == &p_shm)
6790 p = (char_u *)SHM_ALL;
6791 else if (varp == &(p_cpo))
6792 p = (char_u *)CPO_ALL;
6793 else if (varp == &(curbuf->b_p_fo))
6794 p = (char_u *)FO_ALL;
6795 else if (varp == &p_mouse)
6796 {
6797#ifdef FEAT_MOUSE
6798 p = (char_u *)MOUSE_ALL;
6799#else
6800 if (*p_mouse != NUL)
6801 errmsg = (char_u *)N_("E538: No mouse support");
6802#endif
6803 }
6804#if defined(FEAT_GUI)
6805 else if (varp == &p_go)
6806 p = (char_u *)GO_ALL;
6807#endif
6808 if (p != NULL)
6809 {
6810 for (s = *varp; *s; ++s)
6811 if (vim_strchr(p, *s) == NULL)
6812 {
6813 errmsg = illegal_char(errbuf, *s);
6814 break;
6815 }
6816 }
6817 }
6818
6819 /*
6820 * If error detected, restore the previous value.
6821 */
6822 if (errmsg != NULL)
6823 {
6824 if (new_value_alloced)
6825 free_string_option(*varp);
6826 *varp = oldval;
6827 /*
6828 * When resetting some values, need to act on it.
6829 */
6830 if (did_chartab)
6831 (void)init_chartab();
6832 if (varp == &p_hl)
6833 (void)highlight_changed();
6834 }
6835 else
6836 {
6837#ifdef FEAT_EVAL
6838 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006839 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840#endif
6841 /*
6842 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006843 * Use "free_oldval", because recursiveness may change the flags under
6844 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006846 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 free_string_option(oldval);
6848 if (new_value_alloced)
6849 options[opt_idx].flags |= P_ALLOCED;
6850 else
6851 options[opt_idx].flags &= ~P_ALLOCED;
6852
6853 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006854 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 {
6856 /* global option with local value set to use global value; free
6857 * the local value and make it empty */
6858 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6859 free_string_option(*(char_u **)p);
6860 *(char_u **)p = empty_option;
6861 }
6862
6863 /* May set global value for local option. */
6864 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6865 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006866
6867#ifdef FEAT_AUTOCMD
6868 /*
6869 * Trigger the autocommand only after setting the flags.
6870 */
6871# ifdef FEAT_SYN_HL
6872 /* When 'syntax' is set, load the syntax of that name */
6873 if (varp == &(curbuf->b_p_syn))
6874 {
6875 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6876 curbuf->b_fname, TRUE, curbuf);
6877 }
6878# endif
6879 else if (varp == &(curbuf->b_p_ft))
6880 {
6881 /* 'filetype' is set, trigger the FileType autocommand */
6882 did_filetype = TRUE;
6883 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6884 curbuf->b_fname, TRUE, curbuf);
6885 }
6886#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006887#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006888 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006889 {
6890 char_u fname[200];
6891
6892 /*
6893 * Source the spell/LANG.vim in 'runtimepath'.
6894 * They could set 'spellcapcheck' depending on the language.
6895 * Use the first name in 'spelllang' up to '_region' or
6896 * '.encoding'.
6897 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006898 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006899 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6900 break;
6901 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006902 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006903 source_runtime(fname, TRUE);
6904 }
6905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 }
6907
6908#ifdef FEAT_MOUSE
6909 if (varp == &p_mouse)
6910 {
6911# ifdef FEAT_MOUSE_TTY
6912 if (*p_mouse == NUL)
6913 mch_setmouse(FALSE); /* switch mouse off */
6914 else
6915# endif
6916 setmouse(); /* in case 'mouse' changed */
6917 }
6918#endif
6919
6920 if (curwin->w_curswant != MAXCOL)
6921 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006922#ifdef FEAT_GUI
6923 /* check redraw when it's not a GUI option or the GUI is active. */
6924 if (!redraw_gui_only || gui.in_use)
6925#endif
6926 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927
6928 return errmsg;
6929}
6930
Bram Moolenaar1a384422010-07-14 19:53:30 +02006931#ifdef FEAT_SYN_HL
6932/*
6933 * Simple int comparison function for use with qsort()
6934 */
6935 static int
6936int_cmp(a, b)
6937 const void *a;
6938 const void *b;
6939{
6940 return *(const int *)a - *(const int *)b;
6941}
6942
6943/*
6944 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
6945 * Returns error message, NULL if it's OK.
6946 */
6947 char_u *
6948check_colorcolumn(wp)
6949 win_T *wp;
6950{
6951 char_u *s;
6952 int col;
6953 int count = 0;
6954 int color_cols[256];
6955 int i;
6956 int j = 0;
6957
6958 for (s = wp->w_p_cc; *s != NUL && count < 255; ++s)
6959 {
6960 if (*s == '-' || *s == '+')
6961 {
6962 /* -N and +N: add to 'textwidth' */
6963 col = (*s == '-') ? -1 : 1;
6964 ++s;
6965 if (!VIM_ISDIGIT(*s))
6966 return e_invarg;
6967 col = col * getdigits(&s);
6968 if (wp->w_buffer->b_p_tw == 0)
6969 continue; /* 'textwidth' not set, skip this item */
6970 col += wp->w_buffer->b_p_tw;
6971 if (col < 0)
6972 continue;
6973 }
6974 else if (VIM_ISDIGIT(*s))
6975 col = getdigits(&s);
6976 else
6977 return e_invarg;
6978 color_cols[count++] = col - 1; /* 1-based to 0-based */
6979
6980 if (*s == NUL)
6981 break;
6982 if (*s != ',')
6983 return e_invarg;
6984 }
6985
6986 vim_free(wp->w_p_cc_cols);
6987 if (count == 0)
6988 wp->w_p_cc_cols = NULL;
6989 else
6990 {
6991 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
6992 if (wp->w_p_cc_cols != NULL)
6993 {
6994 /* sort the columns for faster usage on screen redraw inside
6995 * win_line() */
6996 qsort(color_cols, count, sizeof(int), int_cmp);
6997
6998 for (i = 0; i < count; ++i)
6999 /* skip duplicates */
7000 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7001 wp->w_p_cc_cols[j++] = color_cols[i];
7002 wp->w_p_cc_cols[j] = -1; /* end marker */
7003 }
7004 }
7005
7006 return NULL; /* no error */
7007}
7008#endif
7009
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010/*
7011 * Handle setting 'listchars' or 'fillchars'.
7012 * Returns error message, NULL if it's OK.
7013 */
7014 static char_u *
7015set_chars_option(varp)
7016 char_u **varp;
7017{
7018 int round, i, len, entries;
7019 char_u *p, *s;
7020 int c1, c2 = 0;
7021 struct charstab
7022 {
7023 int *cp;
7024 char *name;
7025 };
7026#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7027 static struct charstab filltab[] =
7028 {
7029 {&fill_stl, "stl"},
7030 {&fill_stlnc, "stlnc"},
7031 {&fill_vert, "vert"},
7032 {&fill_fold, "fold"},
7033 {&fill_diff, "diff"},
7034 };
7035#endif
7036 static struct charstab lcstab[] =
7037 {
7038 {&lcs_eol, "eol"},
7039 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007040 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 {&lcs_prec, "precedes"},
7042 {&lcs_tab2, "tab"},
7043 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007044#ifdef FEAT_CONCEAL
7045 {&lcs_conceal, "conceal"},
7046#else
7047 {NULL, "conceal"},
7048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 };
7050 struct charstab *tab;
7051
7052#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7053 if (varp == &p_lcs)
7054#endif
7055 {
7056 tab = lcstab;
7057 entries = sizeof(lcstab) / sizeof(struct charstab);
7058 }
7059#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7060 else
7061 {
7062 tab = filltab;
7063 entries = sizeof(filltab) / sizeof(struct charstab);
7064 }
7065#endif
7066
7067 /* first round: check for valid value, second round: assign values */
7068 for (round = 0; round <= 1; ++round)
7069 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007070 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 {
7072 /* After checking that the value is valid: set defaults: space for
7073 * 'fillchars', NUL for 'listchars' */
7074 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007075 if (tab[i].cp != NULL)
7076 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 if (varp == &p_lcs)
7078 lcs_tab1 = NUL;
7079#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7080 else
7081 fill_diff = '-';
7082#endif
7083 }
7084 p = *varp;
7085 while (*p)
7086 {
7087 for (i = 0; i < entries; ++i)
7088 {
7089 len = (int)STRLEN(tab[i].name);
7090 if (STRNCMP(p, tab[i].name, len) == 0
7091 && p[len] == ':'
7092 && p[len + 1] != NUL)
7093 {
7094 s = p + len + 1;
7095#ifdef FEAT_MBYTE
7096 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007097 if (mb_char2cells(c1) > 1)
7098 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099#else
7100 c1 = *s++;
7101#endif
7102 if (tab[i].cp == &lcs_tab2)
7103 {
7104 if (*s == NUL)
7105 continue;
7106#ifdef FEAT_MBYTE
7107 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007108 if (mb_char2cells(c2) > 1)
7109 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110#else
7111 c2 = *s++;
7112#endif
7113 }
7114 if (*s == ',' || *s == NUL)
7115 {
7116 if (round)
7117 {
7118 if (tab[i].cp == &lcs_tab2)
7119 {
7120 lcs_tab1 = c1;
7121 lcs_tab2 = c2;
7122 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007123 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 *(tab[i].cp) = c1;
7125
7126 }
7127 p = s;
7128 break;
7129 }
7130 }
7131 }
7132
7133 if (i == entries)
7134 return e_invarg;
7135 if (*p == ',')
7136 ++p;
7137 }
7138 }
7139
7140 return NULL; /* no error */
7141}
7142
7143#ifdef FEAT_STL_OPT
7144/*
7145 * Check validity of options with the 'statusline' format.
7146 * Return error message or NULL.
7147 */
7148 char_u *
7149check_stl_option(s)
7150 char_u *s;
7151{
7152 int itemcnt = 0;
7153 int groupdepth = 0;
7154 static char_u errbuf[80];
7155
7156 while (*s && itemcnt < STL_MAX_ITEM)
7157 {
7158 /* Check for valid keys after % sequences */
7159 while (*s && *s != '%')
7160 s++;
7161 if (!*s)
7162 break;
7163 s++;
7164 if (*s != '%' && *s != ')')
7165 ++itemcnt;
7166 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7167 {
7168 s++;
7169 continue;
7170 }
7171 if (*s == ')')
7172 {
7173 s++;
7174 if (--groupdepth < 0)
7175 break;
7176 continue;
7177 }
7178 if (*s == '-')
7179 s++;
7180 while (VIM_ISDIGIT(*s))
7181 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007182 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183 continue;
7184 if (*s == '.')
7185 {
7186 s++;
7187 while (*s && VIM_ISDIGIT(*s))
7188 s++;
7189 }
7190 if (*s == '(')
7191 {
7192 groupdepth++;
7193 continue;
7194 }
7195 if (vim_strchr(STL_ALL, *s) == NULL)
7196 {
7197 return illegal_char(errbuf, *s);
7198 }
7199 if (*s == '{')
7200 {
7201 s++;
7202 while (*s != '}' && *s)
7203 s++;
7204 if (*s != '}')
7205 return (char_u *)N_("E540: Unclosed expression sequence");
7206 }
7207 }
7208 if (itemcnt >= STL_MAX_ITEM)
7209 return (char_u *)N_("E541: too many items");
7210 if (groupdepth != 0)
7211 return (char_u *)N_("E542: unbalanced groups");
7212 return NULL;
7213}
7214#endif
7215
7216#ifdef FEAT_CLIPBOARD
7217/*
7218 * Extract the items in the 'clipboard' option and set global values.
7219 */
7220 static char_u *
7221check_clipboard_option()
7222{
7223 int new_unnamed = FALSE;
7224 int new_autoselect = FALSE;
7225 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007226 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 regprog_T *new_exclude_prog = NULL;
7228 char_u *errmsg = NULL;
7229 char_u *p;
7230
7231 for (p = p_cb; *p != NUL; )
7232 {
7233 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7234 {
7235 new_unnamed = TRUE;
7236 p += 7;
7237 }
7238 else if (STRNCMP(p, "autoselect", 10) == 0
7239 && (p[10] == ',' || p[10] == NUL))
7240 {
7241 new_autoselect = TRUE;
7242 p += 10;
7243 }
7244 else if (STRNCMP(p, "autoselectml", 12) == 0
7245 && (p[12] == ',' || p[12] == NUL))
7246 {
7247 new_autoselectml = TRUE;
7248 p += 12;
7249 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007250 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7251 {
7252 new_html = TRUE;
7253 p += 4;
7254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7256 {
7257 p += 8;
7258 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7259 if (new_exclude_prog == NULL)
7260 errmsg = e_invarg;
7261 break;
7262 }
7263 else
7264 {
7265 errmsg = e_invarg;
7266 break;
7267 }
7268 if (*p == ',')
7269 ++p;
7270 }
7271 if (errmsg == NULL)
7272 {
7273 clip_unnamed = new_unnamed;
7274 clip_autoselect = new_autoselect;
7275 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007276 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 vim_free(clip_exclude_prog);
7278 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007279#ifdef FEAT_GUI_GTK
7280 if (gui.in_use)
7281 {
7282 gui_gtk_set_selection_targets();
7283 gui_gtk_set_dnd_targets();
7284 }
7285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286 }
7287 else
7288 vim_free(new_exclude_prog);
7289
7290 return errmsg;
7291}
7292#endif
7293
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007294#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007295/*
7296 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7297 * Return error message when failed, NULL when OK.
7298 */
7299 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007300compile_cap_prog(synblock)
7301 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007302{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007303 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007304 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007305
Bram Moolenaar860cae12010-06-05 23:22:07 +02007306 if (*synblock->b_p_spc == NUL)
7307 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007308 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007309 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007310 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007311 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007312 if (re != NULL)
7313 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007314 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7315 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007316 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007317 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007318 return e_invarg;
7319 }
7320 vim_free(re);
7321 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007322 }
7323
7324 vim_free(rp);
7325 return NULL;
7326}
7327#endif
7328
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007329#if defined(FEAT_EVAL) || defined(PROTO)
7330/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007331 * Set the scriptID for an option, taking care of setting the buffer- or
7332 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007333 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007334 static void
7335set_option_scriptID_idx(opt_idx, opt_flags, id)
7336 int opt_idx;
7337 int opt_flags;
7338 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007339{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007340 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7341 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007342
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007343 /* Remember where the option was set. For local options need to do that
7344 * in the buffer or window structure. */
7345 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007346 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007347 if (both || (opt_flags & OPT_LOCAL))
7348 {
7349 if (indir & PV_BUF)
7350 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7351 else if (indir & PV_WIN)
7352 curwin->w_p_scriptID[indir & PV_MASK] = id;
7353 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007354}
7355#endif
7356
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357/*
7358 * Set the value of a boolean option, and take care of side effects.
7359 * Returns NULL for success, or an error message for an error.
7360 */
7361 static char_u *
7362set_bool_option(opt_idx, varp, value, opt_flags)
7363 int opt_idx; /* index in options[] table */
7364 char_u *varp; /* pointer to the option variable */
7365 int value; /* new value */
7366 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7367{
7368 int old_value = *(int *)varp;
7369
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 /* Disallow changing some options from secure mode */
7371 if ((secure
7372#ifdef HAVE_SANDBOX
7373 || sandbox != 0
7374#endif
7375 ) && (options[opt_idx].flags & P_SECURE))
7376 return e_secure;
7377
7378 *(int *)varp = value; /* set the new value */
7379#ifdef FEAT_EVAL
7380 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007381 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007382#endif
7383
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007384#ifdef FEAT_GUI
7385 need_mouse_correct = TRUE;
7386#endif
7387
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388 /* May set global value for local option. */
7389 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7390 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7391
7392 /*
7393 * Handle side effects of changing a bool option.
7394 */
7395
7396 /* 'compatible' */
7397 if ((int *)varp == &p_cp)
7398 {
7399 compatible_set();
7400 }
7401
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007402 /* 'list', 'number' */
7403 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007404 || (int *)varp == &curwin->w_p_nu
7405 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007406 {
7407 if (curwin->w_curswant != MAXCOL)
7408 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007409
7410 /* If 'number' is set, reset 'relativenumber'. */
7411 /* If 'relativenumber' is set, reset 'number'. */
7412 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7413 curwin->w_p_rnu = FALSE;
7414 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7415 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007416 }
7417
Bram Moolenaar071d4272004-06-13 20:20:40 +00007418 else if ((int *)varp == &curbuf->b_p_ro)
7419 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007420 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007421 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7422 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007423
7424 /* when 'readonly' is set may give W10 again */
7425 if (curbuf->b_p_ro)
7426 curbuf->b_did_warn = FALSE;
7427
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007429 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430#endif
7431 }
7432
Bram Moolenaar370df582010-06-22 05:16:38 +02007433#if defined(FEAT_TITLE) || defined(FEAT_CONCEAL)
7434 /* when 'modifiable' is changed, redraw the window title and
7435 * update current line for concealable items */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007437 {
Bram Moolenaar370df582010-06-22 05:16:38 +02007438# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007439 redraw_titles();
Bram Moolenaar370df582010-06-22 05:16:38 +02007440# endif
7441# ifdef FEAT_CONCEAL
7442 if (curwin->w_p_conceal)
7443 update_single_line(curwin, curwin->w_cursor.lnum);
7444# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007445 }
Bram Moolenaar370df582010-06-22 05:16:38 +02007446#endif
7447#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 /* when 'endofline' is changed, redraw the window title */
7449 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007450 {
7451 redraw_titles();
7452 }
7453# ifdef FEAT_MBYTE
7454 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007455 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007456 {
7457 redraw_titles();
7458 }
7459# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460#endif
7461
7462 /* when 'bin' is set also set some other options */
7463 else if ((int *)varp == &curbuf->b_p_bin)
7464 {
7465 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7466#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007467 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007468#endif
7469 }
7470
7471#ifdef FEAT_AUTOCMD
7472 /* when 'buflisted' changes, trigger autocommands */
7473 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7474 {
7475 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7476 NULL, NULL, TRUE, curbuf);
7477 }
7478#endif
7479
7480 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7481 else if ((int *)varp == &curbuf->b_p_swf)
7482 {
7483 if (curbuf->b_p_swf && p_uc)
7484 ml_open_file(curbuf); /* create the swap file */
7485 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007486 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7487 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 mf_close_file(curbuf, TRUE); /* remove the swap file */
7489 }
7490
7491 /* when 'terse' is set change 'shortmess' */
7492 else if ((int *)varp == &p_terse)
7493 {
7494 char_u *p;
7495
7496 p = vim_strchr(p_shm, SHM_SEARCH);
7497
7498 /* insert 's' in p_shm */
7499 if (p_terse && p == NULL)
7500 {
7501 STRCPY(IObuff, p_shm);
7502 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007503 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 }
7505 /* remove 's' from p_shm */
7506 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007507 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 }
7509
7510 /* when 'paste' is set or reset also change other options */
7511 else if ((int *)varp == &p_paste)
7512 {
7513 paste_option_changed();
7514 }
7515
7516 /* when 'insertmode' is set from an autocommand need to do work here */
7517 else if ((int *)varp == &p_im)
7518 {
7519 if (p_im)
7520 {
7521 if ((State & INSERT) == 0)
7522 need_start_insertmode = TRUE;
7523 stop_insert_mode = FALSE;
7524 }
7525 else
7526 {
7527 need_start_insertmode = FALSE;
7528 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007529 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 clear_cmdline = TRUE; /* remove "(insert)" */
7531 restart_edit = 0;
7532 }
7533 }
7534
7535 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7536 else if ((int *)varp == &p_ic && p_hls)
7537 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007538 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 }
7540
7541#ifdef FEAT_SEARCH_EXTRA
7542 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7543 else if ((int *)varp == &p_hls)
7544 {
7545 no_hlsearch = FALSE;
7546 }
7547#endif
7548
7549#ifdef FEAT_SCROLLBIND
7550 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7551 * at the end of normal_cmd() */
7552 else if ((int *)varp == &curwin->w_p_scb)
7553 {
7554 if (curwin->w_p_scb)
7555 do_check_scrollbind(FALSE);
7556 }
7557#endif
7558
7559#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7560 /* There can be only one window with 'previewwindow' set. */
7561 else if ((int *)varp == &curwin->w_p_pvw)
7562 {
7563 if (curwin->w_p_pvw)
7564 {
7565 win_T *win;
7566
7567 for (win = firstwin; win != NULL; win = win->w_next)
7568 if (win->w_p_pvw && win != curwin)
7569 {
7570 curwin->w_p_pvw = FALSE;
7571 return (char_u *)N_("E590: A preview window already exists");
7572 }
7573 }
7574 }
7575#endif
7576
7577 /* when 'textmode' is set or reset also change 'fileformat' */
7578 else if ((int *)varp == &curbuf->b_p_tx)
7579 {
7580 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7581 }
7582
7583 /* when 'textauto' is set or reset also change 'fileformats' */
7584 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 set_string_option_direct((char_u *)"ffs", -1,
7586 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007587 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588
7589 /*
7590 * When 'lisp' option changes include/exclude '-' in
7591 * keyword characters.
7592 */
7593#ifdef FEAT_LISP
7594 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7595 {
7596 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7597 }
7598#endif
7599
7600#ifdef FEAT_TITLE
7601 /* when 'title' changed, may need to change the title; same for 'icon' */
7602 else if ((int *)varp == &p_title)
7603 {
7604 did_set_title(FALSE);
7605 }
7606
7607 else if ((int *)varp == &p_icon)
7608 {
7609 did_set_title(TRUE);
7610 }
7611#endif
7612
7613 else if ((int *)varp == &curbuf->b_changed)
7614 {
7615 if (!value)
7616 save_file_ff(curbuf); /* Buffer is unchanged */
7617#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007618 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007619#endif
7620#ifdef FEAT_AUTOCMD
7621 modified_was_set = value;
7622#endif
7623 }
7624
7625#ifdef BACKSLASH_IN_FILENAME
7626 else if ((int *)varp == &p_ssl)
7627 {
7628 if (p_ssl)
7629 {
7630 psepc = '/';
7631 psepcN = '\\';
7632 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633 }
7634 else
7635 {
7636 psepc = '\\';
7637 psepcN = '/';
7638 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639 }
7640
7641 /* need to adjust the file name arguments and buffer names. */
7642 buflist_slash_adjust();
7643 alist_slash_adjust();
7644# ifdef FEAT_EVAL
7645 scriptnames_slash_adjust();
7646# endif
7647 }
7648#endif
7649
7650 /* If 'wrap' is set, set w_leftcol to zero. */
7651 else if ((int *)varp == &curwin->w_p_wrap)
7652 {
7653 if (curwin->w_p_wrap)
7654 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007655 if (curwin->w_curswant != MAXCOL)
7656 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 }
7658
7659#ifdef FEAT_WINDOWS
7660 else if ((int *)varp == &p_ea)
7661 {
7662 if (p_ea && !old_value)
7663 win_equal(curwin, FALSE, 0);
7664 }
7665#endif
7666
7667 else if ((int *)varp == &p_wiv)
7668 {
7669 /*
7670 * When 'weirdinvert' changed, set/reset 't_xs'.
7671 * Then set 'weirdinvert' according to value of 't_xs'.
7672 */
7673 if (p_wiv && !old_value)
7674 T_XS = (char_u *)"y";
7675 else if (!p_wiv && old_value)
7676 T_XS = empty_option;
7677 p_wiv = (*T_XS != NUL);
7678 }
7679
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007680#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 else if ((int *)varp == &p_beval)
7682 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 if (p_beval == TRUE)
7684 gui_mch_enable_beval_area(balloonEval);
7685 else
7686 gui_mch_disable_beval_area(balloonEval);
7687 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007690#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 else if ((int *)varp == &p_acd)
7692 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007693 /* Change directories when the 'acd' option is set now. */
7694 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007695 }
7696#endif
7697
7698#ifdef FEAT_DIFF
7699 /* 'diff' */
7700 else if ((int *)varp == &curwin->w_p_diff)
7701 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007702 /* May add or remove the buffer from the list of diff buffers. */
7703 diff_buf_adjust(curwin);
7704# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 if (foldmethodIsDiff(curwin))
7706 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007707# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 }
7709#endif
7710
7711#ifdef USE_IM_CONTROL
7712 /* 'imdisable' */
7713 else if ((int *)varp == &p_imdisable)
7714 {
7715 /* Only de-activate it here, it will be enabled when changing mode. */
7716 if (p_imdisable)
7717 im_set_active(FALSE);
7718 }
7719#endif
7720
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007721#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007722 /* 'spell' */
7723 else if ((int *)varp == &curwin->w_p_spell)
7724 {
7725 if (curwin->w_p_spell)
7726 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007727 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007728 if (errmsg != NULL)
7729 EMSG(_(errmsg));
7730 }
7731 }
7732#endif
7733
Bram Moolenaar071d4272004-06-13 20:20:40 +00007734#ifdef FEAT_FKMAP
7735 else if ((int *)varp == &p_altkeymap)
7736 {
7737 if (old_value != p_altkeymap)
7738 {
7739 if (!p_altkeymap)
7740 {
7741 p_hkmap = p_fkmap;
7742 p_fkmap = 0;
7743 }
7744 else
7745 {
7746 p_fkmap = p_hkmap;
7747 p_hkmap = 0;
7748 }
7749 (void)init_chartab();
7750 }
7751 }
7752
7753 /*
7754 * In case some second language keymapping options have changed, check
7755 * and correct the setting in a consistent way.
7756 */
7757
7758 /*
7759 * If hkmap or fkmap are set, reset Arabic keymapping.
7760 */
7761 if ((p_hkmap || p_fkmap) && p_altkeymap)
7762 {
7763 p_altkeymap = p_fkmap;
7764# ifdef FEAT_ARABIC
7765 curwin->w_p_arab = FALSE;
7766# endif
7767 (void)init_chartab();
7768 }
7769
7770 /*
7771 * If hkmap set, reset Farsi keymapping.
7772 */
7773 if (p_hkmap && p_altkeymap)
7774 {
7775 p_altkeymap = 0;
7776 p_fkmap = 0;
7777# ifdef FEAT_ARABIC
7778 curwin->w_p_arab = FALSE;
7779# endif
7780 (void)init_chartab();
7781 }
7782
7783 /*
7784 * If fkmap set, reset Hebrew keymapping.
7785 */
7786 if (p_fkmap && !p_altkeymap)
7787 {
7788 p_altkeymap = 1;
7789 p_hkmap = 0;
7790# ifdef FEAT_ARABIC
7791 curwin->w_p_arab = FALSE;
7792# endif
7793 (void)init_chartab();
7794 }
7795#endif
7796
7797#ifdef FEAT_ARABIC
7798 if ((int *)varp == &curwin->w_p_arab)
7799 {
7800 if (curwin->w_p_arab)
7801 {
7802 /*
7803 * 'arabic' is set, handle various sub-settings.
7804 */
7805 if (!p_tbidi)
7806 {
7807 /* set rightleft mode */
7808 if (!curwin->w_p_rl)
7809 {
7810 curwin->w_p_rl = TRUE;
7811 changed_window_setting();
7812 }
7813
7814 /* Enable Arabic shaping (major part of what Arabic requires) */
7815 if (!p_arshape)
7816 {
7817 p_arshape = TRUE;
7818 redraw_later_clear();
7819 }
7820 }
7821
7822 /* Arabic requires a utf-8 encoding, inform the user if its not
7823 * set. */
7824 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007825 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007826 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7827
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007828 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007829 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7830#ifdef FEAT_EVAL
7831 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7832#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834
7835# ifdef FEAT_MBYTE
7836 /* set 'delcombine' */
7837 p_deco = TRUE;
7838# endif
7839
7840# ifdef FEAT_KEYMAP
7841 /* Force-set the necessary keymap for arabic */
7842 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7843 OPT_LOCAL);
7844# endif
7845# ifdef FEAT_FKMAP
7846 p_altkeymap = 0;
7847 p_hkmap = 0;
7848 p_fkmap = 0;
7849 (void)init_chartab();
7850# endif
7851 }
7852 else
7853 {
7854 /*
7855 * 'arabic' is reset, handle various sub-settings.
7856 */
7857 if (!p_tbidi)
7858 {
7859 /* reset rightleft mode */
7860 if (curwin->w_p_rl)
7861 {
7862 curwin->w_p_rl = FALSE;
7863 changed_window_setting();
7864 }
7865
7866 /* 'arabicshape' isn't reset, it is a global option and
7867 * another window may still need it "on". */
7868 }
7869
7870 /* 'delcombine' isn't reset, it is a global option and another
7871 * window may still want it "on". */
7872
7873# ifdef FEAT_KEYMAP
7874 /* Revert to the default keymap */
7875 curbuf->b_p_iminsert = B_IMODE_NONE;
7876 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7877# endif
7878 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007879 if (curwin->w_curswant != MAXCOL)
7880 curwin->w_set_curswant = TRUE;
7881 }
7882
7883 else if ((int *)varp == &p_arshape)
7884 {
7885 if (curwin->w_curswant != MAXCOL)
7886 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887 }
7888#endif
7889
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007890#ifdef FEAT_LINEBREAK
7891 if ((int *)varp == &curwin->w_p_lbr)
7892 {
7893 if (curwin->w_curswant != MAXCOL)
7894 curwin->w_set_curswant = TRUE;
7895 }
7896#endif
7897
7898#ifdef FEAT_RIGHTLEFT
7899 if ((int *)varp == &curwin->w_p_rl)
7900 {
7901 if (curwin->w_curswant != MAXCOL)
7902 curwin->w_set_curswant = TRUE;
7903 }
7904#endif
7905
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 /*
7907 * End of handling side effects for bool options.
7908 */
7909
7910 options[opt_idx].flags |= P_WAS_SET;
7911
7912 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007913
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 check_redraw(options[opt_idx].flags);
7915
7916 return NULL;
7917}
7918
7919/*
7920 * Set the value of a number option, and take care of side effects.
7921 * Returns NULL for success, or an error message for an error.
7922 */
7923 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007924set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 int opt_idx; /* index in options[] table */
7926 char_u *varp; /* pointer to the option variable */
7927 long value; /* new value */
7928 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007929 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7931 OPT_MODELINE */
7932{
7933 char_u *errmsg = NULL;
7934 long old_value = *(long *)varp;
7935 long old_Rows = Rows; /* remember old Rows */
7936 long old_Columns = Columns; /* remember old Columns */
7937 long *pp = (long *)varp;
7938
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007939 /* Disallow changing some options from secure mode. */
7940 if ((secure
7941#ifdef HAVE_SANDBOX
7942 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007944 ) && (options[opt_idx].flags & P_SECURE))
7945 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946
7947 *pp = value;
7948#ifdef FEAT_EVAL
7949 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007950 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007952#ifdef FEAT_GUI
7953 need_mouse_correct = TRUE;
7954#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955
7956 if (curbuf->b_p_sw <= 0)
7957 {
7958 errmsg = e_positive;
7959 curbuf->b_p_sw = curbuf->b_p_ts;
7960 }
7961
7962 /*
7963 * Number options that need some action when changed
7964 */
7965#ifdef FEAT_WINDOWS
7966 if (pp == &p_wh || pp == &p_hh)
7967 {
7968 if (p_wh < 1)
7969 {
7970 errmsg = e_positive;
7971 p_wh = 1;
7972 }
7973 if (p_wmh > p_wh)
7974 {
7975 errmsg = e_winheight;
7976 p_wh = p_wmh;
7977 }
7978 if (p_hh < 0)
7979 {
7980 errmsg = e_positive;
7981 p_hh = 0;
7982 }
7983
7984 /* Change window height NOW */
7985 if (lastwin != firstwin)
7986 {
7987 if (pp == &p_wh && curwin->w_height < p_wh)
7988 win_setheight((int)p_wh);
7989 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7990 win_setheight((int)p_hh);
7991 }
7992 }
7993
7994 /* 'winminheight' */
7995 else if (pp == &p_wmh)
7996 {
7997 if (p_wmh < 0)
7998 {
7999 errmsg = e_positive;
8000 p_wmh = 0;
8001 }
8002 if (p_wmh > p_wh)
8003 {
8004 errmsg = e_winheight;
8005 p_wmh = p_wh;
8006 }
8007 win_setminheight();
8008 }
8009
8010# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008011 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 {
8013 if (p_wiw < 1)
8014 {
8015 errmsg = e_positive;
8016 p_wiw = 1;
8017 }
8018 if (p_wmw > p_wiw)
8019 {
8020 errmsg = e_winwidth;
8021 p_wiw = p_wmw;
8022 }
8023
8024 /* Change window width NOW */
8025 if (lastwin != firstwin && curwin->w_width < p_wiw)
8026 win_setwidth((int)p_wiw);
8027 }
8028
8029 /* 'winminwidth' */
8030 else if (pp == &p_wmw)
8031 {
8032 if (p_wmw < 0)
8033 {
8034 errmsg = e_positive;
8035 p_wmw = 0;
8036 }
8037 if (p_wmw > p_wiw)
8038 {
8039 errmsg = e_winwidth;
8040 p_wmw = p_wiw;
8041 }
8042 win_setminheight();
8043 }
8044# endif
8045
8046#endif
8047
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02008048#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008049 else if (pp == &curbuf->b_p_cm)
8050 {
8051 if (curbuf->b_p_cm < 0)
8052 {
8053 errmsg = e_positive;
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008054 curbuf->b_p_cm = old_value;
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008055 }
8056 if (curbuf->b_p_cm > 1)
8057 {
8058 errmsg = e_invarg;
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008059 curbuf->b_p_cm = old_value;
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008060 }
8061 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008062 curbuf->b_p_cm = old_value;
8063
8064 if (curbuf->b_p_cm != old_value && *curbuf->b_p_key != NUL)
8065 /* Need to update the swapfile. */
8066 ml_set_crypt_key(curbuf, curbuf->b_p_key, old_value);
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008067 }
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02008068#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008069
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070#ifdef FEAT_WINDOWS
8071 /* (re)set last window status line */
8072 else if (pp == &p_ls)
8073 {
8074 last_status(FALSE);
8075 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008076
8077 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008078 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008079 {
8080 shell_new_rows(); /* recompute window positions and heights */
8081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082#endif
8083
8084#ifdef FEAT_GUI
8085 else if (pp == &p_linespace)
8086 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008087 /* Recompute gui.char_height and resize the Vim window to keep the
8088 * same number of lines. */
8089 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008090 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 }
8092#endif
8093
8094#ifdef FEAT_FOLDING
8095 /* 'foldlevel' */
8096 else if (pp == &curwin->w_p_fdl)
8097 {
8098 if (curwin->w_p_fdl < 0)
8099 curwin->w_p_fdl = 0;
8100 newFoldLevel();
8101 }
8102
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008103 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 else if (pp == &curwin->w_p_fml)
8105 {
8106 foldUpdateAll(curwin);
8107 }
8108
8109 /* 'foldnestmax' */
8110 else if (pp == &curwin->w_p_fdn)
8111 {
8112 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8113 foldUpdateAll(curwin);
8114 }
8115
8116 /* 'foldcolumn' */
8117 else if (pp == &curwin->w_p_fdc)
8118 {
8119 if (curwin->w_p_fdc < 0)
8120 {
8121 errmsg = e_positive;
8122 curwin->w_p_fdc = 0;
8123 }
8124 else if (curwin->w_p_fdc > 12)
8125 {
8126 errmsg = e_invarg;
8127 curwin->w_p_fdc = 12;
8128 }
8129 }
8130
8131 /* 'shiftwidth' or 'tabstop' */
8132 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8133 {
8134 if (foldmethodIsIndent(curwin))
8135 foldUpdateAll(curwin);
8136 }
8137#endif /* FEAT_FOLDING */
8138
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008139#ifdef FEAT_MBYTE
8140 /* 'maxcombine' */
8141 else if (pp == &p_mco)
8142 {
8143 if (p_mco > MAX_MCO)
8144 p_mco = MAX_MCO;
8145 else if (p_mco < 0)
8146 p_mco = 0;
8147 screenclear(); /* will re-allocate the screen */
8148 }
8149#endif
8150
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 else if (pp == &curbuf->b_p_iminsert)
8152 {
8153 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8154 {
8155 errmsg = e_invarg;
8156 curbuf->b_p_iminsert = B_IMODE_NONE;
8157 }
8158 p_iminsert = curbuf->b_p_iminsert;
8159 if (termcap_active) /* don't do this in the alternate screen */
8160 showmode();
8161#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8162 /* Show/unshow value of 'keymap' in status lines. */
8163 status_redraw_curbuf();
8164#endif
8165 }
8166
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008167 else if (pp == &p_window)
8168 {
8169 if (p_window < 1)
8170 p_window = 1;
8171 else if (p_window >= Rows)
8172 p_window = Rows - 1;
8173 }
8174
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 else if (pp == &curbuf->b_p_imsearch)
8176 {
8177 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8178 {
8179 errmsg = e_invarg;
8180 curbuf->b_p_imsearch = B_IMODE_NONE;
8181 }
8182 p_imsearch = curbuf->b_p_imsearch;
8183 }
8184
8185#ifdef FEAT_TITLE
8186 /* if 'titlelen' has changed, redraw the title */
8187 else if (pp == &p_titlelen)
8188 {
8189 if (p_titlelen < 0)
8190 {
8191 errmsg = e_positive;
8192 p_titlelen = 85;
8193 }
8194 if (starting != NO_SCREEN && old_value != p_titlelen)
8195 need_maketitle = TRUE;
8196 }
8197#endif
8198
8199 /* if p_ch changed value, change the command line height */
8200 else if (pp == &p_ch)
8201 {
8202 if (p_ch < 1)
8203 {
8204 errmsg = e_positive;
8205 p_ch = 1;
8206 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008207 if (p_ch > Rows - min_rows() + 1)
8208 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209
8210 /* Only compute the new window layout when startup has been
8211 * completed. Otherwise the frame sizes may be wrong. */
8212 if (p_ch != old_value && full_screen
8213#ifdef FEAT_GUI
8214 && !gui.starting
8215#endif
8216 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008217 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 }
8219
8220 /* when 'updatecount' changes from zero to non-zero, open swap files */
8221 else if (pp == &p_uc)
8222 {
8223 if (p_uc < 0)
8224 {
8225 errmsg = e_positive;
8226 p_uc = 100;
8227 }
8228 if (p_uc && !old_value)
8229 ml_open_files();
8230 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008231#ifdef FEAT_CONCEAL
Bram Moolenaarf506c5b2010-06-22 06:28:58 +02008232 else if (pp == &curwin->w_p_conceal)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008233 {
8234 if (curwin->w_p_conceal < 0)
8235 {
8236 errmsg = e_positive;
8237 curwin->w_p_conceal = 0;
8238 }
8239 else if (curwin->w_p_conceal > 3)
8240 {
8241 errmsg = e_invarg;
8242 curwin->w_p_conceal = 3;
8243 }
8244 }
8245#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008246#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008247 else if (pp == &p_mzq)
8248 mzvim_reset_timer();
8249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250
8251 /* sync undo before 'undolevels' changes */
8252 else if (pp == &p_ul)
8253 {
8254 /* use the old value, otherwise u_sync() may not work properly */
8255 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008256 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257 p_ul = value;
8258 }
8259
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008260#ifdef FEAT_LINEBREAK
8261 /* 'numberwidth' must be positive */
8262 else if (pp == &curwin->w_p_nuw)
8263 {
8264 if (curwin->w_p_nuw < 1)
8265 {
8266 errmsg = e_positive;
8267 curwin->w_p_nuw = 1;
8268 }
8269 if (curwin->w_p_nuw > 10)
8270 {
8271 errmsg = e_invarg;
8272 curwin->w_p_nuw = 10;
8273 }
8274 curwin->w_nrwidth_line_count = 0;
8275 }
8276#endif
8277
Bram Moolenaar1a384422010-07-14 19:53:30 +02008278 else if (pp == &curbuf->b_p_tw)
8279 {
8280 if (curbuf->b_p_tw < 0)
8281 {
8282 errmsg = e_positive;
8283 curbuf->b_p_tw = 0;
8284 }
8285#ifdef FEAT_SYN_HL
8286# ifdef FEAT_WINDOWS
8287 {
8288 win_T *wp;
8289 tabpage_T *tp;
8290
8291 FOR_ALL_TAB_WINDOWS(tp, wp)
8292 check_colorcolumn(wp);
8293 }
8294# else
8295 check_colorcolumn(curwin);
8296# endif
8297#endif
8298 }
8299
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 /*
8301 * Check the bounds for numeric options here
8302 */
8303 if (Rows < min_rows() && full_screen)
8304 {
8305 if (errbuf != NULL)
8306 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008307 vim_snprintf((char *)errbuf, errbuflen,
8308 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309 errmsg = errbuf;
8310 }
8311 Rows = min_rows();
8312 }
8313 if (Columns < MIN_COLUMNS && full_screen)
8314 {
8315 if (errbuf != NULL)
8316 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008317 vim_snprintf((char *)errbuf, errbuflen,
8318 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319 errmsg = errbuf;
8320 }
8321 Columns = MIN_COLUMNS;
8322 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008323 /* Limit the values to avoid an overflow in Rows * Columns. */
8324 if (Columns > 10000)
8325 Columns = 10000;
8326 if (Rows > 1000)
8327 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328
8329#ifdef DJGPP
8330 /* avoid a crash by checking for a too large value of 'columns' */
8331 if (old_Columns != Columns && full_screen && term_console)
8332 mch_check_columns();
8333#endif
8334
8335 /*
8336 * If the screen (shell) height has been changed, assume it is the
8337 * physical screenheight.
8338 */
8339 if (old_Rows != Rows || old_Columns != Columns)
8340 {
8341 /* Changing the screen size is not allowed while updating the screen. */
8342 if (updating_screen)
8343 *pp = old_value;
8344 else if (full_screen
8345#ifdef FEAT_GUI
8346 && !gui.starting
8347#endif
8348 )
8349 set_shellsize((int)Columns, (int)Rows, TRUE);
8350 else
8351 {
8352 /* Postpone the resizing; check the size and cmdline position for
8353 * messages. */
8354 check_shellsize();
8355 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8356 cmdline_row = Rows - p_ch;
8357 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008358 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008359 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 }
8361
8362 if (curbuf->b_p_sts < 0)
8363 {
8364 errmsg = e_positive;
8365 curbuf->b_p_sts = 0;
8366 }
8367 if (curbuf->b_p_ts <= 0)
8368 {
8369 errmsg = e_positive;
8370 curbuf->b_p_ts = 8;
8371 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 if (p_tm < 0)
8373 {
8374 errmsg = e_positive;
8375 p_tm = 0;
8376 }
8377 if ((curwin->w_p_scr <= 0
8378 || (curwin->w_p_scr > curwin->w_height
8379 && curwin->w_height > 0))
8380 && full_screen)
8381 {
8382 if (pp == &(curwin->w_p_scr))
8383 {
8384 if (curwin->w_p_scr != 0)
8385 errmsg = e_scroll;
8386 win_comp_scroll(curwin);
8387 }
8388 /* If 'scroll' became invalid because of a side effect silently adjust
8389 * it. */
8390 else if (curwin->w_p_scr <= 0)
8391 curwin->w_p_scr = 1;
8392 else /* curwin->w_p_scr > curwin->w_height */
8393 curwin->w_p_scr = curwin->w_height;
8394 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008395 if (p_hi < 0)
8396 {
8397 errmsg = e_positive;
8398 p_hi = 0;
8399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 if (p_report < 0)
8401 {
8402 errmsg = e_positive;
8403 p_report = 1;
8404 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008405 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 {
8407 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8408 p_sj = Rows / 2;
8409 else
8410 {
8411 errmsg = e_scroll;
8412 p_sj = 1;
8413 }
8414 }
8415 if (p_so < 0 && full_screen)
8416 {
8417 errmsg = e_scroll;
8418 p_so = 0;
8419 }
8420 if (p_siso < 0 && full_screen)
8421 {
8422 errmsg = e_positive;
8423 p_siso = 0;
8424 }
8425#ifdef FEAT_CMDWIN
8426 if (p_cwh < 1)
8427 {
8428 errmsg = e_positive;
8429 p_cwh = 1;
8430 }
8431#endif
8432 if (p_ut < 0)
8433 {
8434 errmsg = e_positive;
8435 p_ut = 2000;
8436 }
8437 if (p_ss < 0)
8438 {
8439 errmsg = e_positive;
8440 p_ss = 0;
8441 }
8442
8443 /* May set global value for local option. */
8444 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8445 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8446
8447 options[opt_idx].flags |= P_WAS_SET;
8448
8449 comp_col(); /* in case 'columns' or 'ls' changed */
8450 if (curwin->w_curswant != MAXCOL)
8451 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8452 check_redraw(options[opt_idx].flags);
8453
8454 return errmsg;
8455}
8456
8457/*
8458 * Called after an option changed: check if something needs to be redrawn.
8459 */
8460 static void
8461check_redraw(flags)
8462 long_u flags;
8463{
8464 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8465 int clear = (flags & P_RCLR) == P_RCLR;
8466 int all = ((flags & P_RALL) == P_RALL || clear);
8467
8468#ifdef FEAT_WINDOWS
8469 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8470 status_redraw_all();
8471#endif
8472
8473 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8474 changed_window_setting();
8475 if (flags & P_RBUF)
8476 redraw_curbuf_later(NOT_VALID);
8477 if (clear)
8478 redraw_all_later(CLEAR);
8479 else if (all)
8480 redraw_all_later(NOT_VALID);
8481}
8482
8483/*
8484 * Find index for option 'arg'.
8485 * Return -1 if not found.
8486 */
8487 static int
8488findoption(arg)
8489 char_u *arg;
8490{
8491 int opt_idx;
8492 char *s, *p;
8493 static short quick_tab[27] = {0, 0}; /* quick access table */
8494 int is_term_opt;
8495
8496 /*
8497 * For first call: Initialize the quick-access table.
8498 * It contains the index for the first option that starts with a certain
8499 * letter. There are 26 letters, plus the first "t_" option.
8500 */
8501 if (quick_tab[1] == 0)
8502 {
8503 p = options[0].fullname;
8504 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8505 {
8506 if (s[0] != p[0])
8507 {
8508 if (s[0] == 't' && s[1] == '_')
8509 quick_tab[26] = opt_idx;
8510 else
8511 quick_tab[CharOrdLow(s[0])] = opt_idx;
8512 }
8513 p = s;
8514 }
8515 }
8516
8517 /*
8518 * Check for name starting with an illegal character.
8519 */
8520#ifdef EBCDIC
8521 if (!islower(arg[0]))
8522#else
8523 if (arg[0] < 'a' || arg[0] > 'z')
8524#endif
8525 return -1;
8526
8527 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8528 if (is_term_opt)
8529 opt_idx = quick_tab[26];
8530 else
8531 opt_idx = quick_tab[CharOrdLow(arg[0])];
8532 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8533 {
8534 if (STRCMP(arg, s) == 0) /* match full name */
8535 break;
8536 }
8537 if (s == NULL && !is_term_opt)
8538 {
8539 opt_idx = quick_tab[CharOrdLow(arg[0])];
8540 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8541 {
8542 s = options[opt_idx].shortname;
8543 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8544 break;
8545 s = NULL;
8546 }
8547 }
8548 if (s == NULL)
8549 opt_idx = -1;
8550 return opt_idx;
8551}
8552
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008553#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554/*
8555 * Get the value for an option.
8556 *
8557 * Returns:
8558 * Number or Toggle option: 1, *numval gets value.
8559 * String option: 0, *stringval gets allocated string.
8560 * Hidden Number or Toggle option: -1.
8561 * hidden String option: -2.
8562 * unknown option: -3.
8563 */
8564 int
8565get_option_value(name, numval, stringval, opt_flags)
8566 char_u *name;
8567 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008568 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 int opt_flags;
8570{
8571 int opt_idx;
8572 char_u *varp;
8573
8574 opt_idx = findoption(name);
8575 if (opt_idx < 0) /* unknown option */
8576 return -3;
8577
8578 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8579
8580 if (options[opt_idx].flags & P_STRING)
8581 {
8582 if (varp == NULL) /* hidden option */
8583 return -2;
8584 if (stringval != NULL)
8585 {
8586#ifdef FEAT_CRYPT
8587 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008588 if ((char_u **)varp == &curbuf->b_p_key
8589 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590 *stringval = vim_strsave((char_u *)"*****");
8591 else
8592#endif
8593 *stringval = vim_strsave(*(char_u **)(varp));
8594 }
8595 return 0;
8596 }
8597
8598 if (varp == NULL) /* hidden option */
8599 return -1;
8600 if (options[opt_idx].flags & P_NUM)
8601 *numval = *(long *)varp;
8602 else
8603 {
8604 /* Special case: 'modified' is b_changed, but we also want to consider
8605 * it set when 'ff' or 'fenc' changed. */
8606 if ((int *)varp == &curbuf->b_changed)
8607 *numval = curbufIsChanged();
8608 else
8609 *numval = *(int *)varp;
8610 }
8611 return 1;
8612}
8613#endif
8614
8615/*
8616 * Set the value of option "name".
8617 * Use "string" for string options, use "number" for other options.
8618 */
8619 void
8620set_option_value(name, number, string, opt_flags)
8621 char_u *name;
8622 long number;
8623 char_u *string;
8624 int opt_flags; /* OPT_LOCAL or 0 (both) */
8625{
8626 int opt_idx;
8627 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008628 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629
8630 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008631 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632 EMSG2(_("E355: Unknown option: %s"), name);
8633 else
8634 {
8635 flags = options[opt_idx].flags;
8636#ifdef HAVE_SANDBOX
8637 /* Disallow changing some options in the sandbox */
8638 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008639 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008641 return;
8642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008644 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 set_string_option(opt_idx, string, opt_flags);
8646 else
8647 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008648 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008649 if (varp != NULL) /* hidden option is not changed */
8650 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008651 if (number == 0 && string != NULL)
8652 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008653 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008654
8655 /* Either we are given a string or we are setting option
8656 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008657 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008658 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008659 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008660 {
8661 /* There's another character after zeros or the string
8662 * is empty. In both cases, we are trying to set a
8663 * num option using a string. */
8664 EMSG3(_("E521: Number required: &%s = '%s'"),
8665 name, string);
8666 return; /* do nothing as we hit an error */
8667
8668 }
8669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008671 (void)set_num_option(opt_idx, varp, number,
8672 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008674 (void)set_bool_option(opt_idx, varp, (int)number,
8675 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 }
8677 }
8678 }
8679}
8680
8681/*
8682 * Get the terminal code for a terminal option.
8683 * Returns NULL when not found.
8684 */
8685 char_u *
8686get_term_code(tname)
8687 char_u *tname;
8688{
8689 int opt_idx;
8690 char_u *varp;
8691
8692 if (tname[0] != 't' || tname[1] != '_' ||
8693 tname[2] == NUL || tname[3] == NUL)
8694 return NULL;
8695 if ((opt_idx = findoption(tname)) >= 0)
8696 {
8697 varp = get_varp(&(options[opt_idx]));
8698 if (varp != NULL)
8699 varp = *(char_u **)(varp);
8700 return varp;
8701 }
8702 return find_termcode(tname + 2);
8703}
8704
8705 char_u *
8706get_highlight_default()
8707{
8708 int i;
8709
8710 i = findoption((char_u *)"hl");
8711 if (i >= 0)
8712 return options[i].def_val[VI_DEFAULT];
8713 return (char_u *)NULL;
8714}
8715
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008716#if defined(FEAT_MBYTE) || defined(PROTO)
8717 char_u *
8718get_encoding_default()
8719{
8720 int i;
8721
8722 i = findoption((char_u *)"enc");
8723 if (i >= 0)
8724 return options[i].def_val[VI_DEFAULT];
8725 return (char_u *)NULL;
8726}
8727#endif
8728
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729/*
8730 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8731 */
8732 static int
8733find_key_option(arg)
8734 char_u *arg;
8735{
8736 int key;
8737 int modifiers;
8738
8739 /*
8740 * Don't use get_special_key_code() for t_xx, we don't want it to call
8741 * add_termcap_entry().
8742 */
8743 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8744 key = TERMCAP2KEY(arg[2], arg[3]);
8745 else
8746 {
8747 --arg; /* put arg at the '<' */
8748 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008749 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 if (modifiers) /* can't handle modifiers here */
8751 key = 0;
8752 }
8753 return key;
8754}
8755
8756/*
8757 * if 'all' == 0: show changed options
8758 * if 'all' == 1: show all normal options
8759 * if 'all' == 2: show all terminal options
8760 */
8761 static void
8762showoptions(all, opt_flags)
8763 int all;
8764 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8765{
8766 struct vimoption *p;
8767 int col;
8768 int isterm;
8769 char_u *varp;
8770 struct vimoption **items;
8771 int item_count;
8772 int run;
8773 int row, rows;
8774 int cols;
8775 int i;
8776 int len;
8777
8778#define INC 20
8779#define GAP 3
8780
8781 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8782 PARAM_COUNT));
8783 if (items == NULL)
8784 return;
8785
8786 /* Highlight title */
8787 if (all == 2)
8788 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8789 else if (opt_flags & OPT_GLOBAL)
8790 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8791 else if (opt_flags & OPT_LOCAL)
8792 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8793 else
8794 MSG_PUTS_TITLE(_("\n--- Options ---"));
8795
8796 /*
8797 * do the loop two times:
8798 * 1. display the short items
8799 * 2. display the long items (only strings and numbers)
8800 */
8801 for (run = 1; run <= 2 && !got_int; ++run)
8802 {
8803 /*
8804 * collect the items in items[]
8805 */
8806 item_count = 0;
8807 for (p = &options[0]; p->fullname != NULL; p++)
8808 {
8809 varp = NULL;
8810 isterm = istermoption(p);
8811 if (opt_flags != 0)
8812 {
8813 if (p->indir != PV_NONE && !isterm)
8814 varp = get_varp_scope(p, opt_flags);
8815 }
8816 else
8817 varp = get_varp(p);
8818 if (varp != NULL
8819 && ((all == 2 && isterm)
8820 || (all == 1 && !isterm)
8821 || (all == 0 && !optval_default(p, varp))))
8822 {
8823 if (p->flags & P_BOOL)
8824 len = 1; /* a toggle option fits always */
8825 else
8826 {
8827 option_value2string(p, opt_flags);
8828 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8829 }
8830 if ((len <= INC - GAP && run == 1) ||
8831 (len > INC - GAP && run == 2))
8832 items[item_count++] = p;
8833 }
8834 }
8835
8836 /*
8837 * display the items
8838 */
8839 if (run == 1)
8840 {
8841 cols = (Columns + GAP - 3) / INC;
8842 if (cols == 0)
8843 cols = 1;
8844 rows = (item_count + cols - 1) / cols;
8845 }
8846 else /* run == 2 */
8847 rows = item_count;
8848 for (row = 0; row < rows && !got_int; ++row)
8849 {
8850 msg_putchar('\n'); /* go to next line */
8851 if (got_int) /* 'q' typed in more */
8852 break;
8853 col = 0;
8854 for (i = row; i < item_count; i += rows)
8855 {
8856 msg_col = col; /* make columns */
8857 showoneopt(items[i], opt_flags);
8858 col += INC;
8859 }
8860 out_flush();
8861 ui_breakcheck();
8862 }
8863 }
8864 vim_free(items);
8865}
8866
8867/*
8868 * Return TRUE if option "p" has its default value.
8869 */
8870 static int
8871optval_default(p, varp)
8872 struct vimoption *p;
8873 char_u *varp;
8874{
8875 int dvi;
8876
8877 if (varp == NULL)
8878 return TRUE; /* hidden option is always at default */
8879 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8880 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008881 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008883 /* the cast to long is required for Manx C, long_i is
8884 * needed for MSVC */
8885 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886 /* P_STRING */
8887 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8888}
8889
8890/*
8891 * showoneopt: show the value of one option
8892 * must not be called with a hidden option!
8893 */
8894 static void
8895showoneopt(p, opt_flags)
8896 struct vimoption *p;
8897 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8898{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008899 char_u *varp;
8900 int save_silent = silent_mode;
8901
8902 silent_mode = FALSE;
8903 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904
8905 varp = get_varp_scope(p, opt_flags);
8906
8907 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8908 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8909 ? !curbufIsChanged() : !*(int *)varp))
8910 MSG_PUTS("no");
8911 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8912 MSG_PUTS("--");
8913 else
8914 MSG_PUTS(" ");
8915 MSG_PUTS(p->fullname);
8916 if (!(p->flags & P_BOOL))
8917 {
8918 msg_putchar('=');
8919 /* put value string in NameBuff */
8920 option_value2string(p, opt_flags);
8921 msg_outtrans(NameBuff);
8922 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008923
8924 silent_mode = save_silent;
8925 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926}
8927
8928/*
8929 * Write modified options as ":set" commands to a file.
8930 *
8931 * There are three values for "opt_flags":
8932 * OPT_GLOBAL: Write global option values and fresh values of
8933 * buffer-local options (used for start of a session
8934 * file).
8935 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8936 * curwin (used for a vimrc file).
8937 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8938 * and local values for window-local options of
8939 * curwin. Local values are also written when at the
8940 * default value, because a modeline or autocommand
8941 * may have set them when doing ":edit file" and the
8942 * user has set them back at the default or fresh
8943 * value.
8944 * When "local_only" is TRUE, don't write fresh
8945 * values, only local values (for ":mkview").
8946 * (fresh value = value used for a new buffer or window for a local option).
8947 *
8948 * Return FAIL on error, OK otherwise.
8949 */
8950 int
8951makeset(fd, opt_flags, local_only)
8952 FILE *fd;
8953 int opt_flags;
8954 int local_only;
8955{
8956 struct vimoption *p;
8957 char_u *varp; /* currently used value */
8958 char_u *varp_fresh; /* local value */
8959 char_u *varp_local = NULL; /* fresh value */
8960 char *cmd;
8961 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008962 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963
8964 /*
8965 * The options that don't have a default (terminal name, columns, lines)
8966 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008967 * Do the loop over "options[]" twice: once for options with the
8968 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008970 for (pri = 1; pri >= 0; --pri)
8971 {
8972 for (p = &options[0]; !istermoption(p); p++)
8973 if (!(p->flags & P_NO_MKRC)
8974 && !istermoption(p)
8975 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976 {
8977 /* skip global option when only doing locals */
8978 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8979 continue;
8980
8981 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8982 * file, they are always buffer-specific. */
8983 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8984 continue;
8985
8986 /* Global values are only written when not at the default value. */
8987 varp = get_varp_scope(p, opt_flags);
8988 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8989 continue;
8990
8991 round = 2;
8992 if (p->indir != PV_NONE)
8993 {
8994 if (p->var == VAR_WIN)
8995 {
8996 /* skip window-local option when only doing globals */
8997 if (!(opt_flags & OPT_LOCAL))
8998 continue;
8999 /* When fresh value of window-local option is not at the
9000 * default, need to write it too. */
9001 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9002 {
9003 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9004 if (!optval_default(p, varp_fresh))
9005 {
9006 round = 1;
9007 varp_local = varp;
9008 varp = varp_fresh;
9009 }
9010 }
9011 }
9012 }
9013
9014 /* Round 1: fresh value for window-local options.
9015 * Round 2: other values */
9016 for ( ; round <= 2; varp = varp_local, ++round)
9017 {
9018 if (round == 1 || (opt_flags & OPT_GLOBAL))
9019 cmd = "set";
9020 else
9021 cmd = "setlocal";
9022
9023 if (p->flags & P_BOOL)
9024 {
9025 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9026 return FAIL;
9027 }
9028 else if (p->flags & P_NUM)
9029 {
9030 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9031 return FAIL;
9032 }
9033 else /* P_STRING */
9034 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009035#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9036 int do_endif = FALSE;
9037
Bram Moolenaar071d4272004-06-13 20:20:40 +00009038 /* Don't set 'syntax' and 'filetype' again if the value is
9039 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009040 if (
9041# if defined(FEAT_SYN_HL)
9042 p->indir == PV_SYN
9043# if defined(FEAT_AUTOCMD)
9044 ||
9045# endif
9046# endif
9047# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009048 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009049# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009050 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051 {
9052 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9053 *(char_u **)(varp)) < 0
9054 || put_eol(fd) < 0)
9055 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009056 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9060 (p->flags & P_EXPAND) != 0) == FAIL)
9061 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009062#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9063 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009064 {
9065 if (put_line(fd, "endif") == FAIL)
9066 return FAIL;
9067 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009068#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 }
9070 }
9071 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 return OK;
9074}
9075
9076#if defined(FEAT_FOLDING) || defined(PROTO)
9077/*
9078 * Generate set commands for the local fold options only. Used when
9079 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9080 */
9081 int
9082makefoldset(fd)
9083 FILE *fd;
9084{
9085 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9086# ifdef FEAT_EVAL
9087 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9088 == FAIL
9089# endif
9090 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9091 == FAIL
9092 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9093 == FAIL
9094 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9095 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9096 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9097 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9098 )
9099 return FAIL;
9100
9101 return OK;
9102}
9103#endif
9104
9105 static int
9106put_setstring(fd, cmd, name, valuep, expand)
9107 FILE *fd;
9108 char *cmd;
9109 char *name;
9110 char_u **valuep;
9111 int expand;
9112{
9113 char_u *s;
9114 char_u buf[MAXPATHL];
9115
9116 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9117 return FAIL;
9118 if (*valuep != NULL)
9119 {
9120 /* Output 'pastetoggle' as key names. For other
9121 * options some characters have to be escaped with
9122 * CTRL-V or backslash */
9123 if (valuep == &p_pt)
9124 {
9125 s = *valuep;
9126 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009127 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 return FAIL;
9129 }
9130 else if (expand)
9131 {
9132 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9133 if (put_escstr(fd, buf, 2) == FAIL)
9134 return FAIL;
9135 }
9136 else if (put_escstr(fd, *valuep, 2) == FAIL)
9137 return FAIL;
9138 }
9139 if (put_eol(fd) < 0)
9140 return FAIL;
9141 return OK;
9142}
9143
9144 static int
9145put_setnum(fd, cmd, name, valuep)
9146 FILE *fd;
9147 char *cmd;
9148 char *name;
9149 long *valuep;
9150{
9151 long wc;
9152
9153 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9154 return FAIL;
9155 if (wc_use_keyname((char_u *)valuep, &wc))
9156 {
9157 /* print 'wildchar' and 'wildcharm' as a key name */
9158 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9159 return FAIL;
9160 }
9161 else if (fprintf(fd, "%ld", *valuep) < 0)
9162 return FAIL;
9163 if (put_eol(fd) < 0)
9164 return FAIL;
9165 return OK;
9166}
9167
9168 static int
9169put_setbool(fd, cmd, name, value)
9170 FILE *fd;
9171 char *cmd;
9172 char *name;
9173 int value;
9174{
Bram Moolenaar893de922007-10-02 18:40:57 +00009175 if (value < 0) /* global/local option using global value */
9176 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9178 || put_eol(fd) < 0)
9179 return FAIL;
9180 return OK;
9181}
9182
9183/*
9184 * Clear all the terminal options.
9185 * If the option has been allocated, free the memory.
9186 * Terminal options are never hidden or indirect.
9187 */
9188 void
9189clear_termoptions()
9190{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009191 /*
9192 * Reset a few things before clearing the old options. This may cause
9193 * outputting a few things that the terminal doesn't understand, but the
9194 * screen will be cleared later, so this is OK.
9195 */
9196#ifdef FEAT_MOUSE_TTY
9197 mch_setmouse(FALSE); /* switch mouse off */
9198#endif
9199#ifdef FEAT_TITLE
9200 mch_restore_title(3); /* restore window titles */
9201#endif
9202#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9203 /* When starting the GUI close the display opened for the clipboard.
9204 * After restoring the title, because that will need the display. */
9205 if (gui.starting)
9206 clear_xterm_clip();
9207#endif
9208#ifdef WIN3264
9209 /*
9210 * Check if this is allowed now.
9211 */
9212 if (can_end_termcap_mode(FALSE) == TRUE)
9213#endif
9214 stoptermcap(); /* stop termcap mode */
9215
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009216 free_termoptions();
9217}
9218
9219 void
9220free_termoptions()
9221{
9222 struct vimoption *p;
9223
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 for (p = &options[0]; p->fullname != NULL; p++)
9225 if (istermoption(p))
9226 {
9227 if (p->flags & P_ALLOCED)
9228 free_string_option(*(char_u **)(p->var));
9229 if (p->flags & P_DEF_ALLOCED)
9230 free_string_option(p->def_val[VI_DEFAULT]);
9231 *(char_u **)(p->var) = empty_option;
9232 p->def_val[VI_DEFAULT] = empty_option;
9233 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9234 }
9235 clear_termcodes();
9236}
9237
9238/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009239 * Free the string for one term option, if it was allocated.
9240 * Set the string to empty_option and clear allocated flag.
9241 * "var" points to the option value.
9242 */
9243 void
9244free_one_termoption(var)
9245 char_u *var;
9246{
9247 struct vimoption *p;
9248
9249 for (p = &options[0]; p->fullname != NULL; p++)
9250 if (p->var == var)
9251 {
9252 if (p->flags & P_ALLOCED)
9253 free_string_option(*(char_u **)(p->var));
9254 *(char_u **)(p->var) = empty_option;
9255 p->flags &= ~P_ALLOCED;
9256 break;
9257 }
9258}
9259
9260/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 * Set the terminal option defaults to the current value.
9262 * Used after setting the terminal name.
9263 */
9264 void
9265set_term_defaults()
9266{
9267 struct vimoption *p;
9268
9269 for (p = &options[0]; p->fullname != NULL; p++)
9270 {
9271 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9272 {
9273 if (p->flags & P_DEF_ALLOCED)
9274 {
9275 free_string_option(p->def_val[VI_DEFAULT]);
9276 p->flags &= ~P_DEF_ALLOCED;
9277 }
9278 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9279 if (p->flags & P_ALLOCED)
9280 {
9281 p->flags |= P_DEF_ALLOCED;
9282 p->flags &= ~P_ALLOCED; /* don't free the value now */
9283 }
9284 }
9285 }
9286}
9287
9288/*
9289 * return TRUE if 'p' starts with 't_'
9290 */
9291 static int
9292istermoption(p)
9293 struct vimoption *p;
9294{
9295 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9296}
9297
9298/*
9299 * Compute columns for ruler and shown command. 'sc_col' is also used to
9300 * decide what the maximum length of a message on the status line can be.
9301 * If there is a status line for the last window, 'sc_col' is independent
9302 * of 'ru_col'.
9303 */
9304
9305#define COL_RULER 17 /* columns needed by standard ruler */
9306
9307 void
9308comp_col()
9309{
9310#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9311 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9312
9313 sc_col = 0;
9314 ru_col = 0;
9315 if (p_ru)
9316 {
9317#ifdef FEAT_STL_OPT
9318 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9319#else
9320 ru_col = COL_RULER + 1;
9321#endif
9322 /* no last status line, adjust sc_col */
9323 if (!last_has_status)
9324 sc_col = ru_col;
9325 }
9326 if (p_sc)
9327 {
9328 sc_col += SHOWCMD_COLS;
9329 if (!p_ru || last_has_status) /* no need for separating space */
9330 ++sc_col;
9331 }
9332 sc_col = Columns - sc_col;
9333 ru_col = Columns - ru_col;
9334 if (sc_col <= 0) /* screen too narrow, will become a mess */
9335 sc_col = 1;
9336 if (ru_col <= 0)
9337 ru_col = 1;
9338#else
9339 sc_col = Columns;
9340 ru_col = Columns;
9341#endif
9342}
9343
9344/*
9345 * Get pointer to option variable, depending on local or global scope.
9346 */
9347 static char_u *
9348get_varp_scope(p, opt_flags)
9349 struct vimoption *p;
9350 int opt_flags;
9351{
9352 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9353 {
9354 if (p->var == VAR_WIN)
9355 return (char_u *)GLOBAL_WO(get_varp(p));
9356 return p->var;
9357 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009358 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 {
9360 switch ((int)p->indir)
9361 {
9362#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009363 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9364 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9365 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009367 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9368 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9369 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009370 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009371 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009373 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9374 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375#endif
9376#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009377 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9378 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009380#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9381 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9382#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009383#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009384 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009386 }
9387 return NULL; /* "cannot happen" */
9388 }
9389 return get_varp(p);
9390}
9391
9392/*
9393 * Get pointer to option variable.
9394 */
9395 static char_u *
9396get_varp(p)
9397 struct vimoption *p;
9398{
9399 /* hidden option, always return NULL */
9400 if (p->var == NULL)
9401 return NULL;
9402
9403 switch ((int)p->indir)
9404 {
9405 case PV_NONE: return p->var;
9406
9407 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009408 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009410 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009412 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009414 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009415 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009416 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9418#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009419 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009421 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9423#endif
9424#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009425 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009426 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009427 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009428 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9429#endif
9430#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009431 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009433 case PV_GP: return *curbuf->b_p_gp != NUL
9434 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9435 case PV_MP: return *curbuf->b_p_mp != NUL
9436 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009437#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009438#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9439 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9440 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9441#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009442#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009443 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009444 ? (char_u *)&(curwin->w_p_stl) : p->var;
9445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446
9447#ifdef FEAT_ARABIC
9448 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9449#endif
9450 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009451#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009452 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9453#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009454#ifdef FEAT_SYN_HL
9455 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9456 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009457 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459#ifdef FEAT_DIFF
9460 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9461#endif
9462#ifdef FEAT_FOLDING
9463 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9464 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9465 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9466 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9467 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9468 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9469 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9470# ifdef FEAT_EVAL
9471 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9472 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9473# endif
9474 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9475#endif
9476 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009477 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009478#ifdef FEAT_LINEBREAK
9479 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9480#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009481#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9483#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009484#ifdef FEAT_VERTSPLIT
9485 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9486#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9488 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9489#endif
9490#ifdef FEAT_RIGHTLEFT
9491 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9492 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9493#endif
9494 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9495 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9496#ifdef FEAT_LINEBREAK
9497 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9498#endif
9499#ifdef FEAT_SCROLLBIND
9500 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9501#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009502#ifdef FEAT_CURSORBIND
9503 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9504#endif
9505#ifdef FEAT_CONCEAL
9506 case PV_CONCEAL: return (char_u *)&(curwin->w_p_conceal);
9507#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009508
9509 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9510 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9511#ifdef FEAT_MBYTE
9512 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9513#endif
9514#if defined(FEAT_QUICKFIX)
9515 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9516 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9517#endif
9518 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9519 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9520#ifdef FEAT_CINDENT
9521 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9522 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9523 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9524#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009525#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009526 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9529 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9530#endif
9531#ifdef FEAT_COMMENTS
9532 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9533#endif
9534#ifdef FEAT_FOLDING
9535 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9536#endif
9537#ifdef FEAT_INS_EXPAND
9538 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9539#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009540#ifdef FEAT_COMPL_FUNC
9541 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009542 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009544 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9545 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9546#ifdef FEAT_MBYTE
9547 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9548#endif
9549 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9550#ifdef FEAT_AUTOCMD
9551 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9552#endif
9553 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009554 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9556 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9557 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9558 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9559#ifdef FEAT_FIND_ID
9560# ifdef FEAT_EVAL
9561 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9562# endif
9563#endif
9564#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9565 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9566 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9567#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009568#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009569 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571#ifdef FEAT_CRYPT
9572 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9573#endif
9574#ifdef FEAT_LISP
9575 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9576#endif
9577 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9578 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9579 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9580 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9581 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9582#ifdef FEAT_OSFILETYPE
9583 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9584#endif
9585 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009586#ifdef FEAT_TEXTOBJ
9587 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9590#ifdef FEAT_SMARTINDENT
9591 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9592#endif
9593#ifndef SHORT_FNAME
9594 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9595#endif
9596 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9597#ifdef FEAT_SEARCHPATH
9598 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9599#endif
9600 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9601#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009602 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009603 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9604#endif
9605#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009606 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9607 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9608 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009609#endif
9610 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9611 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9612 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9613 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009614#ifdef FEAT_PERSISTENT_UNDO
9615 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9618#ifdef FEAT_KEYMAP
9619 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9620#endif
9621 default: EMSG(_("E356: get_varp ERROR"));
9622 }
9623 /* always return a valid pointer to avoid a crash! */
9624 return (char_u *)&(curbuf->b_p_wm);
9625}
9626
9627/*
9628 * Get the value of 'equalprg', either the buffer-local one or the global one.
9629 */
9630 char_u *
9631get_equalprg()
9632{
9633 if (*curbuf->b_p_ep == NUL)
9634 return p_ep;
9635 return curbuf->b_p_ep;
9636}
9637
9638#if defined(FEAT_WINDOWS) || defined(PROTO)
9639/*
9640 * Copy options from one window to another.
9641 * Used when splitting a window.
9642 */
9643 void
9644win_copy_options(wp_from, wp_to)
9645 win_T *wp_from;
9646 win_T *wp_to;
9647{
9648 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9649 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9650# ifdef FEAT_RIGHTLEFT
9651# ifdef FEAT_FKMAP
9652 /* Is this right? */
9653 wp_to->w_farsi = wp_from->w_farsi;
9654# endif
9655# endif
9656}
9657#endif
9658
9659/*
9660 * Copy the options from one winopt_T to another.
9661 * Doesn't free the old option values in "to", use clear_winopt() for that.
9662 * The 'scroll' option is not copied, because it depends on the window height.
9663 * The 'previewwindow' option is reset, there can be only one preview window.
9664 */
9665 void
9666copy_winopt(from, to)
9667 winopt_T *from;
9668 winopt_T *to;
9669{
9670#ifdef FEAT_ARABIC
9671 to->wo_arab = from->wo_arab;
9672#endif
9673 to->wo_list = from->wo_list;
9674 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009675 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009676#ifdef FEAT_LINEBREAK
9677 to->wo_nuw = from->wo_nuw;
9678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009679#ifdef FEAT_RIGHTLEFT
9680 to->wo_rl = from->wo_rl;
9681 to->wo_rlc = vim_strsave(from->wo_rlc);
9682#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009683#ifdef FEAT_STL_OPT
9684 to->wo_stl = vim_strsave(from->wo_stl);
9685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686 to->wo_wrap = from->wo_wrap;
9687#ifdef FEAT_LINEBREAK
9688 to->wo_lbr = from->wo_lbr;
9689#endif
9690#ifdef FEAT_SCROLLBIND
9691 to->wo_scb = from->wo_scb;
9692#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009693#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009694 to->wo_spell = from->wo_spell;
9695#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009696#ifdef FEAT_SYN_HL
9697 to->wo_cuc = from->wo_cuc;
9698 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009699 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701#ifdef FEAT_DIFF
9702 to->wo_diff = from->wo_diff;
9703#endif
9704#ifdef FEAT_FOLDING
9705 to->wo_fdc = from->wo_fdc;
9706 to->wo_fen = from->wo_fen;
9707 to->wo_fdi = vim_strsave(from->wo_fdi);
9708 to->wo_fml = from->wo_fml;
9709 to->wo_fdl = from->wo_fdl;
9710 to->wo_fdm = vim_strsave(from->wo_fdm);
9711 to->wo_fdn = from->wo_fdn;
9712# ifdef FEAT_EVAL
9713 to->wo_fde = vim_strsave(from->wo_fde);
9714 to->wo_fdt = vim_strsave(from->wo_fdt);
9715# endif
9716 to->wo_fmr = vim_strsave(from->wo_fmr);
9717#endif
9718 check_winopt(to); /* don't want NULL pointers */
9719}
9720
9721/*
9722 * Check string options in a window for a NULL value.
9723 */
9724 void
9725check_win_options(win)
9726 win_T *win;
9727{
9728 check_winopt(&win->w_onebuf_opt);
9729 check_winopt(&win->w_allbuf_opt);
9730}
9731
9732/*
9733 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9734 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009735 void
9736check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009737 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738{
9739#ifdef FEAT_FOLDING
9740 check_string_option(&wop->wo_fdi);
9741 check_string_option(&wop->wo_fdm);
9742# ifdef FEAT_EVAL
9743 check_string_option(&wop->wo_fde);
9744 check_string_option(&wop->wo_fdt);
9745# endif
9746 check_string_option(&wop->wo_fmr);
9747#endif
9748#ifdef FEAT_RIGHTLEFT
9749 check_string_option(&wop->wo_rlc);
9750#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009751#ifdef FEAT_STL_OPT
9752 check_string_option(&wop->wo_stl);
9753#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009754#ifdef FEAT_SYN_HL
9755 check_string_option(&wop->wo_cc);
9756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757}
9758
9759/*
9760 * Free the allocated memory inside a winopt_T.
9761 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 void
9763clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009764 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765{
9766#ifdef FEAT_FOLDING
9767 clear_string_option(&wop->wo_fdi);
9768 clear_string_option(&wop->wo_fdm);
9769# ifdef FEAT_EVAL
9770 clear_string_option(&wop->wo_fde);
9771 clear_string_option(&wop->wo_fdt);
9772# endif
9773 clear_string_option(&wop->wo_fmr);
9774#endif
9775#ifdef FEAT_RIGHTLEFT
9776 clear_string_option(&wop->wo_rlc);
9777#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009778#ifdef FEAT_STL_OPT
9779 clear_string_option(&wop->wo_stl);
9780#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009781#ifdef FEAT_SYN_HL
9782 clear_string_option(&wop->wo_cc);
9783#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009784}
9785
9786/*
9787 * Copy global option values to local options for one buffer.
9788 * Used when creating a new buffer and sometimes when entering a buffer.
9789 * flags:
9790 * BCO_ENTER We will enter the buf buffer.
9791 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9792 * appropriate.
9793 * BCO_NOHELP Don't copy the values to a help buffer.
9794 */
9795 void
9796buf_copy_options(buf, flags)
9797 buf_T *buf;
9798 int flags;
9799{
9800 int should_copy = TRUE;
9801 char_u *save_p_isk = NULL; /* init for GCC */
9802 int dont_do_help;
9803 int did_isk = FALSE;
9804
9805 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009806 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807 */
9808 if (buf == NULL || !buf_valid(buf))
9809 return;
9810
9811 /*
9812 * Skip this when the option defaults have not been set yet. Happens when
9813 * main() allocates the first buffer.
9814 */
9815 if (p_cpo != NULL)
9816 {
9817 /*
9818 * Always copy when entering and 'cpo' contains 'S'.
9819 * Don't copy when already initialized.
9820 * Don't copy when 'cpo' contains 's' and not entering.
9821 * 'S' BCO_ENTER initialized 's' should_copy
9822 * yes yes X X TRUE
9823 * yes no yes X FALSE
9824 * no X yes X FALSE
9825 * X no no yes FALSE
9826 * X no no no TRUE
9827 * no yes no X TRUE
9828 */
9829 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9830 && (buf->b_p_initialized
9831 || (!(flags & BCO_ENTER)
9832 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9833 should_copy = FALSE;
9834
9835 if (should_copy || (flags & BCO_ALWAYS))
9836 {
9837 /* Don't copy the options specific to a help buffer when
9838 * BCO_NOHELP is given or the options were initialized already
9839 * (jumping back to a help file with CTRL-T or CTRL-O) */
9840 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9841 || buf->b_p_initialized;
9842 if (dont_do_help) /* don't free b_p_isk */
9843 {
9844 save_p_isk = buf->b_p_isk;
9845 buf->b_p_isk = NULL;
9846 }
9847 /*
9848 * Always free the allocated strings.
9849 * If not already initialized, set 'readonly' and copy 'fileformat'.
9850 */
9851 if (!buf->b_p_initialized)
9852 {
9853 free_buf_options(buf, TRUE);
9854 buf->b_p_ro = FALSE; /* don't copy readonly */
9855 buf->b_p_tx = p_tx;
9856#ifdef FEAT_MBYTE
9857 buf->b_p_fenc = vim_strsave(p_fenc);
9858#endif
9859 buf->b_p_ff = vim_strsave(p_ff);
9860#if defined(FEAT_QUICKFIX)
9861 buf->b_p_bh = empty_option;
9862 buf->b_p_bt = empty_option;
9863#endif
9864 }
9865 else
9866 free_buf_options(buf, FALSE);
9867
9868 buf->b_p_ai = p_ai;
9869 buf->b_p_ai_nopaste = p_ai_nopaste;
9870 buf->b_p_sw = p_sw;
9871 buf->b_p_tw = p_tw;
9872 buf->b_p_tw_nopaste = p_tw_nopaste;
9873 buf->b_p_tw_nobin = p_tw_nobin;
9874 buf->b_p_wm = p_wm;
9875 buf->b_p_wm_nopaste = p_wm_nopaste;
9876 buf->b_p_wm_nobin = p_wm_nobin;
9877 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009878#ifdef FEAT_MBYTE
9879 buf->b_p_bomb = p_bomb;
9880#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881 buf->b_p_et = p_et;
9882 buf->b_p_et_nobin = p_et_nobin;
9883 buf->b_p_ml = p_ml;
9884 buf->b_p_ml_nobin = p_ml_nobin;
9885 buf->b_p_inf = p_inf;
9886 buf->b_p_swf = p_swf;
9887#ifdef FEAT_INS_EXPAND
9888 buf->b_p_cpt = vim_strsave(p_cpt);
9889#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009890#ifdef FEAT_COMPL_FUNC
9891 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009892 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 buf->b_p_sts = p_sts;
9895 buf->b_p_sts_nopaste = p_sts_nopaste;
9896#ifndef SHORT_FNAME
9897 buf->b_p_sn = p_sn;
9898#endif
9899#ifdef FEAT_COMMENTS
9900 buf->b_p_com = vim_strsave(p_com);
9901#endif
9902#ifdef FEAT_FOLDING
9903 buf->b_p_cms = vim_strsave(p_cms);
9904#endif
9905 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009906 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009907 buf->b_p_nf = vim_strsave(p_nf);
9908 buf->b_p_mps = vim_strsave(p_mps);
9909#ifdef FEAT_SMARTINDENT
9910 buf->b_p_si = p_si;
9911#endif
9912 buf->b_p_ci = p_ci;
9913#ifdef FEAT_CINDENT
9914 buf->b_p_cin = p_cin;
9915 buf->b_p_cink = vim_strsave(p_cink);
9916 buf->b_p_cino = vim_strsave(p_cino);
9917#endif
9918#ifdef FEAT_AUTOCMD
9919 /* Don't copy 'filetype', it must be detected */
9920 buf->b_p_ft = empty_option;
9921#endif
9922#ifdef FEAT_OSFILETYPE
9923 buf->b_p_oft = vim_strsave(p_oft);
9924#endif
9925 buf->b_p_pi = p_pi;
9926#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9927 buf->b_p_cinw = vim_strsave(p_cinw);
9928#endif
9929#ifdef FEAT_LISP
9930 buf->b_p_lisp = p_lisp;
9931#endif
9932#ifdef FEAT_SYN_HL
9933 /* Don't copy 'syntax', it must be set */
9934 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009935 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009936#endif
9937#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009938 buf->b_s.b_p_spc = vim_strsave(p_spf);
9939 (void)compile_cap_prog(&buf->b_s);
9940 buf->b_s.b_p_spf = vim_strsave(p_spf);
9941 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942#endif
9943#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9944 buf->b_p_inde = vim_strsave(p_inde);
9945 buf->b_p_indk = vim_strsave(p_indk);
9946#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009947#if defined(FEAT_EVAL)
9948 buf->b_p_fex = vim_strsave(p_fex);
9949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950#ifdef FEAT_CRYPT
9951 buf->b_p_key = vim_strsave(p_key);
9952#endif
9953#ifdef FEAT_SEARCHPATH
9954 buf->b_p_sua = vim_strsave(p_sua);
9955#endif
9956#ifdef FEAT_KEYMAP
9957 buf->b_p_keymap = vim_strsave(p_keymap);
9958 buf->b_kmap_state |= KEYMAP_INIT;
9959#endif
9960 /* This isn't really an option, but copying the langmap and IME
9961 * state from the current buffer is better than resetting it. */
9962 buf->b_p_iminsert = p_iminsert;
9963 buf->b_p_imsearch = p_imsearch;
9964
9965 /* options that are normally global but also have a local value
9966 * are not copied, start using the global value */
9967 buf->b_p_ar = -1;
9968#ifdef FEAT_QUICKFIX
9969 buf->b_p_gp = empty_option;
9970 buf->b_p_mp = empty_option;
9971 buf->b_p_efm = empty_option;
9972#endif
9973 buf->b_p_ep = empty_option;
9974 buf->b_p_kp = empty_option;
9975 buf->b_p_path = empty_option;
9976 buf->b_p_tags = empty_option;
9977#ifdef FEAT_FIND_ID
9978 buf->b_p_def = empty_option;
9979 buf->b_p_inc = empty_option;
9980# ifdef FEAT_EVAL
9981 buf->b_p_inex = vim_strsave(p_inex);
9982# endif
9983#endif
9984#ifdef FEAT_INS_EXPAND
9985 buf->b_p_dict = empty_option;
9986 buf->b_p_tsr = empty_option;
9987#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009988#ifdef FEAT_TEXTOBJ
9989 buf->b_p_qe = vim_strsave(p_qe);
9990#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009991#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9992 buf->b_p_bexpr = empty_option;
9993#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009994#ifdef FEAT_PERSISTENT_UNDO
9995 buf->b_p_udf = p_udf;
9996#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997
9998 /*
9999 * Don't copy the options set by ex_help(), use the saved values,
10000 * when going from a help buffer to a non-help buffer.
10001 * Don't touch these at all when BCO_NOHELP is used and going from
10002 * or to a help buffer.
10003 */
10004 if (dont_do_help)
10005 buf->b_p_isk = save_p_isk;
10006 else
10007 {
10008 buf->b_p_isk = vim_strsave(p_isk);
10009 did_isk = TRUE;
10010 buf->b_p_ts = p_ts;
10011 buf->b_help = FALSE;
10012#ifdef FEAT_QUICKFIX
10013 if (buf->b_p_bt[0] == 'h')
10014 clear_string_option(&buf->b_p_bt);
10015#endif
10016 buf->b_p_ma = p_ma;
10017 }
10018 }
10019
10020 /*
10021 * When the options should be copied (ignoring BCO_ALWAYS), set the
10022 * flag that indicates that the options have been initialized.
10023 */
10024 if (should_copy)
10025 buf->b_p_initialized = TRUE;
10026 }
10027
10028 check_buf_options(buf); /* make sure we don't have NULLs */
10029 if (did_isk)
10030 (void)buf_init_chartab(buf, FALSE);
10031}
10032
10033/*
10034 * Reset the 'modifiable' option and its default value.
10035 */
10036 void
10037reset_modifiable()
10038{
10039 int opt_idx;
10040
10041 curbuf->b_p_ma = FALSE;
10042 p_ma = FALSE;
10043 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010044 if (opt_idx >= 0)
10045 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046}
10047
10048/*
10049 * Set the global value for 'iminsert' to the local value.
10050 */
10051 void
10052set_iminsert_global()
10053{
10054 p_iminsert = curbuf->b_p_iminsert;
10055}
10056
10057/*
10058 * Set the global value for 'imsearch' to the local value.
10059 */
10060 void
10061set_imsearch_global()
10062{
10063 p_imsearch = curbuf->b_p_imsearch;
10064}
10065
10066#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10067static int expand_option_idx = -1;
10068static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10069static int expand_option_flags = 0;
10070
10071 void
10072set_context_in_set_cmd(xp, arg, opt_flags)
10073 expand_T *xp;
10074 char_u *arg;
10075 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10076{
10077 int nextchar;
10078 long_u flags = 0; /* init for GCC */
10079 int opt_idx = 0; /* init for GCC */
10080 char_u *p;
10081 char_u *s;
10082 int is_term_option = FALSE;
10083 int key;
10084
10085 expand_option_flags = opt_flags;
10086
10087 xp->xp_context = EXPAND_SETTINGS;
10088 if (*arg == NUL)
10089 {
10090 xp->xp_pattern = arg;
10091 return;
10092 }
10093 p = arg + STRLEN(arg) - 1;
10094 if (*p == ' ' && *(p - 1) != '\\')
10095 {
10096 xp->xp_pattern = p + 1;
10097 return;
10098 }
10099 while (p > arg)
10100 {
10101 s = p;
10102 /* count number of backslashes before ' ' or ',' */
10103 if (*p == ' ' || *p == ',')
10104 {
10105 while (s > arg && *(s - 1) == '\\')
10106 --s;
10107 }
10108 /* break at a space with an even number of backslashes */
10109 if (*p == ' ' && ((p - s) & 1) == 0)
10110 {
10111 ++p;
10112 break;
10113 }
10114 --p;
10115 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010116 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117 {
10118 xp->xp_context = EXPAND_BOOL_SETTINGS;
10119 p += 2;
10120 }
10121 if (STRNCMP(p, "inv", 3) == 0)
10122 {
10123 xp->xp_context = EXPAND_BOOL_SETTINGS;
10124 p += 3;
10125 }
10126 xp->xp_pattern = arg = p;
10127 if (*arg == '<')
10128 {
10129 while (*p != '>')
10130 if (*p++ == NUL) /* expand terminal option name */
10131 return;
10132 key = get_special_key_code(arg + 1);
10133 if (key == 0) /* unknown name */
10134 {
10135 xp->xp_context = EXPAND_NOTHING;
10136 return;
10137 }
10138 nextchar = *++p;
10139 is_term_option = TRUE;
10140 expand_option_name[2] = KEY2TERMCAP0(key);
10141 expand_option_name[3] = KEY2TERMCAP1(key);
10142 }
10143 else
10144 {
10145 if (p[0] == 't' && p[1] == '_')
10146 {
10147 p += 2;
10148 if (*p != NUL)
10149 ++p;
10150 if (*p == NUL)
10151 return; /* expand option name */
10152 nextchar = *++p;
10153 is_term_option = TRUE;
10154 expand_option_name[2] = p[-2];
10155 expand_option_name[3] = p[-1];
10156 }
10157 else
10158 {
10159 /* Allow * wildcard */
10160 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10161 p++;
10162 if (*p == NUL)
10163 return;
10164 nextchar = *p;
10165 *p = NUL;
10166 opt_idx = findoption(arg);
10167 *p = nextchar;
10168 if (opt_idx == -1 || options[opt_idx].var == NULL)
10169 {
10170 xp->xp_context = EXPAND_NOTHING;
10171 return;
10172 }
10173 flags = options[opt_idx].flags;
10174 if (flags & P_BOOL)
10175 {
10176 xp->xp_context = EXPAND_NOTHING;
10177 return;
10178 }
10179 }
10180 }
10181 /* handle "-=" and "+=" */
10182 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10183 {
10184 ++p;
10185 nextchar = '=';
10186 }
10187 if ((nextchar != '=' && nextchar != ':')
10188 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10189 {
10190 xp->xp_context = EXPAND_UNSUCCESSFUL;
10191 return;
10192 }
10193 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10194 {
10195 xp->xp_context = EXPAND_OLD_SETTING;
10196 if (is_term_option)
10197 expand_option_idx = -1;
10198 else
10199 expand_option_idx = opt_idx;
10200 xp->xp_pattern = p + 1;
10201 return;
10202 }
10203 xp->xp_context = EXPAND_NOTHING;
10204 if (is_term_option || (flags & P_NUM))
10205 return;
10206
10207 xp->xp_pattern = p + 1;
10208
10209 if (flags & P_EXPAND)
10210 {
10211 p = options[opt_idx].var;
10212 if (p == (char_u *)&p_bdir
10213 || p == (char_u *)&p_dir
10214 || p == (char_u *)&p_path
10215 || p == (char_u *)&p_rtp
10216#ifdef FEAT_SEARCHPATH
10217 || p == (char_u *)&p_cdpath
10218#endif
10219#ifdef FEAT_SESSION
10220 || p == (char_u *)&p_vdir
10221#endif
10222 )
10223 {
10224 xp->xp_context = EXPAND_DIRECTORIES;
10225 if (p == (char_u *)&p_path
10226#ifdef FEAT_SEARCHPATH
10227 || p == (char_u *)&p_cdpath
10228#endif
10229 )
10230 xp->xp_backslash = XP_BS_THREE;
10231 else
10232 xp->xp_backslash = XP_BS_ONE;
10233 }
10234 else
10235 {
10236 xp->xp_context = EXPAND_FILES;
10237 /* for 'tags' need three backslashes for a space */
10238 if (p == (char_u *)&p_tags)
10239 xp->xp_backslash = XP_BS_THREE;
10240 else
10241 xp->xp_backslash = XP_BS_ONE;
10242 }
10243 }
10244
10245 /* For an option that is a list of file names, find the start of the
10246 * last file name. */
10247 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10248 {
10249 /* count number of backslashes before ' ' or ',' */
10250 if (*p == ' ' || *p == ',')
10251 {
10252 s = p;
10253 while (s > xp->xp_pattern && *(s - 1) == '\\')
10254 --s;
10255 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10256 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10257 {
10258 xp->xp_pattern = p + 1;
10259 break;
10260 }
10261 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010262
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010263#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010264 /* for 'spellsuggest' start at "file:" */
10265 if (options[opt_idx].var == (char_u *)&p_sps
10266 && STRNCMP(p, "file:", 5) == 0)
10267 {
10268 xp->xp_pattern = p + 5;
10269 break;
10270 }
10271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 }
10273
10274 return;
10275}
10276
10277 int
10278ExpandSettings(xp, regmatch, num_file, file)
10279 expand_T *xp;
10280 regmatch_T *regmatch;
10281 int *num_file;
10282 char_u ***file;
10283{
10284 int num_normal = 0; /* Nr of matching non-term-code settings */
10285 int num_term = 0; /* Nr of matching terminal code settings */
10286 int opt_idx;
10287 int match;
10288 int count = 0;
10289 char_u *str;
10290 int loop;
10291 int is_term_opt;
10292 char_u name_buf[MAX_KEY_NAME_LEN];
10293 static char *(names[]) = {"all", "termcap"};
10294 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10295
10296 /* do this loop twice:
10297 * loop == 0: count the number of matching options
10298 * loop == 1: copy the matching options into allocated memory
10299 */
10300 for (loop = 0; loop <= 1; ++loop)
10301 {
10302 regmatch->rm_ic = ic;
10303 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10304 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010305 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10306 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10308 {
10309 if (loop == 0)
10310 num_normal++;
10311 else
10312 (*file)[count++] = vim_strsave((char_u *)names[match]);
10313 }
10314 }
10315 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10316 opt_idx++)
10317 {
10318 if (options[opt_idx].var == NULL)
10319 continue;
10320 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10321 && !(options[opt_idx].flags & P_BOOL))
10322 continue;
10323 is_term_opt = istermoption(&options[opt_idx]);
10324 if (is_term_opt && num_normal > 0)
10325 continue;
10326 match = FALSE;
10327 if (vim_regexec(regmatch, str, (colnr_T)0)
10328 || (options[opt_idx].shortname != NULL
10329 && vim_regexec(regmatch,
10330 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10331 match = TRUE;
10332 else if (is_term_opt)
10333 {
10334 name_buf[0] = '<';
10335 name_buf[1] = 't';
10336 name_buf[2] = '_';
10337 name_buf[3] = str[2];
10338 name_buf[4] = str[3];
10339 name_buf[5] = '>';
10340 name_buf[6] = NUL;
10341 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10342 {
10343 match = TRUE;
10344 str = name_buf;
10345 }
10346 }
10347 if (match)
10348 {
10349 if (loop == 0)
10350 {
10351 if (is_term_opt)
10352 num_term++;
10353 else
10354 num_normal++;
10355 }
10356 else
10357 (*file)[count++] = vim_strsave(str);
10358 }
10359 }
10360 /*
10361 * Check terminal key codes, these are not in the option table
10362 */
10363 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10364 {
10365 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10366 {
10367 if (!isprint(str[0]) || !isprint(str[1]))
10368 continue;
10369
10370 name_buf[0] = 't';
10371 name_buf[1] = '_';
10372 name_buf[2] = str[0];
10373 name_buf[3] = str[1];
10374 name_buf[4] = NUL;
10375
10376 match = FALSE;
10377 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10378 match = TRUE;
10379 else
10380 {
10381 name_buf[0] = '<';
10382 name_buf[1] = 't';
10383 name_buf[2] = '_';
10384 name_buf[3] = str[0];
10385 name_buf[4] = str[1];
10386 name_buf[5] = '>';
10387 name_buf[6] = NUL;
10388
10389 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10390 match = TRUE;
10391 }
10392 if (match)
10393 {
10394 if (loop == 0)
10395 num_term++;
10396 else
10397 (*file)[count++] = vim_strsave(name_buf);
10398 }
10399 }
10400
10401 /*
10402 * Check special key names.
10403 */
10404 regmatch->rm_ic = TRUE; /* ignore case here */
10405 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10406 {
10407 name_buf[0] = '<';
10408 STRCPY(name_buf + 1, str);
10409 STRCAT(name_buf, ">");
10410
10411 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10412 {
10413 if (loop == 0)
10414 num_term++;
10415 else
10416 (*file)[count++] = vim_strsave(name_buf);
10417 }
10418 }
10419 }
10420 if (loop == 0)
10421 {
10422 if (num_normal > 0)
10423 *num_file = num_normal;
10424 else if (num_term > 0)
10425 *num_file = num_term;
10426 else
10427 return OK;
10428 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10429 if (*file == NULL)
10430 {
10431 *file = (char_u **)"";
10432 return FAIL;
10433 }
10434 }
10435 }
10436 return OK;
10437}
10438
10439 int
10440ExpandOldSetting(num_file, file)
10441 int *num_file;
10442 char_u ***file;
10443{
10444 char_u *var = NULL; /* init for GCC */
10445 char_u *buf;
10446
10447 *num_file = 0;
10448 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10449 if (*file == NULL)
10450 return FAIL;
10451
10452 /*
10453 * For a terminal key code expand_option_idx is < 0.
10454 */
10455 if (expand_option_idx < 0)
10456 {
10457 var = find_termcode(expand_option_name + 2);
10458 if (var == NULL)
10459 expand_option_idx = findoption(expand_option_name);
10460 }
10461
10462 if (expand_option_idx >= 0)
10463 {
10464 /* put string of option value in NameBuff */
10465 option_value2string(&options[expand_option_idx], expand_option_flags);
10466 var = NameBuff;
10467 }
10468 else if (var == NULL)
10469 var = (char_u *)"";
10470
10471 /* A backslash is required before some characters. This is the reverse of
10472 * what happens in do_set(). */
10473 buf = vim_strsave_escaped(var, escape_chars);
10474
10475 if (buf == NULL)
10476 {
10477 vim_free(*file);
10478 *file = NULL;
10479 return FAIL;
10480 }
10481
10482#ifdef BACKSLASH_IN_FILENAME
10483 /* For MS-Windows et al. we don't double backslashes at the start and
10484 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010485 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 if (var[0] == '\\' && var[1] == '\\'
10487 && expand_option_idx >= 0
10488 && (options[expand_option_idx].flags & P_EXPAND)
10489 && vim_isfilec(var[2])
10490 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010491 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492#endif
10493
10494 *file[0] = buf;
10495 *num_file = 1;
10496 return OK;
10497}
10498#endif
10499
10500/*
10501 * Get the value for the numeric or string option *opp in a nice format into
10502 * NameBuff[]. Must not be called with a hidden option!
10503 */
10504 static void
10505option_value2string(opp, opt_flags)
10506 struct vimoption *opp;
10507 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10508{
10509 char_u *varp;
10510
10511 varp = get_varp_scope(opp, opt_flags);
10512
10513 if (opp->flags & P_NUM)
10514 {
10515 long wc = 0;
10516
10517 if (wc_use_keyname(varp, &wc))
10518 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10519 else if (wc != 0)
10520 STRCPY(NameBuff, transchar((int)wc));
10521 else
10522 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10523 }
10524 else /* P_STRING */
10525 {
10526 varp = *(char_u **)(varp);
10527 if (varp == NULL) /* just in case */
10528 NameBuff[0] = NUL;
10529#ifdef FEAT_CRYPT
10530 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010531 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 STRCPY(NameBuff, "*****");
10533#endif
10534 else if (opp->flags & P_EXPAND)
10535 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10536 /* Translate 'pastetoggle' into special key names */
10537 else if ((char_u **)opp->var == &p_pt)
10538 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10539 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010540 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 }
10542}
10543
10544/*
10545 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10546 * printed as a keyname.
10547 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10548 */
10549 static int
10550wc_use_keyname(varp, wcp)
10551 char_u *varp;
10552 long *wcp;
10553{
10554 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10555 {
10556 *wcp = *(long *)varp;
10557 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10558 return TRUE;
10559 }
10560 return FALSE;
10561}
10562
10563#ifdef FEAT_LANGMAP
10564/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010565 * Any character has an equivalent 'langmap' character. This is used for
10566 * keyboards that have a special language mode that sends characters above
10567 * 128 (although other characters can be translated too). The "to" field is a
10568 * Vim command character. This avoids having to switch the keyboard back to
10569 * ASCII mode when leaving Insert mode.
10570 *
10571 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10572 * commands.
10573 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10574 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10575 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010577# ifdef FEAT_MBYTE
10578/*
10579 * With multi-byte support use growarray for 'langmap' chars >= 256
10580 */
10581typedef struct
10582{
10583 int from;
10584 int to;
10585} langmap_entry_T;
10586
10587static garray_T langmap_mapga;
10588static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589
10590/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010591 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10592 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010594 static void
10595langmap_set_entry(from, to)
10596 int from;
10597 int to;
10598{
10599 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010600 int a = 0;
10601 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010602
10603 /* Do a binary search for an existing entry. */
10604 while (a != b)
10605 {
10606 int i = (a + b) / 2;
10607 int d = entries[i].from - from;
10608
10609 if (d == 0)
10610 {
10611 entries[i].to = to;
10612 return;
10613 }
10614 if (d < 0)
10615 a = i + 1;
10616 else
10617 b = i;
10618 }
10619
10620 if (ga_grow(&langmap_mapga, 1) != OK)
10621 return; /* out of memory */
10622
10623 /* insert new entry at position "a" */
10624 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10625 mch_memmove(entries + 1, entries,
10626 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10627 ++langmap_mapga.ga_len;
10628 entries[0].from = from;
10629 entries[0].to = to;
10630}
10631
10632/*
10633 * Apply 'langmap' to multi-byte character "c" and return the result.
10634 */
10635 int
10636langmap_adjust_mb(c)
10637 int c;
10638{
10639 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10640 int a = 0;
10641 int b = langmap_mapga.ga_len;
10642
10643 while (a != b)
10644 {
10645 int i = (a + b) / 2;
10646 int d = entries[i].from - c;
10647
10648 if (d == 0)
10649 return entries[i].to; /* found matching entry */
10650 if (d < 0)
10651 a = i + 1;
10652 else
10653 b = i;
10654 }
10655 return c; /* no entry found, return "c" unmodified */
10656}
10657# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010658
10659 static void
10660langmap_init()
10661{
10662 int i;
10663
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010664 for (i = 0; i < 256; i++)
10665 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10666# ifdef FEAT_MBYTE
10667 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10668# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669}
10670
10671/*
10672 * Called when langmap option is set; the language map can be
10673 * changed at any time!
10674 */
10675 static void
10676langmap_set()
10677{
10678 char_u *p;
10679 char_u *p2;
10680 int from, to;
10681
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010682#ifdef FEAT_MBYTE
10683 ga_clear(&langmap_mapga); /* clear the previous map first */
10684#endif
10685 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686
10687 for (p = p_langmap; p[0] != NUL; )
10688 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010689 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10690 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691 {
10692 if (p2[0] == '\\' && p2[1] != NUL)
10693 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 }
10695 if (p2[0] == ';')
10696 ++p2; /* abcd;ABCD form, p2 points to A */
10697 else
10698 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10699 while (p[0])
10700 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010701 if (p[0] == ',')
10702 {
10703 ++p;
10704 break;
10705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706 if (p[0] == '\\' && p[1] != NUL)
10707 ++p;
10708#ifdef FEAT_MBYTE
10709 from = (*mb_ptr2char)(p);
10710#else
10711 from = p[0];
10712#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010713 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714 if (p2 == NULL)
10715 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010716 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010717 if (p[0] != ',')
10718 {
10719 if (p[0] == '\\')
10720 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010722 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010724 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 }
10728 else
10729 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010730 if (p2[0] != ',')
10731 {
10732 if (p2[0] == '\\')
10733 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010735 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010737 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740 }
10741 if (to == NUL)
10742 {
10743 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10744 transchar(from));
10745 return;
10746 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010747
10748#ifdef FEAT_MBYTE
10749 if (from >= 256)
10750 langmap_set_entry(from, to);
10751 else
10752#endif
10753 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754
10755 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010756 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010757 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010758 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010759 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760 if (*p == ';')
10761 {
10762 p = p2;
10763 if (p[0] != NUL)
10764 {
10765 if (p[0] != ',')
10766 {
10767 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10768 return;
10769 }
10770 ++p;
10771 }
10772 break;
10773 }
10774 }
10775 }
10776 }
10777}
10778#endif
10779
10780/*
10781 * Return TRUE if format option 'x' is in effect.
10782 * Take care of no formatting when 'paste' is set.
10783 */
10784 int
10785has_format_option(x)
10786 int x;
10787{
10788 if (p_paste)
10789 return FALSE;
10790 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10791}
10792
10793/*
10794 * Return TRUE if "x" is present in 'shortmess' option, or
10795 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10796 */
10797 int
10798shortmess(x)
10799 int x;
10800{
10801 return ( vim_strchr(p_shm, x) != NULL
10802 || (vim_strchr(p_shm, 'a') != NULL
10803 && vim_strchr((char_u *)SHM_A, x) != NULL));
10804}
10805
10806/*
10807 * paste_option_changed() - Called after p_paste was set or reset.
10808 */
10809 static void
10810paste_option_changed()
10811{
10812 static int old_p_paste = FALSE;
10813 static int save_sm = 0;
10814#ifdef FEAT_CMDL_INFO
10815 static int save_ru = 0;
10816#endif
10817#ifdef FEAT_RIGHTLEFT
10818 static int save_ri = 0;
10819 static int save_hkmap = 0;
10820#endif
10821 buf_T *buf;
10822
10823 if (p_paste)
10824 {
10825 /*
10826 * Paste switched from off to on.
10827 * Save the current values, so they can be restored later.
10828 */
10829 if (!old_p_paste)
10830 {
10831 /* save options for each buffer */
10832 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10833 {
10834 buf->b_p_tw_nopaste = buf->b_p_tw;
10835 buf->b_p_wm_nopaste = buf->b_p_wm;
10836 buf->b_p_sts_nopaste = buf->b_p_sts;
10837 buf->b_p_ai_nopaste = buf->b_p_ai;
10838 }
10839
10840 /* save global options */
10841 save_sm = p_sm;
10842#ifdef FEAT_CMDL_INFO
10843 save_ru = p_ru;
10844#endif
10845#ifdef FEAT_RIGHTLEFT
10846 save_ri = p_ri;
10847 save_hkmap = p_hkmap;
10848#endif
10849 /* save global values for local buffer options */
10850 p_tw_nopaste = p_tw;
10851 p_wm_nopaste = p_wm;
10852 p_sts_nopaste = p_sts;
10853 p_ai_nopaste = p_ai;
10854 }
10855
10856 /*
10857 * Always set the option values, also when 'paste' is set when it is
10858 * already on.
10859 */
10860 /* set options for each buffer */
10861 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10862 {
10863 buf->b_p_tw = 0; /* textwidth is 0 */
10864 buf->b_p_wm = 0; /* wrapmargin is 0 */
10865 buf->b_p_sts = 0; /* softtabstop is 0 */
10866 buf->b_p_ai = 0; /* no auto-indent */
10867 }
10868
10869 /* set global options */
10870 p_sm = 0; /* no showmatch */
10871#ifdef FEAT_CMDL_INFO
10872# ifdef FEAT_WINDOWS
10873 if (p_ru)
10874 status_redraw_all(); /* redraw to remove the ruler */
10875# endif
10876 p_ru = 0; /* no ruler */
10877#endif
10878#ifdef FEAT_RIGHTLEFT
10879 p_ri = 0; /* no reverse insert */
10880 p_hkmap = 0; /* no Hebrew keyboard */
10881#endif
10882 /* set global values for local buffer options */
10883 p_tw = 0;
10884 p_wm = 0;
10885 p_sts = 0;
10886 p_ai = 0;
10887 }
10888
10889 /*
10890 * Paste switched from on to off: Restore saved values.
10891 */
10892 else if (old_p_paste)
10893 {
10894 /* restore options for each buffer */
10895 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10896 {
10897 buf->b_p_tw = buf->b_p_tw_nopaste;
10898 buf->b_p_wm = buf->b_p_wm_nopaste;
10899 buf->b_p_sts = buf->b_p_sts_nopaste;
10900 buf->b_p_ai = buf->b_p_ai_nopaste;
10901 }
10902
10903 /* restore global options */
10904 p_sm = save_sm;
10905#ifdef FEAT_CMDL_INFO
10906# ifdef FEAT_WINDOWS
10907 if (p_ru != save_ru)
10908 status_redraw_all(); /* redraw to draw the ruler */
10909# endif
10910 p_ru = save_ru;
10911#endif
10912#ifdef FEAT_RIGHTLEFT
10913 p_ri = save_ri;
10914 p_hkmap = save_hkmap;
10915#endif
10916 /* set global values for local buffer options */
10917 p_tw = p_tw_nopaste;
10918 p_wm = p_wm_nopaste;
10919 p_sts = p_sts_nopaste;
10920 p_ai = p_ai_nopaste;
10921 }
10922
10923 old_p_paste = p_paste;
10924}
10925
10926/*
10927 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10928 *
10929 * Reset 'compatible' and set the values for options that didn't get set yet
10930 * to the Vim defaults.
10931 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010932 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933 */
10934 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010935vimrc_found(fname, envname)
10936 char_u *fname;
10937 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010939 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010940 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010941 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942
10943 if (!option_was_set((char_u *)"cp"))
10944 {
10945 p_cp = FALSE;
10946 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10947 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10948 set_option_default(opt_idx, OPT_FREE, FALSE);
10949 didset_options();
10950 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010951
10952 if (fname != NULL)
10953 {
10954 p = vim_getenv(envname, &dofree);
10955 if (p == NULL)
10956 {
10957 /* Set $MYVIMRC to the first vimrc file found. */
10958 p = FullName_save(fname, FALSE);
10959 if (p != NULL)
10960 {
10961 vim_setenv(envname, p);
10962 vim_free(p);
10963 }
10964 }
10965 else if (dofree)
10966 vim_free(p);
10967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968}
10969
10970/*
10971 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10972 */
10973 void
10974change_compatible(on)
10975 int on;
10976{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010977 int opt_idx;
10978
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979 if (p_cp != on)
10980 {
10981 p_cp = on;
10982 compatible_set();
10983 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010984 opt_idx = findoption((char_u *)"cp");
10985 if (opt_idx >= 0)
10986 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987}
10988
10989/*
10990 * Return TRUE when option "name" has been set.
10991 */
10992 int
10993option_was_set(name)
10994 char_u *name;
10995{
10996 int idx;
10997
10998 idx = findoption(name);
10999 if (idx < 0) /* unknown option */
11000 return FALSE;
11001 if (options[idx].flags & P_WAS_SET)
11002 return TRUE;
11003 return FALSE;
11004}
11005
11006/*
11007 * compatible_set() - Called when 'compatible' has been set or unset.
11008 *
11009 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11010 * flag) to a Vi compatible value.
11011 * When 'compatible' is unset: Set all options that have a different default
11012 * for Vim (without the P_VI_DEF flag) to that default.
11013 */
11014 static void
11015compatible_set()
11016{
11017 int opt_idx;
11018
11019 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11020 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11021 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11022 set_option_default(opt_idx, OPT_FREE, p_cp);
11023 didset_options();
11024}
11025
11026#ifdef FEAT_LINEBREAK
11027
11028# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11029 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011030 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011031# endif
11032
11033/*
11034 * fill_breakat_flags() -- called when 'breakat' changes value.
11035 */
11036 static void
11037fill_breakat_flags()
11038{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011039 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040 int i;
11041
11042 for (i = 0; i < 256; i++)
11043 breakat_flags[i] = FALSE;
11044
11045 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011046 for (p = p_breakat; *p; p++)
11047 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048}
11049
11050# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011051 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052# endif
11053
11054#endif
11055
11056/*
11057 * Check an option that can be a range of string values.
11058 *
11059 * Return OK for correct value, FAIL otherwise.
11060 * Empty is always OK.
11061 */
11062 static int
11063check_opt_strings(val, values, list)
11064 char_u *val;
11065 char **values;
11066 int list; /* when TRUE: accept a list of values */
11067{
11068 return opt_strings_flags(val, values, NULL, list);
11069}
11070
11071/*
11072 * Handle an option that can be a range of string values.
11073 * Set a flag in "*flagp" for each string present.
11074 *
11075 * Return OK for correct value, FAIL otherwise.
11076 * Empty is always OK.
11077 */
11078 static int
11079opt_strings_flags(val, values, flagp, list)
11080 char_u *val; /* new value */
11081 char **values; /* array of valid string values */
11082 unsigned *flagp;
11083 int list; /* when TRUE: accept a list of values */
11084{
11085 int i;
11086 int len;
11087 unsigned new_flags = 0;
11088
11089 while (*val)
11090 {
11091 for (i = 0; ; ++i)
11092 {
11093 if (values[i] == NULL) /* val not found in values[] */
11094 return FAIL;
11095
11096 len = (int)STRLEN(values[i]);
11097 if (STRNCMP(values[i], val, len) == 0
11098 && ((list && val[len] == ',') || val[len] == NUL))
11099 {
11100 val += len + (val[len] == ',');
11101 new_flags |= (1 << i);
11102 break; /* check next item in val list */
11103 }
11104 }
11105 }
11106 if (flagp != NULL)
11107 *flagp = new_flags;
11108
11109 return OK;
11110}
11111
11112/*
11113 * Read the 'wildmode' option, fill wim_flags[].
11114 */
11115 static int
11116check_opt_wim()
11117{
11118 char_u new_wim_flags[4];
11119 char_u *p;
11120 int i;
11121 int idx = 0;
11122
11123 for (i = 0; i < 4; ++i)
11124 new_wim_flags[i] = 0;
11125
11126 for (p = p_wim; *p; ++p)
11127 {
11128 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11129 ;
11130 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11131 return FAIL;
11132 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11133 new_wim_flags[idx] |= WIM_LONGEST;
11134 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11135 new_wim_flags[idx] |= WIM_FULL;
11136 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11137 new_wim_flags[idx] |= WIM_LIST;
11138 else
11139 return FAIL;
11140 p += i;
11141 if (*p == NUL)
11142 break;
11143 if (*p == ',')
11144 {
11145 if (idx == 3)
11146 return FAIL;
11147 ++idx;
11148 }
11149 }
11150
11151 /* fill remaining entries with last flag */
11152 while (idx < 3)
11153 {
11154 new_wim_flags[idx + 1] = new_wim_flags[idx];
11155 ++idx;
11156 }
11157
11158 /* only when there are no errors, wim_flags[] is changed */
11159 for (i = 0; i < 4; ++i)
11160 wim_flags[i] = new_wim_flags[i];
11161 return OK;
11162}
11163
11164/*
11165 * Check if backspacing over something is allowed.
11166 */
11167 int
11168can_bs(what)
11169 int what; /* BS_INDENT, BS_EOL or BS_START */
11170{
11171 switch (*p_bs)
11172 {
11173 case '2': return TRUE;
11174 case '1': return (what != BS_START);
11175 case '0': return FALSE;
11176 }
11177 return vim_strchr(p_bs, what) != NULL;
11178}
11179
11180/*
11181 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11182 * the file must be considered changed when the value is different.
11183 */
11184 void
11185save_file_ff(buf)
11186 buf_T *buf;
11187{
11188 buf->b_start_ffc = *buf->b_p_ff;
11189 buf->b_start_eol = buf->b_p_eol;
11190#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011191 buf->b_start_bomb = buf->b_p_bomb;
11192
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193 /* Only use free/alloc when necessary, they take time. */
11194 if (buf->b_start_fenc == NULL
11195 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11196 {
11197 vim_free(buf->b_start_fenc);
11198 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11199 }
11200#endif
11201}
11202
11203/*
11204 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11205 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011206 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11207 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208 * Don't consider a new, empty buffer to be changed.
11209 */
11210 int
11211file_ff_differs(buf)
11212 buf_T *buf;
11213{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011214 /* In a buffer that was never loaded the options are not valid. */
11215 if (buf->b_flags & BF_NEVERLOADED)
11216 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 if ((buf->b_flags & BF_NEW)
11218 && buf->b_ml.ml_line_count == 1
11219 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11220 return FALSE;
11221 if (buf->b_start_ffc != *buf->b_p_ff)
11222 return TRUE;
11223 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11224 return TRUE;
11225#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011226 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11227 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011228 if (buf->b_start_fenc == NULL)
11229 return (*buf->b_p_fenc != NUL);
11230 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11231#else
11232 return FALSE;
11233#endif
11234}
11235
11236/*
11237 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11238 */
11239 int
11240check_ff_value(p)
11241 char_u *p;
11242{
11243 return check_opt_strings(p, p_ff_values, FALSE);
11244}