blob: 27a82fde20aa847d378d83b8ab429e138764a447 [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 Moolenaar865242e2010-07-14 21:12:05 +0200454#define P_NO_ML 0x1000000L/* not allowed in modeline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000456#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
457
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000458/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
459 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000460#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000461# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000462#else
463# define ISP_LATIN1 (char_u *)"@,161-255"
464#endif
465
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466/* The 16 bit MS-DOS version is low on space, make the string as short as
467 * possible when compiling with few features. */
468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
469 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200471# 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 +0000472#else
473# 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"
474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
484static struct vimoption
485#ifdef FEAT_GUI_W16
486 _far
487#endif
488 options[] =
489{
490 {"aleph", "al", P_NUM|P_VI_DEF,
491#ifdef FEAT_RIGHTLEFT
492 (char_u *)&p_aleph, PV_NONE,
493#else
494 (char_u *)NULL, PV_NONE,
495#endif
496 {
497#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
498 (char_u *)128L,
499#else
500 (char_u *)224L,
501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
504#if defined(FEAT_GUI) && defined(MACOS_X)
505 (char_u *)&p_antialias, PV_NONE,
506 {(char_u *)FALSE, (char_u *)FALSE}
507#else
508 (char_u *)NULL, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
513#ifdef FEAT_ARABIC
514 (char_u *)VAR_WIN, PV_ARAB,
515#else
516 (char_u *)NULL, PV_NONE,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#ifdef FEAT_ARABIC
521 (char_u *)&p_arshape, PV_NONE,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
527#ifdef FEAT_RIGHTLEFT
528 (char_u *)&p_ari, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
534#ifdef FEAT_FKMAP
535 (char_u *)&p_altkeymap, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
541#if defined(FEAT_MBYTE)
542 (char_u *)&p_ambw, PV_NONE,
543 {(char_u *)"single", (char_u *)0L}
544#else
545 (char_u *)NULL, PV_NONE,
546 {(char_u *)0L, (char_u *)0L}
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000549#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
551 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553#endif
554 {"autoindent", "ai", P_BOOL|P_VI_DEF,
555 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autoprint", "ap", P_BOOL|P_VI_DEF,
558 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000561 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autowrite", "aw", P_BOOL|P_VI_DEF,
564 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowriteall","awa", P_BOOL|P_VI_DEF,
567 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
570 (char_u *)&p_bg, PV_NONE,
571 {
572#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
573 (char_u *)"dark",
574#else
575 (char_u *)"light",
576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
579 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
582 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
585 (char_u *)&p_bkc, PV_NONE,
586#ifdef UNIX
587 {(char_u *)"yes", (char_u *)"auto"}
588#else
589 {(char_u *)"auto", (char_u *)"auto"}
590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
633#ifdef MSDOS
634 (char_u *)&p_biosk, PV_NONE,
635#else
636 (char_u *)NULL, PV_NONE,
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
640#ifdef FEAT_MBYTE
641 (char_u *)&p_bomb, PV_BOMB,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
647#ifdef FEAT_LINEBREAK
648 (char_u *)&p_breakat, PV_NONE,
649 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
656#ifdef FEAT_BROWSE
657 (char_u *)&p_bsdir, PV_NONE,
658 {(char_u *)"last", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
665#if defined(FEAT_QUICKFIX)
666 (char_u *)&p_bh, PV_BH,
667 {(char_u *)"", (char_u *)0L}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)0L, (char_u *)0L}
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
674 (char_u *)&p_bl, PV_BL,
675 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
678#if defined(FEAT_QUICKFIX)
679 (char_u *)&p_bt, PV_BT,
680 {(char_u *)"", (char_u *)0L}
681#else
682 (char_u *)NULL, PV_NONE,
683 {(char_u *)0L, (char_u *)0L}
684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000685 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000686 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000687#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 (char_u *)&p_cmp, PV_NONE,
689 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000690#else
691 (char_u *)NULL, PV_NONE,
692 {(char_u *)0L, (char_u *)0L}
693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
696#ifdef FEAT_SEARCHPATH
697 (char_u *)&p_cdpath, PV_NONE,
698 {(char_u *)",,", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"cedit", NULL, P_STRING,
705#ifdef FEAT_CMDWIN
706 (char_u *)&p_cedit, PV_NONE,
707 {(char_u *)"", (char_u *)CTRL_F_STR}
708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
714#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
715 (char_u *)&p_ccv, PV_NONE,
716 {(char_u *)"", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
723#ifdef FEAT_CINDENT
724 (char_u *)&p_cin, PV_CIN,
725#else
726 (char_u *)NULL, PV_NONE,
727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
730#ifdef FEAT_CINDENT
731 (char_u *)&p_cink, PV_CINK,
732 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
733#else
734 (char_u *)NULL, PV_NONE,
735 {(char_u *)0L, (char_u *)0L}
736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000737 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
739#ifdef FEAT_CINDENT
740 (char_u *)&p_cino, PV_CINO,
741#else
742 (char_u *)NULL, PV_NONE,
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
746#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
747 (char_u *)&p_cinw, PV_CINW,
748 {(char_u *)"if,else,while,do,for,switch",
749 (char_u *)0L}
750#else
751 (char_u *)NULL, PV_NONE,
752 {(char_u *)0L, (char_u *)0L}
753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000754 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
756#ifdef FEAT_CLIPBOARD
757 (char_u *)&p_cb, PV_NONE,
758# ifdef FEAT_XCLIPBOARD
759 {(char_u *)"autoselect,exclude:cons\\|linux",
760 (char_u *)0L}
761# else
762 {(char_u *)"", (char_u *)0L}
763# endif
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)"", (char_u *)0L}
767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
770 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000771 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
773#ifdef FEAT_CMDWIN
774 (char_u *)&p_cwh, PV_NONE,
775#else
776 (char_u *)NULL, PV_NONE,
777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000778 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200779 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
780#ifdef FEAT_SYN_HL
781 (char_u *)VAR_WIN, PV_CC,
782#else
783 (char_u *)NULL, PV_NONE,
784#endif
785 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
787 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000788 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000789 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
790#ifdef FEAT_COMMENTS
791 (char_u *)&p_com, PV_COM,
792 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
793 (char_u *)0L}
794#else
795 (char_u *)NULL, PV_NONE,
796 {(char_u *)0L, (char_u *)0L}
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
800#ifdef FEAT_FOLDING
801 (char_u *)&p_cms, PV_CMS,
802 {(char_u *)"/*%s*/", (char_u *)0L}
803#else
804 (char_u *)NULL, PV_NONE,
805 {(char_u *)0L, (char_u *)0L}
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000808 /* P_PRI_MKRC isn't needed here, optval_default()
809 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"compatible", "cp", P_BOOL|P_RALL,
811 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000812 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
814#ifdef FEAT_INS_EXPAND
815 (char_u *)&p_cpt, PV_CPT,
816 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
817#else
818 (char_u *)NULL, PV_NONE,
819 {(char_u *)0L, (char_u *)0L}
820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000821 SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200822 {"conceallevel","conc", P_NUM|P_RWIN|P_VI_DEF,
823#ifdef FEAT_CONCEAL
824 (char_u *)VAR_WIN, PV_CONCEAL,
825#else
826 (char_u *)NULL, PV_NONE,
827#endif
828 {(char_u *)0L, (char_u *)0L}
829 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000830 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
831#ifdef FEAT_COMPL_FUNC
832 (char_u *)&p_cfu, PV_CFU,
833 {(char_u *)"", (char_u *)0L}
834#else
835 (char_u *)NULL, PV_NONE,
836 {(char_u *)0L, (char_u *)0L}
837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000839 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
840#ifdef FEAT_INS_EXPAND
841 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000842 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000843#else
844 (char_u *)NULL, PV_NONE,
845 {(char_u *)0L, (char_u *)0L}
846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000847 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"confirm", "cf", P_BOOL|P_VI_DEF,
849#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
850 (char_u *)&p_confirm, PV_NONE,
851#else
852 (char_u *)NULL, PV_NONE,
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000855 {"conskey", "consk",P_BOOL|P_VI_DEF,
856#ifdef MSDOS
857 (char_u *)&p_consk, PV_NONE,
858#else
859 (char_u *)NULL, PV_NONE,
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
863 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
866 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
868 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200869 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200870#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200871 (char_u *)&p_cm, PV_CM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200872#else
873 (char_u *)NULL, PV_NONE,
874#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200875 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
877#ifdef FEAT_CSCOPE
878 (char_u *)&p_cspc, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
884#ifdef FEAT_CSCOPE
885 (char_u *)&p_csprg, PV_NONE,
886 {(char_u *)"cscope", (char_u *)0L}
887#else
888 (char_u *)NULL, PV_NONE,
889 {(char_u *)0L, (char_u *)0L}
890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
893#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
894 (char_u *)&p_csqf, PV_NONE,
895 {(char_u *)"", (char_u *)0L}
896#else
897 (char_u *)NULL, PV_NONE,
898 {(char_u *)0L, (char_u *)0L}
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
902#ifdef FEAT_CSCOPE
903 (char_u *)&p_cst, PV_NONE,
904#else
905 (char_u *)NULL, PV_NONE,
906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
909#ifdef FEAT_CSCOPE
910 (char_u *)&p_csto, PV_NONE,
911#else
912 (char_u *)NULL, PV_NONE,
913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
916#ifdef FEAT_CSCOPE
917 (char_u *)&p_csverbose, PV_NONE,
918#else
919 (char_u *)NULL, PV_NONE,
920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200922 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
923#ifdef FEAT_CURSORBIND
924 (char_u *)VAR_WIN, PV_CRBIND,
925#else
926 (char_u *)NULL, PV_NONE,
927#endif
928 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000929 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
930#ifdef FEAT_SYN_HL
931 (char_u *)VAR_WIN, PV_CUC,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000936 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
937#ifdef FEAT_SYN_HL
938 (char_u *)VAR_WIN, PV_CUL,
939#else
940 (char_u *)NULL, PV_NONE,
941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000942 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943 {"debug", NULL, P_STRING|P_VI_DEF,
944 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
947#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000948 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000949 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950#else
951 (char_u *)NULL, PV_NONE,
952 {(char_u *)NULL, (char_u *)0L}
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
956#ifdef FEAT_MBYTE
957 (char_u *)&p_deco, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
963#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000964 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
970#ifdef FEAT_DIFF
971 (char_u *)VAR_WIN, PV_DIFF,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
977#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
978 (char_u *)&p_dex, PV_NONE,
979 {(char_u *)"", (char_u *)0L}
980#else
981 (char_u *)NULL, PV_NONE,
982 {(char_u *)0L, (char_u *)0L}
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
986#ifdef FEAT_DIFF
987 (char_u *)&p_dip, PV_NONE,
988 {(char_u *)"filler", (char_u *)NULL}
989#else
990 (char_u *)NULL, PV_NONE,
991 {(char_u *)"", (char_u *)NULL}
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
995#ifdef FEAT_DIGRAPHS
996 (char_u *)&p_dg, PV_NONE,
997#else
998 (char_u *)NULL, PV_NONE,
999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001000 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1002 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1005 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"eadirection", "ead", P_STRING|P_VI_DEF,
1008#ifdef FEAT_VERTSPLIT
1009 (char_u *)&p_ead, PV_NONE,
1010 {(char_u *)"both", (char_u *)0L}
1011#else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)NULL, (char_u *)0L}
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1017 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001018 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001019 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020#ifdef FEAT_MBYTE
1021 (char_u *)&p_enc, PV_NONE,
1022 {(char_u *)ENC_DFLT, (char_u *)0L}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)0L, (char_u *)0L}
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1029 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1032 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001035 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1038 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1041#ifdef FEAT_QUICKFIX
1042 (char_u *)&p_ef, PV_NONE,
1043 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1044#else
1045 (char_u *)NULL, PV_NONE,
1046 {(char_u *)NULL, (char_u *)0L}
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1050#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001051 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)NULL, (char_u *)0L}
1056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"esckeys", "ek", P_BOOL|P_VIM,
1059 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1062#ifdef FEAT_AUTOCMD
1063 (char_u *)&p_ei, PV_NONE,
1064#else
1065 (char_u *)NULL, PV_NONE,
1066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1069 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1072 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1075#ifdef FEAT_MBYTE
1076 (char_u *)&p_fenc, PV_FENC,
1077 {(char_u *)"", (char_u *)0L}
1078#else
1079 (char_u *)NULL, PV_NONE,
1080 {(char_u *)0L, (char_u *)0L}
1081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1084#ifdef FEAT_MBYTE
1085 (char_u *)&p_fencs, PV_NONE,
1086 {(char_u *)"ucs-bom", (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1093 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1096 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1098 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001099 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#ifdef FEAT_AUTOCMD
1101 (char_u *)&p_ft, PV_FT,
1102 {(char_u *)"", (char_u *)0L}
1103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)0L, (char_u *)0L}
1106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1109#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1110 (char_u *)&p_fcs, PV_NONE,
1111 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1112#else
1113 (char_u *)NULL, PV_NONE,
1114 {(char_u *)"", (char_u *)0L}
1115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1118#ifdef FEAT_FKMAP
1119 (char_u *)&p_fkmap, PV_NONE,
1120#else
1121 (char_u *)NULL, PV_NONE,
1122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"flash", "fl", P_BOOL|P_VI_DEF,
1125 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127#ifdef FEAT_FOLDING
1128 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1129 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1132 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1135 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1138# ifdef FEAT_EVAL
1139 (char_u *)VAR_WIN, PV_FDE,
1140 {(char_u *)"0", (char_u *)NULL}
1141# else
1142 (char_u *)NULL, PV_NONE,
1143 {(char_u *)NULL, (char_u *)0L}
1144# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1147 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001148 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1150 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001151 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1153 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1156 P_RWIN|P_COMMA|P_NODUP,
1157 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 {(char_u *)"{{{,}}}", (char_u *)NULL}
1159 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1161 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1164 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1167 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1170 (char_u *)&p_fdo, PV_NONE,
1171 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1174# ifdef FEAT_EVAL
1175 (char_u *)VAR_WIN, PV_FDT,
1176 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001177# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 (char_u *)NULL, PV_NONE,
1179 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001180# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001183 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001184#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001185 (char_u *)&p_fex, PV_FEX,
1186 {(char_u *)"", (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)0L, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1193 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1195 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001196 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1197 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1199 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1201 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001203 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1204#ifdef HAVE_FSYNC
1205 (char_u *)&p_fs, PV_NONE,
1206 {(char_u *)TRUE, (char_u *)0L}
1207#else
1208 (char_u *)NULL, PV_NONE,
1209 {(char_u *)FALSE, (char_u *)0L}
1210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1213 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"graphic", "gr", P_BOOL|P_VI_DEF,
1216 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1219#ifdef FEAT_QUICKFIX
1220 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222#else
1223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
1225#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1228#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001229 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 {
1231# ifdef WIN3264
1232 /* may be changed to "grep -n" in os_win32.c */
1233 (char_u *)"findstr /n",
1234# else
1235# ifdef UNIX
1236 /* Add an extra file name so that grep will always
1237 * insert a file name in the match line. */
1238 (char_u *)"grep -n $* /dev/null",
1239# else
1240# ifdef VMS
1241 (char_u *)"SEARCH/NUMBERS ",
1242# else
1243 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244# endif
1245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)NULL, (char_u *)0L}
1251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1254#ifdef CURSOR_SHAPE
1255 (char_u *)&p_guicursor, PV_NONE,
1256 {
1257# ifdef FEAT_GUI
1258 (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",
1259# else /* MSDOS or Win32 console */
1260 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1261# endif
1262 (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1269#ifdef FEAT_GUI
1270 (char_u *)&p_guifont, PV_NONE,
1271 {(char_u *)"", (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1278#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1279 (char_u *)&p_guifontset, PV_NONE,
1280 {(char_u *)"", (char_u *)0L}
1281#else
1282 (char_u *)NULL, PV_NONE,
1283 {(char_u *)NULL, (char_u *)0L}
1284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1287#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1288 (char_u *)&p_guifontwide, PV_NONE,
1289 {(char_u *)"", (char_u *)0L}
1290#else
1291 (char_u *)NULL, PV_NONE,
1292 {(char_u *)NULL, (char_u *)0L}
1293#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001294 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001296#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297 (char_u *)&p_ghr, PV_NONE,
1298#else
1299 (char_u *)NULL, PV_NONE,
1300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001301 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001303#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 (char_u *)&p_go, PV_NONE,
1305# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001306 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001308 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309# endif
1310#else
1311 (char_u *)NULL, PV_NONE,
1312 {(char_u *)NULL, (char_u *)0L}
1313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001314 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 {"guipty", NULL, P_BOOL|P_VI_DEF,
1316#if defined(FEAT_GUI)
1317 (char_u *)&p_guipty, PV_NONE,
1318#else
1319 (char_u *)NULL, PV_NONE,
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001322 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001323#if defined(FEAT_GUI_TABLINE)
1324 (char_u *)&p_gtl, PV_NONE,
1325 {(char_u *)"", (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001331 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001332#if defined(FEAT_GUI_TABLINE)
1333 (char_u *)&p_gtt, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1341 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1344 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001345 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1346 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"helpheight", "hh", P_NUM|P_VI_DEF,
1348#ifdef FEAT_WINDOWS
1349 (char_u *)&p_hh, PV_NONE,
1350#else
1351 (char_u *)NULL, PV_NONE,
1352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1355#ifdef FEAT_MULTI_LANG
1356 (char_u *)&p_hlg, PV_NONE,
1357 {(char_u *)"", (char_u *)0L}
1358#else
1359 (char_u *)NULL, PV_NONE,
1360 {(char_u *)0L, (char_u *)0L}
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"hidden", "hid", P_BOOL|P_VI_DEF,
1364 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1367 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"history", "hi", P_NUM|P_VIM,
1371 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1374#ifdef FEAT_RIGHTLEFT
1375 (char_u *)&p_hkmap, PV_NONE,
1376#else
1377 (char_u *)NULL, PV_NONE,
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1381#ifdef FEAT_RIGHTLEFT
1382 (char_u *)&p_hkmapp, PV_NONE,
1383#else
1384 (char_u *)NULL, PV_NONE,
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1388 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 {"icon", NULL, P_BOOL|P_VI_DEF,
1391#ifdef FEAT_TITLE
1392 (char_u *)&p_icon, PV_NONE,
1393#else
1394 (char_u *)NULL, PV_NONE,
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397 {"iconstring", NULL, P_STRING|P_VI_DEF,
1398#ifdef FEAT_TITLE
1399 (char_u *)&p_iconstring, PV_NONE,
1400#else
1401 (char_u *)NULL, PV_NONE,
1402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1405 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001408#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409 (char_u *)&p_imak, PV_NONE,
1410#else
1411 (char_u *)NULL, PV_NONE,
1412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1415#ifdef USE_IM_CONTROL
1416 (char_u *)&p_imcmdline, PV_NONE,
1417#else
1418 (char_u *)NULL, PV_NONE,
1419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1422#ifdef USE_IM_CONTROL
1423 (char_u *)&p_imdisable, PV_NONE,
1424#else
1425 (char_u *)NULL, PV_NONE,
1426#endif
1427#ifdef __sgi
1428 {(char_u *)TRUE, (char_u *)0L}
1429#else
1430 {(char_u *)FALSE, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"iminsert", "imi", P_NUM|P_VI_DEF,
1434 (char_u *)&p_iminsert, PV_IMI,
1435#ifdef B_IMODE_IM
1436 {(char_u *)B_IMODE_IM, (char_u *)0L}
1437#else
1438 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1439#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"imsearch", "ims", P_NUM|P_VI_DEF,
1442 (char_u *)&p_imsearch, PV_IMS,
1443#ifdef B_IMODE_IM
1444 {(char_u *)B_IMODE_IM, (char_u *)0L}
1445#else
1446 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1450#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001451 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1453#else
1454 (char_u *)NULL, PV_NONE,
1455 {(char_u *)0L, (char_u *)0L}
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1459#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1460 (char_u *)&p_inex, PV_INEX,
1461 {(char_u *)"", (char_u *)0L}
1462#else
1463 (char_u *)NULL, PV_NONE,
1464 {(char_u *)0L, (char_u *)0L}
1465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1468 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001469 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1471#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1472 (char_u *)&p_inde, PV_INDE,
1473 {(char_u *)"", (char_u *)0L}
1474#else
1475 (char_u *)NULL, PV_NONE,
1476 {(char_u *)0L, (char_u *)0L}
1477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1480#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1481 (char_u *)&p_indk, PV_INDK,
1482 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"infercase", "inf", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1492 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1495 (char_u *)&p_isf, PV_NONE,
1496 {
1497#ifdef BACKSLASH_IN_FILENAME
1498 /* Excluded are: & and ^ are special in cmd.exe
1499 * ( and ) are used in text separating fnames */
1500 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1501#else
1502# ifdef AMIGA
1503 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1504# else
1505# ifdef VMS
1506 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1507# else /* UNIX et al. */
1508# ifdef EBCDIC
1509 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1510# else
1511 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1512# endif
1513# endif
1514# endif
1515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001516 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1518 (char_u *)&p_isi, PV_NONE,
1519 {
1520#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1521 (char_u *)"@,48-57,_,128-167,224-235",
1522#else
1523# ifdef EBCDIC
1524 /* TODO: EBCDIC Check this! @ == isalpha()*/
1525 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1526 "112-120,128,140-142,156,158,172,"
1527 "174,186,191,203-207,219-225,235-239,"
1528 "251-254",
1529# else
1530 (char_u *)"@,48-57,_,192-255",
1531# endif
1532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1535 (char_u *)&p_isk, PV_ISK,
1536 {
1537#ifdef EBCDIC
1538 (char_u *)"@,240-249,_",
1539 /* TODO: EBCDIC Check this! @ == isalpha()*/
1540 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1541 "112-120,128,140-142,156,158,172,"
1542 "174,186,191,203-207,219-225,235-239,"
1543 "251-254",
1544#else
1545 (char_u *)"@,48-57,_",
1546# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1547 (char_u *)"@,48-57,_,128-167,224-235"
1548# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001549 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550# endif
1551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1554 (char_u *)&p_isp, PV_NONE,
1555 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001556#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1557 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 || defined(VMS)
1559 (char_u *)"@,~-255",
1560#else
1561# ifdef EBCDIC
1562 /* all chars above 63 are printable */
1563 (char_u *)"63-255",
1564# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001565 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566# endif
1567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001568 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1570 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1573#ifdef FEAT_CRYPT
1574 (char_u *)&p_key, PV_KEY,
1575 {(char_u *)"", (char_u *)0L}
1576#else
1577 (char_u *)NULL, PV_NONE,
1578 {(char_u *)0L, (char_u *)0L}
1579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001581 {"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 +00001582#ifdef FEAT_KEYMAP
1583 (char_u *)&p_keymap, PV_KMAP,
1584 {(char_u *)"", (char_u *)0L}
1585#else
1586 (char_u *)NULL, PV_NONE,
1587 {(char_u *)"", (char_u *)0L}
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591#ifdef FEAT_VISUAL
1592 (char_u *)&p_km, PV_NONE,
1593#else
1594 (char_u *)NULL, PV_NONE,
1595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001596 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001598 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {
1600#if defined(MSDOS) || defined(MSWIN)
1601 (char_u *)":help",
1602#else
1603#ifdef VMS
1604 (char_u *)"help",
1605#else
1606# if defined(OS2)
1607 (char_u *)"view /",
1608# else
1609# ifdef USEMAN_S
1610 (char_u *)"man -s",
1611# else
1612 (char_u *)"man",
1613# endif
1614# endif
1615#endif
1616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1619#ifdef FEAT_LANGMAP
1620 (char_u *)&p_langmap, PV_NONE,
1621 {(char_u *)"", /* unmatched } */
1622#else
1623 (char_u *)NULL, PV_NONE,
1624 {(char_u *)NULL,
1625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001626 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001627 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1629 (char_u *)&p_lm, PV_NONE,
1630#else
1631 (char_u *)NULL, PV_NONE,
1632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1635#ifdef FEAT_WINDOWS
1636 (char_u *)&p_ls, PV_NONE,
1637#else
1638 (char_u *)NULL, PV_NONE,
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1642 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1645#ifdef FEAT_LINEBREAK
1646 (char_u *)VAR_WIN, PV_LBR,
1647#else
1648 (char_u *)NULL, PV_NONE,
1649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1652 (char_u *)&Rows, PV_NONE,
1653 {
1654#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1655 (char_u *)25L,
1656#else
1657 (char_u *)24L,
1658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1661#ifdef FEAT_GUI
1662 (char_u *)&p_linespace, PV_NONE,
1663#else
1664 (char_u *)NULL, PV_NONE,
1665#endif
1666#ifdef FEAT_GUI_W32
1667 {(char_u *)1L, (char_u *)0L}
1668#else
1669 {(char_u *)0L, (char_u *)0L}
1670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"lisp", NULL, P_BOOL|P_VI_DEF,
1673#ifdef FEAT_LISP
1674 (char_u *)&p_lisp, PV_LISP,
1675#else
1676 (char_u *)NULL, PV_NONE,
1677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001678 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1680#ifdef FEAT_LISP
1681 (char_u *)&p_lispwords, PV_NONE,
1682 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1683#else
1684 (char_u *)NULL, PV_NONE,
1685 {(char_u *)"", (char_u *)0L}
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1689 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1692 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1695 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001697#ifdef FEAT_GUI_MAC
1698 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1699 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"magic", NULL, P_BOOL|P_VI_DEF,
1703 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001705 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#ifdef FEAT_QUICKFIX
1707 (char_u *)&p_mef, PV_NONE,
1708 {(char_u *)"", (char_u *)0L}
1709#else
1710 (char_u *)NULL, PV_NONE,
1711 {(char_u *)NULL, (char_u *)0L}
1712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1715#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001716 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# ifdef VMS
1718 {(char_u *)"MMS", (char_u *)0L}
1719# else
1720 {(char_u *)"make", (char_u *)0L}
1721# endif
1722#else
1723 (char_u *)NULL, PV_NONE,
1724 {(char_u *)NULL, (char_u *)0L}
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1728 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001729 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"matchtime", "mat", P_NUM|P_VI_DEF,
1732 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001734 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1735#ifdef FEAT_MBYTE
1736 (char_u *)&p_mco, PV_NONE,
1737#else
1738 (char_u *)NULL, PV_NONE,
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1742#ifdef FEAT_EVAL
1743 (char_u *)&p_mfd, PV_NONE,
1744#else
1745 (char_u *)NULL, PV_NONE,
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1749 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"maxmem", "mm", P_NUM|P_VI_DEF,
1752 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1754 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001755 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1756 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1759 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1761 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"menuitems", "mis", P_NUM|P_VI_DEF,
1763#ifdef FEAT_MENU
1764 (char_u *)&p_mis, PV_NONE,
1765#else
1766 (char_u *)NULL, PV_NONE,
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"mesg", NULL, P_BOOL|P_VI_DEF,
1770 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001772 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001773#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001774 (char_u *)&p_msm, PV_NONE,
1775 {(char_u *)"460000,2000,500", (char_u *)0L}
1776#else
1777 (char_u *)NULL, PV_NONE,
1778 {(char_u *)0L, (char_u *)0L}
1779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"modeline", "ml", P_BOOL|P_VIM,
1782 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"modelines", "mls", P_NUM|P_VI_DEF,
1785 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1788 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1791 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"more", NULL, P_BOOL|P_VIM,
1794 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1797 (char_u *)&p_mouse, PV_NONE,
1798 {
1799#if defined(MSDOS) || defined(WIN3264)
1800 (char_u *)"a",
1801#else
1802 (char_u *)"",
1803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1806#ifdef FEAT_GUI
1807 (char_u *)&p_mousef, PV_NONE,
1808#else
1809 (char_u *)NULL, PV_NONE,
1810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001811 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1813#ifdef FEAT_GUI
1814 (char_u *)&p_mh, PV_NONE,
1815#else
1816 (char_u *)NULL, PV_NONE,
1817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001818 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1820 (char_u *)&p_mousem, PV_NONE,
1821 {
1822#if defined(MSDOS) || defined(MSWIN)
1823 (char_u *)"popup",
1824#else
1825# if defined(MACOS)
1826 (char_u *)"popup_setpos",
1827# else
1828 (char_u *)"extend",
1829# endif
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1833#ifdef FEAT_MOUSESHAPE
1834 (char_u *)&p_mouseshape, PV_NONE,
1835 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)NULL, (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1842 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001844 {"mzquantum", "mzq", P_NUM,
1845#ifdef FEAT_MZSCHEME
1846 (char_u *)&p_mzq, PV_NONE,
1847#else
1848 (char_u *)NULL, PV_NONE,
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"novice", NULL, P_BOOL|P_VI_DEF,
1852 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1855 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)"octal,hex", (char_u *)0L}
1857 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1859 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001861 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1862#ifdef FEAT_LINEBREAK
1863 (char_u *)VAR_WIN, PV_NUW,
1864#else
1865 (char_u *)NULL, PV_NONE,
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001868 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001869#ifdef FEAT_COMPL_FUNC
1870 (char_u *)&p_ofu, PV_OFU,
1871 {(char_u *)"", (char_u *)0L}
1872#else
1873 (char_u *)NULL, PV_NONE,
1874 {(char_u *)0L, (char_u *)0L}
1875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"open", NULL, P_BOOL|P_VI_DEF,
1878 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001880 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1881#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1882 (char_u *)&p_odev, PV_NONE,
1883#else
1884 (char_u *)NULL, PV_NONE,
1885#endif
1886 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001888 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1889 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"optimize", "opt", P_BOOL|P_VI_DEF,
1892 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1895#ifdef FEAT_OSFILETYPE
1896 (char_u *)&p_oft, PV_OFT,
1897 {(char_u *)DFLT_OFT, (char_u *)0L}
1898#else
1899 (char_u *)NULL, PV_NONE,
1900 {(char_u *)0L, (char_u *)0L}
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"paragraphs", "para", P_STRING|P_VI_DEF,
1904 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001905 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001907 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1911 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1914#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1915 (char_u *)&p_pex, PV_NONE,
1916 {(char_u *)"", (char_u *)0L}
1917#else
1918 (char_u *)NULL, PV_NONE,
1919 {(char_u *)0L, (char_u *)0L}
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001922 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001926 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {
1928#if defined AMIGA || defined MSDOS || defined MSWIN
1929 (char_u *)".,,",
1930#else
1931# if defined(__EMX__)
1932 (char_u *)".,/emx/include,,",
1933# else /* Unix, probably */
1934 (char_u *)".,/usr/include,,",
1935# endif
1936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1939 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001941 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1943 (char_u *)&p_pvh, PV_NONE,
1944#else
1945 (char_u *)NULL, PV_NONE,
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1949#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1950 (char_u *)VAR_WIN, PV_PVW,
1951#else
1952 (char_u *)NULL, PV_NONE,
1953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001955 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956#ifdef FEAT_PRINTER
1957 (char_u *)&p_pdev, PV_NONE,
1958 {(char_u *)"", (char_u *)0L}
1959#else
1960 (char_u *)NULL, PV_NONE,
1961 {(char_u *)NULL, (char_u *)0L}
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"printencoding", "penc", P_STRING|P_VI_DEF,
1965#ifdef FEAT_POSTSCRIPT
1966 (char_u *)&p_penc, PV_NONE,
1967 {(char_u *)"", (char_u *)0L}
1968#else
1969 (char_u *)NULL, PV_NONE,
1970 {(char_u *)NULL, (char_u *)0L}
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1974#ifdef FEAT_POSTSCRIPT
1975 (char_u *)&p_pexpr, PV_NONE,
1976 {(char_u *)"", (char_u *)0L}
1977#else
1978 (char_u *)NULL, PV_NONE,
1979 {(char_u *)NULL, (char_u *)0L}
1980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"printfont", "pfn", P_STRING|P_VI_DEF,
1983#ifdef FEAT_PRINTER
1984 (char_u *)&p_pfn, PV_NONE,
1985 {
1986# ifdef MSWIN
1987 (char_u *)"Courier_New:h10",
1988# else
1989 (char_u *)"courier",
1990# endif
1991 (char_u *)0L}
1992#else
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)NULL, (char_u *)0L}
1995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1998#ifdef FEAT_PRINTER
1999 (char_u *)&p_header, PV_NONE,
2000 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2001#else
2002 (char_u *)NULL, PV_NONE,
2003 {(char_u *)NULL, (char_u *)0L}
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002006 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2007#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2008 (char_u *)&p_pmcs, PV_NONE,
2009 {(char_u *)"", (char_u *)0L}
2010#else
2011 (char_u *)NULL, PV_NONE,
2012 {(char_u *)NULL, (char_u *)0L}
2013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002014 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002015 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2016#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2017 (char_u *)&p_pmfn, PV_NONE,
2018 {(char_u *)"", (char_u *)0L}
2019#else
2020 (char_u *)NULL, PV_NONE,
2021 {(char_u *)NULL, (char_u *)0L}
2022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002023 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2025#ifdef FEAT_PRINTER
2026 (char_u *)&p_popt, PV_NONE,
2027 {(char_u *)"", (char_u *)0L}
2028#else
2029 (char_u *)NULL, PV_NONE,
2030 {(char_u *)NULL, (char_u *)0L}
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002034 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002036 {"pumheight", "ph", P_NUM|P_VI_DEF,
2037#ifdef FEAT_INS_EXPAND
2038 (char_u *)&p_ph, PV_NONE,
2039#else
2040 (char_u *)NULL, PV_NONE,
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002043 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2044#ifdef FEAT_TEXTOBJ
2045 (char_u *)&p_qe, PV_QE,
2046 {(char_u *)"\\", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2053 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"redraw", NULL, P_BOOL|P_VI_DEF,
2056 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002058 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2059#ifdef FEAT_RELTIME
2060 (char_u *)&p_rdt, PV_NONE,
2061#else
2062 (char_u *)NULL, PV_NONE,
2063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002065 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2066 (char_u *)VAR_WIN, PV_RNU,
2067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 {"remap", NULL, P_BOOL|P_VI_DEF,
2069 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"report", NULL, P_NUM|P_VI_DEF,
2072 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2075#ifdef WIN3264
2076 (char_u *)&p_rs, PV_NONE,
2077#else
2078 (char_u *)NULL, PV_NONE,
2079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2082#ifdef FEAT_RIGHTLEFT
2083 (char_u *)&p_ri, PV_NONE,
2084#else
2085 (char_u *)NULL, PV_NONE,
2086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2089#ifdef FEAT_RIGHTLEFT
2090 (char_u *)VAR_WIN, PV_RL,
2091#else
2092 (char_u *)NULL, PV_NONE,
2093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2096#ifdef FEAT_RIGHTLEFT
2097 (char_u *)VAR_WIN, PV_RLC,
2098 {(char_u *)"search", (char_u *)NULL}
2099#else
2100 (char_u *)NULL, PV_NONE,
2101 {(char_u *)NULL, (char_u *)0L}
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2105#ifdef FEAT_CMDL_INFO
2106 (char_u *)&p_ru, PV_NONE,
2107#else
2108 (char_u *)NULL, PV_NONE,
2109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2112#ifdef FEAT_STL_OPT
2113 (char_u *)&p_ruf, PV_NONE,
2114#else
2115 (char_u *)NULL, PV_NONE,
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2119 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2123 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2126#ifdef FEAT_SCROLLBIND
2127 (char_u *)VAR_WIN, PV_SCBIND,
2128#else
2129 (char_u *)NULL, PV_NONE,
2130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2133 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2136 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2139#ifdef FEAT_SCROLLBIND
2140 (char_u *)&p_sbo, PV_NONE,
2141 {(char_u *)"ver,jump", (char_u *)0L}
2142#else
2143 (char_u *)NULL, PV_NONE,
2144 {(char_u *)0L, (char_u *)0L}
2145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"sections", "sect", P_STRING|P_VI_DEF,
2148 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002149 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2150 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2152 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"selection", "sel", P_STRING|P_VI_DEF,
2155#ifdef FEAT_VISUAL
2156 (char_u *)&p_sel, PV_NONE,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)"inclusive", (char_u *)0L}
2161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2163#ifdef FEAT_VISUAL
2164 (char_u *)&p_slm, PV_NONE,
2165#else
2166 (char_u *)NULL, PV_NONE,
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2170#ifdef FEAT_SESSION
2171 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002172 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)0L, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2180 (char_u *)&p_sh, PV_NONE,
2181 {
2182#ifdef VMS
2183 (char_u *)"-",
2184#else
2185# if defined(MSDOS)
2186 (char_u *)"command",
2187# else
2188# if defined(WIN16)
2189 (char_u *)"command.com",
2190# else
2191# if defined(WIN3264)
2192 (char_u *)"", /* set in set_init_1() */
2193# else
2194# if defined(OS2)
2195 (char_u *)"cmd.exe",
2196# else
2197# if defined(ARCHIE)
2198 (char_u *)"gos",
2199# else
2200 (char_u *)"sh",
2201# endif
2202# endif
2203# endif
2204# endif
2205# endif
2206#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2209 (char_u *)&p_shcf, PV_NONE,
2210 {
2211#if defined(MSDOS) || defined(MSWIN)
2212 (char_u *)"/c",
2213#else
2214# if defined(OS2)
2215 (char_u *)"/c",
2216# else
2217 (char_u *)"-c",
2218# endif
2219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2222#ifdef FEAT_QUICKFIX
2223 (char_u *)&p_sp, PV_NONE,
2224 {
2225#if defined(UNIX) || defined(OS2)
2226# ifdef ARCHIE
2227 (char_u *)"2>",
2228# else
2229 (char_u *)"| tee",
2230# endif
2231#else
2232 (char_u *)">",
2233#endif
2234 (char_u *)0L}
2235#else
2236 (char_u *)NULL, PV_NONE,
2237 {(char_u *)0L, (char_u *)0L}
2238#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2241 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2244 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2247#ifdef BACKSLASH_IN_FILENAME
2248 (char_u *)&p_ssl, PV_NONE,
2249#else
2250 (char_u *)NULL, PV_NONE,
2251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002253 {"shelltemp", "stmp", P_BOOL,
2254 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002255 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 {"shelltype", "st", P_NUM|P_VI_DEF,
2257#ifdef AMIGA
2258 (char_u *)&p_st, PV_NONE,
2259#else
2260 (char_u *)NULL, PV_NONE,
2261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2264 (char_u *)&p_sxq, PV_NONE,
2265 {
2266#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2267 (char_u *)"\"",
2268#else
2269 (char_u *)"",
2270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2273 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002274 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2276 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2279 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)"", (char_u *)"filnxtToO"}
2281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"shortname", "sn", P_BOOL|P_VI_DEF,
2283#ifdef SHORT_FNAME
2284 (char_u *)NULL, PV_NONE,
2285#else
2286 (char_u *)&p_sn, PV_SN,
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2290#ifdef FEAT_LINEBREAK
2291 (char_u *)&p_sbr, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"showcmd", "sc", P_BOOL|P_VIM,
2297#ifdef FEAT_CMDL_INFO
2298 (char_u *)&p_sc, PV_NONE,
2299#else
2300 (char_u *)NULL, PV_NONE,
2301#endif
2302 {(char_u *)FALSE,
2303#ifdef UNIX
2304 (char_u *)FALSE
2305#else
2306 (char_u *)TRUE
2307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2310 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2313 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"showmode", "smd", P_BOOL|P_VIM,
2316 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002318 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2319#ifdef FEAT_WINDOWS
2320 (char_u *)&p_stal, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2326 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2329 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2332 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2335 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2338#ifdef FEAT_SMARTINDENT
2339 (char_u *)&p_si, PV_SI,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2345 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2348 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2351 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002353 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002354#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002355 (char_u *)VAR_WIN, PV_SPELL,
2356#else
2357 (char_u *)NULL, PV_NONE,
2358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002360 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002361#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002362 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002363 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002364#else
2365 (char_u *)NULL, PV_NONE,
2366 {(char_u *)0L, (char_u *)0L}
2367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002369 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002370#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002371 (char_u *)&p_spf, PV_SPF,
2372 {(char_u *)"", (char_u *)0L}
2373#else
2374 (char_u *)NULL, PV_NONE,
2375 {(char_u *)0L, (char_u *)0L}
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002378 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002379#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002380 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002381 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002382#else
2383 (char_u *)NULL, PV_NONE,
2384 {(char_u *)0L, (char_u *)0L}
2385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002386 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002387 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002388#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002389 (char_u *)&p_sps, PV_NONE,
2390 {(char_u *)"best", (char_u *)0L}
2391#else
2392 (char_u *)NULL, PV_NONE,
2393 {(char_u *)0L, (char_u *)0L}
2394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2397#ifdef FEAT_WINDOWS
2398 (char_u *)&p_sb, PV_NONE,
2399#else
2400 (char_u *)NULL, PV_NONE,
2401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"splitright", "spr", P_BOOL|P_VI_DEF,
2404#ifdef FEAT_VERTSPLIT
2405 (char_u *)&p_spr, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2411 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2414#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002415 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416#else
2417 (char_u *)NULL, PV_NONE,
2418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2421 (char_u *)&p_su, PV_NONE,
2422 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002425#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)&p_sua, PV_SUA,
2427 {(char_u *)"", (char_u *)0L}
2428#else
2429 (char_u *)NULL, PV_NONE,
2430 {(char_u *)0L, (char_u *)0L}
2431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2434 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"swapsync", "sws", P_STRING|P_VI_DEF,
2437 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2440 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002442 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2443#ifdef FEAT_SYN_HL
2444 (char_u *)&p_smc, PV_SMC,
2445 {(char_u *)3000L, (char_u *)0L}
2446#else
2447 (char_u *)NULL, PV_NONE,
2448 {(char_u *)0L, (char_u *)0L}
2449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002451 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452#ifdef FEAT_SYN_HL
2453 (char_u *)&p_syn, PV_SYN,
2454 {(char_u *)"", (char_u *)0L}
2455#else
2456 (char_u *)NULL, PV_NONE,
2457 {(char_u *)0L, (char_u *)0L}
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002460 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2461#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002462 (char_u *)&p_tal, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002467 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2468#ifdef FEAT_WINDOWS
2469 (char_u *)&p_tpm, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2475 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2478 (char_u *)&p_tbs, PV_NONE,
2479#ifdef VMS /* binary searching doesn't appear to work on VMS */
2480 {(char_u *)0L, (char_u *)0L}
2481#else
2482 {(char_u *)TRUE, (char_u *)0L}
2483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002484 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"taglength", "tl", P_NUM|P_VI_DEF,
2486 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002487 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"tagrelative", "tr", P_BOOL|P_VIM,
2489 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002492 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {
2494#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2495 (char_u *)"./tags,./TAGS,tags,TAGS",
2496#else
2497 (char_u *)"./tags,tags",
2498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2501 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2504 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2507#ifdef FEAT_ARABIC
2508 (char_u *)&p_tbidi, PV_NONE,
2509#else
2510 (char_u *)NULL, PV_NONE,
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2514#ifdef FEAT_MBYTE
2515 (char_u *)&p_tenc, PV_NONE,
2516 {(char_u *)"", (char_u *)0L}
2517#else
2518 (char_u *)NULL, PV_NONE,
2519 {(char_u *)0L, (char_u *)0L}
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"terse", NULL, P_BOOL|P_VI_DEF,
2523 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"textauto", "ta", P_BOOL|P_VIM,
2526 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2530 (char_u *)&p_tx, PV_TX,
2531 {
2532#ifdef USE_CRNL
2533 (char_u *)TRUE,
2534#else
2535 (char_u *)FALSE,
2536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002538 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2542#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002543 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2549 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"timeout", "to", P_BOOL|P_VI_DEF,
2552 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2555 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"title", NULL, P_BOOL|P_VI_DEF,
2558#ifdef FEAT_TITLE
2559 (char_u *)&p_title, PV_NONE,
2560#else
2561 (char_u *)NULL, PV_NONE,
2562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"titlelen", NULL, P_NUM|P_VI_DEF,
2565#ifdef FEAT_TITLE
2566 (char_u *)&p_titlelen, PV_NONE,
2567#else
2568 (char_u *)NULL, PV_NONE,
2569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002571 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572#ifdef FEAT_TITLE
2573 (char_u *)&p_titleold, PV_NONE,
2574 {(char_u *)N_("Thanks for flying Vim"),
2575 (char_u *)0L}
2576#else
2577 (char_u *)NULL, PV_NONE,
2578 {(char_u *)0L, (char_u *)0L}
2579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"titlestring", NULL, P_STRING|P_VI_DEF,
2582#ifdef FEAT_TITLE
2583 (char_u *)&p_titlestring, PV_NONE,
2584#else
2585 (char_u *)NULL, PV_NONE,
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2589 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2590 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)"icons,tooltips", (char_u *)0L}
2592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002594#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2596 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598#endif
2599 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2600 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2603 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2606 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2609 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2612#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2613 (char_u *)&p_ttym, PV_NONE,
2614#else
2615 (char_u *)NULL, PV_NONE,
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2619 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2622 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002624 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2625#ifdef FEAT_PERSISTENT_UNDO
2626 (char_u *)&p_udir, PV_NONE,
2627 {(char_u *)".", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
2632 SCRIPTID_INIT},
2633 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2634#ifdef FEAT_PERSISTENT_UNDO
2635 (char_u *)&p_udf, PV_UDF,
2636#else
2637 (char_u *)NULL, PV_NONE,
2638#endif
2639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"undolevels", "ul", P_NUM|P_VI_DEF,
2641 (char_u *)&p_ul, PV_NONE,
2642 {
2643#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2644 (char_u *)1000L,
2645#else
2646 (char_u *)100L,
2647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"updatecount", "uc", P_NUM|P_VI_DEF,
2650 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"updatetime", "ut", P_NUM|P_VI_DEF,
2653 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"verbose", "vbs", P_NUM|P_VI_DEF,
2656 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002658 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2659 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2662#ifdef FEAT_SESSION
2663 (char_u *)&p_vdir, PV_NONE,
2664 {(char_u *)DFLT_VDIR, (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2671#ifdef FEAT_SESSION
2672 (char_u *)&p_vop, PV_NONE,
2673 {(char_u *)"folds,options,cursor", (char_u *)0L}
2674#else
2675 (char_u *)NULL, PV_NONE,
2676 {(char_u *)0L, (char_u *)0L}
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2680#ifdef FEAT_VIMINFO
2681 (char_u *)&p_viminfo, PV_NONE,
2682#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002683 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#else
2685# ifdef AMIGA
2686 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002687 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002689 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690# endif
2691#endif
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2698#ifdef FEAT_VIRTUALEDIT
2699 (char_u *)&p_ve, PV_NONE,
2700 {(char_u *)"", (char_u *)""}
2701#else
2702 (char_u *)NULL, PV_NONE,
2703 {(char_u *)0L, (char_u *)0L}
2704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2707 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"w300", NULL, P_NUM|P_VI_DEF,
2710 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"w1200", NULL, P_NUM|P_VI_DEF,
2713 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"w9600", NULL, P_NUM|P_VI_DEF,
2716 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"warn", NULL, P_BOOL|P_VI_DEF,
2719 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2722 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2725 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {"wildchar", "wc", P_NUM|P_VIM,
2728 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2732 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2735#ifdef FEAT_WILDIGN
2736 (char_u *)&p_wig, PV_NONE,
2737#else
2738 (char_u *)NULL, PV_NONE,
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2742#ifdef FEAT_WILDMENU
2743 (char_u *)&p_wmnu, PV_NONE,
2744#else
2745 (char_u *)NULL, PV_NONE,
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2749 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002751 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2752#ifdef FEAT_CMDL_COMPL
2753 (char_u *)&p_wop, PV_NONE,
2754 {(char_u *)"", (char_u *)0L}
2755#else
2756 (char_u *)NULL, PV_NONE,
2757 {(char_u *)NULL, (char_u *)0L}
2758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2761#ifdef FEAT_WAK
2762 (char_u *)&p_wak, PV_NONE,
2763 {(char_u *)"menu", (char_u *)0L}
2764#else
2765 (char_u *)NULL, PV_NONE,
2766 {(char_u *)NULL, (char_u *)0L}
2767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002770 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"winheight", "wh", P_NUM|P_VI_DEF,
2773#ifdef FEAT_WINDOWS
2774 (char_u *)&p_wh, PV_NONE,
2775#else
2776 (char_u *)NULL, PV_NONE,
2777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002780#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 (char_u *)VAR_WIN, PV_WFH,
2782#else
2783 (char_u *)NULL, PV_NONE,
2784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002786 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2787#ifdef FEAT_VERTSPLIT
2788 (char_u *)VAR_WIN, PV_WFW,
2789#else
2790 (char_u *)NULL, PV_NONE,
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2794#ifdef FEAT_WINDOWS
2795 (char_u *)&p_wmh, PV_NONE,
2796#else
2797 (char_u *)NULL, PV_NONE,
2798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2801#ifdef FEAT_VERTSPLIT
2802 (char_u *)&p_wmw, PV_NONE,
2803#else
2804 (char_u *)NULL, PV_NONE,
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2808#ifdef FEAT_VERTSPLIT
2809 (char_u *)&p_wiw, PV_NONE,
2810#else
2811 (char_u *)NULL, PV_NONE,
2812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2815 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2818 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2821 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"write", NULL, P_BOOL|P_VI_DEF,
2824 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"writeany", "wa", P_BOOL|P_VI_DEF,
2827 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2830 (char_u *)&p_wb, PV_NONE,
2831 {
2832#ifdef FEAT_WRITEBACKUP
2833 (char_u *)TRUE,
2834#else
2835 (char_u *)FALSE,
2836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"writedelay", "wd", P_NUM|P_VI_DEF,
2839 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841
2842/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002843#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846
2847 p_term("t_AB", T_CAB)
2848 p_term("t_AF", T_CAF)
2849 p_term("t_AL", T_CAL)
2850 p_term("t_al", T_AL)
2851 p_term("t_bc", T_BC)
2852 p_term("t_cd", T_CD)
2853 p_term("t_ce", T_CE)
2854 p_term("t_cl", T_CL)
2855 p_term("t_cm", T_CM)
2856 p_term("t_Co", T_CCO)
2857 p_term("t_CS", T_CCS)
2858 p_term("t_cs", T_CS)
2859#ifdef FEAT_VERTSPLIT
2860 p_term("t_CV", T_CSV)
2861#endif
2862 p_term("t_ut", T_UT)
2863 p_term("t_da", T_DA)
2864 p_term("t_db", T_DB)
2865 p_term("t_DL", T_CDL)
2866 p_term("t_dl", T_DL)
2867 p_term("t_fs", T_FS)
2868 p_term("t_IE", T_CIE)
2869 p_term("t_IS", T_CIS)
2870 p_term("t_ke", T_KE)
2871 p_term("t_ks", T_KS)
2872 p_term("t_le", T_LE)
2873 p_term("t_mb", T_MB)
2874 p_term("t_md", T_MD)
2875 p_term("t_me", T_ME)
2876 p_term("t_mr", T_MR)
2877 p_term("t_ms", T_MS)
2878 p_term("t_nd", T_ND)
2879 p_term("t_op", T_OP)
2880 p_term("t_RI", T_CRI)
2881 p_term("t_RV", T_CRV)
2882 p_term("t_Sb", T_CSB)
2883 p_term("t_Sf", T_CSF)
2884 p_term("t_se", T_SE)
2885 p_term("t_so", T_SO)
2886 p_term("t_sr", T_SR)
2887 p_term("t_ts", T_TS)
2888 p_term("t_te", T_TE)
2889 p_term("t_ti", T_TI)
2890 p_term("t_ue", T_UE)
2891 p_term("t_us", T_US)
2892 p_term("t_vb", T_VB)
2893 p_term("t_ve", T_VE)
2894 p_term("t_vi", T_VI)
2895 p_term("t_vs", T_VS)
2896 p_term("t_WP", T_CWP)
2897 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002898 p_term("t_SI", T_CSI)
2899 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 p_term("t_xs", T_XS)
2901 p_term("t_ZH", T_CZH)
2902 p_term("t_ZR", T_CZR)
2903
2904/* terminal key codes are not in here */
2905
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 /* end marker */
2907 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908};
2909
2910#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2911
2912#ifdef FEAT_MBYTE
2913static char *(p_ambw_values[]) = {"single", "double", NULL};
2914#endif
2915static char *(p_bg_values[]) = {"light", "dark", NULL};
2916static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2917static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002918#ifdef FEAT_CMDL_COMPL
2919static char *(p_wop_values[]) = {"tagfile", NULL};
2920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921#ifdef FEAT_WAK
2922static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2923#endif
2924static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2925#ifdef FEAT_VISUAL
2926static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2927static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2928#endif
2929#ifdef FEAT_VISUAL
2930static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2931#endif
2932#ifdef FEAT_BROWSE
2933static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2934#endif
2935#ifdef FEAT_SCROLLBIND
2936static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2937#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002938static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939#ifdef FEAT_VERTSPLIT
2940static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2941#endif
2942#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002943# ifdef FEAT_AUTOCMD
2944static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2945# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002947# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2949#endif
2950static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2951#ifdef FEAT_FOLDING
2952static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002953# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002955# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 NULL};
2957static char *(p_fcl_values[]) = {"all", NULL};
2958#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002959#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002960static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962
2963static void set_option_default __ARGS((int, int opt_flags, int compatible));
2964static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002965static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002966static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967static char_u *illegal_char __ARGS((char_u *, int));
2968static int string_to_key __ARGS((char_u *arg));
2969#ifdef FEAT_CMDWIN
2970static char_u *check_cedit __ARGS((void));
2971#endif
2972#ifdef FEAT_TITLE
2973static void did_set_title __ARGS((int icon));
2974#endif
2975static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2976static void didset_options __ARGS((void));
2977static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002978#if defined(FEAT_EVAL) || defined(PROTO)
2979static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2980#else
2981# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2982#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2984static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2985static 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));
2986static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02002987#ifdef FEAT_SYN_HL
2988static int int_cmp __ARGS((const void *a, const void *b));
2989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990#ifdef FEAT_CLIPBOARD
2991static char_u *check_clipboard_option __ARGS((void));
2992#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002993#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02002994static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002995#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002996#ifdef FEAT_EVAL
2997static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003000static 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 +00003001static void check_redraw __ARGS((long_u flags));
3002static int findoption __ARGS((char_u *));
3003static int find_key_option __ARGS((char_u *));
3004static void showoptions __ARGS((int all, int opt_flags));
3005static int optval_default __ARGS((struct vimoption *, char_u *varp));
3006static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3007static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3008static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3009static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3010static int istermoption __ARGS((struct vimoption *));
3011static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3012static char_u *get_varp __ARGS((struct vimoption *));
3013static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3014static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3015#ifdef FEAT_LANGMAP
3016static void langmap_init __ARGS((void));
3017static void langmap_set __ARGS((void));
3018#endif
3019static void paste_option_changed __ARGS((void));
3020static void compatible_set __ARGS((void));
3021#ifdef FEAT_LINEBREAK
3022static void fill_breakat_flags __ARGS((void));
3023#endif
3024static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3025static int check_opt_strings __ARGS((char_u *val, char **values, int));
3026static int check_opt_wim __ARGS((void));
3027
3028/*
3029 * Initialize the options, first part.
3030 *
3031 * Called only once from main(), just after creating the first buffer.
3032 */
3033 void
3034set_init_1()
3035{
3036 char_u *p;
3037 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003038 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039
3040#ifdef FEAT_LANGMAP
3041 langmap_init();
3042#endif
3043
3044 /* Be Vi compatible by default */
3045 p_cp = TRUE;
3046
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003047 /* Use POSIX compatibility when $VIM_POSIX is set. */
3048 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003049 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003050 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003051 set_string_default("shm", (char_u *)"A");
3052 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003053
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 /*
3055 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003056 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003058 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3060# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003061 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003063 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003065 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066# endif
3067#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003068 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 set_string_default("sh", p);
3070
3071#ifdef FEAT_WILDIGN
3072 /*
3073 * Set the default for 'backupskip' to include environment variables for
3074 * temp files.
3075 */
3076 {
3077# ifdef UNIX
3078 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3079# else
3080 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3081# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003082 int len;
3083 garray_T ga;
3084 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085
3086 ga_init2(&ga, 1, 100);
3087 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3088 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003089 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090# ifdef UNIX
3091 if (*names[n] == NUL)
3092 p = (char_u *)"/tmp";
3093 else
3094# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003095 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 if (p != NULL && *p != NUL)
3097 {
3098 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003099 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 if (ga_grow(&ga, len) == OK)
3101 {
3102 if (ga.ga_len > 0)
3103 STRCAT(ga.ga_data, ",");
3104 STRCAT(ga.ga_data, p);
3105 add_pathsep(ga.ga_data);
3106 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 ga.ga_len += len;
3108 }
3109 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003110 if (mustfree)
3111 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112 }
3113 if (ga.ga_data != NULL)
3114 {
3115 set_string_default("bsk", ga.ga_data);
3116 vim_free(ga.ga_data);
3117 }
3118 }
3119#endif
3120
3121 /*
3122 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3123 */
3124 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003125 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003127#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3128 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3129#endif
3130 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003132 /* Use amount of memory available at this moment. */
3133 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#else
3135# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003136 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003137 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003139 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140# endif
3141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003143 opt_idx = findoption((char_u *)"maxmem");
3144 if (opt_idx >= 0)
3145 {
3146#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3147 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3148 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3149#endif
3150 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3151 }
3152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 }
3154
3155#ifdef FEAT_GUI_W32
3156 /* force 'shortname' for Win32s */
3157 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003158 {
3159 opt_idx = findoption((char_u *)"shortname");
3160 if (opt_idx >= 0)
3161 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163#endif
3164
3165#ifdef FEAT_SEARCHPATH
3166 {
3167 char_u *cdpath;
3168 char_u *buf;
3169 int i;
3170 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003171 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172
3173 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003174 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 if (cdpath != NULL)
3176 {
3177 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3178 if (buf != NULL)
3179 {
3180 buf[0] = ','; /* start with ",", current dir first */
3181 j = 1;
3182 for (i = 0; cdpath[i] != NUL; ++i)
3183 {
3184 if (vim_ispathlistsep(cdpath[i]))
3185 buf[j++] = ',';
3186 else
3187 {
3188 if (cdpath[i] == ' ' || cdpath[i] == ',')
3189 buf[j++] = '\\';
3190 buf[j++] = cdpath[i];
3191 }
3192 }
3193 buf[j] = NUL;
3194 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003195 if (opt_idx >= 0)
3196 {
3197 options[opt_idx].def_val[VI_DEFAULT] = buf;
3198 options[opt_idx].flags |= P_DEF_ALLOCED;
3199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003201 if (mustfree)
3202 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 }
3204 }
3205#endif
3206
3207#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3208 /* Set print encoding on platforms that don't default to latin1 */
3209 set_string_default("penc",
3210# if defined(MSWIN) || defined(OS2)
3211 (char_u *)"cp1252"
3212# else
3213# ifdef VMS
3214 (char_u *)"dec-mcs"
3215# else
3216# ifdef EBCDIC
3217 (char_u *)"ebcdic-uk"
3218# else
3219# ifdef MAC
3220 (char_u *)"mac-roman"
3221# else /* HPUX */
3222 (char_u *)"hp-roman8"
3223# endif
3224# endif
3225# endif
3226# endif
3227 );
3228#endif
3229
3230#ifdef FEAT_POSTSCRIPT
3231 /* 'printexpr' must be allocated to be able to evaluate it. */
3232 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003233# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3234 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235# else
3236# ifdef VMS
3237 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3238
3239# else
3240 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3241# endif
3242# endif
3243 );
3244#endif
3245
3246 /*
3247 * Set all the options (except the terminal options) to their default
3248 * value. Also set the global value for local options.
3249 */
3250 set_options_default(0);
3251
3252#ifdef FEAT_GUI
3253 if (found_reverse_arg)
3254 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3255#endif
3256
3257 curbuf->b_p_initialized = TRUE;
3258 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3259 check_buf_options(curbuf);
3260 check_win_options(curwin);
3261 check_options();
3262
3263 /* Must be before option_expand(), because that one needs vim_isIDc() */
3264 didset_options();
3265
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003266#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003267 /* Use the current chartab for the generic chartab. */
3268 init_spell_chartab();
3269#endif
3270
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271#ifdef FEAT_LINEBREAK
3272 /*
3273 * initialize the table for 'breakat'.
3274 */
3275 fill_breakat_flags();
3276#endif
3277
3278 /*
3279 * Expand environment variables and things like "~" for the defaults.
3280 * If option_expand() returns non-NULL the variable is expanded. This can
3281 * only happen for non-indirect options.
3282 * Also set the default to the expanded value, so ":set" does not list
3283 * them.
3284 * Don't set the P_ALLOCED flag, because we don't want to free the
3285 * default.
3286 */
3287 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3288 {
3289 if ((options[opt_idx].flags & P_GETTEXT)
3290 && options[opt_idx].var != NULL)
3291 p = (char_u *)_(*(char **)options[opt_idx].var);
3292 else
3293 p = option_expand(opt_idx, NULL);
3294 if (p != NULL && (p = vim_strsave(p)) != NULL)
3295 {
3296 *(char_u **)options[opt_idx].var = p;
3297 /* VIMEXP
3298 * Defaults for all expanded options are currently the same for Vi
3299 * and Vim. When this changes, add some code here! Also need to
3300 * split P_DEF_ALLOCED in two.
3301 */
3302 if (options[opt_idx].flags & P_DEF_ALLOCED)
3303 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3304 options[opt_idx].def_val[VI_DEFAULT] = p;
3305 options[opt_idx].flags |= P_DEF_ALLOCED;
3306 }
3307 }
3308
3309 /* Initialize the highlight_attr[] table. */
3310 highlight_changed();
3311
3312 save_file_ff(curbuf); /* Buffer is unchanged */
3313
3314 /* Parse default for 'wildmode' */
3315 check_opt_wim();
3316
3317#if defined(FEAT_ARABIC)
3318 /* Detect use of mlterm.
3319 * Mlterm is a terminal emulator akin to xterm that has some special
3320 * abilities (bidi namely).
3321 * NOTE: mlterm's author is being asked to 'set' a variable
3322 * instead of an environment variable due to inheritance.
3323 */
3324 if (mch_getenv((char_u *)"MLTERM") != NULL)
3325 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3326#endif
3327
3328#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3329 /* Parse default for 'fillchars'. */
3330 (void)set_chars_option(&p_fcs);
3331#endif
3332
3333#ifdef FEAT_CLIPBOARD
3334 /* Parse default for 'clipboard' */
3335 (void)check_clipboard_option();
3336#endif
3337
3338#ifdef FEAT_MBYTE
3339# if defined(WIN3264) && defined(FEAT_GETTEXT)
3340 /*
3341 * If $LANG isn't set, try to get a good value for it. This makes the
3342 * right language be used automatically. Don't do this for English.
3343 */
3344 if (mch_getenv((char_u *)"LANG") == NULL)
3345 {
3346 char buf[20];
3347
3348 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3349 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3350 * only the first two. */
3351 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3352 (LPTSTR)buf, 20);
3353 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3354 {
3355 /* There are a few exceptions (probably more) */
3356 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3357 STRCPY(buf, "zh_TW");
3358 else if (STRNICMP(buf, "chs", 3) == 0
3359 || STRNICMP(buf, "zhc", 3) == 0)
3360 STRCPY(buf, "zh_CN");
3361 else if (STRNICMP(buf, "jp", 2) == 0)
3362 STRCPY(buf, "ja");
3363 else
3364 buf[2] = NUL; /* truncate to two-letter code */
3365 vim_setenv("LANG", buf);
3366 }
3367 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003368# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003369# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003370 /* Moved to os_mac_conv.c to avoid dependency problems. */
3371 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003372# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373# endif
3374
3375 /* enc_locale() will try to find the encoding of the current locale. */
3376 p = enc_locale();
3377 if (p != NULL)
3378 {
3379 char_u *save_enc;
3380
3381 /* Try setting 'encoding' and check if the value is valid.
3382 * If not, go back to the default "latin1". */
3383 save_enc = p_enc;
3384 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003385 if (STRCMP(p_enc, "gb18030") == 0)
3386 {
3387 /* We don't support "gb18030", but "cp936" is a good substitute
3388 * for practical purposes, thus use that. It's not an alias to
3389 * still support conversion between gb18030 and utf-8. */
3390 p_enc = vim_strsave((char_u *)"cp936");
3391 vim_free(p);
3392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 if (mb_init() == NULL)
3394 {
3395 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396 if (opt_idx >= 0)
3397 {
3398 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3399 options[opt_idx].flags |= P_DEF_ALLOCED;
3400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003402#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3403 || defined(VMS)
3404 if (STRCMP(p_enc, "latin1") == 0
3405# ifdef FEAT_MBYTE
3406 || enc_utf8
3407# endif
3408 )
3409 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003410 /* Adjust the default for 'isprint' and 'iskeyword' to match
3411 * latin1. Also set the defaults for when 'nocompatible' is
3412 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003413 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003414 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003415 set_string_option_direct((char_u *)"isk", -1,
3416 ISK_LATIN1, OPT_FREE, SID_NONE);
3417 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003418 if (opt_idx >= 0)
3419 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003420 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003421 if (opt_idx >= 0)
3422 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003423 (void)init_chartab();
3424 }
3425#endif
3426
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427# if defined(WIN3264) && !defined(FEAT_GUI)
3428 /* Win32 console: When GetACP() returns a different value from
3429 * GetConsoleCP() set 'termencoding'. */
3430 if (GetACP() != GetConsoleCP())
3431 {
3432 char buf[50];
3433
3434 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3435 p_tenc = vim_strsave((char_u *)buf);
3436 if (p_tenc != NULL)
3437 {
3438 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003439 if (opt_idx >= 0)
3440 {
3441 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3442 options[opt_idx].flags |= P_DEF_ALLOCED;
3443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 convert_setup(&input_conv, p_tenc, p_enc);
3445 convert_setup(&output_conv, p_enc, p_tenc);
3446 }
3447 else
3448 p_tenc = empty_option;
3449 }
3450# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451# if defined(WIN3264) && defined(FEAT_MBYTE)
3452 /* $HOME may have characters in active code page. */
3453 init_homedir();
3454# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455 }
3456 else
3457 {
3458 vim_free(p_enc);
3459 p_enc = save_enc;
3460 }
3461 }
3462#endif
3463
3464#ifdef FEAT_MULTI_LANG
3465 /* Set the default for 'helplang'. */
3466 set_helplang_default(get_mess_lang());
3467#endif
3468}
3469
3470/*
3471 * Set an option to its default value.
3472 * This does not take care of side effects!
3473 */
3474 static void
3475set_option_default(opt_idx, opt_flags, compatible)
3476 int opt_idx;
3477 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3478 int compatible; /* use Vi default value */
3479{
3480 char_u *varp; /* pointer to variable for current option */
3481 int dvi; /* index in def_val[] */
3482 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003483 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3485
3486 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3487 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003488 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489 {
3490 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3491 if (flags & P_STRING)
3492 {
3493 /* Use set_string_option_direct() for local options to handle
3494 * freeing and allocating the value. */
3495 if (options[opt_idx].indir != PV_NONE)
3496 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003497 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 else
3499 {
3500 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3501 free_string_option(*(char_u **)(varp));
3502 *(char_u **)varp = options[opt_idx].def_val[dvi];
3503 options[opt_idx].flags &= ~P_ALLOCED;
3504 }
3505 }
3506 else if (flags & P_NUM)
3507 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003508 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 win_comp_scroll(curwin);
3510 else
3511 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003512 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 /* May also set global value for local option. */
3514 if (both)
3515 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3516 *(long *)varp;
3517 }
3518 }
3519 else /* P_BOOL */
3520 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003521 /* the cast to long is required for Manx C, long_i is needed for
3522 * MSVC */
3523 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003524#ifdef UNIX
3525 /* 'modeline' defaults to off for root */
3526 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3527 *(int *)varp = FALSE;
3528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 /* May also set global value for local option. */
3530 if (both)
3531 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3532 *(int *)varp;
3533 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003534
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003535 /* The default value is not insecure. */
3536 flagsp = insecure_flag(opt_idx, opt_flags);
3537 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003538 }
3539
3540#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003541 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542#endif
3543}
3544
3545/*
3546 * Set all options (except terminal options) to their default value.
3547 */
3548 static void
3549set_options_default(opt_flags)
3550 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3551{
3552 int i;
3553#ifdef FEAT_WINDOWS
3554 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003555 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556#endif
3557
3558 for (i = 0; !istermoption(&options[i]); i++)
3559 if (!(options[i].flags & P_NODEFAULT))
3560 set_option_default(i, opt_flags, p_cp);
3561
3562#ifdef FEAT_WINDOWS
3563 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003564 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 win_comp_scroll(wp);
3566#else
3567 win_comp_scroll(curwin);
3568#endif
3569}
3570
3571/*
3572 * Set the Vi-default value of a string option.
3573 * Used for 'sh', 'backupskip' and 'term'.
3574 */
3575 void
3576set_string_default(name, val)
3577 char *name;
3578 char_u *val;
3579{
3580 char_u *p;
3581 int opt_idx;
3582
3583 p = vim_strsave(val);
3584 if (p != NULL) /* we don't want a NULL */
3585 {
3586 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003587 if (opt_idx >= 0)
3588 {
3589 if (options[opt_idx].flags & P_DEF_ALLOCED)
3590 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3591 options[opt_idx].def_val[VI_DEFAULT] = p;
3592 options[opt_idx].flags |= P_DEF_ALLOCED;
3593 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594 }
3595}
3596
3597/*
3598 * Set the Vi-default value of a number option.
3599 * Used for 'lines' and 'columns'.
3600 */
3601 void
3602set_number_default(name, val)
3603 char *name;
3604 long val;
3605{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003606 int opt_idx;
3607
3608 opt_idx = findoption((char_u *)name);
3609 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003610 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611}
3612
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003613#if defined(EXITFREE) || defined(PROTO)
3614/*
3615 * Free all options.
3616 */
3617 void
3618free_all_options()
3619{
3620 int i;
3621
3622 for (i = 0; !istermoption(&options[i]); i++)
3623 {
3624 if (options[i].indir == PV_NONE)
3625 {
3626 /* global option: free value and default value. */
3627 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3628 free_string_option(*(char_u **)options[i].var);
3629 if (options[i].flags & P_DEF_ALLOCED)
3630 free_string_option(options[i].def_val[VI_DEFAULT]);
3631 }
3632 else if (options[i].var != VAR_WIN
3633 && (options[i].flags & P_STRING))
3634 /* buffer-local option: free global value */
3635 free_string_option(*(char_u **)options[i].var);
3636 }
3637}
3638#endif
3639
3640
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641/*
3642 * Initialize the options, part two: After getting Rows and Columns and
3643 * setting 'term'.
3644 */
3645 void
3646set_init_2()
3647{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003648 int idx;
3649
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650 /*
3651 * 'scroll' defaults to half the window height. Note that this default is
3652 * wrong when the window height changes.
3653 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003654 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003655 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003656 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003657 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658 comp_col();
3659
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003660 /*
3661 * 'window' is only for backwards compatibility with Vi.
3662 * Default is Rows - 1.
3663 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003664 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003665 p_window = Rows - 1;
3666 set_number_default("window", Rows - 1);
3667
Bram Moolenaarf740b292006-02-16 22:11:02 +00003668 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003670 /*
3671 * If 'background' wasn't set by the user, try guessing the value,
3672 * depending on the terminal name. Only need to check for terminals
3673 * with a dark background, that can handle color.
3674 */
3675 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003676 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3677 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003679 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003680 /* don't mark it as set, when starting the GUI it may be
3681 * changed again */
3682 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 }
3684#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003685
3686#ifdef CURSOR_SHAPE
3687 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3688#endif
3689#ifdef FEAT_MOUSESHAPE
3690 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3691#endif
3692#ifdef FEAT_PRINTER
3693 (void)parse_printoptions(); /* parse 'printoptions' default value */
3694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695}
3696
3697/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003698 * Return "dark" or "light" depending on the kind of terminal.
3699 * This is just guessing! Recognized are:
3700 * "linux" Linux console
3701 * "screen.linux" Linux console with screen
3702 * "cygwin" Cygwin shell
3703 * "putty" Putty program
3704 * We also check the COLORFGBG environment variable, which is set by
3705 * rxvt and derivatives. This variable contains either two or three
3706 * values separated by semicolons; we want the last value in either
3707 * case. If this value is 0-6 or 8, our background is dark.
3708 */
3709 static char_u *
3710term_bg_default()
3711{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003712#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3713 /* DOS console nearly always black */
3714 return (char_u *)"dark";
3715#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003716 char_u *p;
3717
Bram Moolenaarf740b292006-02-16 22:11:02 +00003718 if (STRCMP(T_NAME, "linux") == 0
3719 || STRCMP(T_NAME, "screen.linux") == 0
3720 || STRCMP(T_NAME, "cygwin") == 0
3721 || STRCMP(T_NAME, "putty") == 0
3722 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3723 && (p = vim_strrchr(p, ';')) != NULL
3724 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3725 && p[2] == NUL))
3726 return (char_u *)"dark";
3727 return (char_u *)"light";
3728#endif
3729}
3730
3731/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 * Initialize the options, part three: After reading the .vimrc
3733 */
3734 void
3735set_init_3()
3736{
3737#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3738/*
3739 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3740 * This is done after other initializations, where 'shell' might have been
3741 * set, but only if they have not been set before.
3742 */
3743 char_u *p;
3744 int idx_srr;
3745 int do_srr;
3746#ifdef FEAT_QUICKFIX
3747 int idx_sp;
3748 int do_sp;
3749#endif
3750
3751 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003752 if (idx_srr < 0)
3753 do_srr = FALSE;
3754 else
3755 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756#ifdef FEAT_QUICKFIX
3757 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003758 if (idx_sp < 0)
3759 do_sp = FALSE;
3760 else
3761 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762#endif
3763
3764 /*
3765 * Isolate the name of the shell:
3766 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3767 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003768 * But don't allow a space in the path, so that this works:
3769 * "/usr/bin/csh --rcfile ~/.cshrc"
3770 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003772#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 p = gettail(p_sh);
3774 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003775#else
3776 p = skiptowhite(p_sh);
3777 if (*p == NUL)
3778 {
3779 /* No white space, use the tail. */
3780 p = vim_strsave(gettail(p_sh));
3781 }
3782 else
3783 {
3784 char_u *p1, *p2;
3785
3786 /* Find the last path separator before the space. */
3787 p1 = p_sh;
3788 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3789 if (vim_ispathsep(*p2))
3790 p1 = p2 + 1;
3791 p = vim_strnsave(p1, (int)(p - p1));
3792 }
3793#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 if (p != NULL)
3795 {
3796 /*
3797 * Default for p_sp is "| tee", for p_srr is ">".
3798 * For known shells it is changed here to include stderr.
3799 */
3800 if ( fnamecmp(p, "csh") == 0
3801 || fnamecmp(p, "tcsh") == 0
3802# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3803 || fnamecmp(p, "csh.exe") == 0
3804 || fnamecmp(p, "tcsh.exe") == 0
3805# endif
3806 )
3807 {
3808#if defined(FEAT_QUICKFIX)
3809 if (do_sp)
3810 {
3811# ifdef WIN3264
3812 p_sp = (char_u *)">&";
3813# else
3814 p_sp = (char_u *)"|& tee";
3815# endif
3816 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3817 }
3818#endif
3819 if (do_srr)
3820 {
3821 p_srr = (char_u *)">&";
3822 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3823 }
3824 }
3825 else
3826# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3827 if ( fnamecmp(p, "sh") == 0
3828 || fnamecmp(p, "ksh") == 0
3829 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003830 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 || fnamecmp(p, "bash") == 0
3832# ifdef WIN3264
3833 || fnamecmp(p, "cmd") == 0
3834 || fnamecmp(p, "sh.exe") == 0
3835 || fnamecmp(p, "ksh.exe") == 0
3836 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003837 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 || fnamecmp(p, "bash.exe") == 0
3839 || fnamecmp(p, "cmd.exe") == 0
3840# endif
3841 )
3842# endif
3843 {
3844#if defined(FEAT_QUICKFIX)
3845 if (do_sp)
3846 {
3847# ifdef WIN3264
3848 p_sp = (char_u *)">%s 2>&1";
3849# else
3850 p_sp = (char_u *)"2>&1| tee";
3851# endif
3852 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3853 }
3854#endif
3855 if (do_srr)
3856 {
3857 p_srr = (char_u *)">%s 2>&1";
3858 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3859 }
3860 }
3861 vim_free(p);
3862 }
3863#endif
3864
3865#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3866 /*
3867 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3868 * This is done after other initializations, where 'shell' might have been
3869 * set, but only if they have not been set before. Default for p_shcf is
3870 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3871 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3872 * command.com. And for Win32 we need to set p_sxq instead.
3873 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003874 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 {
3876 int idx3;
3877
3878 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003879 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 {
3881 p_shcf = (char_u *)"-c";
3882 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3883 }
3884
3885# ifndef DJGPP
3886# ifdef WIN3264
3887 /* Somehow Win32 requires the quotes around the redirection too */
3888 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 {
3891 p_sxq = (char_u *)"\"";
3892 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3893 }
3894# else
3895 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003896 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 {
3898 p_shq = (char_u *)"\"";
3899 options[idx3].def_val[VI_DEFAULT] = p_shq;
3900 }
3901# endif
3902# endif
3903 }
3904#endif
3905
3906#ifdef FEAT_TITLE
3907 set_title_defaults();
3908#endif
3909}
3910
3911#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3912/*
3913 * When 'helplang' is still at its default value, set it to "lang".
3914 * Only the first two characters of "lang" are used.
3915 */
3916 void
3917set_helplang_default(lang)
3918 char_u *lang;
3919{
3920 int idx;
3921
3922 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3923 return;
3924 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003925 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 {
3927 if (options[idx].flags & P_ALLOCED)
3928 free_string_option(p_hlg);
3929 p_hlg = vim_strsave(lang);
3930 if (p_hlg == NULL)
3931 p_hlg = empty_option;
3932 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003933 {
3934 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3935 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3936 {
3937 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3938 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 options[idx].flags |= P_ALLOCED;
3943 }
3944}
3945#endif
3946
3947#ifdef FEAT_GUI
3948static char_u *gui_bg_default __ARGS((void));
3949
3950 static char_u *
3951gui_bg_default()
3952{
3953 if (gui_get_lightness(gui.back_pixel) < 127)
3954 return (char_u *)"dark";
3955 return (char_u *)"light";
3956}
3957
3958/*
3959 * Option initializations that can only be done after opening the GUI window.
3960 */
3961 void
3962init_gui_options()
3963{
3964 /* Set the 'background' option according to the lightness of the
3965 * background color, unless the user has set it already. */
3966 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3967 {
3968 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3969 highlight_changed();
3970 }
3971}
3972#endif
3973
3974#ifdef FEAT_TITLE
3975/*
3976 * 'title' and 'icon' only default to true if they have not been set or reset
3977 * in .vimrc and we can read the old value.
3978 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3979 * they can be reset. This reduces startup time when using X on a remote
3980 * machine.
3981 */
3982 void
3983set_title_defaults()
3984{
3985 int idx1;
3986 long val;
3987
3988 /*
3989 * If GUI is (going to be) used, we can always set the window title and
3990 * icon name. Saves a bit of time, because the X11 display server does
3991 * not need to be contacted.
3992 */
3993 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003994 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
3996#ifdef FEAT_GUI
3997 if (gui.starting || gui.in_use)
3998 val = TRUE;
3999 else
4000#endif
4001 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004002 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 p_title = val;
4004 }
4005 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004006 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007 {
4008#ifdef FEAT_GUI
4009 if (gui.starting || gui.in_use)
4010 val = TRUE;
4011 else
4012#endif
4013 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004014 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 p_icon = val;
4016 }
4017}
4018#endif
4019
4020/*
4021 * Parse 'arg' for option settings.
4022 *
4023 * 'arg' may be IObuff, but only when no errors can be present and option
4024 * does not need to be expanded with option_expand().
4025 * "opt_flags":
4026 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004027 * OPT_GLOBAL for ":setglobal"
4028 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004030 * OPT_WINONLY to only set window-local options
4031 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032 *
4033 * returns FAIL if an error is detected, OK otherwise
4034 */
4035 int
4036do_set(arg, opt_flags)
4037 char_u *arg; /* option string (may be written to!) */
4038 int opt_flags;
4039{
4040 int opt_idx;
4041 char_u *errmsg;
4042 char_u errbuf[80];
4043 char_u *startarg;
4044 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4045 int nextchar; /* next non-white char after option name */
4046 int afterchar; /* character just after option name */
4047 int len;
4048 int i;
4049 long value;
4050 int key;
4051 long_u flags; /* flags for current option */
4052 char_u *varp = NULL; /* pointer to variable for current option */
4053 int did_show = FALSE; /* already showed one value */
4054 int adding; /* "opt+=arg" */
4055 int prepending; /* "opt^=arg" */
4056 int removing; /* "opt-=arg" */
4057 int cp_val = 0;
4058 char_u key_name[2];
4059
4060 if (*arg == NUL)
4061 {
4062 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004063 did_show = TRUE;
4064 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 }
4066
4067 while (*arg != NUL) /* loop to process all options */
4068 {
4069 errmsg = NULL;
4070 startarg = arg; /* remember for error message */
4071
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004072 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4073 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 {
4075 /*
4076 * ":set all" show all options.
4077 * ":set all&" set all options to their default value.
4078 */
4079 arg += 3;
4080 if (*arg == '&')
4081 {
4082 ++arg;
4083 /* Only for :set command set global value of local options. */
4084 set_options_default(OPT_FREE | opt_flags);
4085 }
4086 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004087 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004089 did_show = TRUE;
4090 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004092 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 {
4094 showoptions(2, opt_flags);
4095 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004096 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 arg += 7;
4098 }
4099 else
4100 {
4101 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004102 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 {
4104 prefix = 0;
4105 arg += 2;
4106 }
4107 else if (STRNCMP(arg, "inv", 3) == 0)
4108 {
4109 prefix = 2;
4110 arg += 3;
4111 }
4112
4113 /* find end of name */
4114 key = 0;
4115 if (*arg == '<')
4116 {
4117 nextchar = 0;
4118 opt_idx = -1;
4119 /* look out for <t_>;> */
4120 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4121 len = 5;
4122 else
4123 {
4124 len = 1;
4125 while (arg[len] != NUL && arg[len] != '>')
4126 ++len;
4127 }
4128 if (arg[len] != '>')
4129 {
4130 errmsg = e_invarg;
4131 goto skip;
4132 }
4133 arg[len] = NUL; /* put NUL after name */
4134 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4135 opt_idx = findoption(arg + 1);
4136 arg[len++] = '>'; /* restore '>' */
4137 if (opt_idx == -1)
4138 key = find_key_option(arg + 1);
4139 }
4140 else
4141 {
4142 len = 0;
4143 /*
4144 * The two characters after "t_" may not be alphanumeric.
4145 */
4146 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4147 len = 4;
4148 else
4149 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4150 ++len;
4151 nextchar = arg[len];
4152 arg[len] = NUL; /* put NUL after name */
4153 opt_idx = findoption(arg);
4154 arg[len] = nextchar; /* restore nextchar */
4155 if (opt_idx == -1)
4156 key = find_key_option(arg);
4157 }
4158
4159 /* remember character after option name */
4160 afterchar = arg[len];
4161
4162 /* skip white space, allow ":set ai ?" */
4163 while (vim_iswhite(arg[len]))
4164 ++len;
4165
4166 adding = FALSE;
4167 prepending = FALSE;
4168 removing = FALSE;
4169 if (arg[len] != NUL && arg[len + 1] == '=')
4170 {
4171 if (arg[len] == '+')
4172 {
4173 adding = TRUE; /* "+=" */
4174 ++len;
4175 }
4176 else if (arg[len] == '^')
4177 {
4178 prepending = TRUE; /* "^=" */
4179 ++len;
4180 }
4181 else if (arg[len] == '-')
4182 {
4183 removing = TRUE; /* "-=" */
4184 ++len;
4185 }
4186 }
4187 nextchar = arg[len];
4188
4189 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4190 {
4191 errmsg = (char_u *)N_("E518: Unknown option");
4192 goto skip;
4193 }
4194
4195 if (opt_idx >= 0)
4196 {
4197 if (options[opt_idx].var == NULL) /* hidden option: skip */
4198 {
4199 /* Only give an error message when requesting the value of
4200 * a hidden option, ignore setting it. */
4201 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4202 && (!(options[opt_idx].flags & P_BOOL)
4203 || nextchar == '?'))
4204 errmsg = (char_u *)N_("E519: Option not supported");
4205 goto skip;
4206 }
4207
4208 flags = options[opt_idx].flags;
4209 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4210 }
4211 else
4212 {
4213 flags = P_STRING;
4214 if (key < 0)
4215 {
4216 key_name[0] = KEY2TERMCAP0(key);
4217 key_name[1] = KEY2TERMCAP1(key);
4218 }
4219 else
4220 {
4221 key_name[0] = KS_KEY;
4222 key_name[1] = (key & 0xff);
4223 }
4224 }
4225
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004226 /* Skip all options that are not window-local (used when showing
4227 * an already loaded buffer in a window). */
4228 if ((opt_flags & OPT_WINONLY)
4229 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4230 goto skip;
4231
Bram Moolenaara3227e22006-03-08 21:32:40 +00004232 /* Skip all options that are window-local (used for :vimgrep). */
4233 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4234 && options[opt_idx].var == VAR_WIN)
4235 goto skip;
4236
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004237 /* Disallow changing some options from modelines. */
4238 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004240 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004241 {
4242 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4243 goto skip;
4244 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004245#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004246 /* In diff mode some options are overruled. This avoids that
4247 * 'foldmethod' becomes "marker" instead of "diff" and that
4248 * "wrap" gets set. */
4249 if (curwin->w_p_diff
4250 && (options[opt_idx].indir == PV_FDM
4251 || options[opt_idx].indir == PV_WRAP))
4252 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254 }
4255
4256#ifdef HAVE_SANDBOX
4257 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004258 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259 {
4260 errmsg = (char_u *)_(e_sandbox);
4261 goto skip;
4262 }
4263#endif
4264
4265 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4266 {
4267 arg += len;
4268 cp_val = p_cp;
4269 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4270 {
4271 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4272 {
4273 cp_val = FALSE;
4274 arg += 3;
4275 }
4276 else /* "opt&vi": set to Vi default */
4277 {
4278 cp_val = TRUE;
4279 arg += 2;
4280 }
4281 }
4282 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4283 && arg[1] != NUL && !vim_iswhite(arg[1]))
4284 {
4285 errmsg = e_trailing;
4286 goto skip;
4287 }
4288 }
4289
4290 /*
4291 * allow '=' and ':' as MSDOS command.com allows only one
4292 * '=' character per "set" command line. grrr. (jw)
4293 */
4294 if (nextchar == '?'
4295 || (prefix == 1
4296 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4297 && !(flags & P_BOOL)))
4298 {
4299 /*
4300 * print value
4301 */
4302 if (did_show)
4303 msg_putchar('\n'); /* cursor below last one */
4304 else
4305 {
4306 gotocmdline(TRUE); /* cursor at status line */
4307 did_show = TRUE; /* remember that we did a line */
4308 }
4309 if (opt_idx >= 0)
4310 {
4311 showoneopt(&options[opt_idx], opt_flags);
4312#ifdef FEAT_EVAL
4313 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004314 {
4315 /* Mention where the option was last set. */
4316 if (varp == options[opt_idx].var)
4317 last_set_msg(options[opt_idx].scriptID);
4318 else if ((int)options[opt_idx].indir & PV_WIN)
4319 last_set_msg(curwin->w_p_scriptID[
4320 (int)options[opt_idx].indir & PV_MASK]);
4321 else if ((int)options[opt_idx].indir & PV_BUF)
4322 last_set_msg(curbuf->b_p_scriptID[
4323 (int)options[opt_idx].indir & PV_MASK]);
4324 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325#endif
4326 }
4327 else
4328 {
4329 char_u *p;
4330
4331 p = find_termcode(key_name);
4332 if (p == NULL)
4333 {
4334 errmsg = (char_u *)N_("E518: Unknown option");
4335 goto skip;
4336 }
4337 else
4338 (void)show_one_termcode(key_name, p, TRUE);
4339 }
4340 if (nextchar != '?'
4341 && nextchar != NUL && !vim_iswhite(afterchar))
4342 errmsg = e_trailing;
4343 }
4344 else
4345 {
4346 if (flags & P_BOOL) /* boolean */
4347 {
4348 if (nextchar == '=' || nextchar == ':')
4349 {
4350 errmsg = e_invarg;
4351 goto skip;
4352 }
4353
4354 /*
4355 * ":set opt!": invert
4356 * ":set opt&": reset to default value
4357 * ":set opt<": reset to global value
4358 */
4359 if (nextchar == '!')
4360 value = *(int *)(varp) ^ 1;
4361 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004362 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 ((flags & P_VI_DEF) || cp_val)
4364 ? VI_DEFAULT : VIM_DEFAULT];
4365 else if (nextchar == '<')
4366 {
4367 /* For 'autoread' -1 means to use global value. */
4368 if ((int *)varp == &curbuf->b_p_ar
4369 && opt_flags == OPT_LOCAL)
4370 value = -1;
4371 else
4372 value = *(int *)get_varp_scope(&(options[opt_idx]),
4373 OPT_GLOBAL);
4374 }
4375 else
4376 {
4377 /*
4378 * ":set invopt": invert
4379 * ":set opt" or ":set noopt": set or reset
4380 */
4381 if (nextchar != NUL && !vim_iswhite(afterchar))
4382 {
4383 errmsg = e_trailing;
4384 goto skip;
4385 }
4386 if (prefix == 2) /* inv */
4387 value = *(int *)(varp) ^ 1;
4388 else
4389 value = prefix;
4390 }
4391
4392 errmsg = set_bool_option(opt_idx, varp, (int)value,
4393 opt_flags);
4394 }
4395 else /* numeric or string */
4396 {
4397 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4398 || prefix != 1)
4399 {
4400 errmsg = e_invarg;
4401 goto skip;
4402 }
4403
4404 if (flags & P_NUM) /* numeric */
4405 {
4406 /*
4407 * Different ways to set a number option:
4408 * & set to default value
4409 * < set to global value
4410 * <xx> accept special key codes for 'wildchar'
4411 * c accept any non-digit for 'wildchar'
4412 * [-]0-9 set number
4413 * other error
4414 */
4415 ++arg;
4416 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004417 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 ((flags & P_VI_DEF) || cp_val)
4419 ? VI_DEFAULT : VIM_DEFAULT];
4420 else if (nextchar == '<')
4421 value = *(long *)get_varp_scope(&(options[opt_idx]),
4422 OPT_GLOBAL);
4423 else if (((long *)varp == &p_wc
4424 || (long *)varp == &p_wcm)
4425 && (*arg == '<'
4426 || *arg == '^'
4427 || ((!arg[1] || vim_iswhite(arg[1]))
4428 && !VIM_ISDIGIT(*arg))))
4429 {
4430 value = string_to_key(arg);
4431 if (value == 0 && (long *)varp != &p_wcm)
4432 {
4433 errmsg = e_invarg;
4434 goto skip;
4435 }
4436 }
4437 /* allow negative numbers (for 'undolevels') */
4438 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4439 {
4440 i = 0;
4441 if (*arg == '-')
4442 i = 1;
4443#ifdef HAVE_STRTOL
4444 value = strtol((char *)arg, NULL, 0);
4445 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4446 i += 2;
4447#else
4448 value = atol((char *)arg);
4449#endif
4450 while (VIM_ISDIGIT(arg[i]))
4451 ++i;
4452 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4453 {
4454 errmsg = e_invarg;
4455 goto skip;
4456 }
4457 }
4458 else
4459 {
4460 errmsg = (char_u *)N_("E521: Number required after =");
4461 goto skip;
4462 }
4463
4464 if (adding)
4465 value = *(long *)varp + value;
4466 if (prepending)
4467 value = *(long *)varp * value;
4468 if (removing)
4469 value = *(long *)varp - value;
4470 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004471 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472 }
4473 else if (opt_idx >= 0) /* string */
4474 {
4475 char_u *save_arg = NULL;
4476 char_u *s = NULL;
4477 char_u *oldval; /* previous value if *varp */
4478 char_u *newval;
4479 char_u *origval;
4480 unsigned newlen;
4481 int comma;
4482 int bs;
4483 int new_value_alloced; /* new string option
4484 was allocated */
4485
4486 /* When using ":set opt=val" for a global option
4487 * with a local value the local value will be
4488 * reset, use the global value here. */
4489 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004490 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491 varp = options[opt_idx].var;
4492
4493 /* The old value is kept until we are sure that the
4494 * new value is valid. */
4495 oldval = *(char_u **)varp;
4496 if (nextchar == '&') /* set to default val */
4497 {
4498 newval = options[opt_idx].def_val[
4499 ((flags & P_VI_DEF) || cp_val)
4500 ? VI_DEFAULT : VIM_DEFAULT];
4501 if ((char_u **)varp == &p_bg)
4502 {
4503 /* guess the value of 'background' */
4504#ifdef FEAT_GUI
4505 if (gui.in_use)
4506 newval = gui_bg_default();
4507 else
4508#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004509 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004510 }
4511
4512 /* expand environment variables and ~ (since the
4513 * default value was already expanded, only
4514 * required when an environment variable was set
4515 * later */
4516 if (newval == NULL)
4517 newval = empty_option;
4518 else
4519 {
4520 s = option_expand(opt_idx, newval);
4521 if (s == NULL)
4522 s = newval;
4523 newval = vim_strsave(s);
4524 }
4525 new_value_alloced = TRUE;
4526 }
4527 else if (nextchar == '<') /* set to global val */
4528 {
4529 newval = vim_strsave(*(char_u **)get_varp_scope(
4530 &(options[opt_idx]), OPT_GLOBAL));
4531 new_value_alloced = TRUE;
4532 }
4533 else
4534 {
4535 ++arg; /* jump to after the '=' or ':' */
4536
4537 /*
4538 * Set 'keywordprg' to ":help" if an empty
4539 * value was passed to :set by the user.
4540 * Misuse errbuf[] for the resulting string.
4541 */
4542 if (varp == (char_u *)&p_kp
4543 && (*arg == NUL || *arg == ' '))
4544 {
4545 STRCPY(errbuf, ":help");
4546 save_arg = arg;
4547 arg = errbuf;
4548 }
4549 /*
4550 * Convert 'whichwrap' number to string, for
4551 * backwards compatibility with Vim 3.0.
4552 * Misuse errbuf[] for the resulting string.
4553 */
4554 else if (varp == (char_u *)&p_ww
4555 && VIM_ISDIGIT(*arg))
4556 {
4557 *errbuf = NUL;
4558 i = getdigits(&arg);
4559 if (i & 1)
4560 STRCAT(errbuf, "b,");
4561 if (i & 2)
4562 STRCAT(errbuf, "s,");
4563 if (i & 4)
4564 STRCAT(errbuf, "h,l,");
4565 if (i & 8)
4566 STRCAT(errbuf, "<,>,");
4567 if (i & 16)
4568 STRCAT(errbuf, "[,],");
4569 if (*errbuf != NUL) /* remove trailing , */
4570 errbuf[STRLEN(errbuf) - 1] = NUL;
4571 save_arg = arg;
4572 arg = errbuf;
4573 }
4574 /*
4575 * Remove '>' before 'dir' and 'bdir', for
4576 * backwards compatibility with version 3.0
4577 */
4578 else if ( *arg == '>'
4579 && (varp == (char_u *)&p_dir
4580 || varp == (char_u *)&p_bdir))
4581 {
4582 ++arg;
4583 }
4584
4585 /* When setting the local value of a global
4586 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004587 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 && (opt_flags & OPT_LOCAL))
4589 origval = *(char_u **)get_varp(
4590 &options[opt_idx]);
4591 else
4592 origval = oldval;
4593
4594 /*
4595 * Copy the new string into allocated memory.
4596 * Can't use set_string_option_direct(), because
4597 * we need to remove the backslashes.
4598 */
4599 /* get a bit too much */
4600 newlen = (unsigned)STRLEN(arg) + 1;
4601 if (adding || prepending || removing)
4602 newlen += (unsigned)STRLEN(origval) + 1;
4603 newval = alloc(newlen);
4604 if (newval == NULL) /* out of mem, don't change */
4605 break;
4606 s = newval;
4607
4608 /*
4609 * Copy the string, skip over escaped chars.
4610 * For MS-DOS and WIN32 backslashes before normal
4611 * file name characters are not removed, and keep
4612 * backslash at start, for "\\machine\path", but
4613 * do remove it for "\\\\machine\\path".
4614 * The reverse is found in ExpandOldSetting().
4615 */
4616 while (*arg && !vim_iswhite(*arg))
4617 {
4618 if (*arg == '\\' && arg[1] != NUL
4619#ifdef BACKSLASH_IN_FILENAME
4620 && !((flags & P_EXPAND)
4621 && vim_isfilec(arg[1])
4622 && (arg[1] != '\\'
4623 || (s == newval
4624 && arg[2] != '\\')))
4625#endif
4626 )
4627 ++arg; /* remove backslash */
4628#ifdef FEAT_MBYTE
4629 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004630 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004631 {
4632 /* copy multibyte char */
4633 mch_memmove(s, arg, (size_t)i);
4634 arg += i;
4635 s += i;
4636 }
4637 else
4638#endif
4639 *s++ = *arg++;
4640 }
4641 *s = NUL;
4642
4643 /*
4644 * Expand environment variables and ~.
4645 * Don't do it when adding without inserting a
4646 * comma.
4647 */
4648 if (!(adding || prepending || removing)
4649 || (flags & P_COMMA))
4650 {
4651 s = option_expand(opt_idx, newval);
4652 if (s != NULL)
4653 {
4654 vim_free(newval);
4655 newlen = (unsigned)STRLEN(s) + 1;
4656 if (adding || prepending || removing)
4657 newlen += (unsigned)STRLEN(origval) + 1;
4658 newval = alloc(newlen);
4659 if (newval == NULL)
4660 break;
4661 STRCPY(newval, s);
4662 }
4663 }
4664
4665 /* locate newval[] in origval[] when removing it
4666 * and when adding to avoid duplicates */
4667 i = 0; /* init for GCC */
4668 if (removing || (flags & P_NODUP))
4669 {
4670 i = (int)STRLEN(newval);
4671 bs = 0;
4672 for (s = origval; *s; ++s)
4673 {
4674 if ((!(flags & P_COMMA)
4675 || s == origval
4676 || (s[-1] == ',' && !(bs & 1)))
4677 && STRNCMP(s, newval, i) == 0
4678 && (!(flags & P_COMMA)
4679 || s[i] == ','
4680 || s[i] == NUL))
4681 break;
4682 /* Count backspaces. Only a comma with an
4683 * even number of backspaces before it is
4684 * recognized as a separator */
4685 if (s > origval && s[-1] == '\\')
4686 ++bs;
4687 else
4688 bs = 0;
4689 }
4690
4691 /* do not add if already there */
4692 if ((adding || prepending) && *s)
4693 {
4694 prepending = FALSE;
4695 adding = FALSE;
4696 STRCPY(newval, origval);
4697 }
4698 }
4699
4700 /* concatenate the two strings; add a ',' if
4701 * needed */
4702 if (adding || prepending)
4703 {
4704 comma = ((flags & P_COMMA) && *origval != NUL
4705 && *newval != NUL);
4706 if (adding)
4707 {
4708 i = (int)STRLEN(origval);
4709 mch_memmove(newval + i + comma, newval,
4710 STRLEN(newval) + 1);
4711 mch_memmove(newval, origval, (size_t)i);
4712 }
4713 else
4714 {
4715 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004716 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004717 }
4718 if (comma)
4719 newval[i] = ',';
4720 }
4721
4722 /* Remove newval[] from origval[]. (Note: "i" has
4723 * been set above and is used here). */
4724 if (removing)
4725 {
4726 STRCPY(newval, origval);
4727 if (*s)
4728 {
4729 /* may need to remove a comma */
4730 if (flags & P_COMMA)
4731 {
4732 if (s == origval)
4733 {
4734 /* include comma after string */
4735 if (s[i] == ',')
4736 ++i;
4737 }
4738 else
4739 {
4740 /* include comma before string */
4741 --s;
4742 ++i;
4743 }
4744 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004745 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 }
4747 }
4748
4749 if (flags & P_FLAGLIST)
4750 {
4751 /* Remove flags that appear twice. */
4752 for (s = newval; *s; ++s)
4753 if ((!(flags & P_COMMA) || *s != ',')
4754 && vim_strchr(s + 1, *s) != NULL)
4755 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004756 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004757 --s;
4758 }
4759 }
4760
4761 if (save_arg != NULL) /* number for 'whichwrap' */
4762 arg = save_arg;
4763 new_value_alloced = TRUE;
4764 }
4765
4766 /* Set the new value. */
4767 *(char_u **)(varp) = newval;
4768
4769 /* Handle side effects, and set the global value for
4770 * ":set" on local options. */
4771 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4772 new_value_alloced, oldval, errbuf, opt_flags);
4773
4774 /* If error detected, print the error message. */
4775 if (errmsg != NULL)
4776 goto skip;
4777 }
4778 else /* key code option */
4779 {
4780 char_u *p;
4781
4782 if (nextchar == '&')
4783 {
4784 if (add_termcap_entry(key_name, TRUE) == FAIL)
4785 errmsg = (char_u *)N_("E522: Not found in termcap");
4786 }
4787 else
4788 {
4789 ++arg; /* jump to after the '=' or ':' */
4790 for (p = arg; *p && !vim_iswhite(*p); ++p)
4791 if (*p == '\\' && p[1] != NUL)
4792 ++p;
4793 nextchar = *p;
4794 *p = NUL;
4795 add_termcode(key_name, arg, FALSE);
4796 *p = nextchar;
4797 }
4798 if (full_screen)
4799 ttest(FALSE);
4800 redraw_all_later(CLEAR);
4801 }
4802 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004803
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004805 did_set_option(opt_idx, opt_flags,
4806 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 }
4808
4809skip:
4810 /*
4811 * Advance to next argument.
4812 * - skip until a blank found, taking care of backslashes
4813 * - skip blanks
4814 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4815 */
4816 for (i = 0; i < 2 ; ++i)
4817 {
4818 while (*arg != NUL && !vim_iswhite(*arg))
4819 if (*arg++ == '\\' && *arg != NUL)
4820 ++arg;
4821 arg = skipwhite(arg);
4822 if (*arg != '=')
4823 break;
4824 }
4825 }
4826
4827 if (errmsg != NULL)
4828 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004829 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004830 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 if (i + (arg - startarg) < IOSIZE)
4832 {
4833 /* append the argument with the error */
4834 STRCAT(IObuff, ": ");
4835 mch_memmove(IObuff + i, startarg, (arg - startarg));
4836 IObuff[i + (arg - startarg)] = NUL;
4837 }
4838 /* make sure all characters are printable */
4839 trans_characters(IObuff, IOSIZE);
4840
4841 ++no_wait_return; /* wait_return done later */
4842 emsg(IObuff); /* show error highlighted */
4843 --no_wait_return;
4844
4845 return FAIL;
4846 }
4847
4848 arg = skipwhite(arg);
4849 }
4850
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004851theend:
4852 if (silent_mode && did_show)
4853 {
4854 /* After displaying option values in silent mode. */
4855 silent_mode = FALSE;
4856 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4857 msg_putchar('\n');
4858 cursor_on(); /* msg_start() switches it off */
4859 out_flush();
4860 silent_mode = TRUE;
4861 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4862 }
4863
Bram Moolenaar071d4272004-06-13 20:20:40 +00004864 return OK;
4865}
4866
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004867/*
4868 * Call this when an option has been given a new value through a user command.
4869 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4870 */
4871 static void
4872did_set_option(opt_idx, opt_flags, new_value)
4873 int opt_idx;
4874 int opt_flags; /* possibly with OPT_MODELINE */
4875 int new_value; /* value was replaced completely */
4876{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004877 long_u *p;
4878
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004879 options[opt_idx].flags |= P_WAS_SET;
4880
4881 /* When an option is set in the sandbox, from a modeline or in secure mode
4882 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004883 * flag. */
4884 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004885 if (secure
4886#ifdef HAVE_SANDBOX
4887 || sandbox != 0
4888#endif
4889 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004890 *p = *p | P_INSECURE;
4891 else if (new_value)
4892 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004893}
4894
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 static char_u *
4896illegal_char(errbuf, c)
4897 char_u *errbuf;
4898 int c;
4899{
4900 if (errbuf == NULL)
4901 return (char_u *)"";
4902 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004903 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004904 return errbuf;
4905}
4906
4907/*
4908 * Convert a key name or string into a key value.
4909 * Used for 'wildchar' and 'cedit' options.
4910 */
4911 static int
4912string_to_key(arg)
4913 char_u *arg;
4914{
4915 if (*arg == '<')
4916 return find_key_option(arg + 1);
4917 if (*arg == '^')
4918 return Ctrl_chr(arg[1]);
4919 return *arg;
4920}
4921
4922#ifdef FEAT_CMDWIN
4923/*
4924 * Check value of 'cedit' and set cedit_key.
4925 * Returns NULL if value is OK, error message otherwise.
4926 */
4927 static char_u *
4928check_cedit()
4929{
4930 int n;
4931
4932 if (*p_cedit == NUL)
4933 cedit_key = -1;
4934 else
4935 {
4936 n = string_to_key(p_cedit);
4937 if (vim_isprintc(n))
4938 return e_invarg;
4939 cedit_key = n;
4940 }
4941 return NULL;
4942}
4943#endif
4944
4945#ifdef FEAT_TITLE
4946/*
4947 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4948 * maketitle() to create and display it.
4949 * When switching the title or icon off, call mch_restore_title() to get
4950 * the old value back.
4951 */
4952 static void
4953did_set_title(icon)
4954 int icon; /* Did set icon instead of title */
4955{
4956 if (starting != NO_SCREEN
4957#ifdef FEAT_GUI
4958 && !gui.starting
4959#endif
4960 )
4961 {
4962 maketitle();
4963 if (icon)
4964 {
4965 if (!p_icon)
4966 mch_restore_title(2);
4967 }
4968 else
4969 {
4970 if (!p_title)
4971 mch_restore_title(1);
4972 }
4973 }
4974}
4975#endif
4976
4977/*
4978 * set_options_bin - called when 'bin' changes value.
4979 */
4980 void
4981set_options_bin(oldval, newval, opt_flags)
4982 int oldval;
4983 int newval;
4984 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4985{
4986 /*
4987 * The option values that are changed when 'bin' changes are
4988 * copied when 'bin is set and restored when 'bin' is reset.
4989 */
4990 if (newval)
4991 {
4992 if (!oldval) /* switched on */
4993 {
4994 if (!(opt_flags & OPT_GLOBAL))
4995 {
4996 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4997 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4998 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4999 curbuf->b_p_et_nobin = curbuf->b_p_et;
5000 }
5001 if (!(opt_flags & OPT_LOCAL))
5002 {
5003 p_tw_nobin = p_tw;
5004 p_wm_nobin = p_wm;
5005 p_ml_nobin = p_ml;
5006 p_et_nobin = p_et;
5007 }
5008 }
5009
5010 if (!(opt_flags & OPT_GLOBAL))
5011 {
5012 curbuf->b_p_tw = 0; /* no automatic line wrap */
5013 curbuf->b_p_wm = 0; /* no automatic line wrap */
5014 curbuf->b_p_ml = 0; /* no modelines */
5015 curbuf->b_p_et = 0; /* no expandtab */
5016 }
5017 if (!(opt_flags & OPT_LOCAL))
5018 {
5019 p_tw = 0;
5020 p_wm = 0;
5021 p_ml = FALSE;
5022 p_et = FALSE;
5023 p_bin = TRUE; /* needed when called for the "-b" argument */
5024 }
5025 }
5026 else if (oldval) /* switched off */
5027 {
5028 if (!(opt_flags & OPT_GLOBAL))
5029 {
5030 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5031 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5032 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5033 curbuf->b_p_et = curbuf->b_p_et_nobin;
5034 }
5035 if (!(opt_flags & OPT_LOCAL))
5036 {
5037 p_tw = p_tw_nobin;
5038 p_wm = p_wm_nobin;
5039 p_ml = p_ml_nobin;
5040 p_et = p_et_nobin;
5041 }
5042 }
5043}
5044
5045#ifdef FEAT_VIMINFO
5046/*
5047 * Find the parameter represented by the given character (eg ', :, ", or /),
5048 * and return its associated value in the 'viminfo' string.
5049 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005050 * If the parameter is not specified in the string or there is no following
5051 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005052 */
5053 int
5054get_viminfo_parameter(type)
5055 int type;
5056{
5057 char_u *p;
5058
5059 p = find_viminfo_parameter(type);
5060 if (p != NULL && VIM_ISDIGIT(*p))
5061 return atoi((char *)p);
5062 return -1;
5063}
5064
5065/*
5066 * Find the parameter represented by the given character (eg ''', ':', '"', or
5067 * '/') in the 'viminfo' option and return a pointer to the string after it.
5068 * Return NULL if the parameter is not specified in the string.
5069 */
5070 char_u *
5071find_viminfo_parameter(type)
5072 int type;
5073{
5074 char_u *p;
5075
5076 for (p = p_viminfo; *p; ++p)
5077 {
5078 if (*p == type)
5079 return p + 1;
5080 if (*p == 'n') /* 'n' is always the last one */
5081 break;
5082 p = vim_strchr(p, ','); /* skip until next ',' */
5083 if (p == NULL) /* hit the end without finding parameter */
5084 break;
5085 }
5086 return NULL;
5087}
5088#endif
5089
5090/*
5091 * Expand environment variables for some string options.
5092 * These string options cannot be indirect!
5093 * If "val" is NULL expand the current value of the option.
5094 * Return pointer to NameBuff, or NULL when not expanded.
5095 */
5096 static char_u *
5097option_expand(opt_idx, val)
5098 int opt_idx;
5099 char_u *val;
5100{
5101 /* if option doesn't need expansion nothing to do */
5102 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5103 return NULL;
5104
5105 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5106 * expand_env() would truncate the string. */
5107 if (val != NULL && STRLEN(val) > MAXPATHL)
5108 return NULL;
5109
5110 if (val == NULL)
5111 val = *(char_u **)options[opt_idx].var;
5112
5113 /*
5114 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5115 * Escape spaces when expanding 'tags', they are used to separate file
5116 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005117 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005118 */
5119 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005120 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005121#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005122 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5123#endif
5124 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5126 return NULL;
5127
5128 return NameBuff;
5129}
5130
5131/*
5132 * After setting various option values: recompute variables that depend on
5133 * option values.
5134 */
5135 static void
5136didset_options()
5137{
5138 /* initialize the table for 'iskeyword' et.al. */
5139 (void)init_chartab();
5140
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005141#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005142 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005144 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5145#ifdef FEAT_SESSION
5146 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5147 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5148#endif
5149#ifdef FEAT_FOLDING
5150 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5151#endif
5152 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5153#ifdef FEAT_VIRTUALEDIT
5154 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5155#endif
5156#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5157 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5158#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005159#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005160 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005161 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005162 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005164#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5165 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5166#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005167#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5169#endif
5170#ifdef FEAT_CMDWIN
5171 /* set cedit_key */
5172 (void)check_cedit();
5173#endif
5174}
5175
5176/*
5177 * Check for string options that are NULL (normally only termcap options).
5178 */
5179 void
5180check_options()
5181{
5182 int opt_idx;
5183
5184 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5185 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5186 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5187}
5188
5189/*
5190 * Check string options in a buffer for NULL value.
5191 */
5192 void
5193check_buf_options(buf)
5194 buf_T *buf;
5195{
5196#if defined(FEAT_QUICKFIX)
5197 check_string_option(&buf->b_p_bh);
5198 check_string_option(&buf->b_p_bt);
5199#endif
5200#ifdef FEAT_MBYTE
5201 check_string_option(&buf->b_p_fenc);
5202#endif
5203 check_string_option(&buf->b_p_ff);
5204#ifdef FEAT_FIND_ID
5205 check_string_option(&buf->b_p_def);
5206 check_string_option(&buf->b_p_inc);
5207# ifdef FEAT_EVAL
5208 check_string_option(&buf->b_p_inex);
5209# endif
5210#endif
5211#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5212 check_string_option(&buf->b_p_inde);
5213 check_string_option(&buf->b_p_indk);
5214#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005215#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5216 check_string_option(&buf->b_p_bexpr);
5217#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005218#if defined(FEAT_EVAL)
5219 check_string_option(&buf->b_p_fex);
5220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221#ifdef FEAT_CRYPT
5222 check_string_option(&buf->b_p_key);
5223#endif
5224 check_string_option(&buf->b_p_kp);
5225 check_string_option(&buf->b_p_mps);
5226 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005227 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 check_string_option(&buf->b_p_isk);
5229#ifdef FEAT_COMMENTS
5230 check_string_option(&buf->b_p_com);
5231#endif
5232#ifdef FEAT_FOLDING
5233 check_string_option(&buf->b_p_cms);
5234#endif
5235 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005236#ifdef FEAT_TEXTOBJ
5237 check_string_option(&buf->b_p_qe);
5238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239#ifdef FEAT_SYN_HL
5240 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005241#endif
5242#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005243 check_string_option(&buf->b_s.b_p_spc);
5244 check_string_option(&buf->b_s.b_p_spf);
5245 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246#endif
5247#ifdef FEAT_SEARCHPATH
5248 check_string_option(&buf->b_p_sua);
5249#endif
5250#ifdef FEAT_CINDENT
5251 check_string_option(&buf->b_p_cink);
5252 check_string_option(&buf->b_p_cino);
5253#endif
5254#ifdef FEAT_AUTOCMD
5255 check_string_option(&buf->b_p_ft);
5256#endif
5257#ifdef FEAT_OSFILETYPE
5258 check_string_option(&buf->b_p_oft);
5259#endif
5260#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5261 check_string_option(&buf->b_p_cinw);
5262#endif
5263#ifdef FEAT_INS_EXPAND
5264 check_string_option(&buf->b_p_cpt);
5265#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005266#ifdef FEAT_COMPL_FUNC
5267 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005268 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270#ifdef FEAT_KEYMAP
5271 check_string_option(&buf->b_p_keymap);
5272#endif
5273#ifdef FEAT_QUICKFIX
5274 check_string_option(&buf->b_p_gp);
5275 check_string_option(&buf->b_p_mp);
5276 check_string_option(&buf->b_p_efm);
5277#endif
5278 check_string_option(&buf->b_p_ep);
5279 check_string_option(&buf->b_p_path);
5280 check_string_option(&buf->b_p_tags);
5281#ifdef FEAT_INS_EXPAND
5282 check_string_option(&buf->b_p_dict);
5283 check_string_option(&buf->b_p_tsr);
5284#endif
5285}
5286
5287/*
5288 * Free the string allocated for an option.
5289 * Checks for the string being empty_option. This may happen if we're out of
5290 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5291 * check_options().
5292 * Does NOT check for P_ALLOCED flag!
5293 */
5294 void
5295free_string_option(p)
5296 char_u *p;
5297{
5298 if (p != empty_option)
5299 vim_free(p);
5300}
5301
5302 void
5303clear_string_option(pp)
5304 char_u **pp;
5305{
5306 if (*pp != empty_option)
5307 vim_free(*pp);
5308 *pp = empty_option;
5309}
5310
5311 static void
5312check_string_option(pp)
5313 char_u **pp;
5314{
5315 if (*pp == NULL)
5316 *pp = empty_option;
5317}
5318
5319/*
5320 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5321 */
5322 void
5323set_term_option_alloced(p)
5324 char_u **p;
5325{
5326 int opt_idx;
5327
5328 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5329 if (options[opt_idx].var == (char_u *)p)
5330 {
5331 options[opt_idx].flags |= P_ALLOCED;
5332 return;
5333 }
5334 return; /* cannot happen: didn't find it! */
5335}
5336
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005337#if defined(FEAT_EVAL) || defined(PROTO)
5338/*
5339 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5340 * Return FALSE when it wasn't.
5341 * Return -1 for an unknown option.
5342 */
5343 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005344was_set_insecurely(opt, opt_flags)
5345 char_u *opt;
5346 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005347{
5348 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005349 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005350
5351 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005352 {
5353 flagp = insecure_flag(idx, opt_flags);
5354 return (*flagp & P_INSECURE) != 0;
5355 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005356 EMSG2(_(e_intern2), "was_set_insecurely()");
5357 return -1;
5358}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005359
5360/*
5361 * Get a pointer to the flags used for the P_INSECURE flag of option
5362 * "opt_idx". For some local options a local flags field is used.
5363 */
5364 static long_u *
5365insecure_flag(opt_idx, opt_flags)
5366 int opt_idx;
5367 int opt_flags;
5368{
5369 if (opt_flags & OPT_LOCAL)
5370 switch ((int)options[opt_idx].indir)
5371 {
5372#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005373 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005374#endif
5375#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005376# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005377 case PV_FDE: return &curwin->w_p_fde_flags;
5378 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005379# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005380# ifdef FEAT_BEVAL
5381 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5382# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005383# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005384 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005385# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005386 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005387# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005388 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005389# endif
5390#endif
5391 }
5392
5393 /* Nothing special, return global flags field. */
5394 return &options[opt_idx].flags;
5395}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005396#endif
5397
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005398#ifdef FEAT_TITLE
5399static void redraw_titles __ARGS((void));
5400
5401/*
5402 * Redraw the window title and/or tab page text later.
5403 */
5404static void redraw_titles()
5405{
5406 need_maketitle = TRUE;
5407# ifdef FEAT_WINDOWS
5408 redraw_tabline = TRUE;
5409# endif
5410}
5411#endif
5412
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413/*
5414 * Set a string option to a new value (without checking the effect).
5415 * The string is copied into allocated memory.
5416 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005417 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005418 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419 */
5420 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005421set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422 char_u *name;
5423 int opt_idx;
5424 char_u *val;
5425 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005426 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427{
5428 char_u *s;
5429 char_u **varp;
5430 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005431 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432
Bram Moolenaar89d40322006-08-29 15:30:07 +00005433 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005434 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005435 idx = findoption(name);
5436 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005437 {
5438 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441 }
5442
Bram Moolenaar89d40322006-08-29 15:30:07 +00005443 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444 return;
5445
5446 s = vim_strsave(val);
5447 if (s != NULL)
5448 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005449 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005451 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452 free_string_option(*varp);
5453 *varp = s;
5454
5455 /* For buffer/window local option may also set the global value. */
5456 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005457 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458
Bram Moolenaar89d40322006-08-29 15:30:07 +00005459 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460
5461 /* When setting both values of a global option with a local value,
5462 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005463 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005464 {
5465 free_string_option(*varp);
5466 *varp = empty_option;
5467 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005468# ifdef FEAT_EVAL
5469 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005470 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005471 set_sid == 0 ? current_SID : set_sid);
5472# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473 }
5474}
5475
5476/*
5477 * Set global value for string option when it's a local option.
5478 */
5479 static void
5480set_string_option_global(opt_idx, varp)
5481 int opt_idx; /* option index */
5482 char_u **varp; /* pointer to option variable */
5483{
5484 char_u **p, *s;
5485
5486 /* the global value is always allocated */
5487 if (options[opt_idx].var == VAR_WIN)
5488 p = (char_u **)GLOBAL_WO(varp);
5489 else
5490 p = (char_u **)options[opt_idx].var;
5491 if (options[opt_idx].indir != PV_NONE
5492 && p != varp
5493 && (s = vim_strsave(*varp)) != NULL)
5494 {
5495 free_string_option(*p);
5496 *p = s;
5497 }
5498}
5499
5500/*
5501 * Set a string option to a new value, and handle the effects.
5502 */
5503 static void
5504set_string_option(opt_idx, value, opt_flags)
5505 int opt_idx;
5506 char_u *value;
5507 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5508{
5509 char_u *s;
5510 char_u **varp;
5511 char_u *oldval;
5512
5513 if (options[opt_idx].var == NULL) /* don't set hidden option */
5514 return;
5515
5516 s = vim_strsave(value);
5517 if (s != NULL)
5518 {
5519 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5520 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005521 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522 ? OPT_GLOBAL : OPT_LOCAL)
5523 : opt_flags);
5524 oldval = *varp;
5525 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005526 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5527 opt_flags) == NULL)
5528 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529 }
5530}
5531
5532/*
5533 * Handle string options that need some action to perform when changed.
5534 * Returns NULL for success, or an error message for an error.
5535 */
5536 static char_u *
5537did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5538 opt_flags)
5539 int opt_idx; /* index in options[] table */
5540 char_u **varp; /* pointer to the option variable */
5541 int new_value_alloced; /* new value was allocated */
5542 char_u *oldval; /* previous value of the option */
5543 char_u *errbuf; /* buffer for errors, or NULL */
5544 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5545{
5546 char_u *errmsg = NULL;
5547 char_u *s, *p;
5548 int did_chartab = FALSE;
5549 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005550 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005551#ifdef FEAT_GUI
5552 /* set when changing an option that only requires a redraw in the GUI */
5553 int redraw_gui_only = FALSE;
5554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555
5556 /* Get the global option to compare with, otherwise we would have to check
5557 * two values for all local options. */
5558 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5559
5560 /* Disallow changing some options from secure mode */
5561 if ((secure
5562#ifdef HAVE_SANDBOX
5563 || sandbox != 0
5564#endif
5565 ) && (options[opt_idx].flags & P_SECURE))
5566 {
5567 errmsg = e_secure;
5568 }
5569
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005570 /* Check for a "normal" file name in some options. Disallow a path
5571 * separator (slash and/or backslash), wildcards and characters that are
5572 * often illegal in a file name. */
5573 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005574 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005575 {
5576 errmsg = e_invarg;
5577 }
5578
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579 /* 'term' */
5580 else if (varp == &T_NAME)
5581 {
5582 if (T_NAME[0] == NUL)
5583 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5584#ifdef FEAT_GUI
5585 if (gui.in_use)
5586 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5587 else if (term_is_gui(T_NAME))
5588 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5589#endif
5590 else if (set_termname(T_NAME) == FAIL)
5591 errmsg = (char_u *)N_("E522: Not found in termcap");
5592 else
5593 /* Screen colors may have changed. */
5594 redraw_later_clear();
5595 }
5596
5597 /* 'backupcopy' */
5598 else if (varp == &p_bkc)
5599 {
5600 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5601 errmsg = e_invarg;
5602 if (((bkc_flags & BKC_AUTO) != 0)
5603 + ((bkc_flags & BKC_YES) != 0)
5604 + ((bkc_flags & BKC_NO) != 0) != 1)
5605 {
5606 /* Must have exactly one of "auto", "yes" and "no". */
5607 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5608 errmsg = e_invarg;
5609 }
5610 }
5611
5612 /* 'backupext' and 'patchmode' */
5613 else if (varp == &p_bex || varp == &p_pm)
5614 {
5615 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5616 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5617 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5618 }
5619
5620 /*
5621 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5622 * If the new option is invalid, use old value. 'lisp' option: refill
5623 * chartab[] for '-' char
5624 */
5625 else if ( varp == &p_isi
5626 || varp == &(curbuf->b_p_isk)
5627 || varp == &p_isp
5628 || varp == &p_isf)
5629 {
5630 if (init_chartab() == FAIL)
5631 {
5632 did_chartab = TRUE; /* need to restore it below */
5633 errmsg = e_invarg; /* error in value */
5634 }
5635 }
5636
5637 /* 'helpfile' */
5638 else if (varp == &p_hf)
5639 {
5640 /* May compute new values for $VIM and $VIMRUNTIME */
5641 if (didset_vim)
5642 {
5643 vim_setenv((char_u *)"VIM", (char_u *)"");
5644 didset_vim = FALSE;
5645 }
5646 if (didset_vimruntime)
5647 {
5648 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5649 didset_vimruntime = FALSE;
5650 }
5651 }
5652
Bram Moolenaar1a384422010-07-14 19:53:30 +02005653#ifdef FEAT_SYN_HL
5654 /* 'colorcolumn' */
5655 else if (varp == &curwin->w_p_cc)
5656 errmsg = check_colorcolumn(curwin);
5657#endif
5658
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659#ifdef FEAT_MULTI_LANG
5660 /* 'helplang' */
5661 else if (varp == &p_hlg)
5662 {
5663 /* Check for "", "ab", "ab,cd", etc. */
5664 for (s = p_hlg; *s != NUL; s += 3)
5665 {
5666 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5667 {
5668 errmsg = e_invarg;
5669 break;
5670 }
5671 if (s[2] == NUL)
5672 break;
5673 }
5674 }
5675#endif
5676
5677 /* 'highlight' */
5678 else if (varp == &p_hl)
5679 {
5680 if (highlight_changed() == FAIL)
5681 errmsg = e_invarg; /* invalid flags */
5682 }
5683
5684 /* 'nrformats' */
5685 else if (gvarp == &p_nf)
5686 {
5687 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5688 errmsg = e_invarg;
5689 }
5690
5691#ifdef FEAT_SESSION
5692 /* 'sessionoptions' */
5693 else if (varp == &p_ssop)
5694 {
5695 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5696 errmsg = e_invarg;
5697 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5698 {
5699 /* Don't allow both "sesdir" and "curdir". */
5700 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5701 errmsg = e_invarg;
5702 }
5703 }
5704 /* 'viewoptions' */
5705 else if (varp == &p_vop)
5706 {
5707 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5708 errmsg = e_invarg;
5709 }
5710#endif
5711
5712 /* 'scrollopt' */
5713#ifdef FEAT_SCROLLBIND
5714 else if (varp == &p_sbo)
5715 {
5716 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5717 errmsg = e_invarg;
5718 }
5719#endif
5720
5721 /* 'ambiwidth' */
5722#ifdef FEAT_MBYTE
5723 else if (varp == &p_ambw)
5724 {
5725 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5726 errmsg = e_invarg;
5727 }
5728#endif
5729
5730 /* 'background' */
5731 else if (varp == &p_bg)
5732 {
5733 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5734 {
5735#ifdef FEAT_EVAL
5736 int dark = (*p_bg == 'd');
5737#endif
5738
5739 init_highlight(FALSE, FALSE);
5740
5741#ifdef FEAT_EVAL
5742 if (dark != (*p_bg == 'd')
5743 && get_var_value((char_u *)"g:colors_name") != NULL)
5744 {
5745 /* The color scheme must have set 'background' back to another
5746 * value, that's not what we want here. Disable the color
5747 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005748 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749 free_string_option(p_bg);
5750 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5751 check_string_option(&p_bg);
5752 init_highlight(FALSE, FALSE);
5753 }
5754#endif
5755 }
5756 else
5757 errmsg = e_invarg;
5758 }
5759
5760 /* 'wildmode' */
5761 else if (varp == &p_wim)
5762 {
5763 if (check_opt_wim() == FAIL)
5764 errmsg = e_invarg;
5765 }
5766
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005767#ifdef FEAT_CMDL_COMPL
5768 /* 'wildoptions' */
5769 else if (varp == &p_wop)
5770 {
5771 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5772 errmsg = e_invarg;
5773 }
5774#endif
5775
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776#ifdef FEAT_WAK
5777 /* 'winaltkeys' */
5778 else if (varp == &p_wak)
5779 {
5780 if (*p_wak == NUL
5781 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5782 errmsg = e_invarg;
5783# ifdef FEAT_MENU
5784# ifdef FEAT_GUI_MOTIF
5785 else if (gui.in_use)
5786 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5787# else
5788# ifdef FEAT_GUI_GTK
5789 else if (gui.in_use)
5790 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5791# endif
5792# endif
5793# endif
5794 }
5795#endif
5796
5797#ifdef FEAT_AUTOCMD
5798 /* 'eventignore' */
5799 else if (varp == &p_ei)
5800 {
5801 if (check_ei() == FAIL)
5802 errmsg = e_invarg;
5803 }
5804#endif
5805
5806#ifdef FEAT_MBYTE
5807 /* 'encoding' and 'fileencoding' */
5808 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5809 {
5810 if (gvarp == &p_fenc)
5811 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005812 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005813 errmsg = e_modifiable;
5814 else if (vim_strchr(*varp, ',') != NULL)
5815 /* No comma allowed in 'fileencoding'; catches confusing it
5816 * with 'fileencodings'. */
5817 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005819 {
5820# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005821 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005822 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005824 /* Add 'fileencoding' to the swap file. */
5825 ml_setflags(curbuf);
5826 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005827 }
5828 if (errmsg == NULL)
5829 {
5830 /* canonize the value, so that STRCMP() can be used on it */
5831 p = enc_canonize(*varp);
5832 if (p != NULL)
5833 {
5834 vim_free(*varp);
5835 *varp = p;
5836 }
5837 if (varp == &p_enc)
5838 {
5839 errmsg = mb_init();
5840# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005841 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842# endif
5843 }
5844 }
5845
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005846# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5848 {
5849 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5850 if (STRCMP(p_tenc, "utf-8") != 0)
5851 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5852 }
5853# endif
5854
5855 if (errmsg == NULL)
5856 {
5857# ifdef FEAT_KEYMAP
5858 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5859 * (with another encoding). */
5860 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5861 (void)keymap_init();
5862# endif
5863
5864 /* When 'termencoding' is not empty and 'encoding' changes or when
5865 * 'termencoding' changes, need to setup for keyboard input and
5866 * display output conversion. */
5867 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5868 {
5869 convert_setup(&input_conv, p_tenc, p_enc);
5870 convert_setup(&output_conv, p_enc, p_tenc);
5871 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005872
5873# if defined(WIN3264) && defined(FEAT_MBYTE)
5874 /* $HOME may have characters in active code page. */
5875 if (varp == &p_enc)
5876 init_homedir();
5877# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 }
5879 }
5880#endif
5881
5882#if defined(FEAT_POSTSCRIPT)
5883 else if (varp == &p_penc)
5884 {
5885 /* Canonize printencoding if VIM standard one */
5886 p = enc_canonize(p_penc);
5887 if (p != NULL)
5888 {
5889 vim_free(p_penc);
5890 p_penc = p;
5891 }
5892 else
5893 {
5894 /* Ensure lower case and '-' for '_' */
5895 for (s = p_penc; *s != NUL; s++)
5896 {
5897 if (*s == '_')
5898 *s = '-';
5899 else
5900 *s = TOLOWER_ASC(*s);
5901 }
5902 }
5903 }
5904#endif
5905
Bram Moolenaar9372a112005-12-06 19:59:18 +00005906#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 else if (varp == &p_imak)
5908 {
5909 if (gui.in_use && !im_xim_isvalid_imactivate())
5910 errmsg = e_invarg;
5911 }
5912#endif
5913
5914#ifdef FEAT_KEYMAP
5915 else if (varp == &curbuf->b_p_keymap)
5916 {
5917 /* load or unload key mapping tables */
5918 errmsg = keymap_init();
5919
Bram Moolenaarfab06232009-03-04 03:13:35 +00005920 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005922 if (*curbuf->b_p_keymap != NUL)
5923 {
5924 /* Installed a new keymap, switch on using it. */
5925 curbuf->b_p_iminsert = B_IMODE_LMAP;
5926 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5927 curbuf->b_p_imsearch = B_IMODE_LMAP;
5928 }
5929 else
5930 {
5931 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5932 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5933 curbuf->b_p_iminsert = B_IMODE_NONE;
5934 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5935 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5936 }
5937 if ((opt_flags & OPT_LOCAL) == 0)
5938 {
5939 set_iminsert_global();
5940 set_imsearch_global();
5941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005942# ifdef FEAT_WINDOWS
5943 status_redraw_curbuf();
5944# endif
5945 }
5946 }
5947#endif
5948
5949 /* 'fileformat' */
5950 else if (gvarp == &p_ff)
5951 {
5952 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5953 errmsg = e_modifiable;
5954 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5955 errmsg = e_invarg;
5956 else
5957 {
5958 /* may also change 'textmode' */
5959 if (get_fileformat(curbuf) == EOL_DOS)
5960 curbuf->b_p_tx = TRUE;
5961 else
5962 curbuf->b_p_tx = FALSE;
5963#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005964 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005966 /* update flag in swap file */
5967 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005968 /* Redraw needed when switching to/from "mac": a CR in the text
5969 * will be displayed differently. */
5970 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5971 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972 }
5973 }
5974
5975 /* 'fileformats' */
5976 else if (varp == &p_ffs)
5977 {
5978 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5979 errmsg = e_invarg;
5980 else
5981 {
5982 /* also change 'textauto' */
5983 if (*p_ffs == NUL)
5984 p_ta = FALSE;
5985 else
5986 p_ta = TRUE;
5987 }
5988 }
5989
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005990#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 /* 'cryptkey' */
5992 else if (gvarp == &p_key)
5993 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005994# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 /* Make sure the ":set" command doesn't show the new value in the
5996 * history. */
5997 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005998# endif
5999 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6000 /* Need to update the swapfile. */
6001 ml_set_crypt_key(curbuf, oldval, curbuf->b_p_cm);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002 }
6003#endif
6004
6005 /* 'matchpairs' */
6006 else if (gvarp == &p_mps)
6007 {
6008 /* Check for "x:y,x:y" */
6009 for (p = *varp; *p != NUL; p += 4)
6010 {
6011 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6012 {
6013 errmsg = e_invarg;
6014 break;
6015 }
6016 if (p[3] == NUL)
6017 break;
6018 }
6019 }
6020
6021#ifdef FEAT_COMMENTS
6022 /* 'comments' */
6023 else if (gvarp == &p_com)
6024 {
6025 for (s = *varp; *s; )
6026 {
6027 while (*s && *s != ':')
6028 {
6029 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6030 && !VIM_ISDIGIT(*s) && *s != '-')
6031 {
6032 errmsg = illegal_char(errbuf, *s);
6033 break;
6034 }
6035 ++s;
6036 }
6037 if (*s++ == NUL)
6038 errmsg = (char_u *)N_("E524: Missing colon");
6039 else if (*s == ',' || *s == NUL)
6040 errmsg = (char_u *)N_("E525: Zero length string");
6041 if (errmsg != NULL)
6042 break;
6043 while (*s && *s != ',')
6044 {
6045 if (*s == '\\' && s[1] != NUL)
6046 ++s;
6047 ++s;
6048 }
6049 s = skip_to_option_part(s);
6050 }
6051 }
6052#endif
6053
6054 /* 'listchars' */
6055 else if (varp == &p_lcs)
6056 {
6057 errmsg = set_chars_option(varp);
6058 }
6059
6060#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6061 /* 'fillchars' */
6062 else if (varp == &p_fcs)
6063 {
6064 errmsg = set_chars_option(varp);
6065 }
6066#endif
6067
6068#ifdef FEAT_CMDWIN
6069 /* 'cedit' */
6070 else if (varp == &p_cedit)
6071 {
6072 errmsg = check_cedit();
6073 }
6074#endif
6075
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006076 /* 'verbosefile' */
6077 else if (varp == &p_vfile)
6078 {
6079 verbose_stop();
6080 if (*p_vfile != NUL && verbose_open() == FAIL)
6081 errmsg = e_invarg;
6082 }
6083
Bram Moolenaar071d4272004-06-13 20:20:40 +00006084#ifdef FEAT_VIMINFO
6085 /* 'viminfo' */
6086 else if (varp == &p_viminfo)
6087 {
6088 for (s = p_viminfo; *s;)
6089 {
6090 /* Check it's a valid character */
6091 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6092 {
6093 errmsg = illegal_char(errbuf, *s);
6094 break;
6095 }
6096 if (*s == 'n') /* name is always last one */
6097 {
6098 break;
6099 }
6100 else if (*s == 'r') /* skip until next ',' */
6101 {
6102 while (*++s && *s != ',')
6103 ;
6104 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006105 else if (*s == '%')
6106 {
6107 /* optional number */
6108 while (vim_isdigit(*++s))
6109 ;
6110 }
6111 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 ++s; /* no extra chars */
6113 else /* must have a number */
6114 {
6115 while (vim_isdigit(*++s))
6116 ;
6117
6118 if (!VIM_ISDIGIT(*(s - 1)))
6119 {
6120 if (errbuf != NULL)
6121 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006122 sprintf((char *)errbuf,
6123 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 transchar_byte(*(s - 1)));
6125 errmsg = errbuf;
6126 }
6127 else
6128 errmsg = (char_u *)"";
6129 break;
6130 }
6131 }
6132 if (*s == ',')
6133 ++s;
6134 else if (*s)
6135 {
6136 if (errbuf != NULL)
6137 errmsg = (char_u *)N_("E527: Missing comma");
6138 else
6139 errmsg = (char_u *)"";
6140 break;
6141 }
6142 }
6143 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6144 errmsg = (char_u *)N_("E528: Must specify a ' value");
6145 }
6146#endif /* FEAT_VIMINFO */
6147
6148 /* terminal options */
6149 else if (istermoption(&options[opt_idx]) && full_screen)
6150 {
6151 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6152 if (varp == &T_CCO)
6153 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006154 int colors = atoi((char *)T_CCO);
6155
6156 /* Only reinitialize colors if t_Co value has really changed to
6157 * avoid expensive reload of colorscheme if t_Co is set to the
6158 * same value multiple times. */
6159 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006161 t_colors = colors;
6162 if (t_colors <= 1)
6163 {
6164 if (new_value_alloced)
6165 vim_free(T_CCO);
6166 T_CCO = empty_option;
6167 }
6168 /* We now have a different color setup, initialize it again. */
6169 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171 }
6172 ttest(FALSE);
6173 if (varp == &T_ME)
6174 {
6175 out_str(T_ME);
6176 redraw_later(CLEAR);
6177#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6178 /* Since t_me has been set, this probably means that the user
6179 * wants to use this as default colors. Need to reset default
6180 * background/foreground colors. */
6181 mch_set_normal_colors();
6182#endif
6183 }
6184 }
6185
6186#ifdef FEAT_LINEBREAK
6187 /* 'showbreak' */
6188 else if (varp == &p_sbr)
6189 {
6190 for (s = p_sbr; *s; )
6191 {
6192 if (ptr2cells(s) != 1)
6193 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006194 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 }
6196 }
6197#endif
6198
6199#ifdef FEAT_GUI
6200 /* 'guifont' */
6201 else if (varp == &p_guifont)
6202 {
6203 if (gui.in_use)
6204 {
6205 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006206# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006207 /*
6208 * Put up a font dialog and let the user select a new value.
6209 * If this is cancelled go back to the old value but don't
6210 * give an error message.
6211 */
6212 if (STRCMP(p, "*") == 0)
6213 {
6214 p = gui_mch_font_dialog(oldval);
6215
6216 if (new_value_alloced)
6217 free_string_option(p_guifont);
6218
6219 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6220 new_value_alloced = TRUE;
6221 }
6222# endif
6223 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6224 {
6225# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6226 if (STRCMP(p_guifont, "*") == 0)
6227 {
6228 /* Dialog was cancelled: Keep the old value without giving
6229 * an error message. */
6230 if (new_value_alloced)
6231 free_string_option(p_guifont);
6232 p_guifont = vim_strsave(oldval);
6233 new_value_alloced = TRUE;
6234 }
6235 else
6236# endif
6237 errmsg = (char_u *)N_("E596: Invalid font(s)");
6238 }
6239 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006240 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006241 }
6242# ifdef FEAT_XFONTSET
6243 else if (varp == &p_guifontset)
6244 {
6245 if (STRCMP(p_guifontset, "*") == 0)
6246 errmsg = (char_u *)N_("E597: can't select fontset");
6247 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6248 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006249 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 }
6251# endif
6252# ifdef FEAT_MBYTE
6253 else if (varp == &p_guifontwide)
6254 {
6255 if (STRCMP(p_guifontwide, "*") == 0)
6256 errmsg = (char_u *)N_("E533: can't select wide font");
6257 else if (gui_get_wide_font() == FAIL)
6258 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006259 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006260 }
6261# endif
6262#endif
6263
6264#ifdef CURSOR_SHAPE
6265 /* 'guicursor' */
6266 else if (varp == &p_guicursor)
6267 errmsg = parse_shape_opt(SHAPE_CURSOR);
6268#endif
6269
6270#ifdef FEAT_MOUSESHAPE
6271 /* 'mouseshape' */
6272 else if (varp == &p_mouseshape)
6273 {
6274 errmsg = parse_shape_opt(SHAPE_MOUSE);
6275 update_mouseshape(-1);
6276 }
6277#endif
6278
6279#ifdef FEAT_PRINTER
6280 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006281 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006282# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006283 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006284 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006285# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286#endif
6287
6288#ifdef FEAT_LANGMAP
6289 /* 'langmap' */
6290 else if (varp == &p_langmap)
6291 langmap_set();
6292#endif
6293
6294#ifdef FEAT_LINEBREAK
6295 /* 'breakat' */
6296 else if (varp == &p_breakat)
6297 fill_breakat_flags();
6298#endif
6299
6300#ifdef FEAT_TITLE
6301 /* 'titlestring' and 'iconstring' */
6302 else if (varp == &p_titlestring || varp == &p_iconstring)
6303 {
6304# ifdef FEAT_STL_OPT
6305 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6306
6307 /* NULL => statusline syntax */
6308 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6309 stl_syntax |= flagval;
6310 else
6311 stl_syntax &= ~flagval;
6312# endif
6313 did_set_title(varp == &p_iconstring);
6314
6315 }
6316#endif
6317
6318#ifdef FEAT_GUI
6319 /* 'guioptions' */
6320 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006321 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006323 redraw_gui_only = TRUE;
6324 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325#endif
6326
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006327#if defined(FEAT_GUI_TABLINE)
6328 /* 'guitablabel' */
6329 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006330 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006331 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006332 redraw_gui_only = TRUE;
6333 }
6334 /* 'guitabtooltip' */
6335 else if (varp == &p_gtt)
6336 {
6337 redraw_gui_only = TRUE;
6338 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006339#endif
6340
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6342 /* 'ttymouse' */
6343 else if (varp == &p_ttym)
6344 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006345 /* Switch the mouse off before changing the escape sequences used for
6346 * that. */
6347 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6349 errmsg = e_invarg;
6350 else
6351 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006352 if (termcap_active)
6353 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 }
6355#endif
6356
6357#ifdef FEAT_VISUAL
6358 /* 'selection' */
6359 else if (varp == &p_sel)
6360 {
6361 if (*p_sel == NUL
6362 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6363 errmsg = e_invarg;
6364 }
6365
6366 /* 'selectmode' */
6367 else if (varp == &p_slm)
6368 {
6369 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6370 errmsg = e_invarg;
6371 }
6372#endif
6373
6374#ifdef FEAT_BROWSE
6375 /* 'browsedir' */
6376 else if (varp == &p_bsdir)
6377 {
6378 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6379 && !mch_isdir(p_bsdir))
6380 errmsg = e_invarg;
6381 }
6382#endif
6383
6384#ifdef FEAT_VISUAL
6385 /* 'keymodel' */
6386 else if (varp == &p_km)
6387 {
6388 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6389 errmsg = e_invarg;
6390 else
6391 {
6392 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6393 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6394 }
6395 }
6396#endif
6397
6398 /* 'mousemodel' */
6399 else if (varp == &p_mousem)
6400 {
6401 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6402 errmsg = e_invarg;
6403#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6404 else if (*p_mousem != *oldval)
6405 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6406 * to create or delete the popup menus. */
6407 gui_motif_update_mousemodel(root_menu);
6408#endif
6409 }
6410
6411 /* 'switchbuf' */
6412 else if (varp == &p_swb)
6413 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006414 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 errmsg = e_invarg;
6416 }
6417
6418 /* 'debug' */
6419 else if (varp == &p_debug)
6420 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006421 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 errmsg = e_invarg;
6423 }
6424
6425 /* 'display' */
6426 else if (varp == &p_dy)
6427 {
6428 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6429 errmsg = e_invarg;
6430 else
6431 (void)init_chartab();
6432
6433 }
6434
6435#ifdef FEAT_VERTSPLIT
6436 /* 'eadirection' */
6437 else if (varp == &p_ead)
6438 {
6439 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6440 errmsg = e_invarg;
6441 }
6442#endif
6443
6444#ifdef FEAT_CLIPBOARD
6445 /* 'clipboard' */
6446 else if (varp == &p_cb)
6447 errmsg = check_clipboard_option();
6448#endif
6449
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006450#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006451 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6452 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006453 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006454 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006455 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006456 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006457
Bram Moolenaar860cae12010-06-05 23:22:07 +02006458 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006459 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006460 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6461 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006462 ".add") != 0))
6463 errmsg = e_invarg;
6464 }
6465
6466 if (errmsg == NULL)
6467 {
6468 FOR_ALL_WINDOWS(wp)
6469 if (wp->w_buffer == curbuf && wp->w_p_spell)
6470 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006471 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006472# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006473 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006474# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006475 }
6476 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006477 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006478 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006479 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006480 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006481 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006482 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006483 /* 'spellsuggest' */
6484 else if (varp == &p_sps)
6485 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006486 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006487 errmsg = e_invarg;
6488 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006489 /* 'mkspellmem' */
6490 else if (varp == &p_msm)
6491 {
6492 if (spell_check_msm() != OK)
6493 errmsg = e_invarg;
6494 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006495#endif
6496
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497#ifdef FEAT_QUICKFIX
6498 /* When 'bufhidden' is set, check for valid value. */
6499 else if (gvarp == &p_bh)
6500 {
6501 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6502 errmsg = e_invarg;
6503 }
6504
6505 /* When 'buftype' is set, check for valid value. */
6506 else if (gvarp == &p_bt)
6507 {
6508 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6509 errmsg = e_invarg;
6510 else
6511 {
6512# ifdef FEAT_WINDOWS
6513 if (curwin->w_status_height)
6514 {
6515 curwin->w_redr_status = TRUE;
6516 redraw_later(VALID);
6517 }
6518# endif
6519 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006520# ifdef FEAT_TITLE
6521 redraw_titles();
6522# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 }
6524 }
6525#endif
6526
6527#ifdef FEAT_STL_OPT
6528 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006529 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 {
6531 int wid;
6532
6533 if (varp == &p_ruf) /* reset ru_wid first */
6534 ru_wid = 0;
6535 s = *varp;
6536 if (varp == &p_ruf && *s == '%')
6537 {
6538 /* set ru_wid if 'ruf' starts with "%99(" */
6539 if (*++s == '-') /* ignore a '-' */
6540 s++;
6541 wid = getdigits(&s);
6542 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6543 ru_wid = wid;
6544 else
6545 errmsg = check_stl_option(p_ruf);
6546 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006547 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006548 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006550 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006551 comp_col();
6552 }
6553#endif
6554
6555#ifdef FEAT_INS_EXPAND
6556 /* check if it is a valid value for 'complete' -- Acevedo */
6557 else if (gvarp == &p_cpt)
6558 {
6559 for (s = *varp; *s;)
6560 {
6561 while(*s == ',' || *s == ' ')
6562 s++;
6563 if (!*s)
6564 break;
6565 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6566 {
6567 errmsg = illegal_char(errbuf, *s);
6568 break;
6569 }
6570 if (*++s != NUL && *s != ',' && *s != ' ')
6571 {
6572 if (s[-1] == 'k' || s[-1] == 's')
6573 {
6574 /* skip optional filename after 'k' and 's' */
6575 while (*s && *s != ',' && *s != ' ')
6576 {
6577 if (*s == '\\')
6578 ++s;
6579 ++s;
6580 }
6581 }
6582 else
6583 {
6584 if (errbuf != NULL)
6585 {
6586 sprintf((char *)errbuf,
6587 _("E535: Illegal character after <%c>"),
6588 *--s);
6589 errmsg = errbuf;
6590 }
6591 else
6592 errmsg = (char_u *)"";
6593 break;
6594 }
6595 }
6596 }
6597 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006598
6599 /* 'completeopt' */
6600 else if (varp == &p_cot)
6601 {
6602 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6603 errmsg = e_invarg;
6604 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605#endif /* FEAT_INS_EXPAND */
6606
6607
6608#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6609 else if (varp == &p_toolbar)
6610 {
6611 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6612 &toolbar_flags, TRUE) != OK)
6613 errmsg = e_invarg;
6614 else
6615 {
6616 out_flush();
6617 gui_mch_show_toolbar((toolbar_flags &
6618 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6619 }
6620 }
6621#endif
6622
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006623#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 /* 'toolbariconsize': GTK+ 2 only */
6625 else if (varp == &p_tbis)
6626 {
6627 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6628 errmsg = e_invarg;
6629 else
6630 {
6631 out_flush();
6632 gui_mch_show_toolbar((toolbar_flags &
6633 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6634 }
6635 }
6636#endif
6637
6638 /* 'pastetoggle': translate key codes like in a mapping */
6639 else if (varp == &p_pt)
6640 {
6641 if (*p_pt)
6642 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006643 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 if (p != NULL)
6645 {
6646 if (new_value_alloced)
6647 free_string_option(p_pt);
6648 p_pt = p;
6649 new_value_alloced = TRUE;
6650 }
6651 }
6652 }
6653
6654 /* 'backspace' */
6655 else if (varp == &p_bs)
6656 {
6657 if (VIM_ISDIGIT(*p_bs))
6658 {
6659 if (*p_bs >'2' || p_bs[1] != NUL)
6660 errmsg = e_invarg;
6661 }
6662 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6663 errmsg = e_invarg;
6664 }
6665
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006666#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006667 /* 'casemap' */
6668 else if (varp == &p_cmp)
6669 {
6670 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6671 errmsg = e_invarg;
6672 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674
6675#ifdef FEAT_DIFF
6676 /* 'diffopt' */
6677 else if (varp == &p_dip)
6678 {
6679 if (diffopt_changed() == FAIL)
6680 errmsg = e_invarg;
6681 }
6682#endif
6683
6684#ifdef FEAT_FOLDING
6685 /* 'foldmethod' */
6686 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6687 {
6688 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6689 || *curwin->w_p_fdm == NUL)
6690 errmsg = e_invarg;
6691 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006692 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006694 if (foldmethodIsDiff(curwin))
6695 newFoldLevel();
6696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697 }
6698# ifdef FEAT_EVAL
6699 /* 'foldexpr' */
6700 else if (varp == &curwin->w_p_fde)
6701 {
6702 if (foldmethodIsExpr(curwin))
6703 foldUpdateAll(curwin);
6704 }
6705# endif
6706 /* 'foldmarker' */
6707 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6708 {
6709 p = vim_strchr(*varp, ',');
6710 if (p == NULL)
6711 errmsg = (char_u *)N_("E536: comma required");
6712 else if (p == *varp || p[1] == NUL)
6713 errmsg = e_invarg;
6714 else if (foldmethodIsMarker(curwin))
6715 foldUpdateAll(curwin);
6716 }
6717 /* 'commentstring' */
6718 else if (gvarp == &p_cms)
6719 {
6720 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6721 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6722 }
6723 /* 'foldopen' */
6724 else if (varp == &p_fdo)
6725 {
6726 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6727 errmsg = e_invarg;
6728 }
6729 /* 'foldclose' */
6730 else if (varp == &p_fcl)
6731 {
6732 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6733 errmsg = e_invarg;
6734 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006735 /* 'foldignore' */
6736 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6737 {
6738 if (foldmethodIsIndent(curwin))
6739 foldUpdateAll(curwin);
6740 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741#endif
6742
6743#ifdef FEAT_VIRTUALEDIT
6744 /* 'virtualedit' */
6745 else if (varp == &p_ve)
6746 {
6747 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6748 errmsg = e_invarg;
6749 else if (STRCMP(p_ve, oldval) != 0)
6750 {
6751 /* Recompute cursor position in case the new 've' setting
6752 * changes something. */
6753 validate_virtcol();
6754 coladvance(curwin->w_virtcol);
6755 }
6756 }
6757#endif
6758
6759#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6760 else if (varp == &p_csqf)
6761 {
6762 if (p_csqf != NULL)
6763 {
6764 p = p_csqf;
6765 while (*p != NUL)
6766 {
6767 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6768 || p[1] == NUL
6769 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6770 || (p[2] != NUL && p[2] != ','))
6771 {
6772 errmsg = e_invarg;
6773 break;
6774 }
6775 else if (p[2] == NUL)
6776 break;
6777 else
6778 p += 3;
6779 }
6780 }
6781 }
6782#endif
6783
6784 /* Options that are a list of flags. */
6785 else
6786 {
6787 p = NULL;
6788 if (varp == &p_ww)
6789 p = (char_u *)WW_ALL;
6790 if (varp == &p_shm)
6791 p = (char_u *)SHM_ALL;
6792 else if (varp == &(p_cpo))
6793 p = (char_u *)CPO_ALL;
6794 else if (varp == &(curbuf->b_p_fo))
6795 p = (char_u *)FO_ALL;
6796 else if (varp == &p_mouse)
6797 {
6798#ifdef FEAT_MOUSE
6799 p = (char_u *)MOUSE_ALL;
6800#else
6801 if (*p_mouse != NUL)
6802 errmsg = (char_u *)N_("E538: No mouse support");
6803#endif
6804 }
6805#if defined(FEAT_GUI)
6806 else if (varp == &p_go)
6807 p = (char_u *)GO_ALL;
6808#endif
6809 if (p != NULL)
6810 {
6811 for (s = *varp; *s; ++s)
6812 if (vim_strchr(p, *s) == NULL)
6813 {
6814 errmsg = illegal_char(errbuf, *s);
6815 break;
6816 }
6817 }
6818 }
6819
6820 /*
6821 * If error detected, restore the previous value.
6822 */
6823 if (errmsg != NULL)
6824 {
6825 if (new_value_alloced)
6826 free_string_option(*varp);
6827 *varp = oldval;
6828 /*
6829 * When resetting some values, need to act on it.
6830 */
6831 if (did_chartab)
6832 (void)init_chartab();
6833 if (varp == &p_hl)
6834 (void)highlight_changed();
6835 }
6836 else
6837 {
6838#ifdef FEAT_EVAL
6839 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006840 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841#endif
6842 /*
6843 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006844 * Use "free_oldval", because recursiveness may change the flags under
6845 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006846 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006847 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 free_string_option(oldval);
6849 if (new_value_alloced)
6850 options[opt_idx].flags |= P_ALLOCED;
6851 else
6852 options[opt_idx].flags &= ~P_ALLOCED;
6853
6854 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006855 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 {
6857 /* global option with local value set to use global value; free
6858 * the local value and make it empty */
6859 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6860 free_string_option(*(char_u **)p);
6861 *(char_u **)p = empty_option;
6862 }
6863
6864 /* May set global value for local option. */
6865 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6866 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006867
6868#ifdef FEAT_AUTOCMD
6869 /*
6870 * Trigger the autocommand only after setting the flags.
6871 */
6872# ifdef FEAT_SYN_HL
6873 /* When 'syntax' is set, load the syntax of that name */
6874 if (varp == &(curbuf->b_p_syn))
6875 {
6876 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6877 curbuf->b_fname, TRUE, curbuf);
6878 }
6879# endif
6880 else if (varp == &(curbuf->b_p_ft))
6881 {
6882 /* 'filetype' is set, trigger the FileType autocommand */
6883 did_filetype = TRUE;
6884 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6885 curbuf->b_fname, TRUE, curbuf);
6886 }
6887#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006888#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006889 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006890 {
6891 char_u fname[200];
6892
6893 /*
6894 * Source the spell/LANG.vim in 'runtimepath'.
6895 * They could set 'spellcapcheck' depending on the language.
6896 * Use the first name in 'spelllang' up to '_region' or
6897 * '.encoding'.
6898 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006899 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006900 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6901 break;
6902 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006903 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006904 source_runtime(fname, TRUE);
6905 }
6906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907 }
6908
6909#ifdef FEAT_MOUSE
6910 if (varp == &p_mouse)
6911 {
6912# ifdef FEAT_MOUSE_TTY
6913 if (*p_mouse == NUL)
6914 mch_setmouse(FALSE); /* switch mouse off */
6915 else
6916# endif
6917 setmouse(); /* in case 'mouse' changed */
6918 }
6919#endif
6920
6921 if (curwin->w_curswant != MAXCOL)
6922 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006923#ifdef FEAT_GUI
6924 /* check redraw when it's not a GUI option or the GUI is active. */
6925 if (!redraw_gui_only || gui.in_use)
6926#endif
6927 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928
6929 return errmsg;
6930}
6931
Bram Moolenaar1a384422010-07-14 19:53:30 +02006932#ifdef FEAT_SYN_HL
6933/*
6934 * Simple int comparison function for use with qsort()
6935 */
6936 static int
6937int_cmp(a, b)
6938 const void *a;
6939 const void *b;
6940{
6941 return *(const int *)a - *(const int *)b;
6942}
6943
6944/*
6945 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
6946 * Returns error message, NULL if it's OK.
6947 */
6948 char_u *
6949check_colorcolumn(wp)
6950 win_T *wp;
6951{
6952 char_u *s;
6953 int col;
6954 int count = 0;
6955 int color_cols[256];
6956 int i;
6957 int j = 0;
6958
Bram Moolenaar11505dc2010-07-16 21:29:06 +02006959 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02006960 {
6961 if (*s == '-' || *s == '+')
6962 {
6963 /* -N and +N: add to 'textwidth' */
6964 col = (*s == '-') ? -1 : 1;
6965 ++s;
6966 if (!VIM_ISDIGIT(*s))
6967 return e_invarg;
6968 col = col * getdigits(&s);
6969 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02006970 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02006971 col += wp->w_buffer->b_p_tw;
6972 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02006973 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02006974 }
6975 else if (VIM_ISDIGIT(*s))
6976 col = getdigits(&s);
6977 else
6978 return e_invarg;
6979 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02006980skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02006981 if (*s == NUL)
6982 break;
6983 if (*s != ',')
6984 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02006985 if (*++s == NUL)
6986 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02006987 }
6988
6989 vim_free(wp->w_p_cc_cols);
6990 if (count == 0)
6991 wp->w_p_cc_cols = NULL;
6992 else
6993 {
6994 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
6995 if (wp->w_p_cc_cols != NULL)
6996 {
6997 /* sort the columns for faster usage on screen redraw inside
6998 * win_line() */
6999 qsort(color_cols, count, sizeof(int), int_cmp);
7000
7001 for (i = 0; i < count; ++i)
7002 /* skip duplicates */
7003 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7004 wp->w_p_cc_cols[j++] = color_cols[i];
7005 wp->w_p_cc_cols[j] = -1; /* end marker */
7006 }
7007 }
7008
7009 return NULL; /* no error */
7010}
7011#endif
7012
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013/*
7014 * Handle setting 'listchars' or 'fillchars'.
7015 * Returns error message, NULL if it's OK.
7016 */
7017 static char_u *
7018set_chars_option(varp)
7019 char_u **varp;
7020{
7021 int round, i, len, entries;
7022 char_u *p, *s;
7023 int c1, c2 = 0;
7024 struct charstab
7025 {
7026 int *cp;
7027 char *name;
7028 };
7029#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7030 static struct charstab filltab[] =
7031 {
7032 {&fill_stl, "stl"},
7033 {&fill_stlnc, "stlnc"},
7034 {&fill_vert, "vert"},
7035 {&fill_fold, "fold"},
7036 {&fill_diff, "diff"},
7037 };
7038#endif
7039 static struct charstab lcstab[] =
7040 {
7041 {&lcs_eol, "eol"},
7042 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007043 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 {&lcs_prec, "precedes"},
7045 {&lcs_tab2, "tab"},
7046 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007047#ifdef FEAT_CONCEAL
7048 {&lcs_conceal, "conceal"},
7049#else
7050 {NULL, "conceal"},
7051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052 };
7053 struct charstab *tab;
7054
7055#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7056 if (varp == &p_lcs)
7057#endif
7058 {
7059 tab = lcstab;
7060 entries = sizeof(lcstab) / sizeof(struct charstab);
7061 }
7062#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7063 else
7064 {
7065 tab = filltab;
7066 entries = sizeof(filltab) / sizeof(struct charstab);
7067 }
7068#endif
7069
7070 /* first round: check for valid value, second round: assign values */
7071 for (round = 0; round <= 1; ++round)
7072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007073 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 {
7075 /* After checking that the value is valid: set defaults: space for
7076 * 'fillchars', NUL for 'listchars' */
7077 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007078 if (tab[i].cp != NULL)
7079 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080 if (varp == &p_lcs)
7081 lcs_tab1 = NUL;
7082#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7083 else
7084 fill_diff = '-';
7085#endif
7086 }
7087 p = *varp;
7088 while (*p)
7089 {
7090 for (i = 0; i < entries; ++i)
7091 {
7092 len = (int)STRLEN(tab[i].name);
7093 if (STRNCMP(p, tab[i].name, len) == 0
7094 && p[len] == ':'
7095 && p[len + 1] != NUL)
7096 {
7097 s = p + len + 1;
7098#ifdef FEAT_MBYTE
7099 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007100 if (mb_char2cells(c1) > 1)
7101 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102#else
7103 c1 = *s++;
7104#endif
7105 if (tab[i].cp == &lcs_tab2)
7106 {
7107 if (*s == NUL)
7108 continue;
7109#ifdef FEAT_MBYTE
7110 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007111 if (mb_char2cells(c2) > 1)
7112 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007113#else
7114 c2 = *s++;
7115#endif
7116 }
7117 if (*s == ',' || *s == NUL)
7118 {
7119 if (round)
7120 {
7121 if (tab[i].cp == &lcs_tab2)
7122 {
7123 lcs_tab1 = c1;
7124 lcs_tab2 = c2;
7125 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007126 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 *(tab[i].cp) = c1;
7128
7129 }
7130 p = s;
7131 break;
7132 }
7133 }
7134 }
7135
7136 if (i == entries)
7137 return e_invarg;
7138 if (*p == ',')
7139 ++p;
7140 }
7141 }
7142
7143 return NULL; /* no error */
7144}
7145
7146#ifdef FEAT_STL_OPT
7147/*
7148 * Check validity of options with the 'statusline' format.
7149 * Return error message or NULL.
7150 */
7151 char_u *
7152check_stl_option(s)
7153 char_u *s;
7154{
7155 int itemcnt = 0;
7156 int groupdepth = 0;
7157 static char_u errbuf[80];
7158
7159 while (*s && itemcnt < STL_MAX_ITEM)
7160 {
7161 /* Check for valid keys after % sequences */
7162 while (*s && *s != '%')
7163 s++;
7164 if (!*s)
7165 break;
7166 s++;
7167 if (*s != '%' && *s != ')')
7168 ++itemcnt;
7169 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7170 {
7171 s++;
7172 continue;
7173 }
7174 if (*s == ')')
7175 {
7176 s++;
7177 if (--groupdepth < 0)
7178 break;
7179 continue;
7180 }
7181 if (*s == '-')
7182 s++;
7183 while (VIM_ISDIGIT(*s))
7184 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007185 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186 continue;
7187 if (*s == '.')
7188 {
7189 s++;
7190 while (*s && VIM_ISDIGIT(*s))
7191 s++;
7192 }
7193 if (*s == '(')
7194 {
7195 groupdepth++;
7196 continue;
7197 }
7198 if (vim_strchr(STL_ALL, *s) == NULL)
7199 {
7200 return illegal_char(errbuf, *s);
7201 }
7202 if (*s == '{')
7203 {
7204 s++;
7205 while (*s != '}' && *s)
7206 s++;
7207 if (*s != '}')
7208 return (char_u *)N_("E540: Unclosed expression sequence");
7209 }
7210 }
7211 if (itemcnt >= STL_MAX_ITEM)
7212 return (char_u *)N_("E541: too many items");
7213 if (groupdepth != 0)
7214 return (char_u *)N_("E542: unbalanced groups");
7215 return NULL;
7216}
7217#endif
7218
7219#ifdef FEAT_CLIPBOARD
7220/*
7221 * Extract the items in the 'clipboard' option and set global values.
7222 */
7223 static char_u *
7224check_clipboard_option()
7225{
7226 int new_unnamed = FALSE;
7227 int new_autoselect = FALSE;
7228 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007229 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 regprog_T *new_exclude_prog = NULL;
7231 char_u *errmsg = NULL;
7232 char_u *p;
7233
7234 for (p = p_cb; *p != NUL; )
7235 {
7236 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7237 {
7238 new_unnamed = TRUE;
7239 p += 7;
7240 }
7241 else if (STRNCMP(p, "autoselect", 10) == 0
7242 && (p[10] == ',' || p[10] == NUL))
7243 {
7244 new_autoselect = TRUE;
7245 p += 10;
7246 }
7247 else if (STRNCMP(p, "autoselectml", 12) == 0
7248 && (p[12] == ',' || p[12] == NUL))
7249 {
7250 new_autoselectml = TRUE;
7251 p += 12;
7252 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007253 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7254 {
7255 new_html = TRUE;
7256 p += 4;
7257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7259 {
7260 p += 8;
7261 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7262 if (new_exclude_prog == NULL)
7263 errmsg = e_invarg;
7264 break;
7265 }
7266 else
7267 {
7268 errmsg = e_invarg;
7269 break;
7270 }
7271 if (*p == ',')
7272 ++p;
7273 }
7274 if (errmsg == NULL)
7275 {
7276 clip_unnamed = new_unnamed;
7277 clip_autoselect = new_autoselect;
7278 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007279 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 vim_free(clip_exclude_prog);
7281 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007282#ifdef FEAT_GUI_GTK
7283 if (gui.in_use)
7284 {
7285 gui_gtk_set_selection_targets();
7286 gui_gtk_set_dnd_targets();
7287 }
7288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007289 }
7290 else
7291 vim_free(new_exclude_prog);
7292
7293 return errmsg;
7294}
7295#endif
7296
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007297#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007298/*
7299 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7300 * Return error message when failed, NULL when OK.
7301 */
7302 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007303compile_cap_prog(synblock)
7304 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007305{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007306 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007307 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007308
Bram Moolenaar860cae12010-06-05 23:22:07 +02007309 if (*synblock->b_p_spc == NUL)
7310 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007311 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007312 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007313 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007314 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007315 if (re != NULL)
7316 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007317 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7318 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007319 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007320 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007321 return e_invarg;
7322 }
7323 vim_free(re);
7324 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007325 }
7326
7327 vim_free(rp);
7328 return NULL;
7329}
7330#endif
7331
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007332#if defined(FEAT_EVAL) || defined(PROTO)
7333/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007334 * Set the scriptID for an option, taking care of setting the buffer- or
7335 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007336 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007337 static void
7338set_option_scriptID_idx(opt_idx, opt_flags, id)
7339 int opt_idx;
7340 int opt_flags;
7341 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007342{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007343 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7344 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007345
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007346 /* Remember where the option was set. For local options need to do that
7347 * in the buffer or window structure. */
7348 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007349 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007350 if (both || (opt_flags & OPT_LOCAL))
7351 {
7352 if (indir & PV_BUF)
7353 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7354 else if (indir & PV_WIN)
7355 curwin->w_p_scriptID[indir & PV_MASK] = id;
7356 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007357}
7358#endif
7359
Bram Moolenaar071d4272004-06-13 20:20:40 +00007360/*
7361 * Set the value of a boolean option, and take care of side effects.
7362 * Returns NULL for success, or an error message for an error.
7363 */
7364 static char_u *
7365set_bool_option(opt_idx, varp, value, opt_flags)
7366 int opt_idx; /* index in options[] table */
7367 char_u *varp; /* pointer to the option variable */
7368 int value; /* new value */
7369 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7370{
7371 int old_value = *(int *)varp;
7372
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 /* Disallow changing some options from secure mode */
7374 if ((secure
7375#ifdef HAVE_SANDBOX
7376 || sandbox != 0
7377#endif
7378 ) && (options[opt_idx].flags & P_SECURE))
7379 return e_secure;
7380
7381 *(int *)varp = value; /* set the new value */
7382#ifdef FEAT_EVAL
7383 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007384 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385#endif
7386
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007387#ifdef FEAT_GUI
7388 need_mouse_correct = TRUE;
7389#endif
7390
Bram Moolenaar071d4272004-06-13 20:20:40 +00007391 /* May set global value for local option. */
7392 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7393 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7394
7395 /*
7396 * Handle side effects of changing a bool option.
7397 */
7398
7399 /* 'compatible' */
7400 if ((int *)varp == &p_cp)
7401 {
7402 compatible_set();
7403 }
7404
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007405 /* 'list', 'number' */
7406 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007407 || (int *)varp == &curwin->w_p_nu
7408 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007409 {
7410 if (curwin->w_curswant != MAXCOL)
7411 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007412
7413 /* If 'number' is set, reset 'relativenumber'. */
7414 /* If 'relativenumber' is set, reset 'number'. */
7415 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7416 curwin->w_p_rnu = FALSE;
7417 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7418 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007419 }
7420
Bram Moolenaar071d4272004-06-13 20:20:40 +00007421 else if ((int *)varp == &curbuf->b_p_ro)
7422 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007423 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007424 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7425 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007426
7427 /* when 'readonly' is set may give W10 again */
7428 if (curbuf->b_p_ro)
7429 curbuf->b_did_warn = FALSE;
7430
Bram Moolenaar071d4272004-06-13 20:20:40 +00007431#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007432 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007433#endif
7434 }
7435
Bram Moolenaar370df582010-06-22 05:16:38 +02007436#if defined(FEAT_TITLE) || defined(FEAT_CONCEAL)
7437 /* when 'modifiable' is changed, redraw the window title and
7438 * update current line for concealable items */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007440 {
Bram Moolenaar370df582010-06-22 05:16:38 +02007441# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007442 redraw_titles();
Bram Moolenaar370df582010-06-22 05:16:38 +02007443# endif
7444# ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02007445 if (curwin->w_p_conc > 0)
Bram Moolenaar370df582010-06-22 05:16:38 +02007446 update_single_line(curwin, curwin->w_cursor.lnum);
7447# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007448 }
Bram Moolenaar370df582010-06-22 05:16:38 +02007449#endif
7450#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 /* when 'endofline' is changed, redraw the window title */
7452 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007453 {
7454 redraw_titles();
7455 }
7456# ifdef FEAT_MBYTE
7457 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007458 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007459 {
7460 redraw_titles();
7461 }
7462# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463#endif
7464
7465 /* when 'bin' is set also set some other options */
7466 else if ((int *)varp == &curbuf->b_p_bin)
7467 {
7468 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7469#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007470 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471#endif
7472 }
7473
7474#ifdef FEAT_AUTOCMD
7475 /* when 'buflisted' changes, trigger autocommands */
7476 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7477 {
7478 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7479 NULL, NULL, TRUE, curbuf);
7480 }
7481#endif
7482
7483 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7484 else if ((int *)varp == &curbuf->b_p_swf)
7485 {
7486 if (curbuf->b_p_swf && p_uc)
7487 ml_open_file(curbuf); /* create the swap file */
7488 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007489 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7490 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 mf_close_file(curbuf, TRUE); /* remove the swap file */
7492 }
7493
7494 /* when 'terse' is set change 'shortmess' */
7495 else if ((int *)varp == &p_terse)
7496 {
7497 char_u *p;
7498
7499 p = vim_strchr(p_shm, SHM_SEARCH);
7500
7501 /* insert 's' in p_shm */
7502 if (p_terse && p == NULL)
7503 {
7504 STRCPY(IObuff, p_shm);
7505 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007506 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 }
7508 /* remove 's' from p_shm */
7509 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007510 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 }
7512
7513 /* when 'paste' is set or reset also change other options */
7514 else if ((int *)varp == &p_paste)
7515 {
7516 paste_option_changed();
7517 }
7518
7519 /* when 'insertmode' is set from an autocommand need to do work here */
7520 else if ((int *)varp == &p_im)
7521 {
7522 if (p_im)
7523 {
7524 if ((State & INSERT) == 0)
7525 need_start_insertmode = TRUE;
7526 stop_insert_mode = FALSE;
7527 }
7528 else
7529 {
7530 need_start_insertmode = FALSE;
7531 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007532 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 clear_cmdline = TRUE; /* remove "(insert)" */
7534 restart_edit = 0;
7535 }
7536 }
7537
7538 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7539 else if ((int *)varp == &p_ic && p_hls)
7540 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007541 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542 }
7543
7544#ifdef FEAT_SEARCH_EXTRA
7545 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7546 else if ((int *)varp == &p_hls)
7547 {
7548 no_hlsearch = FALSE;
7549 }
7550#endif
7551
7552#ifdef FEAT_SCROLLBIND
7553 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7554 * at the end of normal_cmd() */
7555 else if ((int *)varp == &curwin->w_p_scb)
7556 {
7557 if (curwin->w_p_scb)
7558 do_check_scrollbind(FALSE);
7559 }
7560#endif
7561
7562#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7563 /* There can be only one window with 'previewwindow' set. */
7564 else if ((int *)varp == &curwin->w_p_pvw)
7565 {
7566 if (curwin->w_p_pvw)
7567 {
7568 win_T *win;
7569
7570 for (win = firstwin; win != NULL; win = win->w_next)
7571 if (win->w_p_pvw && win != curwin)
7572 {
7573 curwin->w_p_pvw = FALSE;
7574 return (char_u *)N_("E590: A preview window already exists");
7575 }
7576 }
7577 }
7578#endif
7579
7580 /* when 'textmode' is set or reset also change 'fileformat' */
7581 else if ((int *)varp == &curbuf->b_p_tx)
7582 {
7583 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7584 }
7585
7586 /* when 'textauto' is set or reset also change 'fileformats' */
7587 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 set_string_option_direct((char_u *)"ffs", -1,
7589 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007590 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591
7592 /*
7593 * When 'lisp' option changes include/exclude '-' in
7594 * keyword characters.
7595 */
7596#ifdef FEAT_LISP
7597 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7598 {
7599 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7600 }
7601#endif
7602
7603#ifdef FEAT_TITLE
7604 /* when 'title' changed, may need to change the title; same for 'icon' */
7605 else if ((int *)varp == &p_title)
7606 {
7607 did_set_title(FALSE);
7608 }
7609
7610 else if ((int *)varp == &p_icon)
7611 {
7612 did_set_title(TRUE);
7613 }
7614#endif
7615
7616 else if ((int *)varp == &curbuf->b_changed)
7617 {
7618 if (!value)
7619 save_file_ff(curbuf); /* Buffer is unchanged */
7620#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007621 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622#endif
7623#ifdef FEAT_AUTOCMD
7624 modified_was_set = value;
7625#endif
7626 }
7627
7628#ifdef BACKSLASH_IN_FILENAME
7629 else if ((int *)varp == &p_ssl)
7630 {
7631 if (p_ssl)
7632 {
7633 psepc = '/';
7634 psepcN = '\\';
7635 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 }
7637 else
7638 {
7639 psepc = '\\';
7640 psepcN = '/';
7641 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642 }
7643
7644 /* need to adjust the file name arguments and buffer names. */
7645 buflist_slash_adjust();
7646 alist_slash_adjust();
7647# ifdef FEAT_EVAL
7648 scriptnames_slash_adjust();
7649# endif
7650 }
7651#endif
7652
7653 /* If 'wrap' is set, set w_leftcol to zero. */
7654 else if ((int *)varp == &curwin->w_p_wrap)
7655 {
7656 if (curwin->w_p_wrap)
7657 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007658 if (curwin->w_curswant != MAXCOL)
7659 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 }
7661
7662#ifdef FEAT_WINDOWS
7663 else if ((int *)varp == &p_ea)
7664 {
7665 if (p_ea && !old_value)
7666 win_equal(curwin, FALSE, 0);
7667 }
7668#endif
7669
7670 else if ((int *)varp == &p_wiv)
7671 {
7672 /*
7673 * When 'weirdinvert' changed, set/reset 't_xs'.
7674 * Then set 'weirdinvert' according to value of 't_xs'.
7675 */
7676 if (p_wiv && !old_value)
7677 T_XS = (char_u *)"y";
7678 else if (!p_wiv && old_value)
7679 T_XS = empty_option;
7680 p_wiv = (*T_XS != NUL);
7681 }
7682
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007683#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 else if ((int *)varp == &p_beval)
7685 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 if (p_beval == TRUE)
7687 gui_mch_enable_beval_area(balloonEval);
7688 else
7689 gui_mch_disable_beval_area(balloonEval);
7690 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007693#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007694 else if ((int *)varp == &p_acd)
7695 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007696 /* Change directories when the 'acd' option is set now. */
7697 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698 }
7699#endif
7700
7701#ifdef FEAT_DIFF
7702 /* 'diff' */
7703 else if ((int *)varp == &curwin->w_p_diff)
7704 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007705 /* May add or remove the buffer from the list of diff buffers. */
7706 diff_buf_adjust(curwin);
7707# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 if (foldmethodIsDiff(curwin))
7709 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007710# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007711 }
7712#endif
7713
7714#ifdef USE_IM_CONTROL
7715 /* 'imdisable' */
7716 else if ((int *)varp == &p_imdisable)
7717 {
7718 /* Only de-activate it here, it will be enabled when changing mode. */
7719 if (p_imdisable)
7720 im_set_active(FALSE);
7721 }
7722#endif
7723
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007724#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007725 /* 'spell' */
7726 else if ((int *)varp == &curwin->w_p_spell)
7727 {
7728 if (curwin->w_p_spell)
7729 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007730 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007731 if (errmsg != NULL)
7732 EMSG(_(errmsg));
7733 }
7734 }
7735#endif
7736
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737#ifdef FEAT_FKMAP
7738 else if ((int *)varp == &p_altkeymap)
7739 {
7740 if (old_value != p_altkeymap)
7741 {
7742 if (!p_altkeymap)
7743 {
7744 p_hkmap = p_fkmap;
7745 p_fkmap = 0;
7746 }
7747 else
7748 {
7749 p_fkmap = p_hkmap;
7750 p_hkmap = 0;
7751 }
7752 (void)init_chartab();
7753 }
7754 }
7755
7756 /*
7757 * In case some second language keymapping options have changed, check
7758 * and correct the setting in a consistent way.
7759 */
7760
7761 /*
7762 * If hkmap or fkmap are set, reset Arabic keymapping.
7763 */
7764 if ((p_hkmap || p_fkmap) && p_altkeymap)
7765 {
7766 p_altkeymap = p_fkmap;
7767# ifdef FEAT_ARABIC
7768 curwin->w_p_arab = FALSE;
7769# endif
7770 (void)init_chartab();
7771 }
7772
7773 /*
7774 * If hkmap set, reset Farsi keymapping.
7775 */
7776 if (p_hkmap && p_altkeymap)
7777 {
7778 p_altkeymap = 0;
7779 p_fkmap = 0;
7780# ifdef FEAT_ARABIC
7781 curwin->w_p_arab = FALSE;
7782# endif
7783 (void)init_chartab();
7784 }
7785
7786 /*
7787 * If fkmap set, reset Hebrew keymapping.
7788 */
7789 if (p_fkmap && !p_altkeymap)
7790 {
7791 p_altkeymap = 1;
7792 p_hkmap = 0;
7793# ifdef FEAT_ARABIC
7794 curwin->w_p_arab = FALSE;
7795# endif
7796 (void)init_chartab();
7797 }
7798#endif
7799
7800#ifdef FEAT_ARABIC
7801 if ((int *)varp == &curwin->w_p_arab)
7802 {
7803 if (curwin->w_p_arab)
7804 {
7805 /*
7806 * 'arabic' is set, handle various sub-settings.
7807 */
7808 if (!p_tbidi)
7809 {
7810 /* set rightleft mode */
7811 if (!curwin->w_p_rl)
7812 {
7813 curwin->w_p_rl = TRUE;
7814 changed_window_setting();
7815 }
7816
7817 /* Enable Arabic shaping (major part of what Arabic requires) */
7818 if (!p_arshape)
7819 {
7820 p_arshape = TRUE;
7821 redraw_later_clear();
7822 }
7823 }
7824
7825 /* Arabic requires a utf-8 encoding, inform the user if its not
7826 * set. */
7827 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007828 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007829 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7830
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007831 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007832 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7833#ifdef FEAT_EVAL
7834 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7835#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837
7838# ifdef FEAT_MBYTE
7839 /* set 'delcombine' */
7840 p_deco = TRUE;
7841# endif
7842
7843# ifdef FEAT_KEYMAP
7844 /* Force-set the necessary keymap for arabic */
7845 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7846 OPT_LOCAL);
7847# endif
7848# ifdef FEAT_FKMAP
7849 p_altkeymap = 0;
7850 p_hkmap = 0;
7851 p_fkmap = 0;
7852 (void)init_chartab();
7853# endif
7854 }
7855 else
7856 {
7857 /*
7858 * 'arabic' is reset, handle various sub-settings.
7859 */
7860 if (!p_tbidi)
7861 {
7862 /* reset rightleft mode */
7863 if (curwin->w_p_rl)
7864 {
7865 curwin->w_p_rl = FALSE;
7866 changed_window_setting();
7867 }
7868
7869 /* 'arabicshape' isn't reset, it is a global option and
7870 * another window may still need it "on". */
7871 }
7872
7873 /* 'delcombine' isn't reset, it is a global option and another
7874 * window may still want it "on". */
7875
7876# ifdef FEAT_KEYMAP
7877 /* Revert to the default keymap */
7878 curbuf->b_p_iminsert = B_IMODE_NONE;
7879 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7880# endif
7881 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007882 if (curwin->w_curswant != MAXCOL)
7883 curwin->w_set_curswant = TRUE;
7884 }
7885
7886 else if ((int *)varp == &p_arshape)
7887 {
7888 if (curwin->w_curswant != MAXCOL)
7889 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 }
7891#endif
7892
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007893#ifdef FEAT_LINEBREAK
7894 if ((int *)varp == &curwin->w_p_lbr)
7895 {
7896 if (curwin->w_curswant != MAXCOL)
7897 curwin->w_set_curswant = TRUE;
7898 }
7899#endif
7900
7901#ifdef FEAT_RIGHTLEFT
7902 if ((int *)varp == &curwin->w_p_rl)
7903 {
7904 if (curwin->w_curswant != MAXCOL)
7905 curwin->w_set_curswant = TRUE;
7906 }
7907#endif
7908
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 /*
7910 * End of handling side effects for bool options.
7911 */
7912
7913 options[opt_idx].flags |= P_WAS_SET;
7914
7915 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007916
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 check_redraw(options[opt_idx].flags);
7918
7919 return NULL;
7920}
7921
7922/*
7923 * Set the value of a number option, and take care of side effects.
7924 * Returns NULL for success, or an error message for an error.
7925 */
7926 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007927set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 int opt_idx; /* index in options[] table */
7929 char_u *varp; /* pointer to the option variable */
7930 long value; /* new value */
7931 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007932 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7934 OPT_MODELINE */
7935{
7936 char_u *errmsg = NULL;
7937 long old_value = *(long *)varp;
7938 long old_Rows = Rows; /* remember old Rows */
7939 long old_Columns = Columns; /* remember old Columns */
7940 long *pp = (long *)varp;
7941
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007942 /* Disallow changing some options from secure mode. */
7943 if ((secure
7944#ifdef HAVE_SANDBOX
7945 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007947 ) && (options[opt_idx].flags & P_SECURE))
7948 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949
7950 *pp = value;
7951#ifdef FEAT_EVAL
7952 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007953 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007955#ifdef FEAT_GUI
7956 need_mouse_correct = TRUE;
7957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958
7959 if (curbuf->b_p_sw <= 0)
7960 {
7961 errmsg = e_positive;
7962 curbuf->b_p_sw = curbuf->b_p_ts;
7963 }
7964
7965 /*
7966 * Number options that need some action when changed
7967 */
7968#ifdef FEAT_WINDOWS
7969 if (pp == &p_wh || pp == &p_hh)
7970 {
7971 if (p_wh < 1)
7972 {
7973 errmsg = e_positive;
7974 p_wh = 1;
7975 }
7976 if (p_wmh > p_wh)
7977 {
7978 errmsg = e_winheight;
7979 p_wh = p_wmh;
7980 }
7981 if (p_hh < 0)
7982 {
7983 errmsg = e_positive;
7984 p_hh = 0;
7985 }
7986
7987 /* Change window height NOW */
7988 if (lastwin != firstwin)
7989 {
7990 if (pp == &p_wh && curwin->w_height < p_wh)
7991 win_setheight((int)p_wh);
7992 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7993 win_setheight((int)p_hh);
7994 }
7995 }
7996
7997 /* 'winminheight' */
7998 else if (pp == &p_wmh)
7999 {
8000 if (p_wmh < 0)
8001 {
8002 errmsg = e_positive;
8003 p_wmh = 0;
8004 }
8005 if (p_wmh > p_wh)
8006 {
8007 errmsg = e_winheight;
8008 p_wmh = p_wh;
8009 }
8010 win_setminheight();
8011 }
8012
8013# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008014 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 {
8016 if (p_wiw < 1)
8017 {
8018 errmsg = e_positive;
8019 p_wiw = 1;
8020 }
8021 if (p_wmw > p_wiw)
8022 {
8023 errmsg = e_winwidth;
8024 p_wiw = p_wmw;
8025 }
8026
8027 /* Change window width NOW */
8028 if (lastwin != firstwin && curwin->w_width < p_wiw)
8029 win_setwidth((int)p_wiw);
8030 }
8031
8032 /* 'winminwidth' */
8033 else if (pp == &p_wmw)
8034 {
8035 if (p_wmw < 0)
8036 {
8037 errmsg = e_positive;
8038 p_wmw = 0;
8039 }
8040 if (p_wmw > p_wiw)
8041 {
8042 errmsg = e_winwidth;
8043 p_wmw = p_wiw;
8044 }
8045 win_setminheight();
8046 }
8047# endif
8048
8049#endif
8050
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02008051#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008052 else if (pp == &curbuf->b_p_cm)
8053 {
8054 if (curbuf->b_p_cm < 0)
8055 {
8056 errmsg = e_positive;
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008057 curbuf->b_p_cm = old_value;
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008058 }
8059 if (curbuf->b_p_cm > 1)
8060 {
8061 errmsg = e_invarg;
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008062 curbuf->b_p_cm = old_value;
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008063 }
8064 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02008065 curbuf->b_p_cm = old_value;
8066
8067 if (curbuf->b_p_cm != old_value && *curbuf->b_p_key != NUL)
8068 /* Need to update the swapfile. */
8069 ml_set_crypt_key(curbuf, curbuf->b_p_key, old_value);
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008070 }
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02008071#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02008072
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073#ifdef FEAT_WINDOWS
8074 /* (re)set last window status line */
8075 else if (pp == &p_ls)
8076 {
8077 last_status(FALSE);
8078 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008079
8080 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008081 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008082 {
8083 shell_new_rows(); /* recompute window positions and heights */
8084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085#endif
8086
8087#ifdef FEAT_GUI
8088 else if (pp == &p_linespace)
8089 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008090 /* Recompute gui.char_height and resize the Vim window to keep the
8091 * same number of lines. */
8092 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008093 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094 }
8095#endif
8096
8097#ifdef FEAT_FOLDING
8098 /* 'foldlevel' */
8099 else if (pp == &curwin->w_p_fdl)
8100 {
8101 if (curwin->w_p_fdl < 0)
8102 curwin->w_p_fdl = 0;
8103 newFoldLevel();
8104 }
8105
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008106 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 else if (pp == &curwin->w_p_fml)
8108 {
8109 foldUpdateAll(curwin);
8110 }
8111
8112 /* 'foldnestmax' */
8113 else if (pp == &curwin->w_p_fdn)
8114 {
8115 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8116 foldUpdateAll(curwin);
8117 }
8118
8119 /* 'foldcolumn' */
8120 else if (pp == &curwin->w_p_fdc)
8121 {
8122 if (curwin->w_p_fdc < 0)
8123 {
8124 errmsg = e_positive;
8125 curwin->w_p_fdc = 0;
8126 }
8127 else if (curwin->w_p_fdc > 12)
8128 {
8129 errmsg = e_invarg;
8130 curwin->w_p_fdc = 12;
8131 }
8132 }
8133
8134 /* 'shiftwidth' or 'tabstop' */
8135 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8136 {
8137 if (foldmethodIsIndent(curwin))
8138 foldUpdateAll(curwin);
8139 }
8140#endif /* FEAT_FOLDING */
8141
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008142#ifdef FEAT_MBYTE
8143 /* 'maxcombine' */
8144 else if (pp == &p_mco)
8145 {
8146 if (p_mco > MAX_MCO)
8147 p_mco = MAX_MCO;
8148 else if (p_mco < 0)
8149 p_mco = 0;
8150 screenclear(); /* will re-allocate the screen */
8151 }
8152#endif
8153
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154 else if (pp == &curbuf->b_p_iminsert)
8155 {
8156 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8157 {
8158 errmsg = e_invarg;
8159 curbuf->b_p_iminsert = B_IMODE_NONE;
8160 }
8161 p_iminsert = curbuf->b_p_iminsert;
8162 if (termcap_active) /* don't do this in the alternate screen */
8163 showmode();
8164#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8165 /* Show/unshow value of 'keymap' in status lines. */
8166 status_redraw_curbuf();
8167#endif
8168 }
8169
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008170 else if (pp == &p_window)
8171 {
8172 if (p_window < 1)
8173 p_window = 1;
8174 else if (p_window >= Rows)
8175 p_window = Rows - 1;
8176 }
8177
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 else if (pp == &curbuf->b_p_imsearch)
8179 {
8180 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8181 {
8182 errmsg = e_invarg;
8183 curbuf->b_p_imsearch = B_IMODE_NONE;
8184 }
8185 p_imsearch = curbuf->b_p_imsearch;
8186 }
8187
8188#ifdef FEAT_TITLE
8189 /* if 'titlelen' has changed, redraw the title */
8190 else if (pp == &p_titlelen)
8191 {
8192 if (p_titlelen < 0)
8193 {
8194 errmsg = e_positive;
8195 p_titlelen = 85;
8196 }
8197 if (starting != NO_SCREEN && old_value != p_titlelen)
8198 need_maketitle = TRUE;
8199 }
8200#endif
8201
8202 /* if p_ch changed value, change the command line height */
8203 else if (pp == &p_ch)
8204 {
8205 if (p_ch < 1)
8206 {
8207 errmsg = e_positive;
8208 p_ch = 1;
8209 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008210 if (p_ch > Rows - min_rows() + 1)
8211 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212
8213 /* Only compute the new window layout when startup has been
8214 * completed. Otherwise the frame sizes may be wrong. */
8215 if (p_ch != old_value && full_screen
8216#ifdef FEAT_GUI
8217 && !gui.starting
8218#endif
8219 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008220 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221 }
8222
8223 /* when 'updatecount' changes from zero to non-zero, open swap files */
8224 else if (pp == &p_uc)
8225 {
8226 if (p_uc < 0)
8227 {
8228 errmsg = e_positive;
8229 p_uc = 100;
8230 }
8231 if (p_uc && !old_value)
8232 ml_open_files();
8233 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008234#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008235 else if (pp == &curwin->w_p_conc)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008236 {
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008237 if (curwin->w_p_conc < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008238 {
8239 errmsg = e_positive;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008240 curwin->w_p_conc = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008241 }
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008242 else if (curwin->w_p_conc > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008243 {
8244 errmsg = e_invarg;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008245 curwin->w_p_conc = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008246 }
8247 }
8248#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008249#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008250 else if (pp == &p_mzq)
8251 mzvim_reset_timer();
8252#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253
8254 /* sync undo before 'undolevels' changes */
8255 else if (pp == &p_ul)
8256 {
8257 /* use the old value, otherwise u_sync() may not work properly */
8258 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008259 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260 p_ul = value;
8261 }
8262
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008263#ifdef FEAT_LINEBREAK
8264 /* 'numberwidth' must be positive */
8265 else if (pp == &curwin->w_p_nuw)
8266 {
8267 if (curwin->w_p_nuw < 1)
8268 {
8269 errmsg = e_positive;
8270 curwin->w_p_nuw = 1;
8271 }
8272 if (curwin->w_p_nuw > 10)
8273 {
8274 errmsg = e_invarg;
8275 curwin->w_p_nuw = 10;
8276 }
8277 curwin->w_nrwidth_line_count = 0;
8278 }
8279#endif
8280
Bram Moolenaar1a384422010-07-14 19:53:30 +02008281 else if (pp == &curbuf->b_p_tw)
8282 {
8283 if (curbuf->b_p_tw < 0)
8284 {
8285 errmsg = e_positive;
8286 curbuf->b_p_tw = 0;
8287 }
8288#ifdef FEAT_SYN_HL
8289# ifdef FEAT_WINDOWS
8290 {
8291 win_T *wp;
8292 tabpage_T *tp;
8293
8294 FOR_ALL_TAB_WINDOWS(tp, wp)
8295 check_colorcolumn(wp);
8296 }
8297# else
8298 check_colorcolumn(curwin);
8299# endif
8300#endif
8301 }
8302
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 /*
8304 * Check the bounds for numeric options here
8305 */
8306 if (Rows < min_rows() && full_screen)
8307 {
8308 if (errbuf != NULL)
8309 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008310 vim_snprintf((char *)errbuf, errbuflen,
8311 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 errmsg = errbuf;
8313 }
8314 Rows = min_rows();
8315 }
8316 if (Columns < MIN_COLUMNS && full_screen)
8317 {
8318 if (errbuf != NULL)
8319 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008320 vim_snprintf((char *)errbuf, errbuflen,
8321 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 errmsg = errbuf;
8323 }
8324 Columns = MIN_COLUMNS;
8325 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008326 /* Limit the values to avoid an overflow in Rows * Columns. */
8327 if (Columns > 10000)
8328 Columns = 10000;
8329 if (Rows > 1000)
8330 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331
8332#ifdef DJGPP
8333 /* avoid a crash by checking for a too large value of 'columns' */
8334 if (old_Columns != Columns && full_screen && term_console)
8335 mch_check_columns();
8336#endif
8337
8338 /*
8339 * If the screen (shell) height has been changed, assume it is the
8340 * physical screenheight.
8341 */
8342 if (old_Rows != Rows || old_Columns != Columns)
8343 {
8344 /* Changing the screen size is not allowed while updating the screen. */
8345 if (updating_screen)
8346 *pp = old_value;
8347 else if (full_screen
8348#ifdef FEAT_GUI
8349 && !gui.starting
8350#endif
8351 )
8352 set_shellsize((int)Columns, (int)Rows, TRUE);
8353 else
8354 {
8355 /* Postpone the resizing; check the size and cmdline position for
8356 * messages. */
8357 check_shellsize();
8358 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8359 cmdline_row = Rows - p_ch;
8360 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008361 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008362 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 }
8364
8365 if (curbuf->b_p_sts < 0)
8366 {
8367 errmsg = e_positive;
8368 curbuf->b_p_sts = 0;
8369 }
8370 if (curbuf->b_p_ts <= 0)
8371 {
8372 errmsg = e_positive;
8373 curbuf->b_p_ts = 8;
8374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 if (p_tm < 0)
8376 {
8377 errmsg = e_positive;
8378 p_tm = 0;
8379 }
8380 if ((curwin->w_p_scr <= 0
8381 || (curwin->w_p_scr > curwin->w_height
8382 && curwin->w_height > 0))
8383 && full_screen)
8384 {
8385 if (pp == &(curwin->w_p_scr))
8386 {
8387 if (curwin->w_p_scr != 0)
8388 errmsg = e_scroll;
8389 win_comp_scroll(curwin);
8390 }
8391 /* If 'scroll' became invalid because of a side effect silently adjust
8392 * it. */
8393 else if (curwin->w_p_scr <= 0)
8394 curwin->w_p_scr = 1;
8395 else /* curwin->w_p_scr > curwin->w_height */
8396 curwin->w_p_scr = curwin->w_height;
8397 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008398 if (p_hi < 0)
8399 {
8400 errmsg = e_positive;
8401 p_hi = 0;
8402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 if (p_report < 0)
8404 {
8405 errmsg = e_positive;
8406 p_report = 1;
8407 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008408 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 {
8410 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8411 p_sj = Rows / 2;
8412 else
8413 {
8414 errmsg = e_scroll;
8415 p_sj = 1;
8416 }
8417 }
8418 if (p_so < 0 && full_screen)
8419 {
8420 errmsg = e_scroll;
8421 p_so = 0;
8422 }
8423 if (p_siso < 0 && full_screen)
8424 {
8425 errmsg = e_positive;
8426 p_siso = 0;
8427 }
8428#ifdef FEAT_CMDWIN
8429 if (p_cwh < 1)
8430 {
8431 errmsg = e_positive;
8432 p_cwh = 1;
8433 }
8434#endif
8435 if (p_ut < 0)
8436 {
8437 errmsg = e_positive;
8438 p_ut = 2000;
8439 }
8440 if (p_ss < 0)
8441 {
8442 errmsg = e_positive;
8443 p_ss = 0;
8444 }
8445
8446 /* May set global value for local option. */
8447 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8448 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8449
8450 options[opt_idx].flags |= P_WAS_SET;
8451
8452 comp_col(); /* in case 'columns' or 'ls' changed */
8453 if (curwin->w_curswant != MAXCOL)
8454 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8455 check_redraw(options[opt_idx].flags);
8456
8457 return errmsg;
8458}
8459
8460/*
8461 * Called after an option changed: check if something needs to be redrawn.
8462 */
8463 static void
8464check_redraw(flags)
8465 long_u flags;
8466{
8467 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8468 int clear = (flags & P_RCLR) == P_RCLR;
8469 int all = ((flags & P_RALL) == P_RALL || clear);
8470
8471#ifdef FEAT_WINDOWS
8472 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8473 status_redraw_all();
8474#endif
8475
8476 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8477 changed_window_setting();
8478 if (flags & P_RBUF)
8479 redraw_curbuf_later(NOT_VALID);
8480 if (clear)
8481 redraw_all_later(CLEAR);
8482 else if (all)
8483 redraw_all_later(NOT_VALID);
8484}
8485
8486/*
8487 * Find index for option 'arg'.
8488 * Return -1 if not found.
8489 */
8490 static int
8491findoption(arg)
8492 char_u *arg;
8493{
8494 int opt_idx;
8495 char *s, *p;
8496 static short quick_tab[27] = {0, 0}; /* quick access table */
8497 int is_term_opt;
8498
8499 /*
8500 * For first call: Initialize the quick-access table.
8501 * It contains the index for the first option that starts with a certain
8502 * letter. There are 26 letters, plus the first "t_" option.
8503 */
8504 if (quick_tab[1] == 0)
8505 {
8506 p = options[0].fullname;
8507 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8508 {
8509 if (s[0] != p[0])
8510 {
8511 if (s[0] == 't' && s[1] == '_')
8512 quick_tab[26] = opt_idx;
8513 else
8514 quick_tab[CharOrdLow(s[0])] = opt_idx;
8515 }
8516 p = s;
8517 }
8518 }
8519
8520 /*
8521 * Check for name starting with an illegal character.
8522 */
8523#ifdef EBCDIC
8524 if (!islower(arg[0]))
8525#else
8526 if (arg[0] < 'a' || arg[0] > 'z')
8527#endif
8528 return -1;
8529
8530 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8531 if (is_term_opt)
8532 opt_idx = quick_tab[26];
8533 else
8534 opt_idx = quick_tab[CharOrdLow(arg[0])];
8535 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8536 {
8537 if (STRCMP(arg, s) == 0) /* match full name */
8538 break;
8539 }
8540 if (s == NULL && !is_term_opt)
8541 {
8542 opt_idx = quick_tab[CharOrdLow(arg[0])];
8543 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8544 {
8545 s = options[opt_idx].shortname;
8546 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8547 break;
8548 s = NULL;
8549 }
8550 }
8551 if (s == NULL)
8552 opt_idx = -1;
8553 return opt_idx;
8554}
8555
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008556#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557/*
8558 * Get the value for an option.
8559 *
8560 * Returns:
8561 * Number or Toggle option: 1, *numval gets value.
8562 * String option: 0, *stringval gets allocated string.
8563 * Hidden Number or Toggle option: -1.
8564 * hidden String option: -2.
8565 * unknown option: -3.
8566 */
8567 int
8568get_option_value(name, numval, stringval, opt_flags)
8569 char_u *name;
8570 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008571 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 int opt_flags;
8573{
8574 int opt_idx;
8575 char_u *varp;
8576
8577 opt_idx = findoption(name);
8578 if (opt_idx < 0) /* unknown option */
8579 return -3;
8580
8581 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8582
8583 if (options[opt_idx].flags & P_STRING)
8584 {
8585 if (varp == NULL) /* hidden option */
8586 return -2;
8587 if (stringval != NULL)
8588 {
8589#ifdef FEAT_CRYPT
8590 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008591 if ((char_u **)varp == &curbuf->b_p_key
8592 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593 *stringval = vim_strsave((char_u *)"*****");
8594 else
8595#endif
8596 *stringval = vim_strsave(*(char_u **)(varp));
8597 }
8598 return 0;
8599 }
8600
8601 if (varp == NULL) /* hidden option */
8602 return -1;
8603 if (options[opt_idx].flags & P_NUM)
8604 *numval = *(long *)varp;
8605 else
8606 {
8607 /* Special case: 'modified' is b_changed, but we also want to consider
8608 * it set when 'ff' or 'fenc' changed. */
8609 if ((int *)varp == &curbuf->b_changed)
8610 *numval = curbufIsChanged();
8611 else
8612 *numval = *(int *)varp;
8613 }
8614 return 1;
8615}
8616#endif
8617
8618/*
8619 * Set the value of option "name".
8620 * Use "string" for string options, use "number" for other options.
8621 */
8622 void
8623set_option_value(name, number, string, opt_flags)
8624 char_u *name;
8625 long number;
8626 char_u *string;
8627 int opt_flags; /* OPT_LOCAL or 0 (both) */
8628{
8629 int opt_idx;
8630 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008631 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632
8633 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008634 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 EMSG2(_("E355: Unknown option: %s"), name);
8636 else
8637 {
8638 flags = options[opt_idx].flags;
8639#ifdef HAVE_SANDBOX
8640 /* Disallow changing some options in the sandbox */
8641 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008642 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008644 return;
8645 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008647 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 set_string_option(opt_idx, string, opt_flags);
8649 else
8650 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008651 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 if (varp != NULL) /* hidden option is not changed */
8653 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008654 if (number == 0 && string != NULL)
8655 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008656 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008657
8658 /* Either we are given a string or we are setting option
8659 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008660 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008661 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008662 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008663 {
8664 /* There's another character after zeros or the string
8665 * is empty. In both cases, we are trying to set a
8666 * num option using a string. */
8667 EMSG3(_("E521: Number required: &%s = '%s'"),
8668 name, string);
8669 return; /* do nothing as we hit an error */
8670
8671 }
8672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008674 (void)set_num_option(opt_idx, varp, number,
8675 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008677 (void)set_bool_option(opt_idx, varp, (int)number,
8678 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 }
8680 }
8681 }
8682}
8683
8684/*
8685 * Get the terminal code for a terminal option.
8686 * Returns NULL when not found.
8687 */
8688 char_u *
8689get_term_code(tname)
8690 char_u *tname;
8691{
8692 int opt_idx;
8693 char_u *varp;
8694
8695 if (tname[0] != 't' || tname[1] != '_' ||
8696 tname[2] == NUL || tname[3] == NUL)
8697 return NULL;
8698 if ((opt_idx = findoption(tname)) >= 0)
8699 {
8700 varp = get_varp(&(options[opt_idx]));
8701 if (varp != NULL)
8702 varp = *(char_u **)(varp);
8703 return varp;
8704 }
8705 return find_termcode(tname + 2);
8706}
8707
8708 char_u *
8709get_highlight_default()
8710{
8711 int i;
8712
8713 i = findoption((char_u *)"hl");
8714 if (i >= 0)
8715 return options[i].def_val[VI_DEFAULT];
8716 return (char_u *)NULL;
8717}
8718
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008719#if defined(FEAT_MBYTE) || defined(PROTO)
8720 char_u *
8721get_encoding_default()
8722{
8723 int i;
8724
8725 i = findoption((char_u *)"enc");
8726 if (i >= 0)
8727 return options[i].def_val[VI_DEFAULT];
8728 return (char_u *)NULL;
8729}
8730#endif
8731
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732/*
8733 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8734 */
8735 static int
8736find_key_option(arg)
8737 char_u *arg;
8738{
8739 int key;
8740 int modifiers;
8741
8742 /*
8743 * Don't use get_special_key_code() for t_xx, we don't want it to call
8744 * add_termcap_entry().
8745 */
8746 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8747 key = TERMCAP2KEY(arg[2], arg[3]);
8748 else
8749 {
8750 --arg; /* put arg at the '<' */
8751 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008752 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753 if (modifiers) /* can't handle modifiers here */
8754 key = 0;
8755 }
8756 return key;
8757}
8758
8759/*
8760 * if 'all' == 0: show changed options
8761 * if 'all' == 1: show all normal options
8762 * if 'all' == 2: show all terminal options
8763 */
8764 static void
8765showoptions(all, opt_flags)
8766 int all;
8767 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8768{
8769 struct vimoption *p;
8770 int col;
8771 int isterm;
8772 char_u *varp;
8773 struct vimoption **items;
8774 int item_count;
8775 int run;
8776 int row, rows;
8777 int cols;
8778 int i;
8779 int len;
8780
8781#define INC 20
8782#define GAP 3
8783
8784 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8785 PARAM_COUNT));
8786 if (items == NULL)
8787 return;
8788
8789 /* Highlight title */
8790 if (all == 2)
8791 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8792 else if (opt_flags & OPT_GLOBAL)
8793 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8794 else if (opt_flags & OPT_LOCAL)
8795 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8796 else
8797 MSG_PUTS_TITLE(_("\n--- Options ---"));
8798
8799 /*
8800 * do the loop two times:
8801 * 1. display the short items
8802 * 2. display the long items (only strings and numbers)
8803 */
8804 for (run = 1; run <= 2 && !got_int; ++run)
8805 {
8806 /*
8807 * collect the items in items[]
8808 */
8809 item_count = 0;
8810 for (p = &options[0]; p->fullname != NULL; p++)
8811 {
8812 varp = NULL;
8813 isterm = istermoption(p);
8814 if (opt_flags != 0)
8815 {
8816 if (p->indir != PV_NONE && !isterm)
8817 varp = get_varp_scope(p, opt_flags);
8818 }
8819 else
8820 varp = get_varp(p);
8821 if (varp != NULL
8822 && ((all == 2 && isterm)
8823 || (all == 1 && !isterm)
8824 || (all == 0 && !optval_default(p, varp))))
8825 {
8826 if (p->flags & P_BOOL)
8827 len = 1; /* a toggle option fits always */
8828 else
8829 {
8830 option_value2string(p, opt_flags);
8831 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8832 }
8833 if ((len <= INC - GAP && run == 1) ||
8834 (len > INC - GAP && run == 2))
8835 items[item_count++] = p;
8836 }
8837 }
8838
8839 /*
8840 * display the items
8841 */
8842 if (run == 1)
8843 {
8844 cols = (Columns + GAP - 3) / INC;
8845 if (cols == 0)
8846 cols = 1;
8847 rows = (item_count + cols - 1) / cols;
8848 }
8849 else /* run == 2 */
8850 rows = item_count;
8851 for (row = 0; row < rows && !got_int; ++row)
8852 {
8853 msg_putchar('\n'); /* go to next line */
8854 if (got_int) /* 'q' typed in more */
8855 break;
8856 col = 0;
8857 for (i = row; i < item_count; i += rows)
8858 {
8859 msg_col = col; /* make columns */
8860 showoneopt(items[i], opt_flags);
8861 col += INC;
8862 }
8863 out_flush();
8864 ui_breakcheck();
8865 }
8866 }
8867 vim_free(items);
8868}
8869
8870/*
8871 * Return TRUE if option "p" has its default value.
8872 */
8873 static int
8874optval_default(p, varp)
8875 struct vimoption *p;
8876 char_u *varp;
8877{
8878 int dvi;
8879
8880 if (varp == NULL)
8881 return TRUE; /* hidden option is always at default */
8882 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8883 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008884 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008886 /* the cast to long is required for Manx C, long_i is
8887 * needed for MSVC */
8888 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 /* P_STRING */
8890 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8891}
8892
8893/*
8894 * showoneopt: show the value of one option
8895 * must not be called with a hidden option!
8896 */
8897 static void
8898showoneopt(p, opt_flags)
8899 struct vimoption *p;
8900 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8901{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008902 char_u *varp;
8903 int save_silent = silent_mode;
8904
8905 silent_mode = FALSE;
8906 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907
8908 varp = get_varp_scope(p, opt_flags);
8909
8910 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8911 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8912 ? !curbufIsChanged() : !*(int *)varp))
8913 MSG_PUTS("no");
8914 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8915 MSG_PUTS("--");
8916 else
8917 MSG_PUTS(" ");
8918 MSG_PUTS(p->fullname);
8919 if (!(p->flags & P_BOOL))
8920 {
8921 msg_putchar('=');
8922 /* put value string in NameBuff */
8923 option_value2string(p, opt_flags);
8924 msg_outtrans(NameBuff);
8925 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008926
8927 silent_mode = save_silent;
8928 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929}
8930
8931/*
8932 * Write modified options as ":set" commands to a file.
8933 *
8934 * There are three values for "opt_flags":
8935 * OPT_GLOBAL: Write global option values and fresh values of
8936 * buffer-local options (used for start of a session
8937 * file).
8938 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8939 * curwin (used for a vimrc file).
8940 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8941 * and local values for window-local options of
8942 * curwin. Local values are also written when at the
8943 * default value, because a modeline or autocommand
8944 * may have set them when doing ":edit file" and the
8945 * user has set them back at the default or fresh
8946 * value.
8947 * When "local_only" is TRUE, don't write fresh
8948 * values, only local values (for ":mkview").
8949 * (fresh value = value used for a new buffer or window for a local option).
8950 *
8951 * Return FAIL on error, OK otherwise.
8952 */
8953 int
8954makeset(fd, opt_flags, local_only)
8955 FILE *fd;
8956 int opt_flags;
8957 int local_only;
8958{
8959 struct vimoption *p;
8960 char_u *varp; /* currently used value */
8961 char_u *varp_fresh; /* local value */
8962 char_u *varp_local = NULL; /* fresh value */
8963 char *cmd;
8964 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008965 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966
8967 /*
8968 * The options that don't have a default (terminal name, columns, lines)
8969 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008970 * Do the loop over "options[]" twice: once for options with the
8971 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008973 for (pri = 1; pri >= 0; --pri)
8974 {
8975 for (p = &options[0]; !istermoption(p); p++)
8976 if (!(p->flags & P_NO_MKRC)
8977 && !istermoption(p)
8978 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008979 {
8980 /* skip global option when only doing locals */
8981 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8982 continue;
8983
8984 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8985 * file, they are always buffer-specific. */
8986 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8987 continue;
8988
8989 /* Global values are only written when not at the default value. */
8990 varp = get_varp_scope(p, opt_flags);
8991 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8992 continue;
8993
8994 round = 2;
8995 if (p->indir != PV_NONE)
8996 {
8997 if (p->var == VAR_WIN)
8998 {
8999 /* skip window-local option when only doing globals */
9000 if (!(opt_flags & OPT_LOCAL))
9001 continue;
9002 /* When fresh value of window-local option is not at the
9003 * default, need to write it too. */
9004 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9005 {
9006 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9007 if (!optval_default(p, varp_fresh))
9008 {
9009 round = 1;
9010 varp_local = varp;
9011 varp = varp_fresh;
9012 }
9013 }
9014 }
9015 }
9016
9017 /* Round 1: fresh value for window-local options.
9018 * Round 2: other values */
9019 for ( ; round <= 2; varp = varp_local, ++round)
9020 {
9021 if (round == 1 || (opt_flags & OPT_GLOBAL))
9022 cmd = "set";
9023 else
9024 cmd = "setlocal";
9025
9026 if (p->flags & P_BOOL)
9027 {
9028 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9029 return FAIL;
9030 }
9031 else if (p->flags & P_NUM)
9032 {
9033 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9034 return FAIL;
9035 }
9036 else /* P_STRING */
9037 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009038#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9039 int do_endif = FALSE;
9040
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 /* Don't set 'syntax' and 'filetype' again if the value is
9042 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009043 if (
9044# if defined(FEAT_SYN_HL)
9045 p->indir == PV_SYN
9046# if defined(FEAT_AUTOCMD)
9047 ||
9048# endif
9049# endif
9050# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009051 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009052# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009053 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 {
9055 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9056 *(char_u **)(varp)) < 0
9057 || put_eol(fd) < 0)
9058 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009059 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9063 (p->flags & P_EXPAND) != 0) == FAIL)
9064 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009065#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9066 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067 {
9068 if (put_line(fd, "endif") == FAIL)
9069 return FAIL;
9070 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 }
9073 }
9074 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009075 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 return OK;
9077}
9078
9079#if defined(FEAT_FOLDING) || defined(PROTO)
9080/*
9081 * Generate set commands for the local fold options only. Used when
9082 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9083 */
9084 int
9085makefoldset(fd)
9086 FILE *fd;
9087{
9088 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9089# ifdef FEAT_EVAL
9090 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9091 == FAIL
9092# endif
9093 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9094 == FAIL
9095 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9096 == FAIL
9097 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9098 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9099 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9100 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9101 )
9102 return FAIL;
9103
9104 return OK;
9105}
9106#endif
9107
9108 static int
9109put_setstring(fd, cmd, name, valuep, expand)
9110 FILE *fd;
9111 char *cmd;
9112 char *name;
9113 char_u **valuep;
9114 int expand;
9115{
9116 char_u *s;
9117 char_u buf[MAXPATHL];
9118
9119 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9120 return FAIL;
9121 if (*valuep != NULL)
9122 {
9123 /* Output 'pastetoggle' as key names. For other
9124 * options some characters have to be escaped with
9125 * CTRL-V or backslash */
9126 if (valuep == &p_pt)
9127 {
9128 s = *valuep;
9129 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009130 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 return FAIL;
9132 }
9133 else if (expand)
9134 {
9135 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9136 if (put_escstr(fd, buf, 2) == FAIL)
9137 return FAIL;
9138 }
9139 else if (put_escstr(fd, *valuep, 2) == FAIL)
9140 return FAIL;
9141 }
9142 if (put_eol(fd) < 0)
9143 return FAIL;
9144 return OK;
9145}
9146
9147 static int
9148put_setnum(fd, cmd, name, valuep)
9149 FILE *fd;
9150 char *cmd;
9151 char *name;
9152 long *valuep;
9153{
9154 long wc;
9155
9156 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9157 return FAIL;
9158 if (wc_use_keyname((char_u *)valuep, &wc))
9159 {
9160 /* print 'wildchar' and 'wildcharm' as a key name */
9161 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9162 return FAIL;
9163 }
9164 else if (fprintf(fd, "%ld", *valuep) < 0)
9165 return FAIL;
9166 if (put_eol(fd) < 0)
9167 return FAIL;
9168 return OK;
9169}
9170
9171 static int
9172put_setbool(fd, cmd, name, value)
9173 FILE *fd;
9174 char *cmd;
9175 char *name;
9176 int value;
9177{
Bram Moolenaar893de922007-10-02 18:40:57 +00009178 if (value < 0) /* global/local option using global value */
9179 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9181 || put_eol(fd) < 0)
9182 return FAIL;
9183 return OK;
9184}
9185
9186/*
9187 * Clear all the terminal options.
9188 * If the option has been allocated, free the memory.
9189 * Terminal options are never hidden or indirect.
9190 */
9191 void
9192clear_termoptions()
9193{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 /*
9195 * Reset a few things before clearing the old options. This may cause
9196 * outputting a few things that the terminal doesn't understand, but the
9197 * screen will be cleared later, so this is OK.
9198 */
9199#ifdef FEAT_MOUSE_TTY
9200 mch_setmouse(FALSE); /* switch mouse off */
9201#endif
9202#ifdef FEAT_TITLE
9203 mch_restore_title(3); /* restore window titles */
9204#endif
9205#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9206 /* When starting the GUI close the display opened for the clipboard.
9207 * After restoring the title, because that will need the display. */
9208 if (gui.starting)
9209 clear_xterm_clip();
9210#endif
9211#ifdef WIN3264
9212 /*
9213 * Check if this is allowed now.
9214 */
9215 if (can_end_termcap_mode(FALSE) == TRUE)
9216#endif
9217 stoptermcap(); /* stop termcap mode */
9218
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009219 free_termoptions();
9220}
9221
9222 void
9223free_termoptions()
9224{
9225 struct vimoption *p;
9226
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 for (p = &options[0]; p->fullname != NULL; p++)
9228 if (istermoption(p))
9229 {
9230 if (p->flags & P_ALLOCED)
9231 free_string_option(*(char_u **)(p->var));
9232 if (p->flags & P_DEF_ALLOCED)
9233 free_string_option(p->def_val[VI_DEFAULT]);
9234 *(char_u **)(p->var) = empty_option;
9235 p->def_val[VI_DEFAULT] = empty_option;
9236 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9237 }
9238 clear_termcodes();
9239}
9240
9241/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009242 * Free the string for one term option, if it was allocated.
9243 * Set the string to empty_option and clear allocated flag.
9244 * "var" points to the option value.
9245 */
9246 void
9247free_one_termoption(var)
9248 char_u *var;
9249{
9250 struct vimoption *p;
9251
9252 for (p = &options[0]; p->fullname != NULL; p++)
9253 if (p->var == var)
9254 {
9255 if (p->flags & P_ALLOCED)
9256 free_string_option(*(char_u **)(p->var));
9257 *(char_u **)(p->var) = empty_option;
9258 p->flags &= ~P_ALLOCED;
9259 break;
9260 }
9261}
9262
9263/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 * Set the terminal option defaults to the current value.
9265 * Used after setting the terminal name.
9266 */
9267 void
9268set_term_defaults()
9269{
9270 struct vimoption *p;
9271
9272 for (p = &options[0]; p->fullname != NULL; p++)
9273 {
9274 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9275 {
9276 if (p->flags & P_DEF_ALLOCED)
9277 {
9278 free_string_option(p->def_val[VI_DEFAULT]);
9279 p->flags &= ~P_DEF_ALLOCED;
9280 }
9281 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9282 if (p->flags & P_ALLOCED)
9283 {
9284 p->flags |= P_DEF_ALLOCED;
9285 p->flags &= ~P_ALLOCED; /* don't free the value now */
9286 }
9287 }
9288 }
9289}
9290
9291/*
9292 * return TRUE if 'p' starts with 't_'
9293 */
9294 static int
9295istermoption(p)
9296 struct vimoption *p;
9297{
9298 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9299}
9300
9301/*
9302 * Compute columns for ruler and shown command. 'sc_col' is also used to
9303 * decide what the maximum length of a message on the status line can be.
9304 * If there is a status line for the last window, 'sc_col' is independent
9305 * of 'ru_col'.
9306 */
9307
9308#define COL_RULER 17 /* columns needed by standard ruler */
9309
9310 void
9311comp_col()
9312{
9313#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9314 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9315
9316 sc_col = 0;
9317 ru_col = 0;
9318 if (p_ru)
9319 {
9320#ifdef FEAT_STL_OPT
9321 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9322#else
9323 ru_col = COL_RULER + 1;
9324#endif
9325 /* no last status line, adjust sc_col */
9326 if (!last_has_status)
9327 sc_col = ru_col;
9328 }
9329 if (p_sc)
9330 {
9331 sc_col += SHOWCMD_COLS;
9332 if (!p_ru || last_has_status) /* no need for separating space */
9333 ++sc_col;
9334 }
9335 sc_col = Columns - sc_col;
9336 ru_col = Columns - ru_col;
9337 if (sc_col <= 0) /* screen too narrow, will become a mess */
9338 sc_col = 1;
9339 if (ru_col <= 0)
9340 ru_col = 1;
9341#else
9342 sc_col = Columns;
9343 ru_col = Columns;
9344#endif
9345}
9346
9347/*
9348 * Get pointer to option variable, depending on local or global scope.
9349 */
9350 static char_u *
9351get_varp_scope(p, opt_flags)
9352 struct vimoption *p;
9353 int opt_flags;
9354{
9355 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9356 {
9357 if (p->var == VAR_WIN)
9358 return (char_u *)GLOBAL_WO(get_varp(p));
9359 return p->var;
9360 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009361 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 {
9363 switch ((int)p->indir)
9364 {
9365#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009366 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9367 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9368 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009370 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9371 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9372 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009373 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009374 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009376 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9377 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378#endif
9379#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009380 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9381 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009383#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9384 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9385#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009386#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009387 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009388#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389 }
9390 return NULL; /* "cannot happen" */
9391 }
9392 return get_varp(p);
9393}
9394
9395/*
9396 * Get pointer to option variable.
9397 */
9398 static char_u *
9399get_varp(p)
9400 struct vimoption *p;
9401{
9402 /* hidden option, always return NULL */
9403 if (p->var == NULL)
9404 return NULL;
9405
9406 switch ((int)p->indir)
9407 {
9408 case PV_NONE: return p->var;
9409
9410 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009411 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009413 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009414 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009415 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009417 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009419 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9421#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009422 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009424 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9426#endif
9427#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009428 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009430 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9432#endif
9433#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009434 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009436 case PV_GP: return *curbuf->b_p_gp != NUL
9437 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9438 case PV_MP: return *curbuf->b_p_mp != NUL
9439 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009441#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9442 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9443 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9444#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009445#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009446 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009447 ? (char_u *)&(curwin->w_p_stl) : p->var;
9448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009449
9450#ifdef FEAT_ARABIC
9451 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9452#endif
9453 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009454#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009455 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9456#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009457#ifdef FEAT_SYN_HL
9458 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9459 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009460 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009461#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462#ifdef FEAT_DIFF
9463 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9464#endif
9465#ifdef FEAT_FOLDING
9466 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9467 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9468 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9469 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9470 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9471 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9472 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9473# ifdef FEAT_EVAL
9474 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9475 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9476# endif
9477 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9478#endif
9479 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009480 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009481#ifdef FEAT_LINEBREAK
9482 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9483#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009484#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9486#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009487#ifdef FEAT_VERTSPLIT
9488 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9491 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9492#endif
9493#ifdef FEAT_RIGHTLEFT
9494 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9495 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9496#endif
9497 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9498 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9499#ifdef FEAT_LINEBREAK
9500 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9501#endif
9502#ifdef FEAT_SCROLLBIND
9503 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9504#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009505#ifdef FEAT_CURSORBIND
9506 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9507#endif
9508#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02009509 case PV_CONCEAL: return (char_u *)&(curwin->w_p_conc);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009511
9512 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9513 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9514#ifdef FEAT_MBYTE
9515 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9516#endif
9517#if defined(FEAT_QUICKFIX)
9518 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9519 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9520#endif
9521 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9522 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9523#ifdef FEAT_CINDENT
9524 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9525 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9526 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9527#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009528#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009529 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009531#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9532 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9533#endif
9534#ifdef FEAT_COMMENTS
9535 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9536#endif
9537#ifdef FEAT_FOLDING
9538 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9539#endif
9540#ifdef FEAT_INS_EXPAND
9541 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9542#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009543#ifdef FEAT_COMPL_FUNC
9544 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009545 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9548 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9549#ifdef FEAT_MBYTE
9550 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9551#endif
9552 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9553#ifdef FEAT_AUTOCMD
9554 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9555#endif
9556 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009557 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9559 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9560 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9561 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9562#ifdef FEAT_FIND_ID
9563# ifdef FEAT_EVAL
9564 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9565# endif
9566#endif
9567#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9568 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9569 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9570#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009571#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009572 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009574#ifdef FEAT_CRYPT
9575 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9576#endif
9577#ifdef FEAT_LISP
9578 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9579#endif
9580 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9581 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9582 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9583 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9584 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9585#ifdef FEAT_OSFILETYPE
9586 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9587#endif
9588 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009589#ifdef FEAT_TEXTOBJ
9590 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9593#ifdef FEAT_SMARTINDENT
9594 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9595#endif
9596#ifndef SHORT_FNAME
9597 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9598#endif
9599 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9600#ifdef FEAT_SEARCHPATH
9601 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9602#endif
9603 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9604#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009605 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009606 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9607#endif
9608#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009609 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9610 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9611 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612#endif
9613 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9614 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9615 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9616 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009617#ifdef FEAT_PERSISTENT_UNDO
9618 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9621#ifdef FEAT_KEYMAP
9622 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9623#endif
9624 default: EMSG(_("E356: get_varp ERROR"));
9625 }
9626 /* always return a valid pointer to avoid a crash! */
9627 return (char_u *)&(curbuf->b_p_wm);
9628}
9629
9630/*
9631 * Get the value of 'equalprg', either the buffer-local one or the global one.
9632 */
9633 char_u *
9634get_equalprg()
9635{
9636 if (*curbuf->b_p_ep == NUL)
9637 return p_ep;
9638 return curbuf->b_p_ep;
9639}
9640
9641#if defined(FEAT_WINDOWS) || defined(PROTO)
9642/*
9643 * Copy options from one window to another.
9644 * Used when splitting a window.
9645 */
9646 void
9647win_copy_options(wp_from, wp_to)
9648 win_T *wp_from;
9649 win_T *wp_to;
9650{
9651 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9652 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9653# ifdef FEAT_RIGHTLEFT
9654# ifdef FEAT_FKMAP
9655 /* Is this right? */
9656 wp_to->w_farsi = wp_from->w_farsi;
9657# endif
9658# endif
9659}
9660#endif
9661
9662/*
9663 * Copy the options from one winopt_T to another.
9664 * Doesn't free the old option values in "to", use clear_winopt() for that.
9665 * The 'scroll' option is not copied, because it depends on the window height.
9666 * The 'previewwindow' option is reset, there can be only one preview window.
9667 */
9668 void
9669copy_winopt(from, to)
9670 winopt_T *from;
9671 winopt_T *to;
9672{
9673#ifdef FEAT_ARABIC
9674 to->wo_arab = from->wo_arab;
9675#endif
9676 to->wo_list = from->wo_list;
9677 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009678 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009679#ifdef FEAT_LINEBREAK
9680 to->wo_nuw = from->wo_nuw;
9681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682#ifdef FEAT_RIGHTLEFT
9683 to->wo_rl = from->wo_rl;
9684 to->wo_rlc = vim_strsave(from->wo_rlc);
9685#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009686#ifdef FEAT_STL_OPT
9687 to->wo_stl = vim_strsave(from->wo_stl);
9688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689 to->wo_wrap = from->wo_wrap;
9690#ifdef FEAT_LINEBREAK
9691 to->wo_lbr = from->wo_lbr;
9692#endif
9693#ifdef FEAT_SCROLLBIND
9694 to->wo_scb = from->wo_scb;
9695#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009696#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009697 to->wo_spell = from->wo_spell;
9698#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009699#ifdef FEAT_SYN_HL
9700 to->wo_cuc = from->wo_cuc;
9701 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009702 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704#ifdef FEAT_DIFF
9705 to->wo_diff = from->wo_diff;
9706#endif
9707#ifdef FEAT_FOLDING
9708 to->wo_fdc = from->wo_fdc;
9709 to->wo_fen = from->wo_fen;
9710 to->wo_fdi = vim_strsave(from->wo_fdi);
9711 to->wo_fml = from->wo_fml;
9712 to->wo_fdl = from->wo_fdl;
9713 to->wo_fdm = vim_strsave(from->wo_fdm);
9714 to->wo_fdn = from->wo_fdn;
9715# ifdef FEAT_EVAL
9716 to->wo_fde = vim_strsave(from->wo_fde);
9717 to->wo_fdt = vim_strsave(from->wo_fdt);
9718# endif
9719 to->wo_fmr = vim_strsave(from->wo_fmr);
9720#endif
9721 check_winopt(to); /* don't want NULL pointers */
9722}
9723
9724/*
9725 * Check string options in a window for a NULL value.
9726 */
9727 void
9728check_win_options(win)
9729 win_T *win;
9730{
9731 check_winopt(&win->w_onebuf_opt);
9732 check_winopt(&win->w_allbuf_opt);
9733}
9734
9735/*
9736 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9737 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738 void
9739check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009740 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741{
9742#ifdef FEAT_FOLDING
9743 check_string_option(&wop->wo_fdi);
9744 check_string_option(&wop->wo_fdm);
9745# ifdef FEAT_EVAL
9746 check_string_option(&wop->wo_fde);
9747 check_string_option(&wop->wo_fdt);
9748# endif
9749 check_string_option(&wop->wo_fmr);
9750#endif
9751#ifdef FEAT_RIGHTLEFT
9752 check_string_option(&wop->wo_rlc);
9753#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009754#ifdef FEAT_STL_OPT
9755 check_string_option(&wop->wo_stl);
9756#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009757#ifdef FEAT_SYN_HL
9758 check_string_option(&wop->wo_cc);
9759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760}
9761
9762/*
9763 * Free the allocated memory inside a winopt_T.
9764 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765 void
9766clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009767 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768{
9769#ifdef FEAT_FOLDING
9770 clear_string_option(&wop->wo_fdi);
9771 clear_string_option(&wop->wo_fdm);
9772# ifdef FEAT_EVAL
9773 clear_string_option(&wop->wo_fde);
9774 clear_string_option(&wop->wo_fdt);
9775# endif
9776 clear_string_option(&wop->wo_fmr);
9777#endif
9778#ifdef FEAT_RIGHTLEFT
9779 clear_string_option(&wop->wo_rlc);
9780#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009781#ifdef FEAT_STL_OPT
9782 clear_string_option(&wop->wo_stl);
9783#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009784#ifdef FEAT_SYN_HL
9785 clear_string_option(&wop->wo_cc);
9786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787}
9788
9789/*
9790 * Copy global option values to local options for one buffer.
9791 * Used when creating a new buffer and sometimes when entering a buffer.
9792 * flags:
9793 * BCO_ENTER We will enter the buf buffer.
9794 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9795 * appropriate.
9796 * BCO_NOHELP Don't copy the values to a help buffer.
9797 */
9798 void
9799buf_copy_options(buf, flags)
9800 buf_T *buf;
9801 int flags;
9802{
9803 int should_copy = TRUE;
9804 char_u *save_p_isk = NULL; /* init for GCC */
9805 int dont_do_help;
9806 int did_isk = FALSE;
9807
9808 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009809 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 */
9811 if (buf == NULL || !buf_valid(buf))
9812 return;
9813
9814 /*
9815 * Skip this when the option defaults have not been set yet. Happens when
9816 * main() allocates the first buffer.
9817 */
9818 if (p_cpo != NULL)
9819 {
9820 /*
9821 * Always copy when entering and 'cpo' contains 'S'.
9822 * Don't copy when already initialized.
9823 * Don't copy when 'cpo' contains 's' and not entering.
9824 * 'S' BCO_ENTER initialized 's' should_copy
9825 * yes yes X X TRUE
9826 * yes no yes X FALSE
9827 * no X yes X FALSE
9828 * X no no yes FALSE
9829 * X no no no TRUE
9830 * no yes no X TRUE
9831 */
9832 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9833 && (buf->b_p_initialized
9834 || (!(flags & BCO_ENTER)
9835 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9836 should_copy = FALSE;
9837
9838 if (should_copy || (flags & BCO_ALWAYS))
9839 {
9840 /* Don't copy the options specific to a help buffer when
9841 * BCO_NOHELP is given or the options were initialized already
9842 * (jumping back to a help file with CTRL-T or CTRL-O) */
9843 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9844 || buf->b_p_initialized;
9845 if (dont_do_help) /* don't free b_p_isk */
9846 {
9847 save_p_isk = buf->b_p_isk;
9848 buf->b_p_isk = NULL;
9849 }
9850 /*
9851 * Always free the allocated strings.
9852 * If not already initialized, set 'readonly' and copy 'fileformat'.
9853 */
9854 if (!buf->b_p_initialized)
9855 {
9856 free_buf_options(buf, TRUE);
9857 buf->b_p_ro = FALSE; /* don't copy readonly */
9858 buf->b_p_tx = p_tx;
9859#ifdef FEAT_MBYTE
9860 buf->b_p_fenc = vim_strsave(p_fenc);
9861#endif
9862 buf->b_p_ff = vim_strsave(p_ff);
9863#if defined(FEAT_QUICKFIX)
9864 buf->b_p_bh = empty_option;
9865 buf->b_p_bt = empty_option;
9866#endif
9867 }
9868 else
9869 free_buf_options(buf, FALSE);
9870
9871 buf->b_p_ai = p_ai;
9872 buf->b_p_ai_nopaste = p_ai_nopaste;
9873 buf->b_p_sw = p_sw;
9874 buf->b_p_tw = p_tw;
9875 buf->b_p_tw_nopaste = p_tw_nopaste;
9876 buf->b_p_tw_nobin = p_tw_nobin;
9877 buf->b_p_wm = p_wm;
9878 buf->b_p_wm_nopaste = p_wm_nopaste;
9879 buf->b_p_wm_nobin = p_wm_nobin;
9880 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009881#ifdef FEAT_MBYTE
9882 buf->b_p_bomb = p_bomb;
9883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884 buf->b_p_et = p_et;
9885 buf->b_p_et_nobin = p_et_nobin;
9886 buf->b_p_ml = p_ml;
9887 buf->b_p_ml_nobin = p_ml_nobin;
9888 buf->b_p_inf = p_inf;
9889 buf->b_p_swf = p_swf;
9890#ifdef FEAT_INS_EXPAND
9891 buf->b_p_cpt = vim_strsave(p_cpt);
9892#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009893#ifdef FEAT_COMPL_FUNC
9894 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009895 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009896#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 buf->b_p_sts = p_sts;
9898 buf->b_p_sts_nopaste = p_sts_nopaste;
9899#ifndef SHORT_FNAME
9900 buf->b_p_sn = p_sn;
9901#endif
9902#ifdef FEAT_COMMENTS
9903 buf->b_p_com = vim_strsave(p_com);
9904#endif
9905#ifdef FEAT_FOLDING
9906 buf->b_p_cms = vim_strsave(p_cms);
9907#endif
9908 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009909 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 buf->b_p_nf = vim_strsave(p_nf);
9911 buf->b_p_mps = vim_strsave(p_mps);
9912#ifdef FEAT_SMARTINDENT
9913 buf->b_p_si = p_si;
9914#endif
9915 buf->b_p_ci = p_ci;
9916#ifdef FEAT_CINDENT
9917 buf->b_p_cin = p_cin;
9918 buf->b_p_cink = vim_strsave(p_cink);
9919 buf->b_p_cino = vim_strsave(p_cino);
9920#endif
9921#ifdef FEAT_AUTOCMD
9922 /* Don't copy 'filetype', it must be detected */
9923 buf->b_p_ft = empty_option;
9924#endif
9925#ifdef FEAT_OSFILETYPE
9926 buf->b_p_oft = vim_strsave(p_oft);
9927#endif
9928 buf->b_p_pi = p_pi;
9929#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9930 buf->b_p_cinw = vim_strsave(p_cinw);
9931#endif
9932#ifdef FEAT_LISP
9933 buf->b_p_lisp = p_lisp;
9934#endif
9935#ifdef FEAT_SYN_HL
9936 /* Don't copy 'syntax', it must be set */
9937 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009938 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009939#endif
9940#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009941 buf->b_s.b_p_spc = vim_strsave(p_spf);
9942 (void)compile_cap_prog(&buf->b_s);
9943 buf->b_s.b_p_spf = vim_strsave(p_spf);
9944 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945#endif
9946#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9947 buf->b_p_inde = vim_strsave(p_inde);
9948 buf->b_p_indk = vim_strsave(p_indk);
9949#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009950#if defined(FEAT_EVAL)
9951 buf->b_p_fex = vim_strsave(p_fex);
9952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953#ifdef FEAT_CRYPT
9954 buf->b_p_key = vim_strsave(p_key);
9955#endif
9956#ifdef FEAT_SEARCHPATH
9957 buf->b_p_sua = vim_strsave(p_sua);
9958#endif
9959#ifdef FEAT_KEYMAP
9960 buf->b_p_keymap = vim_strsave(p_keymap);
9961 buf->b_kmap_state |= KEYMAP_INIT;
9962#endif
9963 /* This isn't really an option, but copying the langmap and IME
9964 * state from the current buffer is better than resetting it. */
9965 buf->b_p_iminsert = p_iminsert;
9966 buf->b_p_imsearch = p_imsearch;
9967
9968 /* options that are normally global but also have a local value
9969 * are not copied, start using the global value */
9970 buf->b_p_ar = -1;
9971#ifdef FEAT_QUICKFIX
9972 buf->b_p_gp = empty_option;
9973 buf->b_p_mp = empty_option;
9974 buf->b_p_efm = empty_option;
9975#endif
9976 buf->b_p_ep = empty_option;
9977 buf->b_p_kp = empty_option;
9978 buf->b_p_path = empty_option;
9979 buf->b_p_tags = empty_option;
9980#ifdef FEAT_FIND_ID
9981 buf->b_p_def = empty_option;
9982 buf->b_p_inc = empty_option;
9983# ifdef FEAT_EVAL
9984 buf->b_p_inex = vim_strsave(p_inex);
9985# endif
9986#endif
9987#ifdef FEAT_INS_EXPAND
9988 buf->b_p_dict = empty_option;
9989 buf->b_p_tsr = empty_option;
9990#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009991#ifdef FEAT_TEXTOBJ
9992 buf->b_p_qe = vim_strsave(p_qe);
9993#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009994#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9995 buf->b_p_bexpr = empty_option;
9996#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009997#ifdef FEAT_PERSISTENT_UNDO
9998 buf->b_p_udf = p_udf;
9999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000
10001 /*
10002 * Don't copy the options set by ex_help(), use the saved values,
10003 * when going from a help buffer to a non-help buffer.
10004 * Don't touch these at all when BCO_NOHELP is used and going from
10005 * or to a help buffer.
10006 */
10007 if (dont_do_help)
10008 buf->b_p_isk = save_p_isk;
10009 else
10010 {
10011 buf->b_p_isk = vim_strsave(p_isk);
10012 did_isk = TRUE;
10013 buf->b_p_ts = p_ts;
10014 buf->b_help = FALSE;
10015#ifdef FEAT_QUICKFIX
10016 if (buf->b_p_bt[0] == 'h')
10017 clear_string_option(&buf->b_p_bt);
10018#endif
10019 buf->b_p_ma = p_ma;
10020 }
10021 }
10022
10023 /*
10024 * When the options should be copied (ignoring BCO_ALWAYS), set the
10025 * flag that indicates that the options have been initialized.
10026 */
10027 if (should_copy)
10028 buf->b_p_initialized = TRUE;
10029 }
10030
10031 check_buf_options(buf); /* make sure we don't have NULLs */
10032 if (did_isk)
10033 (void)buf_init_chartab(buf, FALSE);
10034}
10035
10036/*
10037 * Reset the 'modifiable' option and its default value.
10038 */
10039 void
10040reset_modifiable()
10041{
10042 int opt_idx;
10043
10044 curbuf->b_p_ma = FALSE;
10045 p_ma = FALSE;
10046 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010047 if (opt_idx >= 0)
10048 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049}
10050
10051/*
10052 * Set the global value for 'iminsert' to the local value.
10053 */
10054 void
10055set_iminsert_global()
10056{
10057 p_iminsert = curbuf->b_p_iminsert;
10058}
10059
10060/*
10061 * Set the global value for 'imsearch' to the local value.
10062 */
10063 void
10064set_imsearch_global()
10065{
10066 p_imsearch = curbuf->b_p_imsearch;
10067}
10068
10069#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10070static int expand_option_idx = -1;
10071static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10072static int expand_option_flags = 0;
10073
10074 void
10075set_context_in_set_cmd(xp, arg, opt_flags)
10076 expand_T *xp;
10077 char_u *arg;
10078 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10079{
10080 int nextchar;
10081 long_u flags = 0; /* init for GCC */
10082 int opt_idx = 0; /* init for GCC */
10083 char_u *p;
10084 char_u *s;
10085 int is_term_option = FALSE;
10086 int key;
10087
10088 expand_option_flags = opt_flags;
10089
10090 xp->xp_context = EXPAND_SETTINGS;
10091 if (*arg == NUL)
10092 {
10093 xp->xp_pattern = arg;
10094 return;
10095 }
10096 p = arg + STRLEN(arg) - 1;
10097 if (*p == ' ' && *(p - 1) != '\\')
10098 {
10099 xp->xp_pattern = p + 1;
10100 return;
10101 }
10102 while (p > arg)
10103 {
10104 s = p;
10105 /* count number of backslashes before ' ' or ',' */
10106 if (*p == ' ' || *p == ',')
10107 {
10108 while (s > arg && *(s - 1) == '\\')
10109 --s;
10110 }
10111 /* break at a space with an even number of backslashes */
10112 if (*p == ' ' && ((p - s) & 1) == 0)
10113 {
10114 ++p;
10115 break;
10116 }
10117 --p;
10118 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010119 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 {
10121 xp->xp_context = EXPAND_BOOL_SETTINGS;
10122 p += 2;
10123 }
10124 if (STRNCMP(p, "inv", 3) == 0)
10125 {
10126 xp->xp_context = EXPAND_BOOL_SETTINGS;
10127 p += 3;
10128 }
10129 xp->xp_pattern = arg = p;
10130 if (*arg == '<')
10131 {
10132 while (*p != '>')
10133 if (*p++ == NUL) /* expand terminal option name */
10134 return;
10135 key = get_special_key_code(arg + 1);
10136 if (key == 0) /* unknown name */
10137 {
10138 xp->xp_context = EXPAND_NOTHING;
10139 return;
10140 }
10141 nextchar = *++p;
10142 is_term_option = TRUE;
10143 expand_option_name[2] = KEY2TERMCAP0(key);
10144 expand_option_name[3] = KEY2TERMCAP1(key);
10145 }
10146 else
10147 {
10148 if (p[0] == 't' && p[1] == '_')
10149 {
10150 p += 2;
10151 if (*p != NUL)
10152 ++p;
10153 if (*p == NUL)
10154 return; /* expand option name */
10155 nextchar = *++p;
10156 is_term_option = TRUE;
10157 expand_option_name[2] = p[-2];
10158 expand_option_name[3] = p[-1];
10159 }
10160 else
10161 {
10162 /* Allow * wildcard */
10163 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10164 p++;
10165 if (*p == NUL)
10166 return;
10167 nextchar = *p;
10168 *p = NUL;
10169 opt_idx = findoption(arg);
10170 *p = nextchar;
10171 if (opt_idx == -1 || options[opt_idx].var == NULL)
10172 {
10173 xp->xp_context = EXPAND_NOTHING;
10174 return;
10175 }
10176 flags = options[opt_idx].flags;
10177 if (flags & P_BOOL)
10178 {
10179 xp->xp_context = EXPAND_NOTHING;
10180 return;
10181 }
10182 }
10183 }
10184 /* handle "-=" and "+=" */
10185 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10186 {
10187 ++p;
10188 nextchar = '=';
10189 }
10190 if ((nextchar != '=' && nextchar != ':')
10191 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10192 {
10193 xp->xp_context = EXPAND_UNSUCCESSFUL;
10194 return;
10195 }
10196 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10197 {
10198 xp->xp_context = EXPAND_OLD_SETTING;
10199 if (is_term_option)
10200 expand_option_idx = -1;
10201 else
10202 expand_option_idx = opt_idx;
10203 xp->xp_pattern = p + 1;
10204 return;
10205 }
10206 xp->xp_context = EXPAND_NOTHING;
10207 if (is_term_option || (flags & P_NUM))
10208 return;
10209
10210 xp->xp_pattern = p + 1;
10211
10212 if (flags & P_EXPAND)
10213 {
10214 p = options[opt_idx].var;
10215 if (p == (char_u *)&p_bdir
10216 || p == (char_u *)&p_dir
10217 || p == (char_u *)&p_path
10218 || p == (char_u *)&p_rtp
10219#ifdef FEAT_SEARCHPATH
10220 || p == (char_u *)&p_cdpath
10221#endif
10222#ifdef FEAT_SESSION
10223 || p == (char_u *)&p_vdir
10224#endif
10225 )
10226 {
10227 xp->xp_context = EXPAND_DIRECTORIES;
10228 if (p == (char_u *)&p_path
10229#ifdef FEAT_SEARCHPATH
10230 || p == (char_u *)&p_cdpath
10231#endif
10232 )
10233 xp->xp_backslash = XP_BS_THREE;
10234 else
10235 xp->xp_backslash = XP_BS_ONE;
10236 }
10237 else
10238 {
10239 xp->xp_context = EXPAND_FILES;
10240 /* for 'tags' need three backslashes for a space */
10241 if (p == (char_u *)&p_tags)
10242 xp->xp_backslash = XP_BS_THREE;
10243 else
10244 xp->xp_backslash = XP_BS_ONE;
10245 }
10246 }
10247
10248 /* For an option that is a list of file names, find the start of the
10249 * last file name. */
10250 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10251 {
10252 /* count number of backslashes before ' ' or ',' */
10253 if (*p == ' ' || *p == ',')
10254 {
10255 s = p;
10256 while (s > xp->xp_pattern && *(s - 1) == '\\')
10257 --s;
10258 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10259 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10260 {
10261 xp->xp_pattern = p + 1;
10262 break;
10263 }
10264 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010265
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010266#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010267 /* for 'spellsuggest' start at "file:" */
10268 if (options[opt_idx].var == (char_u *)&p_sps
10269 && STRNCMP(p, "file:", 5) == 0)
10270 {
10271 xp->xp_pattern = p + 5;
10272 break;
10273 }
10274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 }
10276
10277 return;
10278}
10279
10280 int
10281ExpandSettings(xp, regmatch, num_file, file)
10282 expand_T *xp;
10283 regmatch_T *regmatch;
10284 int *num_file;
10285 char_u ***file;
10286{
10287 int num_normal = 0; /* Nr of matching non-term-code settings */
10288 int num_term = 0; /* Nr of matching terminal code settings */
10289 int opt_idx;
10290 int match;
10291 int count = 0;
10292 char_u *str;
10293 int loop;
10294 int is_term_opt;
10295 char_u name_buf[MAX_KEY_NAME_LEN];
10296 static char *(names[]) = {"all", "termcap"};
10297 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10298
10299 /* do this loop twice:
10300 * loop == 0: count the number of matching options
10301 * loop == 1: copy the matching options into allocated memory
10302 */
10303 for (loop = 0; loop <= 1; ++loop)
10304 {
10305 regmatch->rm_ic = ic;
10306 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10307 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010308 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10309 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10311 {
10312 if (loop == 0)
10313 num_normal++;
10314 else
10315 (*file)[count++] = vim_strsave((char_u *)names[match]);
10316 }
10317 }
10318 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10319 opt_idx++)
10320 {
10321 if (options[opt_idx].var == NULL)
10322 continue;
10323 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10324 && !(options[opt_idx].flags & P_BOOL))
10325 continue;
10326 is_term_opt = istermoption(&options[opt_idx]);
10327 if (is_term_opt && num_normal > 0)
10328 continue;
10329 match = FALSE;
10330 if (vim_regexec(regmatch, str, (colnr_T)0)
10331 || (options[opt_idx].shortname != NULL
10332 && vim_regexec(regmatch,
10333 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10334 match = TRUE;
10335 else if (is_term_opt)
10336 {
10337 name_buf[0] = '<';
10338 name_buf[1] = 't';
10339 name_buf[2] = '_';
10340 name_buf[3] = str[2];
10341 name_buf[4] = str[3];
10342 name_buf[5] = '>';
10343 name_buf[6] = NUL;
10344 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10345 {
10346 match = TRUE;
10347 str = name_buf;
10348 }
10349 }
10350 if (match)
10351 {
10352 if (loop == 0)
10353 {
10354 if (is_term_opt)
10355 num_term++;
10356 else
10357 num_normal++;
10358 }
10359 else
10360 (*file)[count++] = vim_strsave(str);
10361 }
10362 }
10363 /*
10364 * Check terminal key codes, these are not in the option table
10365 */
10366 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10367 {
10368 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10369 {
10370 if (!isprint(str[0]) || !isprint(str[1]))
10371 continue;
10372
10373 name_buf[0] = 't';
10374 name_buf[1] = '_';
10375 name_buf[2] = str[0];
10376 name_buf[3] = str[1];
10377 name_buf[4] = NUL;
10378
10379 match = FALSE;
10380 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10381 match = TRUE;
10382 else
10383 {
10384 name_buf[0] = '<';
10385 name_buf[1] = 't';
10386 name_buf[2] = '_';
10387 name_buf[3] = str[0];
10388 name_buf[4] = str[1];
10389 name_buf[5] = '>';
10390 name_buf[6] = NUL;
10391
10392 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10393 match = TRUE;
10394 }
10395 if (match)
10396 {
10397 if (loop == 0)
10398 num_term++;
10399 else
10400 (*file)[count++] = vim_strsave(name_buf);
10401 }
10402 }
10403
10404 /*
10405 * Check special key names.
10406 */
10407 regmatch->rm_ic = TRUE; /* ignore case here */
10408 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10409 {
10410 name_buf[0] = '<';
10411 STRCPY(name_buf + 1, str);
10412 STRCAT(name_buf, ">");
10413
10414 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10415 {
10416 if (loop == 0)
10417 num_term++;
10418 else
10419 (*file)[count++] = vim_strsave(name_buf);
10420 }
10421 }
10422 }
10423 if (loop == 0)
10424 {
10425 if (num_normal > 0)
10426 *num_file = num_normal;
10427 else if (num_term > 0)
10428 *num_file = num_term;
10429 else
10430 return OK;
10431 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10432 if (*file == NULL)
10433 {
10434 *file = (char_u **)"";
10435 return FAIL;
10436 }
10437 }
10438 }
10439 return OK;
10440}
10441
10442 int
10443ExpandOldSetting(num_file, file)
10444 int *num_file;
10445 char_u ***file;
10446{
10447 char_u *var = NULL; /* init for GCC */
10448 char_u *buf;
10449
10450 *num_file = 0;
10451 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10452 if (*file == NULL)
10453 return FAIL;
10454
10455 /*
10456 * For a terminal key code expand_option_idx is < 0.
10457 */
10458 if (expand_option_idx < 0)
10459 {
10460 var = find_termcode(expand_option_name + 2);
10461 if (var == NULL)
10462 expand_option_idx = findoption(expand_option_name);
10463 }
10464
10465 if (expand_option_idx >= 0)
10466 {
10467 /* put string of option value in NameBuff */
10468 option_value2string(&options[expand_option_idx], expand_option_flags);
10469 var = NameBuff;
10470 }
10471 else if (var == NULL)
10472 var = (char_u *)"";
10473
10474 /* A backslash is required before some characters. This is the reverse of
10475 * what happens in do_set(). */
10476 buf = vim_strsave_escaped(var, escape_chars);
10477
10478 if (buf == NULL)
10479 {
10480 vim_free(*file);
10481 *file = NULL;
10482 return FAIL;
10483 }
10484
10485#ifdef BACKSLASH_IN_FILENAME
10486 /* For MS-Windows et al. we don't double backslashes at the start and
10487 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010488 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489 if (var[0] == '\\' && var[1] == '\\'
10490 && expand_option_idx >= 0
10491 && (options[expand_option_idx].flags & P_EXPAND)
10492 && vim_isfilec(var[2])
10493 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010494 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495#endif
10496
10497 *file[0] = buf;
10498 *num_file = 1;
10499 return OK;
10500}
10501#endif
10502
10503/*
10504 * Get the value for the numeric or string option *opp in a nice format into
10505 * NameBuff[]. Must not be called with a hidden option!
10506 */
10507 static void
10508option_value2string(opp, opt_flags)
10509 struct vimoption *opp;
10510 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10511{
10512 char_u *varp;
10513
10514 varp = get_varp_scope(opp, opt_flags);
10515
10516 if (opp->flags & P_NUM)
10517 {
10518 long wc = 0;
10519
10520 if (wc_use_keyname(varp, &wc))
10521 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10522 else if (wc != 0)
10523 STRCPY(NameBuff, transchar((int)wc));
10524 else
10525 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10526 }
10527 else /* P_STRING */
10528 {
10529 varp = *(char_u **)(varp);
10530 if (varp == NULL) /* just in case */
10531 NameBuff[0] = NUL;
10532#ifdef FEAT_CRYPT
10533 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010534 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 STRCPY(NameBuff, "*****");
10536#endif
10537 else if (opp->flags & P_EXPAND)
10538 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10539 /* Translate 'pastetoggle' into special key names */
10540 else if ((char_u **)opp->var == &p_pt)
10541 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10542 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010543 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 }
10545}
10546
10547/*
10548 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10549 * printed as a keyname.
10550 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10551 */
10552 static int
10553wc_use_keyname(varp, wcp)
10554 char_u *varp;
10555 long *wcp;
10556{
10557 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10558 {
10559 *wcp = *(long *)varp;
10560 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10561 return TRUE;
10562 }
10563 return FALSE;
10564}
10565
10566#ifdef FEAT_LANGMAP
10567/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010568 * Any character has an equivalent 'langmap' character. This is used for
10569 * keyboards that have a special language mode that sends characters above
10570 * 128 (although other characters can be translated too). The "to" field is a
10571 * Vim command character. This avoids having to switch the keyboard back to
10572 * ASCII mode when leaving Insert mode.
10573 *
10574 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10575 * commands.
10576 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10577 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10578 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010580# ifdef FEAT_MBYTE
10581/*
10582 * With multi-byte support use growarray for 'langmap' chars >= 256
10583 */
10584typedef struct
10585{
10586 int from;
10587 int to;
10588} langmap_entry_T;
10589
10590static garray_T langmap_mapga;
10591static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592
10593/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010594 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10595 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010597 static void
10598langmap_set_entry(from, to)
10599 int from;
10600 int to;
10601{
10602 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010603 int a = 0;
10604 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010605
10606 /* Do a binary search for an existing entry. */
10607 while (a != b)
10608 {
10609 int i = (a + b) / 2;
10610 int d = entries[i].from - from;
10611
10612 if (d == 0)
10613 {
10614 entries[i].to = to;
10615 return;
10616 }
10617 if (d < 0)
10618 a = i + 1;
10619 else
10620 b = i;
10621 }
10622
10623 if (ga_grow(&langmap_mapga, 1) != OK)
10624 return; /* out of memory */
10625
10626 /* insert new entry at position "a" */
10627 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10628 mch_memmove(entries + 1, entries,
10629 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10630 ++langmap_mapga.ga_len;
10631 entries[0].from = from;
10632 entries[0].to = to;
10633}
10634
10635/*
10636 * Apply 'langmap' to multi-byte character "c" and return the result.
10637 */
10638 int
10639langmap_adjust_mb(c)
10640 int c;
10641{
10642 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10643 int a = 0;
10644 int b = langmap_mapga.ga_len;
10645
10646 while (a != b)
10647 {
10648 int i = (a + b) / 2;
10649 int d = entries[i].from - c;
10650
10651 if (d == 0)
10652 return entries[i].to; /* found matching entry */
10653 if (d < 0)
10654 a = i + 1;
10655 else
10656 b = i;
10657 }
10658 return c; /* no entry found, return "c" unmodified */
10659}
10660# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661
10662 static void
10663langmap_init()
10664{
10665 int i;
10666
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010667 for (i = 0; i < 256; i++)
10668 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10669# ifdef FEAT_MBYTE
10670 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10671# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010672}
10673
10674/*
10675 * Called when langmap option is set; the language map can be
10676 * changed at any time!
10677 */
10678 static void
10679langmap_set()
10680{
10681 char_u *p;
10682 char_u *p2;
10683 int from, to;
10684
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010685#ifdef FEAT_MBYTE
10686 ga_clear(&langmap_mapga); /* clear the previous map first */
10687#endif
10688 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689
10690 for (p = p_langmap; p[0] != NUL; )
10691 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010692 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10693 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 {
10695 if (p2[0] == '\\' && p2[1] != NUL)
10696 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697 }
10698 if (p2[0] == ';')
10699 ++p2; /* abcd;ABCD form, p2 points to A */
10700 else
10701 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10702 while (p[0])
10703 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010704 if (p[0] == ',')
10705 {
10706 ++p;
10707 break;
10708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 if (p[0] == '\\' && p[1] != NUL)
10710 ++p;
10711#ifdef FEAT_MBYTE
10712 from = (*mb_ptr2char)(p);
10713#else
10714 from = p[0];
10715#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010716 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 if (p2 == NULL)
10718 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010719 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010720 if (p[0] != ',')
10721 {
10722 if (p[0] == '\\')
10723 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010725 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010727 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 }
10731 else
10732 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010733 if (p2[0] != ',')
10734 {
10735 if (p2[0] == '\\')
10736 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010738 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010740 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 }
10744 if (to == NUL)
10745 {
10746 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10747 transchar(from));
10748 return;
10749 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010750
10751#ifdef FEAT_MBYTE
10752 if (from >= 256)
10753 langmap_set_entry(from, to);
10754 else
10755#endif
10756 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757
10758 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010759 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010760 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010762 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 if (*p == ';')
10764 {
10765 p = p2;
10766 if (p[0] != NUL)
10767 {
10768 if (p[0] != ',')
10769 {
10770 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10771 return;
10772 }
10773 ++p;
10774 }
10775 break;
10776 }
10777 }
10778 }
10779 }
10780}
10781#endif
10782
10783/*
10784 * Return TRUE if format option 'x' is in effect.
10785 * Take care of no formatting when 'paste' is set.
10786 */
10787 int
10788has_format_option(x)
10789 int x;
10790{
10791 if (p_paste)
10792 return FALSE;
10793 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10794}
10795
10796/*
10797 * Return TRUE if "x" is present in 'shortmess' option, or
10798 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10799 */
10800 int
10801shortmess(x)
10802 int x;
10803{
10804 return ( vim_strchr(p_shm, x) != NULL
10805 || (vim_strchr(p_shm, 'a') != NULL
10806 && vim_strchr((char_u *)SHM_A, x) != NULL));
10807}
10808
10809/*
10810 * paste_option_changed() - Called after p_paste was set or reset.
10811 */
10812 static void
10813paste_option_changed()
10814{
10815 static int old_p_paste = FALSE;
10816 static int save_sm = 0;
10817#ifdef FEAT_CMDL_INFO
10818 static int save_ru = 0;
10819#endif
10820#ifdef FEAT_RIGHTLEFT
10821 static int save_ri = 0;
10822 static int save_hkmap = 0;
10823#endif
10824 buf_T *buf;
10825
10826 if (p_paste)
10827 {
10828 /*
10829 * Paste switched from off to on.
10830 * Save the current values, so they can be restored later.
10831 */
10832 if (!old_p_paste)
10833 {
10834 /* save options for each buffer */
10835 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10836 {
10837 buf->b_p_tw_nopaste = buf->b_p_tw;
10838 buf->b_p_wm_nopaste = buf->b_p_wm;
10839 buf->b_p_sts_nopaste = buf->b_p_sts;
10840 buf->b_p_ai_nopaste = buf->b_p_ai;
10841 }
10842
10843 /* save global options */
10844 save_sm = p_sm;
10845#ifdef FEAT_CMDL_INFO
10846 save_ru = p_ru;
10847#endif
10848#ifdef FEAT_RIGHTLEFT
10849 save_ri = p_ri;
10850 save_hkmap = p_hkmap;
10851#endif
10852 /* save global values for local buffer options */
10853 p_tw_nopaste = p_tw;
10854 p_wm_nopaste = p_wm;
10855 p_sts_nopaste = p_sts;
10856 p_ai_nopaste = p_ai;
10857 }
10858
10859 /*
10860 * Always set the option values, also when 'paste' is set when it is
10861 * already on.
10862 */
10863 /* set options for each buffer */
10864 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10865 {
10866 buf->b_p_tw = 0; /* textwidth is 0 */
10867 buf->b_p_wm = 0; /* wrapmargin is 0 */
10868 buf->b_p_sts = 0; /* softtabstop is 0 */
10869 buf->b_p_ai = 0; /* no auto-indent */
10870 }
10871
10872 /* set global options */
10873 p_sm = 0; /* no showmatch */
10874#ifdef FEAT_CMDL_INFO
10875# ifdef FEAT_WINDOWS
10876 if (p_ru)
10877 status_redraw_all(); /* redraw to remove the ruler */
10878# endif
10879 p_ru = 0; /* no ruler */
10880#endif
10881#ifdef FEAT_RIGHTLEFT
10882 p_ri = 0; /* no reverse insert */
10883 p_hkmap = 0; /* no Hebrew keyboard */
10884#endif
10885 /* set global values for local buffer options */
10886 p_tw = 0;
10887 p_wm = 0;
10888 p_sts = 0;
10889 p_ai = 0;
10890 }
10891
10892 /*
10893 * Paste switched from on to off: Restore saved values.
10894 */
10895 else if (old_p_paste)
10896 {
10897 /* restore options for each buffer */
10898 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10899 {
10900 buf->b_p_tw = buf->b_p_tw_nopaste;
10901 buf->b_p_wm = buf->b_p_wm_nopaste;
10902 buf->b_p_sts = buf->b_p_sts_nopaste;
10903 buf->b_p_ai = buf->b_p_ai_nopaste;
10904 }
10905
10906 /* restore global options */
10907 p_sm = save_sm;
10908#ifdef FEAT_CMDL_INFO
10909# ifdef FEAT_WINDOWS
10910 if (p_ru != save_ru)
10911 status_redraw_all(); /* redraw to draw the ruler */
10912# endif
10913 p_ru = save_ru;
10914#endif
10915#ifdef FEAT_RIGHTLEFT
10916 p_ri = save_ri;
10917 p_hkmap = save_hkmap;
10918#endif
10919 /* set global values for local buffer options */
10920 p_tw = p_tw_nopaste;
10921 p_wm = p_wm_nopaste;
10922 p_sts = p_sts_nopaste;
10923 p_ai = p_ai_nopaste;
10924 }
10925
10926 old_p_paste = p_paste;
10927}
10928
10929/*
10930 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10931 *
10932 * Reset 'compatible' and set the values for options that didn't get set yet
10933 * to the Vim defaults.
10934 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010935 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 */
10937 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010938vimrc_found(fname, envname)
10939 char_u *fname;
10940 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010942 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010943 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010944 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945
10946 if (!option_was_set((char_u *)"cp"))
10947 {
10948 p_cp = FALSE;
10949 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10950 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10951 set_option_default(opt_idx, OPT_FREE, FALSE);
10952 didset_options();
10953 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010954
10955 if (fname != NULL)
10956 {
10957 p = vim_getenv(envname, &dofree);
10958 if (p == NULL)
10959 {
10960 /* Set $MYVIMRC to the first vimrc file found. */
10961 p = FullName_save(fname, FALSE);
10962 if (p != NULL)
10963 {
10964 vim_setenv(envname, p);
10965 vim_free(p);
10966 }
10967 }
10968 else if (dofree)
10969 vim_free(p);
10970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971}
10972
10973/*
10974 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10975 */
10976 void
10977change_compatible(on)
10978 int on;
10979{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010980 int opt_idx;
10981
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 if (p_cp != on)
10983 {
10984 p_cp = on;
10985 compatible_set();
10986 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010987 opt_idx = findoption((char_u *)"cp");
10988 if (opt_idx >= 0)
10989 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990}
10991
10992/*
10993 * Return TRUE when option "name" has been set.
10994 */
10995 int
10996option_was_set(name)
10997 char_u *name;
10998{
10999 int idx;
11000
11001 idx = findoption(name);
11002 if (idx < 0) /* unknown option */
11003 return FALSE;
11004 if (options[idx].flags & P_WAS_SET)
11005 return TRUE;
11006 return FALSE;
11007}
11008
11009/*
11010 * compatible_set() - Called when 'compatible' has been set or unset.
11011 *
11012 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11013 * flag) to a Vi compatible value.
11014 * When 'compatible' is unset: Set all options that have a different default
11015 * for Vim (without the P_VI_DEF flag) to that default.
11016 */
11017 static void
11018compatible_set()
11019{
11020 int opt_idx;
11021
11022 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11023 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11024 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11025 set_option_default(opt_idx, OPT_FREE, p_cp);
11026 didset_options();
11027}
11028
11029#ifdef FEAT_LINEBREAK
11030
11031# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11032 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011033 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034# endif
11035
11036/*
11037 * fill_breakat_flags() -- called when 'breakat' changes value.
11038 */
11039 static void
11040fill_breakat_flags()
11041{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011042 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043 int i;
11044
11045 for (i = 0; i < 256; i++)
11046 breakat_flags[i] = FALSE;
11047
11048 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011049 for (p = p_breakat; *p; p++)
11050 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051}
11052
11053# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011054 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055# endif
11056
11057#endif
11058
11059/*
11060 * Check an option that can be a range of string values.
11061 *
11062 * Return OK for correct value, FAIL otherwise.
11063 * Empty is always OK.
11064 */
11065 static int
11066check_opt_strings(val, values, list)
11067 char_u *val;
11068 char **values;
11069 int list; /* when TRUE: accept a list of values */
11070{
11071 return opt_strings_flags(val, values, NULL, list);
11072}
11073
11074/*
11075 * Handle an option that can be a range of string values.
11076 * Set a flag in "*flagp" for each string present.
11077 *
11078 * Return OK for correct value, FAIL otherwise.
11079 * Empty is always OK.
11080 */
11081 static int
11082opt_strings_flags(val, values, flagp, list)
11083 char_u *val; /* new value */
11084 char **values; /* array of valid string values */
11085 unsigned *flagp;
11086 int list; /* when TRUE: accept a list of values */
11087{
11088 int i;
11089 int len;
11090 unsigned new_flags = 0;
11091
11092 while (*val)
11093 {
11094 for (i = 0; ; ++i)
11095 {
11096 if (values[i] == NULL) /* val not found in values[] */
11097 return FAIL;
11098
11099 len = (int)STRLEN(values[i]);
11100 if (STRNCMP(values[i], val, len) == 0
11101 && ((list && val[len] == ',') || val[len] == NUL))
11102 {
11103 val += len + (val[len] == ',');
11104 new_flags |= (1 << i);
11105 break; /* check next item in val list */
11106 }
11107 }
11108 }
11109 if (flagp != NULL)
11110 *flagp = new_flags;
11111
11112 return OK;
11113}
11114
11115/*
11116 * Read the 'wildmode' option, fill wim_flags[].
11117 */
11118 static int
11119check_opt_wim()
11120{
11121 char_u new_wim_flags[4];
11122 char_u *p;
11123 int i;
11124 int idx = 0;
11125
11126 for (i = 0; i < 4; ++i)
11127 new_wim_flags[i] = 0;
11128
11129 for (p = p_wim; *p; ++p)
11130 {
11131 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11132 ;
11133 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11134 return FAIL;
11135 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11136 new_wim_flags[idx] |= WIM_LONGEST;
11137 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11138 new_wim_flags[idx] |= WIM_FULL;
11139 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11140 new_wim_flags[idx] |= WIM_LIST;
11141 else
11142 return FAIL;
11143 p += i;
11144 if (*p == NUL)
11145 break;
11146 if (*p == ',')
11147 {
11148 if (idx == 3)
11149 return FAIL;
11150 ++idx;
11151 }
11152 }
11153
11154 /* fill remaining entries with last flag */
11155 while (idx < 3)
11156 {
11157 new_wim_flags[idx + 1] = new_wim_flags[idx];
11158 ++idx;
11159 }
11160
11161 /* only when there are no errors, wim_flags[] is changed */
11162 for (i = 0; i < 4; ++i)
11163 wim_flags[i] = new_wim_flags[i];
11164 return OK;
11165}
11166
11167/*
11168 * Check if backspacing over something is allowed.
11169 */
11170 int
11171can_bs(what)
11172 int what; /* BS_INDENT, BS_EOL or BS_START */
11173{
11174 switch (*p_bs)
11175 {
11176 case '2': return TRUE;
11177 case '1': return (what != BS_START);
11178 case '0': return FALSE;
11179 }
11180 return vim_strchr(p_bs, what) != NULL;
11181}
11182
11183/*
11184 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11185 * the file must be considered changed when the value is different.
11186 */
11187 void
11188save_file_ff(buf)
11189 buf_T *buf;
11190{
11191 buf->b_start_ffc = *buf->b_p_ff;
11192 buf->b_start_eol = buf->b_p_eol;
11193#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011194 buf->b_start_bomb = buf->b_p_bomb;
11195
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196 /* Only use free/alloc when necessary, they take time. */
11197 if (buf->b_start_fenc == NULL
11198 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11199 {
11200 vim_free(buf->b_start_fenc);
11201 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11202 }
11203#endif
11204}
11205
11206/*
11207 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11208 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011209 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11210 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211 * Don't consider a new, empty buffer to be changed.
11212 */
11213 int
11214file_ff_differs(buf)
11215 buf_T *buf;
11216{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011217 /* In a buffer that was never loaded the options are not valid. */
11218 if (buf->b_flags & BF_NEVERLOADED)
11219 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 if ((buf->b_flags & BF_NEW)
11221 && buf->b_ml.ml_line_count == 1
11222 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11223 return FALSE;
11224 if (buf->b_start_ffc != *buf->b_p_ff)
11225 return TRUE;
11226 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11227 return TRUE;
11228#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011229 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11230 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231 if (buf->b_start_fenc == NULL)
11232 return (*buf->b_p_fenc != NUL);
11233 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11234#else
11235 return FALSE;
11236#endif
11237}
11238
11239/*
11240 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11241 */
11242 int
11243check_ff_value(p)
11244 char_u *p;
11245{
11246 return check_opt_strings(p, p_ff_values, FALSE);
11247}