blob: 63c0f2efb50ea905b2b92a277353241dd669ba30 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
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
290#ifdef FEAT_COMMENTS
291static char_u *p_com;
292#endif
293#ifdef FEAT_FOLDING
294static char_u *p_cms;
295#endif
296#ifdef FEAT_INS_EXPAND
297static char_u *p_cpt;
298#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000299#ifdef FEAT_COMPL_FUNC
300static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000301static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303static int p_eol;
304static int p_et;
305#ifdef FEAT_MBYTE
306static char_u *p_fenc;
307#endif
308static char_u *p_ff;
309static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000310static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311#ifdef FEAT_AUTOCMD
312static char_u *p_ft;
313#endif
314static long p_iminsert;
315static long p_imsearch;
316#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317static char_u *p_inex;
318#endif
319#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320static char_u *p_inde;
321static char_u *p_indk;
322#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000323#if defined(FEAT_EVAL)
324static char_u *p_fex;
325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326static int p_inf;
327static char_u *p_isk;
328#ifdef FEAT_CRYPT
329static char_u *p_key;
330#endif
331#ifdef FEAT_LISP
332static int p_lisp;
333#endif
334static int p_ml;
335static int p_ma;
336static int p_mod;
337static char_u *p_mps;
338static char_u *p_nf;
339#ifdef FEAT_OSFILETYPE
340static char_u *p_oft;
341#endif
342static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000343#ifdef FEAT_TEXTOBJ
344static char_u *p_qe;
345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_ro;
347#ifdef FEAT_SMARTINDENT
348static int p_si;
349#endif
350#ifndef SHORT_FNAME
351static int p_sn;
352#endif
353static long p_sts;
354#if defined(FEAT_SEARCHPATH)
355static char_u *p_sua;
356#endif
357static long p_sw;
358static int p_swf;
359#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000360static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000362#endif
363#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000364static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000365static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000366static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367#endif
368static long p_ts;
369static long p_tw;
370static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200371#ifdef FEAT_PERSISTENT_UNDO
372static int p_udf;
373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374static long p_wm;
375#ifdef FEAT_KEYMAP
376static char_u *p_keymap;
377#endif
378
379/* Saved values for when 'bin' is set. */
380static int p_et_nobin;
381static int p_ml_nobin;
382static long p_tw_nobin;
383static long p_wm_nobin;
384
385/* Saved values for when 'paste' is set */
386static long p_tw_nopaste;
387static long p_wm_nopaste;
388static long p_sts_nopaste;
389static int p_ai_nopaste;
390
391struct vimoption
392{
393 char *fullname; /* full option name */
394 char *shortname; /* permissible abbreviation */
395 long_u flags; /* see below */
396 char_u *var; /* global option: pointer to variable;
397 * window-local option: VAR_WIN;
398 * buffer-local option: global value */
399 idopt_T indir; /* global option: PV_NONE;
400 * local option: indirect option index */
401 char_u *def_val[2]; /* default values for variable (vi and vim) */
402#ifdef FEAT_EVAL
403 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000404# define SCRIPTID_INIT , 0
405#else
406# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407#endif
408};
409
410#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
411#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
412
413/*
414 * Flags
415 */
416#define P_BOOL 0x01 /* the option is boolean */
417#define P_NUM 0x02 /* the option is numeric */
418#define P_STRING 0x04 /* the option is a string */
419#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000420 must use free_string_option() when
421 assigning new value. Not set if default is
422 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
424 never be used for local or hidden options! */
425#define P_NODEFAULT 0x40 /* don't set to default value */
426#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
427 use vim_free() when assigning new value */
428#define P_WAS_SET 0x100 /* option has been set/reset */
429#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
430#define P_VI_DEF 0x400 /* Use Vi default for Vim */
431#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
432
433 /* when option changed, what to display: */
434#define P_RSTAT 0x1000 /* redraw status lines */
435#define P_RWIN 0x2000 /* redraw current window */
436#define P_RBUF 0x4000 /* redraw current buffer */
437#define P_RALL 0x6000 /* redraw all windows */
438#define P_RCLR 0x7000 /* clear and redraw all */
439
440#define P_COMMA 0x8000 /* comma separated list */
441#define P_NODUP 0x10000L/* don't allow duplicate strings */
442#define P_FLAGLIST 0x20000L/* list of single-char flags */
443
444#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
445#define P_GETTEXT 0x80000L/* expand default value with _() */
446#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000447#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000448#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000449#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
450 side effects) */
Bram Moolenaar865242e2010-07-14 21:12:05 +0200451#define P_NO_ML 0x1000000L/* not allowed in modeline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000453#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
454
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000455/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
456 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000457#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000458# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000459#else
460# define ISP_LATIN1 (char_u *)"@,161-255"
461#endif
462
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000463/* The 16 bit MS-DOS version is low on space, make the string as short as
464 * possible when compiling with few features. */
465#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
466 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200467 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200468# 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 +0000469#else
470# 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"
471#endif
472
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473/*
474 * options[] is initialized here.
475 * The order of the options MUST be alphabetic for ":set all" and findoption().
476 * All option names MUST start with a lowercase letter (for findoption()).
477 * Exception: "t_" options are at the end.
478 * The options with a NULL variable are 'hidden': a set command for them is
479 * ignored and they are not printed.
480 */
481static struct vimoption
482#ifdef FEAT_GUI_W16
483 _far
484#endif
485 options[] =
486{
487 {"aleph", "al", P_NUM|P_VI_DEF,
488#ifdef FEAT_RIGHTLEFT
489 (char_u *)&p_aleph, PV_NONE,
490#else
491 (char_u *)NULL, PV_NONE,
492#endif
493 {
494#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
495 (char_u *)128L,
496#else
497 (char_u *)224L,
498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000499 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
501#if defined(FEAT_GUI) && defined(MACOS_X)
502 (char_u *)&p_antialias, PV_NONE,
503 {(char_u *)FALSE, (char_u *)FALSE}
504#else
505 (char_u *)NULL, PV_NONE,
506 {(char_u *)FALSE, (char_u *)FALSE}
507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000508 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
510#ifdef FEAT_ARABIC
511 (char_u *)VAR_WIN, PV_ARAB,
512#else
513 (char_u *)NULL, PV_NONE,
514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
517#ifdef FEAT_ARABIC
518 (char_u *)&p_arshape, PV_NONE,
519#else
520 (char_u *)NULL, PV_NONE,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
524#ifdef FEAT_RIGHTLEFT
525 (char_u *)&p_ari, PV_NONE,
526#else
527 (char_u *)NULL, PV_NONE,
528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
531#ifdef FEAT_FKMAP
532 (char_u *)&p_altkeymap, PV_NONE,
533#else
534 (char_u *)NULL, PV_NONE,
535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
538#if defined(FEAT_MBYTE)
539 (char_u *)&p_ambw, PV_NONE,
540 {(char_u *)"single", (char_u *)0L}
541#else
542 (char_u *)NULL, PV_NONE,
543 {(char_u *)0L, (char_u *)0L}
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000546#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"autochdir", "acd", P_BOOL|P_VI_DEF,
548 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550#endif
551 {"autoindent", "ai", P_BOOL|P_VI_DEF,
552 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"autoprint", "ap", P_BOOL|P_VI_DEF,
555 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000558 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autowrite", "aw", P_BOOL|P_VI_DEF,
561 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autowriteall","awa", P_BOOL|P_VI_DEF,
564 (char_u *)&p_awa, 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 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
567 (char_u *)&p_bg, PV_NONE,
568 {
569#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
570 (char_u *)"dark",
571#else
572 (char_u *)"light",
573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
576 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
579 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
582 (char_u *)&p_bkc, PV_NONE,
583#ifdef UNIX
584 {(char_u *)"yes", (char_u *)"auto"}
585#else
586 {(char_u *)"auto", (char_u *)"auto"}
587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
590 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000592 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bex, PV_NONE,
594 {
595#ifdef VMS
596 (char_u *)"_",
597#else
598 (char_u *)"~",
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
602#ifdef FEAT_WILDIGN
603 (char_u *)&p_bsk, PV_NONE,
604 {(char_u *)"", (char_u *)0L}
605#else
606 (char_u *)NULL, PV_NONE,
607 {(char_u *)0L, (char_u *)0L}
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef FEAT_BEVAL
611 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
612 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
615 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000617# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000618 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000619 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622#endif
623 {"beautify", "bf", P_BOOL|P_VI_DEF,
624 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
627 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
630#ifdef MSDOS
631 (char_u *)&p_biosk, PV_NONE,
632#else
633 (char_u *)NULL, PV_NONE,
634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000635 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
637#ifdef FEAT_MBYTE
638 (char_u *)&p_bomb, PV_BOMB,
639#else
640 (char_u *)NULL, PV_NONE,
641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
644#ifdef FEAT_LINEBREAK
645 (char_u *)&p_breakat, PV_NONE,
646 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000651 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
653#ifdef FEAT_BROWSE
654 (char_u *)&p_bsdir, PV_NONE,
655 {(char_u *)"last", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000660 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
662#if defined(FEAT_QUICKFIX)
663 (char_u *)&p_bh, PV_BH,
664 {(char_u *)"", (char_u *)0L}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)0L, (char_u *)0L}
668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
671 (char_u *)&p_bl, PV_BL,
672 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
675#if defined(FEAT_QUICKFIX)
676 (char_u *)&p_bt, PV_BT,
677 {(char_u *)"", (char_u *)0L}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)0L, (char_u *)0L}
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000684#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 (char_u *)&p_cmp, PV_NONE,
686 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
693#ifdef FEAT_SEARCHPATH
694 (char_u *)&p_cdpath, PV_NONE,
695 {(char_u *)",,", (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"cedit", NULL, P_STRING,
702#ifdef FEAT_CMDWIN
703 (char_u *)&p_cedit, PV_NONE,
704 {(char_u *)"", (char_u *)CTRL_F_STR}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
711#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
712 (char_u *)&p_ccv, PV_NONE,
713 {(char_u *)"", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
720#ifdef FEAT_CINDENT
721 (char_u *)&p_cin, PV_CIN,
722#else
723 (char_u *)NULL, PV_NONE,
724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
727#ifdef FEAT_CINDENT
728 (char_u *)&p_cink, PV_CINK,
729 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
730#else
731 (char_u *)NULL, PV_NONE,
732 {(char_u *)0L, (char_u *)0L}
733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000734 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
736#ifdef FEAT_CINDENT
737 (char_u *)&p_cino, PV_CINO,
738#else
739 (char_u *)NULL, PV_NONE,
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
743#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
744 (char_u *)&p_cinw, PV_CINW,
745 {(char_u *)"if,else,while,do,for,switch",
746 (char_u *)0L}
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
753#ifdef FEAT_CLIPBOARD
754 (char_u *)&p_cb, PV_NONE,
755# ifdef FEAT_XCLIPBOARD
756 {(char_u *)"autoselect,exclude:cons\\|linux",
757 (char_u *)0L}
758# else
759 {(char_u *)"", (char_u *)0L}
760# endif
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
767 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
770#ifdef FEAT_CMDWIN
771 (char_u *)&p_cwh, PV_NONE,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200776 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
777#ifdef FEAT_SYN_HL
778 (char_u *)VAR_WIN, PV_CC,
779#else
780 (char_u *)NULL, PV_NONE,
781#endif
782 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
784 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000785 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
787#ifdef FEAT_COMMENTS
788 (char_u *)&p_com, PV_COM,
789 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
790 (char_u *)0L}
791#else
792 (char_u *)NULL, PV_NONE,
793 {(char_u *)0L, (char_u *)0L}
794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000795 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
797#ifdef FEAT_FOLDING
798 (char_u *)&p_cms, PV_CMS,
799 {(char_u *)"/*%s*/", (char_u *)0L}
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)0L, (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000805 /* P_PRI_MKRC isn't needed here, optval_default()
806 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"compatible", "cp", P_BOOL|P_RALL,
808 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000809 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
811#ifdef FEAT_INS_EXPAND
812 (char_u *)&p_cpt, PV_CPT,
813 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
814#else
815 (char_u *)NULL, PV_NONE,
816 {(char_u *)0L, (char_u *)0L}
817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200819 {"conceallevel","conc", P_NUM|P_RWIN|P_VI_DEF,
820#ifdef FEAT_CONCEAL
821 (char_u *)VAR_WIN, PV_CONCEAL,
822#else
823 (char_u *)NULL, PV_NONE,
824#endif
825 {(char_u *)0L, (char_u *)0L}
826 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000827 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
828#ifdef FEAT_COMPL_FUNC
829 (char_u *)&p_cfu, PV_CFU,
830 {(char_u *)"", (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000836 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
837#ifdef FEAT_INS_EXPAND
838 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000839 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845 {"confirm", "cf", P_BOOL|P_VI_DEF,
846#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
847 (char_u *)&p_confirm, PV_NONE,
848#else
849 (char_u *)NULL, PV_NONE,
850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852 {"conskey", "consk",P_BOOL|P_VI_DEF,
853#ifdef MSDOS
854 (char_u *)&p_consk, PV_NONE,
855#else
856 (char_u *)NULL, PV_NONE,
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000859 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
860 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
863 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000864 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
865 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200866 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200867#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200868 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200869 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200870#else
871 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200872 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200873#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
876#ifdef FEAT_CSCOPE
877 (char_u *)&p_cspc, PV_NONE,
878#else
879 (char_u *)NULL, PV_NONE,
880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
883#ifdef FEAT_CSCOPE
884 (char_u *)&p_csprg, PV_NONE,
885 {(char_u *)"cscope", (char_u *)0L}
886#else
887 (char_u *)NULL, PV_NONE,
888 {(char_u *)0L, (char_u *)0L}
889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000890 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
892#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
893 (char_u *)&p_csqf, PV_NONE,
894 {(char_u *)"", (char_u *)0L}
895#else
896 (char_u *)NULL, PV_NONE,
897 {(char_u *)0L, (char_u *)0L}
898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
901#ifdef FEAT_CSCOPE
902 (char_u *)&p_cst, PV_NONE,
903#else
904 (char_u *)NULL, PV_NONE,
905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
908#ifdef FEAT_CSCOPE
909 (char_u *)&p_csto, PV_NONE,
910#else
911 (char_u *)NULL, PV_NONE,
912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
915#ifdef FEAT_CSCOPE
916 (char_u *)&p_csverbose, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200921 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
922#ifdef FEAT_CURSORBIND
923 (char_u *)VAR_WIN, PV_CRBIND,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000928 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
929#ifdef FEAT_SYN_HL
930 (char_u *)VAR_WIN, PV_CUC,
931#else
932 (char_u *)NULL, PV_NONE,
933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000934 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000935 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
936#ifdef FEAT_SYN_HL
937 (char_u *)VAR_WIN, PV_CUL,
938#else
939 (char_u *)NULL, PV_NONE,
940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000941 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942 {"debug", NULL, P_STRING|P_VI_DEF,
943 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
946#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000947 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000948 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)NULL, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_MBYTE
956 (char_u *)&p_deco, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
962#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000963 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
969#ifdef FEAT_DIFF
970 (char_u *)VAR_WIN, PV_DIFF,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
976#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
977 (char_u *)&p_dex, PV_NONE,
978 {(char_u *)"", (char_u *)0L}
979#else
980 (char_u *)NULL, PV_NONE,
981 {(char_u *)0L, (char_u *)0L}
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
985#ifdef FEAT_DIFF
986 (char_u *)&p_dip, PV_NONE,
987 {(char_u *)"filler", (char_u *)NULL}
988#else
989 (char_u *)NULL, PV_NONE,
990 {(char_u *)"", (char_u *)NULL}
991#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
994#ifdef FEAT_DIGRAPHS
995 (char_u *)&p_dg, PV_NONE,
996#else
997 (char_u *)NULL, PV_NONE,
998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1001 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1004 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"eadirection", "ead", P_STRING|P_VI_DEF,
1007#ifdef FEAT_VERTSPLIT
1008 (char_u *)&p_ead, PV_NONE,
1009 {(char_u *)"both", (char_u *)0L}
1010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1016 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001018 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#ifdef FEAT_MBYTE
1020 (char_u *)&p_enc, PV_NONE,
1021 {(char_u *)ENC_DFLT, (char_u *)0L}
1022#else
1023 (char_u *)NULL, PV_NONE,
1024 {(char_u *)0L, (char_u *)0L}
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1028 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1031 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001034 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1037 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1040#ifdef FEAT_QUICKFIX
1041 (char_u *)&p_ef, PV_NONE,
1042 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)NULL, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1049#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001050 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)NULL, (char_u *)0L}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"esckeys", "ek", P_BOOL|P_VIM,
1058 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1061#ifdef FEAT_AUTOCMD
1062 (char_u *)&p_ei, PV_NONE,
1063#else
1064 (char_u *)NULL, PV_NONE,
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1068 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1071 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1074#ifdef FEAT_MBYTE
1075 (char_u *)&p_fenc, PV_FENC,
1076 {(char_u *)"", (char_u *)0L}
1077#else
1078 (char_u *)NULL, PV_NONE,
1079 {(char_u *)0L, (char_u *)0L}
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1083#ifdef FEAT_MBYTE
1084 (char_u *)&p_fencs, PV_NONE,
1085 {(char_u *)"ucs-bom", (char_u *)0L}
1086#else
1087 (char_u *)NULL, PV_NONE,
1088 {(char_u *)0L, (char_u *)0L}
1089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1092 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1095 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1097 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001098 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_AUTOCMD
1100 (char_u *)&p_ft, PV_FT,
1101 {(char_u *)"", (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)0L, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1108#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1109 (char_u *)&p_fcs, PV_NONE,
1110 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)"", (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1117#ifdef FEAT_FKMAP
1118 (char_u *)&p_fkmap, PV_NONE,
1119#else
1120 (char_u *)NULL, PV_NONE,
1121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"flash", "fl", P_BOOL|P_VI_DEF,
1124 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_FOLDING
1127 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1128 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1131 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1134 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001135 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1137# ifdef FEAT_EVAL
1138 (char_u *)VAR_WIN, PV_FDE,
1139 {(char_u *)"0", (char_u *)NULL}
1140# else
1141 (char_u *)NULL, PV_NONE,
1142 {(char_u *)NULL, (char_u *)0L}
1143# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1146 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1149 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1152 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1155 P_RWIN|P_COMMA|P_NODUP,
1156 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)"{{{,}}}", (char_u *)NULL}
1158 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1160 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1163 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1166 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1169 (char_u *)&p_fdo, PV_NONE,
1170 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1173# ifdef FEAT_EVAL
1174 (char_u *)VAR_WIN, PV_FDT,
1175 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001176# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001179# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001182 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001183#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001184 (char_u *)&p_fex, PV_FEX,
1185 {(char_u *)"", (char_u *)0L}
1186#else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)0L, (char_u *)0L}
1189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1192 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1194 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001195 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1196 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1198 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1200 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001202 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1203#ifdef HAVE_FSYNC
1204 (char_u *)&p_fs, PV_NONE,
1205 {(char_u *)TRUE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)FALSE, (char_u *)0L}
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1212 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"graphic", "gr", P_BOOL|P_VI_DEF,
1215 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1218#ifdef FEAT_QUICKFIX
1219 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1227#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001228 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {
1230# ifdef WIN3264
1231 /* may be changed to "grep -n" in os_win32.c */
1232 (char_u *)"findstr /n",
1233# else
1234# ifdef UNIX
1235 /* Add an extra file name so that grep will always
1236 * insert a file name in the match line. */
1237 (char_u *)"grep -n $* /dev/null",
1238# else
1239# ifdef VMS
1240 (char_u *)"SEARCH/NUMBERS ",
1241# else
1242 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243# endif
1244# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)NULL, (char_u *)0L}
1250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001251 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1253#ifdef CURSOR_SHAPE
1254 (char_u *)&p_guicursor, PV_NONE,
1255 {
1256# ifdef FEAT_GUI
1257 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1258# else /* MSDOS or Win32 console */
1259 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1260# endif
1261 (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1268#ifdef FEAT_GUI
1269 (char_u *)&p_guifont, PV_NONE,
1270 {(char_u *)"", (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1277#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1278 (char_u *)&p_guifontset, PV_NONE,
1279 {(char_u *)"", (char_u *)0L}
1280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1286#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1287 (char_u *)&p_guifontwide, PV_NONE,
1288 {(char_u *)"", (char_u *)0L}
1289#else
1290 (char_u *)NULL, PV_NONE,
1291 {(char_u *)NULL, (char_u *)0L}
1292#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001295#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 (char_u *)&p_ghr, PV_NONE,
1297#else
1298 (char_u *)NULL, PV_NONE,
1299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001300 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001302#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303 (char_u *)&p_go, PV_NONE,
1304# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001305 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001307 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308# endif
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"guipty", NULL, P_BOOL|P_VI_DEF,
1315#if defined(FEAT_GUI)
1316 (char_u *)&p_guipty, PV_NONE,
1317#else
1318 (char_u *)NULL, PV_NONE,
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001321 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001322#if defined(FEAT_GUI_TABLINE)
1323 (char_u *)&p_gtl, PV_NONE,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)NULL, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001330 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001331#if defined(FEAT_GUI_TABLINE)
1332 (char_u *)&p_gtt, PV_NONE,
1333 {(char_u *)"", (char_u *)0L}
1334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1340 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1343 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1345 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 {"helpheight", "hh", P_NUM|P_VI_DEF,
1347#ifdef FEAT_WINDOWS
1348 (char_u *)&p_hh, PV_NONE,
1349#else
1350 (char_u *)NULL, PV_NONE,
1351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1354#ifdef FEAT_MULTI_LANG
1355 (char_u *)&p_hlg, PV_NONE,
1356 {(char_u *)"", (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)0L, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"hidden", "hid", P_BOOL|P_VI_DEF,
1363 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1366 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 {"history", "hi", P_NUM|P_VIM,
1370 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1373#ifdef FEAT_RIGHTLEFT
1374 (char_u *)&p_hkmap, PV_NONE,
1375#else
1376 (char_u *)NULL, PV_NONE,
1377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1380#ifdef FEAT_RIGHTLEFT
1381 (char_u *)&p_hkmapp, PV_NONE,
1382#else
1383 (char_u *)NULL, PV_NONE,
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1387 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"icon", NULL, P_BOOL|P_VI_DEF,
1390#ifdef FEAT_TITLE
1391 (char_u *)&p_icon, PV_NONE,
1392#else
1393 (char_u *)NULL, PV_NONE,
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"iconstring", NULL, P_STRING|P_VI_DEF,
1397#ifdef FEAT_TITLE
1398 (char_u *)&p_iconstring, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1404 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001407#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 (char_u *)&p_imak, PV_NONE,
1409#else
1410 (char_u *)NULL, PV_NONE,
1411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001412 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1414#ifdef USE_IM_CONTROL
1415 (char_u *)&p_imcmdline, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1421#ifdef USE_IM_CONTROL
1422 (char_u *)&p_imdisable, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
1426#ifdef __sgi
1427 {(char_u *)TRUE, (char_u *)0L}
1428#else
1429 {(char_u *)FALSE, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"iminsert", "imi", P_NUM|P_VI_DEF,
1433 (char_u *)&p_iminsert, PV_IMI,
1434#ifdef B_IMODE_IM
1435 {(char_u *)B_IMODE_IM, (char_u *)0L}
1436#else
1437 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"imsearch", "ims", P_NUM|P_VI_DEF,
1441 (char_u *)&p_imsearch, PV_IMS,
1442#ifdef B_IMODE_IM
1443 {(char_u *)B_IMODE_IM, (char_u *)0L}
1444#else
1445 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1449#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001450 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1452#else
1453 (char_u *)NULL, PV_NONE,
1454 {(char_u *)0L, (char_u *)0L}
1455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001456 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1458#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1459 (char_u *)&p_inex, PV_INEX,
1460 {(char_u *)"", (char_u *)0L}
1461#else
1462 (char_u *)NULL, PV_NONE,
1463 {(char_u *)0L, (char_u *)0L}
1464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001465 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1467 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1470#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1471 (char_u *)&p_inde, PV_INDE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)0L, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1479#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1480 (char_u *)&p_indk, PV_INDK,
1481 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1482#else
1483 (char_u *)NULL, PV_NONE,
1484 {(char_u *)0L, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"infercase", "inf", P_BOOL|P_VI_DEF,
1488 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1491 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1494 (char_u *)&p_isf, PV_NONE,
1495 {
1496#ifdef BACKSLASH_IN_FILENAME
1497 /* Excluded are: & and ^ are special in cmd.exe
1498 * ( and ) are used in text separating fnames */
1499 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1500#else
1501# ifdef AMIGA
1502 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1503# else
1504# ifdef VMS
1505 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1506# else /* UNIX et al. */
1507# ifdef EBCDIC
1508 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1509# else
1510 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1511# endif
1512# endif
1513# endif
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1517 (char_u *)&p_isi, PV_NONE,
1518 {
1519#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1520 (char_u *)"@,48-57,_,128-167,224-235",
1521#else
1522# ifdef EBCDIC
1523 /* TODO: EBCDIC Check this! @ == isalpha()*/
1524 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1525 "112-120,128,140-142,156,158,172,"
1526 "174,186,191,203-207,219-225,235-239,"
1527 "251-254",
1528# else
1529 (char_u *)"@,48-57,_,192-255",
1530# endif
1531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1534 (char_u *)&p_isk, PV_ISK,
1535 {
1536#ifdef EBCDIC
1537 (char_u *)"@,240-249,_",
1538 /* TODO: EBCDIC Check this! @ == isalpha()*/
1539 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1540 "112-120,128,140-142,156,158,172,"
1541 "174,186,191,203-207,219-225,235-239,"
1542 "251-254",
1543#else
1544 (char_u *)"@,48-57,_",
1545# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1546 (char_u *)"@,48-57,_,128-167,224-235"
1547# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001548 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549# endif
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1553 (char_u *)&p_isp, PV_NONE,
1554 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001555#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1556 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 || defined(VMS)
1558 (char_u *)"@,~-255",
1559#else
1560# ifdef EBCDIC
1561 /* all chars above 63 are printable */
1562 (char_u *)"63-255",
1563# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001564 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565# endif
1566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001567 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1569 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1572#ifdef FEAT_CRYPT
1573 (char_u *)&p_key, PV_KEY,
1574 {(char_u *)"", (char_u *)0L}
1575#else
1576 (char_u *)NULL, PV_NONE,
1577 {(char_u *)0L, (char_u *)0L}
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001580 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581#ifdef FEAT_KEYMAP
1582 (char_u *)&p_keymap, PV_KMAP,
1583 {(char_u *)"", (char_u *)0L}
1584#else
1585 (char_u *)NULL, PV_NONE,
1586 {(char_u *)"", (char_u *)0L}
1587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001588 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1590#ifdef FEAT_VISUAL
1591 (char_u *)&p_km, PV_NONE,
1592#else
1593 (char_u *)NULL, PV_NONE,
1594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001597 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {
1599#if defined(MSDOS) || defined(MSWIN)
1600 (char_u *)":help",
1601#else
1602#ifdef VMS
1603 (char_u *)"help",
1604#else
1605# if defined(OS2)
1606 (char_u *)"view /",
1607# else
1608# ifdef USEMAN_S
1609 (char_u *)"man -s",
1610# else
1611 (char_u *)"man",
1612# endif
1613# endif
1614#endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1618#ifdef FEAT_LANGMAP
1619 (char_u *)&p_langmap, PV_NONE,
1620 {(char_u *)"", /* unmatched } */
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)NULL,
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001626 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1628 (char_u *)&p_lm, PV_NONE,
1629#else
1630 (char_u *)NULL, PV_NONE,
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1634#ifdef FEAT_WINDOWS
1635 (char_u *)&p_ls, PV_NONE,
1636#else
1637 (char_u *)NULL, PV_NONE,
1638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001639 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1641 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1644#ifdef FEAT_LINEBREAK
1645 (char_u *)VAR_WIN, PV_LBR,
1646#else
1647 (char_u *)NULL, PV_NONE,
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1651 (char_u *)&Rows, PV_NONE,
1652 {
1653#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1654 (char_u *)25L,
1655#else
1656 (char_u *)24L,
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1660#ifdef FEAT_GUI
1661 (char_u *)&p_linespace, PV_NONE,
1662#else
1663 (char_u *)NULL, PV_NONE,
1664#endif
1665#ifdef FEAT_GUI_W32
1666 {(char_u *)1L, (char_u *)0L}
1667#else
1668 {(char_u *)0L, (char_u *)0L}
1669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"lisp", NULL, P_BOOL|P_VI_DEF,
1672#ifdef FEAT_LISP
1673 (char_u *)&p_lisp, PV_LISP,
1674#else
1675 (char_u *)NULL, PV_NONE,
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1679#ifdef FEAT_LISP
1680 (char_u *)&p_lispwords, PV_NONE,
1681 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1682#else
1683 (char_u *)NULL, PV_NONE,
1684 {(char_u *)"", (char_u *)0L}
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1688 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001689 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1691 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1694 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001696#ifdef FEAT_GUI_MAC
1697 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1698 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"magic", NULL, P_BOOL|P_VI_DEF,
1702 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001704 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#ifdef FEAT_QUICKFIX
1706 (char_u *)&p_mef, PV_NONE,
1707 {(char_u *)"", (char_u *)0L}
1708#else
1709 (char_u *)NULL, PV_NONE,
1710 {(char_u *)NULL, (char_u *)0L}
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1714#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001715 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716# ifdef VMS
1717 {(char_u *)"MMS", (char_u *)0L}
1718# else
1719 {(char_u *)"make", (char_u *)0L}
1720# endif
1721#else
1722 (char_u *)NULL, PV_NONE,
1723 {(char_u *)NULL, (char_u *)0L}
1724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1727 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"matchtime", "mat", P_NUM|P_VI_DEF,
1731 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001733 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1734#ifdef FEAT_MBYTE
1735 (char_u *)&p_mco, PV_NONE,
1736#else
1737 (char_u *)NULL, PV_NONE,
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1741#ifdef FEAT_EVAL
1742 (char_u *)&p_mfd, PV_NONE,
1743#else
1744 (char_u *)NULL, PV_NONE,
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1748 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"maxmem", "mm", P_NUM|P_VI_DEF,
1751 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1753 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001754 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1755 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1758 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1760 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"menuitems", "mis", P_NUM|P_VI_DEF,
1762#ifdef FEAT_MENU
1763 (char_u *)&p_mis, PV_NONE,
1764#else
1765 (char_u *)NULL, PV_NONE,
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"mesg", NULL, P_BOOL|P_VI_DEF,
1769 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001771 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001772#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001773 (char_u *)&p_msm, PV_NONE,
1774 {(char_u *)"460000,2000,500", (char_u *)0L}
1775#else
1776 (char_u *)NULL, PV_NONE,
1777 {(char_u *)0L, (char_u *)0L}
1778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"modeline", "ml", P_BOOL|P_VIM,
1781 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"modelines", "mls", P_NUM|P_VI_DEF,
1784 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1787 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1790 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"more", NULL, P_BOOL|P_VIM,
1793 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1796 (char_u *)&p_mouse, PV_NONE,
1797 {
1798#if defined(MSDOS) || defined(WIN3264)
1799 (char_u *)"a",
1800#else
1801 (char_u *)"",
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1805#ifdef FEAT_GUI
1806 (char_u *)&p_mousef, PV_NONE,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1812#ifdef FEAT_GUI
1813 (char_u *)&p_mh, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1819 (char_u *)&p_mousem, PV_NONE,
1820 {
1821#if defined(MSDOS) || defined(MSWIN)
1822 (char_u *)"popup",
1823#else
1824# if defined(MACOS)
1825 (char_u *)"popup_setpos",
1826# else
1827 (char_u *)"extend",
1828# endif
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1832#ifdef FEAT_MOUSESHAPE
1833 (char_u *)&p_mouseshape, PV_NONE,
1834 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)NULL, (char_u *)0L}
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1841 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001843 {"mzquantum", "mzq", P_NUM,
1844#ifdef FEAT_MZSCHEME
1845 (char_u *)&p_mzq, PV_NONE,
1846#else
1847 (char_u *)NULL, PV_NONE,
1848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"novice", NULL, P_BOOL|P_VI_DEF,
1851 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1854 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)"octal,hex", (char_u *)0L}
1856 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1858 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001860 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1861#ifdef FEAT_LINEBREAK
1862 (char_u *)VAR_WIN, PV_NUW,
1863#else
1864 (char_u *)NULL, PV_NONE,
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001867 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001868#ifdef FEAT_COMPL_FUNC
1869 (char_u *)&p_ofu, PV_OFU,
1870 {(char_u *)"", (char_u *)0L}
1871#else
1872 (char_u *)NULL, PV_NONE,
1873 {(char_u *)0L, (char_u *)0L}
1874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"open", NULL, P_BOOL|P_VI_DEF,
1877 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001879 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1880#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1881 (char_u *)&p_odev, PV_NONE,
1882#else
1883 (char_u *)NULL, PV_NONE,
1884#endif
1885 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001887 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1888 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"optimize", "opt", P_BOOL|P_VI_DEF,
1891 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1894#ifdef FEAT_OSFILETYPE
1895 (char_u *)&p_oft, PV_OFT,
1896 {(char_u *)DFLT_OFT, (char_u *)0L}
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)0L, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"paragraphs", "para", P_STRING|P_VI_DEF,
1903 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001904 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001906 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1910 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1913#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1914 (char_u *)&p_pex, PV_NONE,
1915 {(char_u *)"", (char_u *)0L}
1916#else
1917 (char_u *)NULL, PV_NONE,
1918 {(char_u *)0L, (char_u *)0L}
1919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001921 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001925 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {
1927#if defined AMIGA || defined MSDOS || defined MSWIN
1928 (char_u *)".,,",
1929#else
1930# if defined(__EMX__)
1931 (char_u *)".,/emx/include,,",
1932# else /* Unix, probably */
1933 (char_u *)".,/usr/include,,",
1934# endif
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1938 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001940 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1942 (char_u *)&p_pvh, PV_NONE,
1943#else
1944 (char_u *)NULL, PV_NONE,
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1948#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1949 (char_u *)VAR_WIN, PV_PVW,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001954 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955#ifdef FEAT_PRINTER
1956 (char_u *)&p_pdev, PV_NONE,
1957 {(char_u *)"", (char_u *)0L}
1958#else
1959 (char_u *)NULL, PV_NONE,
1960 {(char_u *)NULL, (char_u *)0L}
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"printencoding", "penc", P_STRING|P_VI_DEF,
1964#ifdef FEAT_POSTSCRIPT
1965 (char_u *)&p_penc, PV_NONE,
1966 {(char_u *)"", (char_u *)0L}
1967#else
1968 (char_u *)NULL, PV_NONE,
1969 {(char_u *)NULL, (char_u *)0L}
1970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1973#ifdef FEAT_POSTSCRIPT
1974 (char_u *)&p_pexpr, PV_NONE,
1975 {(char_u *)"", (char_u *)0L}
1976#else
1977 (char_u *)NULL, PV_NONE,
1978 {(char_u *)NULL, (char_u *)0L}
1979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"printfont", "pfn", P_STRING|P_VI_DEF,
1982#ifdef FEAT_PRINTER
1983 (char_u *)&p_pfn, PV_NONE,
1984 {
1985# ifdef MSWIN
1986 (char_u *)"Courier_New:h10",
1987# else
1988 (char_u *)"courier",
1989# endif
1990 (char_u *)0L}
1991#else
1992 (char_u *)NULL, PV_NONE,
1993 {(char_u *)NULL, (char_u *)0L}
1994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1997#ifdef FEAT_PRINTER
1998 (char_u *)&p_header, PV_NONE,
1999 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2000#else
2001 (char_u *)NULL, PV_NONE,
2002 {(char_u *)NULL, (char_u *)0L}
2003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002004 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002005 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2006#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2007 (char_u *)&p_pmcs, PV_NONE,
2008 {(char_u *)"", (char_u *)0L}
2009#else
2010 (char_u *)NULL, PV_NONE,
2011 {(char_u *)NULL, (char_u *)0L}
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002014 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2015#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2016 (char_u *)&p_pmfn, PV_NONE,
2017 {(char_u *)"", (char_u *)0L}
2018#else
2019 (char_u *)NULL, PV_NONE,
2020 {(char_u *)NULL, (char_u *)0L}
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2024#ifdef FEAT_PRINTER
2025 (char_u *)&p_popt, PV_NONE,
2026 {(char_u *)"", (char_u *)0L}
2027#else
2028 (char_u *)NULL, PV_NONE,
2029 {(char_u *)NULL, (char_u *)0L}
2030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002031 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002033 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002035 {"pumheight", "ph", P_NUM|P_VI_DEF,
2036#ifdef FEAT_INS_EXPAND
2037 (char_u *)&p_ph, PV_NONE,
2038#else
2039 (char_u *)NULL, PV_NONE,
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002042 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2043#ifdef FEAT_TEXTOBJ
2044 (char_u *)&p_qe, PV_QE,
2045 {(char_u *)"\\", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2052 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"redraw", NULL, P_BOOL|P_VI_DEF,
2055 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002057 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2058#ifdef FEAT_RELTIME
2059 (char_u *)&p_rdt, PV_NONE,
2060#else
2061 (char_u *)NULL, PV_NONE,
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002064 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2065 (char_u *)VAR_WIN, PV_RNU,
2066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"remap", NULL, P_BOOL|P_VI_DEF,
2068 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"report", NULL, P_NUM|P_VI_DEF,
2071 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2074#ifdef WIN3264
2075 (char_u *)&p_rs, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2081#ifdef FEAT_RIGHTLEFT
2082 (char_u *)&p_ri, PV_NONE,
2083#else
2084 (char_u *)NULL, PV_NONE,
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2088#ifdef FEAT_RIGHTLEFT
2089 (char_u *)VAR_WIN, PV_RL,
2090#else
2091 (char_u *)NULL, PV_NONE,
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2095#ifdef FEAT_RIGHTLEFT
2096 (char_u *)VAR_WIN, PV_RLC,
2097 {(char_u *)"search", (char_u *)NULL}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2104#ifdef FEAT_CMDL_INFO
2105 (char_u *)&p_ru, PV_NONE,
2106#else
2107 (char_u *)NULL, PV_NONE,
2108#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2111#ifdef FEAT_STL_OPT
2112 (char_u *)&p_ruf, PV_NONE,
2113#else
2114 (char_u *)NULL, PV_NONE,
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2118 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2122 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2125#ifdef FEAT_SCROLLBIND
2126 (char_u *)VAR_WIN, PV_SCBIND,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2132 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2135 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2138#ifdef FEAT_SCROLLBIND
2139 (char_u *)&p_sbo, PV_NONE,
2140 {(char_u *)"ver,jump", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)0L, (char_u *)0L}
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"sections", "sect", P_STRING|P_VI_DEF,
2147 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2149 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2151 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"selection", "sel", P_STRING|P_VI_DEF,
2154#ifdef FEAT_VISUAL
2155 (char_u *)&p_sel, PV_NONE,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)"inclusive", (char_u *)0L}
2160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2162#ifdef FEAT_VISUAL
2163 (char_u *)&p_slm, PV_NONE,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2169#ifdef FEAT_SESSION
2170 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002171 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)0L, (char_u *)0L}
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2179 (char_u *)&p_sh, PV_NONE,
2180 {
2181#ifdef VMS
2182 (char_u *)"-",
2183#else
2184# if defined(MSDOS)
2185 (char_u *)"command",
2186# else
2187# if defined(WIN16)
2188 (char_u *)"command.com",
2189# else
2190# if defined(WIN3264)
2191 (char_u *)"", /* set in set_init_1() */
2192# else
2193# if defined(OS2)
2194 (char_u *)"cmd.exe",
2195# else
2196# if defined(ARCHIE)
2197 (char_u *)"gos",
2198# else
2199 (char_u *)"sh",
2200# endif
2201# endif
2202# endif
2203# endif
2204# endif
2205#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2208 (char_u *)&p_shcf, PV_NONE,
2209 {
2210#if defined(MSDOS) || defined(MSWIN)
2211 (char_u *)"/c",
2212#else
2213# if defined(OS2)
2214 (char_u *)"/c",
2215# else
2216 (char_u *)"-c",
2217# endif
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2221#ifdef FEAT_QUICKFIX
2222 (char_u *)&p_sp, PV_NONE,
2223 {
2224#if defined(UNIX) || defined(OS2)
2225# ifdef ARCHIE
2226 (char_u *)"2>",
2227# else
2228 (char_u *)"| tee",
2229# endif
2230#else
2231 (char_u *)">",
2232#endif
2233 (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)0L, (char_u *)0L}
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2240 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2243 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2246#ifdef BACKSLASH_IN_FILENAME
2247 (char_u *)&p_ssl, PV_NONE,
2248#else
2249 (char_u *)NULL, PV_NONE,
2250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002252 {"shelltemp", "stmp", P_BOOL,
2253 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"shelltype", "st", P_NUM|P_VI_DEF,
2256#ifdef AMIGA
2257 (char_u *)&p_st, PV_NONE,
2258#else
2259 (char_u *)NULL, PV_NONE,
2260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2263 (char_u *)&p_sxq, PV_NONE,
2264 {
2265#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2266 (char_u *)"\"",
2267#else
2268 (char_u *)"",
2269#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2272 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2275 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2278 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)"", (char_u *)"filnxtToO"}
2280 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"shortname", "sn", P_BOOL|P_VI_DEF,
2282#ifdef SHORT_FNAME
2283 (char_u *)NULL, PV_NONE,
2284#else
2285 (char_u *)&p_sn, PV_SN,
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2289#ifdef FEAT_LINEBREAK
2290 (char_u *)&p_sbr, PV_NONE,
2291#else
2292 (char_u *)NULL, PV_NONE,
2293#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"showcmd", "sc", P_BOOL|P_VIM,
2296#ifdef FEAT_CMDL_INFO
2297 (char_u *)&p_sc, PV_NONE,
2298#else
2299 (char_u *)NULL, PV_NONE,
2300#endif
2301 {(char_u *)FALSE,
2302#ifdef UNIX
2303 (char_u *)FALSE
2304#else
2305 (char_u *)TRUE
2306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2309 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2312 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002313 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"showmode", "smd", P_BOOL|P_VIM,
2315 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002317 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2318#ifdef FEAT_WINDOWS
2319 (char_u *)&p_stal, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2325 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2328 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2331 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2334 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2337#ifdef FEAT_SMARTINDENT
2338 (char_u *)&p_si, PV_SI,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2344 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2347 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2350 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002352 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002353#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002354 (char_u *)VAR_WIN, PV_SPELL,
2355#else
2356 (char_u *)NULL, PV_NONE,
2357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002359 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002360#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002361 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002362 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002363#else
2364 (char_u *)NULL, PV_NONE,
2365 {(char_u *)0L, (char_u *)0L}
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002368 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002369#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002370 (char_u *)&p_spf, PV_SPF,
2371 {(char_u *)"", (char_u *)0L}
2372#else
2373 (char_u *)NULL, PV_NONE,
2374 {(char_u *)0L, (char_u *)0L}
2375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002377 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002378#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002379 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002380 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002381#else
2382 (char_u *)NULL, PV_NONE,
2383 {(char_u *)0L, (char_u *)0L}
2384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002386 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002387#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002388 (char_u *)&p_sps, PV_NONE,
2389 {(char_u *)"best", (char_u *)0L}
2390#else
2391 (char_u *)NULL, PV_NONE,
2392 {(char_u *)0L, (char_u *)0L}
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2396#ifdef FEAT_WINDOWS
2397 (char_u *)&p_sb, PV_NONE,
2398#else
2399 (char_u *)NULL, PV_NONE,
2400#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"splitright", "spr", P_BOOL|P_VI_DEF,
2403#ifdef FEAT_VERTSPLIT
2404 (char_u *)&p_spr, PV_NONE,
2405#else
2406 (char_u *)NULL, PV_NONE,
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2410 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2413#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002414 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415#else
2416 (char_u *)NULL, PV_NONE,
2417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2420 (char_u *)&p_su, PV_NONE,
2421 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002424#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 (char_u *)&p_sua, PV_SUA,
2426 {(char_u *)"", (char_u *)0L}
2427#else
2428 (char_u *)NULL, PV_NONE,
2429 {(char_u *)0L, (char_u *)0L}
2430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2433 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"swapsync", "sws", P_STRING|P_VI_DEF,
2436 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2439 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002441 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2442#ifdef FEAT_SYN_HL
2443 (char_u *)&p_smc, PV_SMC,
2444 {(char_u *)3000L, (char_u *)0L}
2445#else
2446 (char_u *)NULL, PV_NONE,
2447 {(char_u *)0L, (char_u *)0L}
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002450 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451#ifdef FEAT_SYN_HL
2452 (char_u *)&p_syn, PV_SYN,
2453 {(char_u *)"", (char_u *)0L}
2454#else
2455 (char_u *)NULL, PV_NONE,
2456 {(char_u *)0L, (char_u *)0L}
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002459 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2460#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002461 (char_u *)&p_tal, PV_NONE,
2462#else
2463 (char_u *)NULL, PV_NONE,
2464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002466 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2467#ifdef FEAT_WINDOWS
2468 (char_u *)&p_tpm, PV_NONE,
2469#else
2470 (char_u *)NULL, PV_NONE,
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2474 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2477 (char_u *)&p_tbs, PV_NONE,
2478#ifdef VMS /* binary searching doesn't appear to work on VMS */
2479 {(char_u *)0L, (char_u *)0L}
2480#else
2481 {(char_u *)TRUE, (char_u *)0L}
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"taglength", "tl", P_NUM|P_VI_DEF,
2485 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"tagrelative", "tr", P_BOOL|P_VIM,
2488 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002491 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {
2493#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2494 (char_u *)"./tags,./TAGS,tags,TAGS",
2495#else
2496 (char_u *)"./tags,tags",
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2500 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2503 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2506#ifdef FEAT_ARABIC
2507 (char_u *)&p_tbidi, PV_NONE,
2508#else
2509 (char_u *)NULL, PV_NONE,
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2513#ifdef FEAT_MBYTE
2514 (char_u *)&p_tenc, PV_NONE,
2515 {(char_u *)"", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"terse", NULL, P_BOOL|P_VI_DEF,
2522 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"textauto", "ta", P_BOOL|P_VIM,
2525 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2529 (char_u *)&p_tx, PV_TX,
2530 {
2531#ifdef USE_CRNL
2532 (char_u *)TRUE,
2533#else
2534 (char_u *)FALSE,
2535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002537 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2541#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002542 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543#else
2544 (char_u *)NULL, PV_NONE,
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2548 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"timeout", "to", P_BOOL|P_VI_DEF,
2551 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2554 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"title", NULL, P_BOOL|P_VI_DEF,
2557#ifdef FEAT_TITLE
2558 (char_u *)&p_title, PV_NONE,
2559#else
2560 (char_u *)NULL, PV_NONE,
2561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"titlelen", NULL, P_NUM|P_VI_DEF,
2564#ifdef FEAT_TITLE
2565 (char_u *)&p_titlelen, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002570 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571#ifdef FEAT_TITLE
2572 (char_u *)&p_titleold, PV_NONE,
2573 {(char_u *)N_("Thanks for flying Vim"),
2574 (char_u *)0L}
2575#else
2576 (char_u *)NULL, PV_NONE,
2577 {(char_u *)0L, (char_u *)0L}
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"titlestring", NULL, P_STRING|P_VI_DEF,
2581#ifdef FEAT_TITLE
2582 (char_u *)&p_titlestring, PV_NONE,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2588 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2589 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)"icons,tooltips", (char_u *)0L}
2591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002593#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2595 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597#endif
2598 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2599 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2602 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2605 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2608 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2611#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2612 (char_u *)&p_ttym, PV_NONE,
2613#else
2614 (char_u *)NULL, PV_NONE,
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2618 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2621 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002623 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2624#ifdef FEAT_PERSISTENT_UNDO
2625 (char_u *)&p_udir, PV_NONE,
2626 {(char_u *)".", (char_u *)0L}
2627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}
2630#endif
2631 SCRIPTID_INIT},
2632 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2633#ifdef FEAT_PERSISTENT_UNDO
2634 (char_u *)&p_udf, PV_UDF,
2635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
2638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"undolevels", "ul", P_NUM|P_VI_DEF,
2640 (char_u *)&p_ul, PV_NONE,
2641 {
2642#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2643 (char_u *)1000L,
2644#else
2645 (char_u *)100L,
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"updatecount", "uc", P_NUM|P_VI_DEF,
2649 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"updatetime", "ut", P_NUM|P_VI_DEF,
2652 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"verbose", "vbs", P_NUM|P_VI_DEF,
2655 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002657 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2658 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2661#ifdef FEAT_SESSION
2662 (char_u *)&p_vdir, PV_NONE,
2663 {(char_u *)DFLT_VDIR, (char_u *)0L}
2664#else
2665 (char_u *)NULL, PV_NONE,
2666 {(char_u *)0L, (char_u *)0L}
2667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2670#ifdef FEAT_SESSION
2671 (char_u *)&p_vop, PV_NONE,
2672 {(char_u *)"folds,options,cursor", (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2679#ifdef FEAT_VIMINFO
2680 (char_u *)&p_viminfo, PV_NONE,
2681#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002682 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#else
2684# ifdef AMIGA
2685 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002686 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002688 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689# endif
2690#endif
2691#else
2692 (char_u *)NULL, PV_NONE,
2693 {(char_u *)0L, (char_u *)0L}
2694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2697#ifdef FEAT_VIRTUALEDIT
2698 (char_u *)&p_ve, PV_NONE,
2699 {(char_u *)"", (char_u *)""}
2700#else
2701 (char_u *)NULL, PV_NONE,
2702 {(char_u *)0L, (char_u *)0L}
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2706 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"w300", NULL, P_NUM|P_VI_DEF,
2709 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"w1200", NULL, P_NUM|P_VI_DEF,
2712 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"w9600", NULL, P_NUM|P_VI_DEF,
2715 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"warn", NULL, P_BOOL|P_VI_DEF,
2718 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2721 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2724 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"wildchar", "wc", P_NUM|P_VIM,
2727 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2731 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2734#ifdef FEAT_WILDIGN
2735 (char_u *)&p_wig, PV_NONE,
2736#else
2737 (char_u *)NULL, PV_NONE,
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2741#ifdef FEAT_WILDMENU
2742 (char_u *)&p_wmnu, PV_NONE,
2743#else
2744 (char_u *)NULL, PV_NONE,
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2748 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002750 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2751#ifdef FEAT_CMDL_COMPL
2752 (char_u *)&p_wop, PV_NONE,
2753 {(char_u *)"", (char_u *)0L}
2754#else
2755 (char_u *)NULL, PV_NONE,
2756 {(char_u *)NULL, (char_u *)0L}
2757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2760#ifdef FEAT_WAK
2761 (char_u *)&p_wak, PV_NONE,
2762 {(char_u *)"menu", (char_u *)0L}
2763#else
2764 (char_u *)NULL, PV_NONE,
2765 {(char_u *)NULL, (char_u *)0L}
2766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002769 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"winheight", "wh", P_NUM|P_VI_DEF,
2772#ifdef FEAT_WINDOWS
2773 (char_u *)&p_wh, PV_NONE,
2774#else
2775 (char_u *)NULL, PV_NONE,
2776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002779#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 (char_u *)VAR_WIN, PV_WFH,
2781#else
2782 (char_u *)NULL, PV_NONE,
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002785 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2786#ifdef FEAT_VERTSPLIT
2787 (char_u *)VAR_WIN, PV_WFW,
2788#else
2789 (char_u *)NULL, PV_NONE,
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2793#ifdef FEAT_WINDOWS
2794 (char_u *)&p_wmh, PV_NONE,
2795#else
2796 (char_u *)NULL, PV_NONE,
2797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2800#ifdef FEAT_VERTSPLIT
2801 (char_u *)&p_wmw, PV_NONE,
2802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2807#ifdef FEAT_VERTSPLIT
2808 (char_u *)&p_wiw, PV_NONE,
2809#else
2810 (char_u *)NULL, PV_NONE,
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2814 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2817 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2820 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"write", NULL, P_BOOL|P_VI_DEF,
2823 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"writeany", "wa", P_BOOL|P_VI_DEF,
2826 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2829 (char_u *)&p_wb, PV_NONE,
2830 {
2831#ifdef FEAT_WRITEBACKUP
2832 (char_u *)TRUE,
2833#else
2834 (char_u *)FALSE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"writedelay", "wd", P_NUM|P_VI_DEF,
2838 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840
2841/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002842#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845
2846 p_term("t_AB", T_CAB)
2847 p_term("t_AF", T_CAF)
2848 p_term("t_AL", T_CAL)
2849 p_term("t_al", T_AL)
2850 p_term("t_bc", T_BC)
2851 p_term("t_cd", T_CD)
2852 p_term("t_ce", T_CE)
2853 p_term("t_cl", T_CL)
2854 p_term("t_cm", T_CM)
2855 p_term("t_Co", T_CCO)
2856 p_term("t_CS", T_CCS)
2857 p_term("t_cs", T_CS)
2858#ifdef FEAT_VERTSPLIT
2859 p_term("t_CV", T_CSV)
2860#endif
2861 p_term("t_ut", T_UT)
2862 p_term("t_da", T_DA)
2863 p_term("t_db", T_DB)
2864 p_term("t_DL", T_CDL)
2865 p_term("t_dl", T_DL)
2866 p_term("t_fs", T_FS)
2867 p_term("t_IE", T_CIE)
2868 p_term("t_IS", T_CIS)
2869 p_term("t_ke", T_KE)
2870 p_term("t_ks", T_KS)
2871 p_term("t_le", T_LE)
2872 p_term("t_mb", T_MB)
2873 p_term("t_md", T_MD)
2874 p_term("t_me", T_ME)
2875 p_term("t_mr", T_MR)
2876 p_term("t_ms", T_MS)
2877 p_term("t_nd", T_ND)
2878 p_term("t_op", T_OP)
2879 p_term("t_RI", T_CRI)
2880 p_term("t_RV", T_CRV)
2881 p_term("t_Sb", T_CSB)
2882 p_term("t_Sf", T_CSF)
2883 p_term("t_se", T_SE)
2884 p_term("t_so", T_SO)
2885 p_term("t_sr", T_SR)
2886 p_term("t_ts", T_TS)
2887 p_term("t_te", T_TE)
2888 p_term("t_ti", T_TI)
2889 p_term("t_ue", T_UE)
2890 p_term("t_us", T_US)
2891 p_term("t_vb", T_VB)
2892 p_term("t_ve", T_VE)
2893 p_term("t_vi", T_VI)
2894 p_term("t_vs", T_VS)
2895 p_term("t_WP", T_CWP)
2896 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002897 p_term("t_SI", T_CSI)
2898 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 p_term("t_xs", T_XS)
2900 p_term("t_ZH", T_CZH)
2901 p_term("t_ZR", T_CZR)
2902
2903/* terminal key codes are not in here */
2904
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 /* end marker */
2906 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907};
2908
2909#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2910
2911#ifdef FEAT_MBYTE
2912static char *(p_ambw_values[]) = {"single", "double", NULL};
2913#endif
2914static char *(p_bg_values[]) = {"light", "dark", NULL};
2915static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2916static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002917#ifdef FEAT_CRYPT
2918static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2919#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002920#ifdef FEAT_CMDL_COMPL
2921static char *(p_wop_values[]) = {"tagfile", NULL};
2922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923#ifdef FEAT_WAK
2924static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2925#endif
2926static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2927#ifdef FEAT_VISUAL
2928static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2929static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2930#endif
2931#ifdef FEAT_VISUAL
2932static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2933#endif
2934#ifdef FEAT_BROWSE
2935static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2936#endif
2937#ifdef FEAT_SCROLLBIND
2938static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2939#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002940static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#ifdef FEAT_VERTSPLIT
2942static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2943#endif
2944#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002945# ifdef FEAT_AUTOCMD
2946static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2947# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002949# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2951#endif
2952static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2953#ifdef FEAT_FOLDING
2954static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002955# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002957# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 NULL};
2959static char *(p_fcl_values[]) = {"all", NULL};
2960#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002961#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002962static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964
2965static void set_option_default __ARGS((int, int opt_flags, int compatible));
2966static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002967static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002968static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969static char_u *illegal_char __ARGS((char_u *, int));
2970static int string_to_key __ARGS((char_u *arg));
2971#ifdef FEAT_CMDWIN
2972static char_u *check_cedit __ARGS((void));
2973#endif
2974#ifdef FEAT_TITLE
2975static void did_set_title __ARGS((int icon));
2976#endif
2977static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2978static void didset_options __ARGS((void));
2979static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002980#if defined(FEAT_EVAL) || defined(PROTO)
2981static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2982#else
2983# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2984#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2986static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2987static 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));
2988static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02002989#ifdef FEAT_SYN_HL
2990static int int_cmp __ARGS((const void *a, const void *b));
2991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992#ifdef FEAT_CLIPBOARD
2993static char_u *check_clipboard_option __ARGS((void));
2994#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002995#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02002996static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002997#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002998#ifdef FEAT_EVAL
2999static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003002static 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 +00003003static void check_redraw __ARGS((long_u flags));
3004static int findoption __ARGS((char_u *));
3005static int find_key_option __ARGS((char_u *));
3006static void showoptions __ARGS((int all, int opt_flags));
3007static int optval_default __ARGS((struct vimoption *, char_u *varp));
3008static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3009static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3010static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3011static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3012static int istermoption __ARGS((struct vimoption *));
3013static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3014static char_u *get_varp __ARGS((struct vimoption *));
3015static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3016static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3017#ifdef FEAT_LANGMAP
3018static void langmap_init __ARGS((void));
3019static void langmap_set __ARGS((void));
3020#endif
3021static void paste_option_changed __ARGS((void));
3022static void compatible_set __ARGS((void));
3023#ifdef FEAT_LINEBREAK
3024static void fill_breakat_flags __ARGS((void));
3025#endif
3026static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3027static int check_opt_strings __ARGS((char_u *val, char **values, int));
3028static int check_opt_wim __ARGS((void));
3029
3030/*
3031 * Initialize the options, first part.
3032 *
3033 * Called only once from main(), just after creating the first buffer.
3034 */
3035 void
3036set_init_1()
3037{
3038 char_u *p;
3039 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003040 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041
3042#ifdef FEAT_LANGMAP
3043 langmap_init();
3044#endif
3045
3046 /* Be Vi compatible by default */
3047 p_cp = TRUE;
3048
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003049 /* Use POSIX compatibility when $VIM_POSIX is set. */
3050 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003051 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003052 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003053 set_string_default("shm", (char_u *)"A");
3054 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003055
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 /*
3057 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003058 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003060 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3062# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003063 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003065 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003067 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068# endif
3069#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003070 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 set_string_default("sh", p);
3072
3073#ifdef FEAT_WILDIGN
3074 /*
3075 * Set the default for 'backupskip' to include environment variables for
3076 * temp files.
3077 */
3078 {
3079# ifdef UNIX
3080 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3081# else
3082 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3083# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003084 int len;
3085 garray_T ga;
3086 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087
3088 ga_init2(&ga, 1, 100);
3089 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3090 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003091 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092# ifdef UNIX
3093 if (*names[n] == NUL)
3094 p = (char_u *)"/tmp";
3095 else
3096# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003097 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 if (p != NULL && *p != NUL)
3099 {
3100 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003101 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 if (ga_grow(&ga, len) == OK)
3103 {
3104 if (ga.ga_len > 0)
3105 STRCAT(ga.ga_data, ",");
3106 STRCAT(ga.ga_data, p);
3107 add_pathsep(ga.ga_data);
3108 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 ga.ga_len += len;
3110 }
3111 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003112 if (mustfree)
3113 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 }
3115 if (ga.ga_data != NULL)
3116 {
3117 set_string_default("bsk", ga.ga_data);
3118 vim_free(ga.ga_data);
3119 }
3120 }
3121#endif
3122
3123 /*
3124 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3125 */
3126 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003127 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003129#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3130 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3131#endif
3132 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003134 /* Use amount of memory available at this moment. */
3135 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136#else
3137# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003138 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003139 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003141 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142# endif
3143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003145 opt_idx = findoption((char_u *)"maxmem");
3146 if (opt_idx >= 0)
3147 {
3148#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3149 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3150 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3151#endif
3152 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3153 }
3154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 }
3156
3157#ifdef FEAT_GUI_W32
3158 /* force 'shortname' for Win32s */
3159 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003160 {
3161 opt_idx = findoption((char_u *)"shortname");
3162 if (opt_idx >= 0)
3163 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165#endif
3166
3167#ifdef FEAT_SEARCHPATH
3168 {
3169 char_u *cdpath;
3170 char_u *buf;
3171 int i;
3172 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003173 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174
3175 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003176 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 if (cdpath != NULL)
3178 {
3179 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3180 if (buf != NULL)
3181 {
3182 buf[0] = ','; /* start with ",", current dir first */
3183 j = 1;
3184 for (i = 0; cdpath[i] != NUL; ++i)
3185 {
3186 if (vim_ispathlistsep(cdpath[i]))
3187 buf[j++] = ',';
3188 else
3189 {
3190 if (cdpath[i] == ' ' || cdpath[i] == ',')
3191 buf[j++] = '\\';
3192 buf[j++] = cdpath[i];
3193 }
3194 }
3195 buf[j] = NUL;
3196 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003197 if (opt_idx >= 0)
3198 {
3199 options[opt_idx].def_val[VI_DEFAULT] = buf;
3200 options[opt_idx].flags |= P_DEF_ALLOCED;
3201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003203 if (mustfree)
3204 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 }
3206 }
3207#endif
3208
3209#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3210 /* Set print encoding on platforms that don't default to latin1 */
3211 set_string_default("penc",
3212# if defined(MSWIN) || defined(OS2)
3213 (char_u *)"cp1252"
3214# else
3215# ifdef VMS
3216 (char_u *)"dec-mcs"
3217# else
3218# ifdef EBCDIC
3219 (char_u *)"ebcdic-uk"
3220# else
3221# ifdef MAC
3222 (char_u *)"mac-roman"
3223# else /* HPUX */
3224 (char_u *)"hp-roman8"
3225# endif
3226# endif
3227# endif
3228# endif
3229 );
3230#endif
3231
3232#ifdef FEAT_POSTSCRIPT
3233 /* 'printexpr' must be allocated to be able to evaluate it. */
3234 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003235# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3236 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237# else
3238# ifdef VMS
3239 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3240
3241# else
3242 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3243# endif
3244# endif
3245 );
3246#endif
3247
3248 /*
3249 * Set all the options (except the terminal options) to their default
3250 * value. Also set the global value for local options.
3251 */
3252 set_options_default(0);
3253
3254#ifdef FEAT_GUI
3255 if (found_reverse_arg)
3256 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3257#endif
3258
3259 curbuf->b_p_initialized = TRUE;
3260 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3261 check_buf_options(curbuf);
3262 check_win_options(curwin);
3263 check_options();
3264
3265 /* Must be before option_expand(), because that one needs vim_isIDc() */
3266 didset_options();
3267
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003269 /* Use the current chartab for the generic chartab. */
3270 init_spell_chartab();
3271#endif
3272
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#ifdef FEAT_LINEBREAK
3274 /*
3275 * initialize the table for 'breakat'.
3276 */
3277 fill_breakat_flags();
3278#endif
3279
3280 /*
3281 * Expand environment variables and things like "~" for the defaults.
3282 * If option_expand() returns non-NULL the variable is expanded. This can
3283 * only happen for non-indirect options.
3284 * Also set the default to the expanded value, so ":set" does not list
3285 * them.
3286 * Don't set the P_ALLOCED flag, because we don't want to free the
3287 * default.
3288 */
3289 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3290 {
3291 if ((options[opt_idx].flags & P_GETTEXT)
3292 && options[opt_idx].var != NULL)
3293 p = (char_u *)_(*(char **)options[opt_idx].var);
3294 else
3295 p = option_expand(opt_idx, NULL);
3296 if (p != NULL && (p = vim_strsave(p)) != NULL)
3297 {
3298 *(char_u **)options[opt_idx].var = p;
3299 /* VIMEXP
3300 * Defaults for all expanded options are currently the same for Vi
3301 * and Vim. When this changes, add some code here! Also need to
3302 * split P_DEF_ALLOCED in two.
3303 */
3304 if (options[opt_idx].flags & P_DEF_ALLOCED)
3305 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3306 options[opt_idx].def_val[VI_DEFAULT] = p;
3307 options[opt_idx].flags |= P_DEF_ALLOCED;
3308 }
3309 }
3310
3311 /* Initialize the highlight_attr[] table. */
3312 highlight_changed();
3313
3314 save_file_ff(curbuf); /* Buffer is unchanged */
3315
3316 /* Parse default for 'wildmode' */
3317 check_opt_wim();
3318
3319#if defined(FEAT_ARABIC)
3320 /* Detect use of mlterm.
3321 * Mlterm is a terminal emulator akin to xterm that has some special
3322 * abilities (bidi namely).
3323 * NOTE: mlterm's author is being asked to 'set' a variable
3324 * instead of an environment variable due to inheritance.
3325 */
3326 if (mch_getenv((char_u *)"MLTERM") != NULL)
3327 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3328#endif
3329
3330#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3331 /* Parse default for 'fillchars'. */
3332 (void)set_chars_option(&p_fcs);
3333#endif
3334
3335#ifdef FEAT_CLIPBOARD
3336 /* Parse default for 'clipboard' */
3337 (void)check_clipboard_option();
3338#endif
3339
3340#ifdef FEAT_MBYTE
3341# if defined(WIN3264) && defined(FEAT_GETTEXT)
3342 /*
3343 * If $LANG isn't set, try to get a good value for it. This makes the
3344 * right language be used automatically. Don't do this for English.
3345 */
3346 if (mch_getenv((char_u *)"LANG") == NULL)
3347 {
3348 char buf[20];
3349
3350 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3351 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3352 * only the first two. */
3353 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3354 (LPTSTR)buf, 20);
3355 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3356 {
3357 /* There are a few exceptions (probably more) */
3358 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3359 STRCPY(buf, "zh_TW");
3360 else if (STRNICMP(buf, "chs", 3) == 0
3361 || STRNICMP(buf, "zhc", 3) == 0)
3362 STRCPY(buf, "zh_CN");
3363 else if (STRNICMP(buf, "jp", 2) == 0)
3364 STRCPY(buf, "ja");
3365 else
3366 buf[2] = NUL; /* truncate to two-letter code */
3367 vim_setenv("LANG", buf);
3368 }
3369 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003370# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003371# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003372 /* Moved to os_mac_conv.c to avoid dependency problems. */
3373 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375# endif
3376
3377 /* enc_locale() will try to find the encoding of the current locale. */
3378 p = enc_locale();
3379 if (p != NULL)
3380 {
3381 char_u *save_enc;
3382
3383 /* Try setting 'encoding' and check if the value is valid.
3384 * If not, go back to the default "latin1". */
3385 save_enc = p_enc;
3386 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003387 if (STRCMP(p_enc, "gb18030") == 0)
3388 {
3389 /* We don't support "gb18030", but "cp936" is a good substitute
3390 * for practical purposes, thus use that. It's not an alias to
3391 * still support conversion between gb18030 and utf-8. */
3392 p_enc = vim_strsave((char_u *)"cp936");
3393 vim_free(p);
3394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 if (mb_init() == NULL)
3396 {
3397 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398 if (opt_idx >= 0)
3399 {
3400 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3401 options[opt_idx].flags |= P_DEF_ALLOCED;
3402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003404#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3405 || defined(VMS)
3406 if (STRCMP(p_enc, "latin1") == 0
3407# ifdef FEAT_MBYTE
3408 || enc_utf8
3409# endif
3410 )
3411 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003412 /* Adjust the default for 'isprint' and 'iskeyword' to match
3413 * latin1. Also set the defaults for when 'nocompatible' is
3414 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003415 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003416 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003417 set_string_option_direct((char_u *)"isk", -1,
3418 ISK_LATIN1, OPT_FREE, SID_NONE);
3419 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 if (opt_idx >= 0)
3421 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003422 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003423 if (opt_idx >= 0)
3424 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003425 (void)init_chartab();
3426 }
3427#endif
3428
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429# if defined(WIN3264) && !defined(FEAT_GUI)
3430 /* Win32 console: When GetACP() returns a different value from
3431 * GetConsoleCP() set 'termencoding'. */
3432 if (GetACP() != GetConsoleCP())
3433 {
3434 char buf[50];
3435
3436 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3437 p_tenc = vim_strsave((char_u *)buf);
3438 if (p_tenc != NULL)
3439 {
3440 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003441 if (opt_idx >= 0)
3442 {
3443 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3444 options[opt_idx].flags |= P_DEF_ALLOCED;
3445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446 convert_setup(&input_conv, p_tenc, p_enc);
3447 convert_setup(&output_conv, p_enc, p_tenc);
3448 }
3449 else
3450 p_tenc = empty_option;
3451 }
3452# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003453# if defined(WIN3264) && defined(FEAT_MBYTE)
3454 /* $HOME may have characters in active code page. */
3455 init_homedir();
3456# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457 }
3458 else
3459 {
3460 vim_free(p_enc);
3461 p_enc = save_enc;
3462 }
3463 }
3464#endif
3465
3466#ifdef FEAT_MULTI_LANG
3467 /* Set the default for 'helplang'. */
3468 set_helplang_default(get_mess_lang());
3469#endif
3470}
3471
3472/*
3473 * Set an option to its default value.
3474 * This does not take care of side effects!
3475 */
3476 static void
3477set_option_default(opt_idx, opt_flags, compatible)
3478 int opt_idx;
3479 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3480 int compatible; /* use Vi default value */
3481{
3482 char_u *varp; /* pointer to variable for current option */
3483 int dvi; /* index in def_val[] */
3484 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003485 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3487
3488 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3489 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003490 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 {
3492 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3493 if (flags & P_STRING)
3494 {
3495 /* Use set_string_option_direct() for local options to handle
3496 * freeing and allocating the value. */
3497 if (options[opt_idx].indir != PV_NONE)
3498 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003499 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 else
3501 {
3502 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3503 free_string_option(*(char_u **)(varp));
3504 *(char_u **)varp = options[opt_idx].def_val[dvi];
3505 options[opt_idx].flags &= ~P_ALLOCED;
3506 }
3507 }
3508 else if (flags & P_NUM)
3509 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003510 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 win_comp_scroll(curwin);
3512 else
3513 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003514 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515 /* May also set global value for local option. */
3516 if (both)
3517 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3518 *(long *)varp;
3519 }
3520 }
3521 else /* P_BOOL */
3522 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003523 /* the cast to long is required for Manx C, long_i is needed for
3524 * MSVC */
3525 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003526#ifdef UNIX
3527 /* 'modeline' defaults to off for root */
3528 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3529 *(int *)varp = FALSE;
3530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531 /* May also set global value for local option. */
3532 if (both)
3533 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3534 *(int *)varp;
3535 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003536
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003537 /* The default value is not insecure. */
3538 flagsp = insecure_flag(opt_idx, opt_flags);
3539 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 }
3541
3542#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003543 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544#endif
3545}
3546
3547/*
3548 * Set all options (except terminal options) to their default value.
3549 */
3550 static void
3551set_options_default(opt_flags)
3552 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3553{
3554 int i;
3555#ifdef FEAT_WINDOWS
3556 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003557 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558#endif
3559
3560 for (i = 0; !istermoption(&options[i]); i++)
3561 if (!(options[i].flags & P_NODEFAULT))
3562 set_option_default(i, opt_flags, p_cp);
3563
3564#ifdef FEAT_WINDOWS
3565 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003566 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003567 win_comp_scroll(wp);
3568#else
3569 win_comp_scroll(curwin);
3570#endif
3571}
3572
3573/*
3574 * Set the Vi-default value of a string option.
3575 * Used for 'sh', 'backupskip' and 'term'.
3576 */
3577 void
3578set_string_default(name, val)
3579 char *name;
3580 char_u *val;
3581{
3582 char_u *p;
3583 int opt_idx;
3584
3585 p = vim_strsave(val);
3586 if (p != NULL) /* we don't want a NULL */
3587 {
3588 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003589 if (opt_idx >= 0)
3590 {
3591 if (options[opt_idx].flags & P_DEF_ALLOCED)
3592 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3593 options[opt_idx].def_val[VI_DEFAULT] = p;
3594 options[opt_idx].flags |= P_DEF_ALLOCED;
3595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 }
3597}
3598
3599/*
3600 * Set the Vi-default value of a number option.
3601 * Used for 'lines' and 'columns'.
3602 */
3603 void
3604set_number_default(name, val)
3605 char *name;
3606 long val;
3607{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003608 int opt_idx;
3609
3610 opt_idx = findoption((char_u *)name);
3611 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003612 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613}
3614
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003615#if defined(EXITFREE) || defined(PROTO)
3616/*
3617 * Free all options.
3618 */
3619 void
3620free_all_options()
3621{
3622 int i;
3623
3624 for (i = 0; !istermoption(&options[i]); i++)
3625 {
3626 if (options[i].indir == PV_NONE)
3627 {
3628 /* global option: free value and default value. */
3629 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3630 free_string_option(*(char_u **)options[i].var);
3631 if (options[i].flags & P_DEF_ALLOCED)
3632 free_string_option(options[i].def_val[VI_DEFAULT]);
3633 }
3634 else if (options[i].var != VAR_WIN
3635 && (options[i].flags & P_STRING))
3636 /* buffer-local option: free global value */
3637 free_string_option(*(char_u **)options[i].var);
3638 }
3639}
3640#endif
3641
3642
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643/*
3644 * Initialize the options, part two: After getting Rows and Columns and
3645 * setting 'term'.
3646 */
3647 void
3648set_init_2()
3649{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003650 int idx;
3651
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 /*
3653 * 'scroll' defaults to half the window height. Note that this default is
3654 * wrong when the window height changes.
3655 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003656 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003657 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003658 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003659 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660 comp_col();
3661
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003662 /*
3663 * 'window' is only for backwards compatibility with Vi.
3664 * Default is Rows - 1.
3665 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003666 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003667 p_window = Rows - 1;
3668 set_number_default("window", Rows - 1);
3669
Bram Moolenaarf740b292006-02-16 22:11:02 +00003670 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003672 /*
3673 * If 'background' wasn't set by the user, try guessing the value,
3674 * depending on the terminal name. Only need to check for terminals
3675 * with a dark background, that can handle color.
3676 */
3677 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3679 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003681 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003682 /* don't mark it as set, when starting the GUI it may be
3683 * changed again */
3684 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 }
3686#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003687
3688#ifdef CURSOR_SHAPE
3689 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3690#endif
3691#ifdef FEAT_MOUSESHAPE
3692 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3693#endif
3694#ifdef FEAT_PRINTER
3695 (void)parse_printoptions(); /* parse 'printoptions' default value */
3696#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697}
3698
3699/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003700 * Return "dark" or "light" depending on the kind of terminal.
3701 * This is just guessing! Recognized are:
3702 * "linux" Linux console
3703 * "screen.linux" Linux console with screen
3704 * "cygwin" Cygwin shell
3705 * "putty" Putty program
3706 * We also check the COLORFGBG environment variable, which is set by
3707 * rxvt and derivatives. This variable contains either two or three
3708 * values separated by semicolons; we want the last value in either
3709 * case. If this value is 0-6 or 8, our background is dark.
3710 */
3711 static char_u *
3712term_bg_default()
3713{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003714#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3715 /* DOS console nearly always black */
3716 return (char_u *)"dark";
3717#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003718 char_u *p;
3719
Bram Moolenaarf740b292006-02-16 22:11:02 +00003720 if (STRCMP(T_NAME, "linux") == 0
3721 || STRCMP(T_NAME, "screen.linux") == 0
3722 || STRCMP(T_NAME, "cygwin") == 0
3723 || STRCMP(T_NAME, "putty") == 0
3724 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3725 && (p = vim_strrchr(p, ';')) != NULL
3726 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3727 && p[2] == NUL))
3728 return (char_u *)"dark";
3729 return (char_u *)"light";
3730#endif
3731}
3732
3733/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 * Initialize the options, part three: After reading the .vimrc
3735 */
3736 void
3737set_init_3()
3738{
3739#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3740/*
3741 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3742 * This is done after other initializations, where 'shell' might have been
3743 * set, but only if they have not been set before.
3744 */
3745 char_u *p;
3746 int idx_srr;
3747 int do_srr;
3748#ifdef FEAT_QUICKFIX
3749 int idx_sp;
3750 int do_sp;
3751#endif
3752
3753 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003754 if (idx_srr < 0)
3755 do_srr = FALSE;
3756 else
3757 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758#ifdef FEAT_QUICKFIX
3759 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003760 if (idx_sp < 0)
3761 do_sp = FALSE;
3762 else
3763 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764#endif
3765
3766 /*
3767 * Isolate the name of the shell:
3768 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3769 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003770 * But don't allow a space in the path, so that this works:
3771 * "/usr/bin/csh --rcfile ~/.cshrc"
3772 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003774#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 p = gettail(p_sh);
3776 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003777#else
3778 p = skiptowhite(p_sh);
3779 if (*p == NUL)
3780 {
3781 /* No white space, use the tail. */
3782 p = vim_strsave(gettail(p_sh));
3783 }
3784 else
3785 {
3786 char_u *p1, *p2;
3787
3788 /* Find the last path separator before the space. */
3789 p1 = p_sh;
3790 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3791 if (vim_ispathsep(*p2))
3792 p1 = p2 + 1;
3793 p = vim_strnsave(p1, (int)(p - p1));
3794 }
3795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 if (p != NULL)
3797 {
3798 /*
3799 * Default for p_sp is "| tee", for p_srr is ">".
3800 * For known shells it is changed here to include stderr.
3801 */
3802 if ( fnamecmp(p, "csh") == 0
3803 || fnamecmp(p, "tcsh") == 0
3804# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3805 || fnamecmp(p, "csh.exe") == 0
3806 || fnamecmp(p, "tcsh.exe") == 0
3807# endif
3808 )
3809 {
3810#if defined(FEAT_QUICKFIX)
3811 if (do_sp)
3812 {
3813# ifdef WIN3264
3814 p_sp = (char_u *)">&";
3815# else
3816 p_sp = (char_u *)"|& tee";
3817# endif
3818 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3819 }
3820#endif
3821 if (do_srr)
3822 {
3823 p_srr = (char_u *)">&";
3824 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3825 }
3826 }
3827 else
3828# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3829 if ( fnamecmp(p, "sh") == 0
3830 || fnamecmp(p, "ksh") == 0
3831 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003832 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 || fnamecmp(p, "bash") == 0
3834# ifdef WIN3264
3835 || fnamecmp(p, "cmd") == 0
3836 || fnamecmp(p, "sh.exe") == 0
3837 || fnamecmp(p, "ksh.exe") == 0
3838 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003839 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 || fnamecmp(p, "bash.exe") == 0
3841 || fnamecmp(p, "cmd.exe") == 0
3842# endif
3843 )
3844# endif
3845 {
3846#if defined(FEAT_QUICKFIX)
3847 if (do_sp)
3848 {
3849# ifdef WIN3264
3850 p_sp = (char_u *)">%s 2>&1";
3851# else
3852 p_sp = (char_u *)"2>&1| tee";
3853# endif
3854 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3855 }
3856#endif
3857 if (do_srr)
3858 {
3859 p_srr = (char_u *)">%s 2>&1";
3860 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3861 }
3862 }
3863 vim_free(p);
3864 }
3865#endif
3866
3867#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3868 /*
3869 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3870 * This is done after other initializations, where 'shell' might have been
3871 * set, but only if they have not been set before. Default for p_shcf is
3872 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3873 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3874 * command.com. And for Win32 we need to set p_sxq instead.
3875 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003876 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 {
3878 int idx3;
3879
3880 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882 {
3883 p_shcf = (char_u *)"-c";
3884 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3885 }
3886
3887# ifndef DJGPP
3888# ifdef WIN3264
3889 /* Somehow Win32 requires the quotes around the redirection too */
3890 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003891 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 {
3893 p_sxq = (char_u *)"\"";
3894 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3895 }
3896# else
3897 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003898 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 {
3900 p_shq = (char_u *)"\"";
3901 options[idx3].def_val[VI_DEFAULT] = p_shq;
3902 }
3903# endif
3904# endif
3905 }
3906#endif
3907
3908#ifdef FEAT_TITLE
3909 set_title_defaults();
3910#endif
3911}
3912
3913#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3914/*
3915 * When 'helplang' is still at its default value, set it to "lang".
3916 * Only the first two characters of "lang" are used.
3917 */
3918 void
3919set_helplang_default(lang)
3920 char_u *lang;
3921{
3922 int idx;
3923
3924 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3925 return;
3926 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003927 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 {
3929 if (options[idx].flags & P_ALLOCED)
3930 free_string_option(p_hlg);
3931 p_hlg = vim_strsave(lang);
3932 if (p_hlg == NULL)
3933 p_hlg = empty_option;
3934 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003935 {
3936 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3937 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3938 {
3939 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3940 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003943 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 options[idx].flags |= P_ALLOCED;
3945 }
3946}
3947#endif
3948
3949#ifdef FEAT_GUI
3950static char_u *gui_bg_default __ARGS((void));
3951
3952 static char_u *
3953gui_bg_default()
3954{
3955 if (gui_get_lightness(gui.back_pixel) < 127)
3956 return (char_u *)"dark";
3957 return (char_u *)"light";
3958}
3959
3960/*
3961 * Option initializations that can only be done after opening the GUI window.
3962 */
3963 void
3964init_gui_options()
3965{
3966 /* Set the 'background' option according to the lightness of the
3967 * background color, unless the user has set it already. */
3968 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3969 {
3970 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3971 highlight_changed();
3972 }
3973}
3974#endif
3975
3976#ifdef FEAT_TITLE
3977/*
3978 * 'title' and 'icon' only default to true if they have not been set or reset
3979 * in .vimrc and we can read the old value.
3980 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3981 * they can be reset. This reduces startup time when using X on a remote
3982 * machine.
3983 */
3984 void
3985set_title_defaults()
3986{
3987 int idx1;
3988 long val;
3989
3990 /*
3991 * If GUI is (going to be) used, we can always set the window title and
3992 * icon name. Saves a bit of time, because the X11 display server does
3993 * not need to be contacted.
3994 */
3995 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003996 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 {
3998#ifdef FEAT_GUI
3999 if (gui.starting || gui.in_use)
4000 val = TRUE;
4001 else
4002#endif
4003 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004004 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 p_title = val;
4006 }
4007 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 {
4010#ifdef FEAT_GUI
4011 if (gui.starting || gui.in_use)
4012 val = TRUE;
4013 else
4014#endif
4015 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004016 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 p_icon = val;
4018 }
4019}
4020#endif
4021
4022/*
4023 * Parse 'arg' for option settings.
4024 *
4025 * 'arg' may be IObuff, but only when no errors can be present and option
4026 * does not need to be expanded with option_expand().
4027 * "opt_flags":
4028 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004029 * OPT_GLOBAL for ":setglobal"
4030 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004032 * OPT_WINONLY to only set window-local options
4033 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 *
4035 * returns FAIL if an error is detected, OK otherwise
4036 */
4037 int
4038do_set(arg, opt_flags)
4039 char_u *arg; /* option string (may be written to!) */
4040 int opt_flags;
4041{
4042 int opt_idx;
4043 char_u *errmsg;
4044 char_u errbuf[80];
4045 char_u *startarg;
4046 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4047 int nextchar; /* next non-white char after option name */
4048 int afterchar; /* character just after option name */
4049 int len;
4050 int i;
4051 long value;
4052 int key;
4053 long_u flags; /* flags for current option */
4054 char_u *varp = NULL; /* pointer to variable for current option */
4055 int did_show = FALSE; /* already showed one value */
4056 int adding; /* "opt+=arg" */
4057 int prepending; /* "opt^=arg" */
4058 int removing; /* "opt-=arg" */
4059 int cp_val = 0;
4060 char_u key_name[2];
4061
4062 if (*arg == NUL)
4063 {
4064 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004065 did_show = TRUE;
4066 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 }
4068
4069 while (*arg != NUL) /* loop to process all options */
4070 {
4071 errmsg = NULL;
4072 startarg = arg; /* remember for error message */
4073
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004074 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4075 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 {
4077 /*
4078 * ":set all" show all options.
4079 * ":set all&" set all options to their default value.
4080 */
4081 arg += 3;
4082 if (*arg == '&')
4083 {
4084 ++arg;
4085 /* Only for :set command set global value of local options. */
4086 set_options_default(OPT_FREE | opt_flags);
4087 }
4088 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004089 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004091 did_show = TRUE;
4092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004094 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 {
4096 showoptions(2, opt_flags);
4097 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004098 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 arg += 7;
4100 }
4101 else
4102 {
4103 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004104 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
4106 prefix = 0;
4107 arg += 2;
4108 }
4109 else if (STRNCMP(arg, "inv", 3) == 0)
4110 {
4111 prefix = 2;
4112 arg += 3;
4113 }
4114
4115 /* find end of name */
4116 key = 0;
4117 if (*arg == '<')
4118 {
4119 nextchar = 0;
4120 opt_idx = -1;
4121 /* look out for <t_>;> */
4122 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4123 len = 5;
4124 else
4125 {
4126 len = 1;
4127 while (arg[len] != NUL && arg[len] != '>')
4128 ++len;
4129 }
4130 if (arg[len] != '>')
4131 {
4132 errmsg = e_invarg;
4133 goto skip;
4134 }
4135 arg[len] = NUL; /* put NUL after name */
4136 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4137 opt_idx = findoption(arg + 1);
4138 arg[len++] = '>'; /* restore '>' */
4139 if (opt_idx == -1)
4140 key = find_key_option(arg + 1);
4141 }
4142 else
4143 {
4144 len = 0;
4145 /*
4146 * The two characters after "t_" may not be alphanumeric.
4147 */
4148 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4149 len = 4;
4150 else
4151 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4152 ++len;
4153 nextchar = arg[len];
4154 arg[len] = NUL; /* put NUL after name */
4155 opt_idx = findoption(arg);
4156 arg[len] = nextchar; /* restore nextchar */
4157 if (opt_idx == -1)
4158 key = find_key_option(arg);
4159 }
4160
4161 /* remember character after option name */
4162 afterchar = arg[len];
4163
4164 /* skip white space, allow ":set ai ?" */
4165 while (vim_iswhite(arg[len]))
4166 ++len;
4167
4168 adding = FALSE;
4169 prepending = FALSE;
4170 removing = FALSE;
4171 if (arg[len] != NUL && arg[len + 1] == '=')
4172 {
4173 if (arg[len] == '+')
4174 {
4175 adding = TRUE; /* "+=" */
4176 ++len;
4177 }
4178 else if (arg[len] == '^')
4179 {
4180 prepending = TRUE; /* "^=" */
4181 ++len;
4182 }
4183 else if (arg[len] == '-')
4184 {
4185 removing = TRUE; /* "-=" */
4186 ++len;
4187 }
4188 }
4189 nextchar = arg[len];
4190
4191 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4192 {
4193 errmsg = (char_u *)N_("E518: Unknown option");
4194 goto skip;
4195 }
4196
4197 if (opt_idx >= 0)
4198 {
4199 if (options[opt_idx].var == NULL) /* hidden option: skip */
4200 {
4201 /* Only give an error message when requesting the value of
4202 * a hidden option, ignore setting it. */
4203 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4204 && (!(options[opt_idx].flags & P_BOOL)
4205 || nextchar == '?'))
4206 errmsg = (char_u *)N_("E519: Option not supported");
4207 goto skip;
4208 }
4209
4210 flags = options[opt_idx].flags;
4211 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4212 }
4213 else
4214 {
4215 flags = P_STRING;
4216 if (key < 0)
4217 {
4218 key_name[0] = KEY2TERMCAP0(key);
4219 key_name[1] = KEY2TERMCAP1(key);
4220 }
4221 else
4222 {
4223 key_name[0] = KS_KEY;
4224 key_name[1] = (key & 0xff);
4225 }
4226 }
4227
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004228 /* Skip all options that are not window-local (used when showing
4229 * an already loaded buffer in a window). */
4230 if ((opt_flags & OPT_WINONLY)
4231 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4232 goto skip;
4233
Bram Moolenaara3227e22006-03-08 21:32:40 +00004234 /* Skip all options that are window-local (used for :vimgrep). */
4235 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4236 && options[opt_idx].var == VAR_WIN)
4237 goto skip;
4238
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004239 /* Disallow changing some options from modelines. */
4240 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004242 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004243 {
4244 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4245 goto skip;
4246 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004247#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004248 /* In diff mode some options are overruled. This avoids that
4249 * 'foldmethod' becomes "marker" instead of "diff" and that
4250 * "wrap" gets set. */
4251 if (curwin->w_p_diff
4252 && (options[opt_idx].indir == PV_FDM
4253 || options[opt_idx].indir == PV_WRAP))
4254 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 }
4257
4258#ifdef HAVE_SANDBOX
4259 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004260 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261 {
4262 errmsg = (char_u *)_(e_sandbox);
4263 goto skip;
4264 }
4265#endif
4266
4267 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4268 {
4269 arg += len;
4270 cp_val = p_cp;
4271 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4272 {
4273 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4274 {
4275 cp_val = FALSE;
4276 arg += 3;
4277 }
4278 else /* "opt&vi": set to Vi default */
4279 {
4280 cp_val = TRUE;
4281 arg += 2;
4282 }
4283 }
4284 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4285 && arg[1] != NUL && !vim_iswhite(arg[1]))
4286 {
4287 errmsg = e_trailing;
4288 goto skip;
4289 }
4290 }
4291
4292 /*
4293 * allow '=' and ':' as MSDOS command.com allows only one
4294 * '=' character per "set" command line. grrr. (jw)
4295 */
4296 if (nextchar == '?'
4297 || (prefix == 1
4298 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4299 && !(flags & P_BOOL)))
4300 {
4301 /*
4302 * print value
4303 */
4304 if (did_show)
4305 msg_putchar('\n'); /* cursor below last one */
4306 else
4307 {
4308 gotocmdline(TRUE); /* cursor at status line */
4309 did_show = TRUE; /* remember that we did a line */
4310 }
4311 if (opt_idx >= 0)
4312 {
4313 showoneopt(&options[opt_idx], opt_flags);
4314#ifdef FEAT_EVAL
4315 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004316 {
4317 /* Mention where the option was last set. */
4318 if (varp == options[opt_idx].var)
4319 last_set_msg(options[opt_idx].scriptID);
4320 else if ((int)options[opt_idx].indir & PV_WIN)
4321 last_set_msg(curwin->w_p_scriptID[
4322 (int)options[opt_idx].indir & PV_MASK]);
4323 else if ((int)options[opt_idx].indir & PV_BUF)
4324 last_set_msg(curbuf->b_p_scriptID[
4325 (int)options[opt_idx].indir & PV_MASK]);
4326 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004327#endif
4328 }
4329 else
4330 {
4331 char_u *p;
4332
4333 p = find_termcode(key_name);
4334 if (p == NULL)
4335 {
4336 errmsg = (char_u *)N_("E518: Unknown option");
4337 goto skip;
4338 }
4339 else
4340 (void)show_one_termcode(key_name, p, TRUE);
4341 }
4342 if (nextchar != '?'
4343 && nextchar != NUL && !vim_iswhite(afterchar))
4344 errmsg = e_trailing;
4345 }
4346 else
4347 {
4348 if (flags & P_BOOL) /* boolean */
4349 {
4350 if (nextchar == '=' || nextchar == ':')
4351 {
4352 errmsg = e_invarg;
4353 goto skip;
4354 }
4355
4356 /*
4357 * ":set opt!": invert
4358 * ":set opt&": reset to default value
4359 * ":set opt<": reset to global value
4360 */
4361 if (nextchar == '!')
4362 value = *(int *)(varp) ^ 1;
4363 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004364 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 ((flags & P_VI_DEF) || cp_val)
4366 ? VI_DEFAULT : VIM_DEFAULT];
4367 else if (nextchar == '<')
4368 {
4369 /* For 'autoread' -1 means to use global value. */
4370 if ((int *)varp == &curbuf->b_p_ar
4371 && opt_flags == OPT_LOCAL)
4372 value = -1;
4373 else
4374 value = *(int *)get_varp_scope(&(options[opt_idx]),
4375 OPT_GLOBAL);
4376 }
4377 else
4378 {
4379 /*
4380 * ":set invopt": invert
4381 * ":set opt" or ":set noopt": set or reset
4382 */
4383 if (nextchar != NUL && !vim_iswhite(afterchar))
4384 {
4385 errmsg = e_trailing;
4386 goto skip;
4387 }
4388 if (prefix == 2) /* inv */
4389 value = *(int *)(varp) ^ 1;
4390 else
4391 value = prefix;
4392 }
4393
4394 errmsg = set_bool_option(opt_idx, varp, (int)value,
4395 opt_flags);
4396 }
4397 else /* numeric or string */
4398 {
4399 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4400 || prefix != 1)
4401 {
4402 errmsg = e_invarg;
4403 goto skip;
4404 }
4405
4406 if (flags & P_NUM) /* numeric */
4407 {
4408 /*
4409 * Different ways to set a number option:
4410 * & set to default value
4411 * < set to global value
4412 * <xx> accept special key codes for 'wildchar'
4413 * c accept any non-digit for 'wildchar'
4414 * [-]0-9 set number
4415 * other error
4416 */
4417 ++arg;
4418 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004419 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 ((flags & P_VI_DEF) || cp_val)
4421 ? VI_DEFAULT : VIM_DEFAULT];
4422 else if (nextchar == '<')
4423 value = *(long *)get_varp_scope(&(options[opt_idx]),
4424 OPT_GLOBAL);
4425 else if (((long *)varp == &p_wc
4426 || (long *)varp == &p_wcm)
4427 && (*arg == '<'
4428 || *arg == '^'
4429 || ((!arg[1] || vim_iswhite(arg[1]))
4430 && !VIM_ISDIGIT(*arg))))
4431 {
4432 value = string_to_key(arg);
4433 if (value == 0 && (long *)varp != &p_wcm)
4434 {
4435 errmsg = e_invarg;
4436 goto skip;
4437 }
4438 }
4439 /* allow negative numbers (for 'undolevels') */
4440 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4441 {
4442 i = 0;
4443 if (*arg == '-')
4444 i = 1;
4445#ifdef HAVE_STRTOL
4446 value = strtol((char *)arg, NULL, 0);
4447 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4448 i += 2;
4449#else
4450 value = atol((char *)arg);
4451#endif
4452 while (VIM_ISDIGIT(arg[i]))
4453 ++i;
4454 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4455 {
4456 errmsg = e_invarg;
4457 goto skip;
4458 }
4459 }
4460 else
4461 {
4462 errmsg = (char_u *)N_("E521: Number required after =");
4463 goto skip;
4464 }
4465
4466 if (adding)
4467 value = *(long *)varp + value;
4468 if (prepending)
4469 value = *(long *)varp * value;
4470 if (removing)
4471 value = *(long *)varp - value;
4472 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004473 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 }
4475 else if (opt_idx >= 0) /* string */
4476 {
4477 char_u *save_arg = NULL;
4478 char_u *s = NULL;
4479 char_u *oldval; /* previous value if *varp */
4480 char_u *newval;
4481 char_u *origval;
4482 unsigned newlen;
4483 int comma;
4484 int bs;
4485 int new_value_alloced; /* new string option
4486 was allocated */
4487
4488 /* When using ":set opt=val" for a global option
4489 * with a local value the local value will be
4490 * reset, use the global value here. */
4491 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004492 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 varp = options[opt_idx].var;
4494
4495 /* The old value is kept until we are sure that the
4496 * new value is valid. */
4497 oldval = *(char_u **)varp;
4498 if (nextchar == '&') /* set to default val */
4499 {
4500 newval = options[opt_idx].def_val[
4501 ((flags & P_VI_DEF) || cp_val)
4502 ? VI_DEFAULT : VIM_DEFAULT];
4503 if ((char_u **)varp == &p_bg)
4504 {
4505 /* guess the value of 'background' */
4506#ifdef FEAT_GUI
4507 if (gui.in_use)
4508 newval = gui_bg_default();
4509 else
4510#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004511 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004512 }
4513
4514 /* expand environment variables and ~ (since the
4515 * default value was already expanded, only
4516 * required when an environment variable was set
4517 * later */
4518 if (newval == NULL)
4519 newval = empty_option;
4520 else
4521 {
4522 s = option_expand(opt_idx, newval);
4523 if (s == NULL)
4524 s = newval;
4525 newval = vim_strsave(s);
4526 }
4527 new_value_alloced = TRUE;
4528 }
4529 else if (nextchar == '<') /* set to global val */
4530 {
4531 newval = vim_strsave(*(char_u **)get_varp_scope(
4532 &(options[opt_idx]), OPT_GLOBAL));
4533 new_value_alloced = TRUE;
4534 }
4535 else
4536 {
4537 ++arg; /* jump to after the '=' or ':' */
4538
4539 /*
4540 * Set 'keywordprg' to ":help" if an empty
4541 * value was passed to :set by the user.
4542 * Misuse errbuf[] for the resulting string.
4543 */
4544 if (varp == (char_u *)&p_kp
4545 && (*arg == NUL || *arg == ' '))
4546 {
4547 STRCPY(errbuf, ":help");
4548 save_arg = arg;
4549 arg = errbuf;
4550 }
4551 /*
4552 * Convert 'whichwrap' number to string, for
4553 * backwards compatibility with Vim 3.0.
4554 * Misuse errbuf[] for the resulting string.
4555 */
4556 else if (varp == (char_u *)&p_ww
4557 && VIM_ISDIGIT(*arg))
4558 {
4559 *errbuf = NUL;
4560 i = getdigits(&arg);
4561 if (i & 1)
4562 STRCAT(errbuf, "b,");
4563 if (i & 2)
4564 STRCAT(errbuf, "s,");
4565 if (i & 4)
4566 STRCAT(errbuf, "h,l,");
4567 if (i & 8)
4568 STRCAT(errbuf, "<,>,");
4569 if (i & 16)
4570 STRCAT(errbuf, "[,],");
4571 if (*errbuf != NUL) /* remove trailing , */
4572 errbuf[STRLEN(errbuf) - 1] = NUL;
4573 save_arg = arg;
4574 arg = errbuf;
4575 }
4576 /*
4577 * Remove '>' before 'dir' and 'bdir', for
4578 * backwards compatibility with version 3.0
4579 */
4580 else if ( *arg == '>'
4581 && (varp == (char_u *)&p_dir
4582 || varp == (char_u *)&p_bdir))
4583 {
4584 ++arg;
4585 }
4586
4587 /* When setting the local value of a global
4588 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004589 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 && (opt_flags & OPT_LOCAL))
4591 origval = *(char_u **)get_varp(
4592 &options[opt_idx]);
4593 else
4594 origval = oldval;
4595
4596 /*
4597 * Copy the new string into allocated memory.
4598 * Can't use set_string_option_direct(), because
4599 * we need to remove the backslashes.
4600 */
4601 /* get a bit too much */
4602 newlen = (unsigned)STRLEN(arg) + 1;
4603 if (adding || prepending || removing)
4604 newlen += (unsigned)STRLEN(origval) + 1;
4605 newval = alloc(newlen);
4606 if (newval == NULL) /* out of mem, don't change */
4607 break;
4608 s = newval;
4609
4610 /*
4611 * Copy the string, skip over escaped chars.
4612 * For MS-DOS and WIN32 backslashes before normal
4613 * file name characters are not removed, and keep
4614 * backslash at start, for "\\machine\path", but
4615 * do remove it for "\\\\machine\\path".
4616 * The reverse is found in ExpandOldSetting().
4617 */
4618 while (*arg && !vim_iswhite(*arg))
4619 {
4620 if (*arg == '\\' && arg[1] != NUL
4621#ifdef BACKSLASH_IN_FILENAME
4622 && !((flags & P_EXPAND)
4623 && vim_isfilec(arg[1])
4624 && (arg[1] != '\\'
4625 || (s == newval
4626 && arg[2] != '\\')))
4627#endif
4628 )
4629 ++arg; /* remove backslash */
4630#ifdef FEAT_MBYTE
4631 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004632 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 {
4634 /* copy multibyte char */
4635 mch_memmove(s, arg, (size_t)i);
4636 arg += i;
4637 s += i;
4638 }
4639 else
4640#endif
4641 *s++ = *arg++;
4642 }
4643 *s = NUL;
4644
4645 /*
4646 * Expand environment variables and ~.
4647 * Don't do it when adding without inserting a
4648 * comma.
4649 */
4650 if (!(adding || prepending || removing)
4651 || (flags & P_COMMA))
4652 {
4653 s = option_expand(opt_idx, newval);
4654 if (s != NULL)
4655 {
4656 vim_free(newval);
4657 newlen = (unsigned)STRLEN(s) + 1;
4658 if (adding || prepending || removing)
4659 newlen += (unsigned)STRLEN(origval) + 1;
4660 newval = alloc(newlen);
4661 if (newval == NULL)
4662 break;
4663 STRCPY(newval, s);
4664 }
4665 }
4666
4667 /* locate newval[] in origval[] when removing it
4668 * and when adding to avoid duplicates */
4669 i = 0; /* init for GCC */
4670 if (removing || (flags & P_NODUP))
4671 {
4672 i = (int)STRLEN(newval);
4673 bs = 0;
4674 for (s = origval; *s; ++s)
4675 {
4676 if ((!(flags & P_COMMA)
4677 || s == origval
4678 || (s[-1] == ',' && !(bs & 1)))
4679 && STRNCMP(s, newval, i) == 0
4680 && (!(flags & P_COMMA)
4681 || s[i] == ','
4682 || s[i] == NUL))
4683 break;
4684 /* Count backspaces. Only a comma with an
4685 * even number of backspaces before it is
4686 * recognized as a separator */
4687 if (s > origval && s[-1] == '\\')
4688 ++bs;
4689 else
4690 bs = 0;
4691 }
4692
4693 /* do not add if already there */
4694 if ((adding || prepending) && *s)
4695 {
4696 prepending = FALSE;
4697 adding = FALSE;
4698 STRCPY(newval, origval);
4699 }
4700 }
4701
4702 /* concatenate the two strings; add a ',' if
4703 * needed */
4704 if (adding || prepending)
4705 {
4706 comma = ((flags & P_COMMA) && *origval != NUL
4707 && *newval != NUL);
4708 if (adding)
4709 {
4710 i = (int)STRLEN(origval);
4711 mch_memmove(newval + i + comma, newval,
4712 STRLEN(newval) + 1);
4713 mch_memmove(newval, origval, (size_t)i);
4714 }
4715 else
4716 {
4717 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004718 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 }
4720 if (comma)
4721 newval[i] = ',';
4722 }
4723
4724 /* Remove newval[] from origval[]. (Note: "i" has
4725 * been set above and is used here). */
4726 if (removing)
4727 {
4728 STRCPY(newval, origval);
4729 if (*s)
4730 {
4731 /* may need to remove a comma */
4732 if (flags & P_COMMA)
4733 {
4734 if (s == origval)
4735 {
4736 /* include comma after string */
4737 if (s[i] == ',')
4738 ++i;
4739 }
4740 else
4741 {
4742 /* include comma before string */
4743 --s;
4744 ++i;
4745 }
4746 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004747 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 }
4749 }
4750
4751 if (flags & P_FLAGLIST)
4752 {
4753 /* Remove flags that appear twice. */
4754 for (s = newval; *s; ++s)
4755 if ((!(flags & P_COMMA) || *s != ',')
4756 && vim_strchr(s + 1, *s) != NULL)
4757 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004758 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 --s;
4760 }
4761 }
4762
4763 if (save_arg != NULL) /* number for 'whichwrap' */
4764 arg = save_arg;
4765 new_value_alloced = TRUE;
4766 }
4767
4768 /* Set the new value. */
4769 *(char_u **)(varp) = newval;
4770
4771 /* Handle side effects, and set the global value for
4772 * ":set" on local options. */
4773 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4774 new_value_alloced, oldval, errbuf, opt_flags);
4775
4776 /* If error detected, print the error message. */
4777 if (errmsg != NULL)
4778 goto skip;
4779 }
4780 else /* key code option */
4781 {
4782 char_u *p;
4783
4784 if (nextchar == '&')
4785 {
4786 if (add_termcap_entry(key_name, TRUE) == FAIL)
4787 errmsg = (char_u *)N_("E522: Not found in termcap");
4788 }
4789 else
4790 {
4791 ++arg; /* jump to after the '=' or ':' */
4792 for (p = arg; *p && !vim_iswhite(*p); ++p)
4793 if (*p == '\\' && p[1] != NUL)
4794 ++p;
4795 nextchar = *p;
4796 *p = NUL;
4797 add_termcode(key_name, arg, FALSE);
4798 *p = nextchar;
4799 }
4800 if (full_screen)
4801 ttest(FALSE);
4802 redraw_all_later(CLEAR);
4803 }
4804 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004805
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004807 did_set_option(opt_idx, opt_flags,
4808 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004809 }
4810
4811skip:
4812 /*
4813 * Advance to next argument.
4814 * - skip until a blank found, taking care of backslashes
4815 * - skip blanks
4816 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4817 */
4818 for (i = 0; i < 2 ; ++i)
4819 {
4820 while (*arg != NUL && !vim_iswhite(*arg))
4821 if (*arg++ == '\\' && *arg != NUL)
4822 ++arg;
4823 arg = skipwhite(arg);
4824 if (*arg != '=')
4825 break;
4826 }
4827 }
4828
4829 if (errmsg != NULL)
4830 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004831 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004832 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004833 if (i + (arg - startarg) < IOSIZE)
4834 {
4835 /* append the argument with the error */
4836 STRCAT(IObuff, ": ");
4837 mch_memmove(IObuff + i, startarg, (arg - startarg));
4838 IObuff[i + (arg - startarg)] = NUL;
4839 }
4840 /* make sure all characters are printable */
4841 trans_characters(IObuff, IOSIZE);
4842
4843 ++no_wait_return; /* wait_return done later */
4844 emsg(IObuff); /* show error highlighted */
4845 --no_wait_return;
4846
4847 return FAIL;
4848 }
4849
4850 arg = skipwhite(arg);
4851 }
4852
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004853theend:
4854 if (silent_mode && did_show)
4855 {
4856 /* After displaying option values in silent mode. */
4857 silent_mode = FALSE;
4858 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4859 msg_putchar('\n');
4860 cursor_on(); /* msg_start() switches it off */
4861 out_flush();
4862 silent_mode = TRUE;
4863 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4864 }
4865
Bram Moolenaar071d4272004-06-13 20:20:40 +00004866 return OK;
4867}
4868
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004869/*
4870 * Call this when an option has been given a new value through a user command.
4871 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4872 */
4873 static void
4874did_set_option(opt_idx, opt_flags, new_value)
4875 int opt_idx;
4876 int opt_flags; /* possibly with OPT_MODELINE */
4877 int new_value; /* value was replaced completely */
4878{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004879 long_u *p;
4880
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004881 options[opt_idx].flags |= P_WAS_SET;
4882
4883 /* When an option is set in the sandbox, from a modeline or in secure mode
4884 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004885 * flag. */
4886 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004887 if (secure
4888#ifdef HAVE_SANDBOX
4889 || sandbox != 0
4890#endif
4891 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004892 *p = *p | P_INSECURE;
4893 else if (new_value)
4894 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004895}
4896
Bram Moolenaar071d4272004-06-13 20:20:40 +00004897 static char_u *
4898illegal_char(errbuf, c)
4899 char_u *errbuf;
4900 int c;
4901{
4902 if (errbuf == NULL)
4903 return (char_u *)"";
4904 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004905 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004906 return errbuf;
4907}
4908
4909/*
4910 * Convert a key name or string into a key value.
4911 * Used for 'wildchar' and 'cedit' options.
4912 */
4913 static int
4914string_to_key(arg)
4915 char_u *arg;
4916{
4917 if (*arg == '<')
4918 return find_key_option(arg + 1);
4919 if (*arg == '^')
4920 return Ctrl_chr(arg[1]);
4921 return *arg;
4922}
4923
4924#ifdef FEAT_CMDWIN
4925/*
4926 * Check value of 'cedit' and set cedit_key.
4927 * Returns NULL if value is OK, error message otherwise.
4928 */
4929 static char_u *
4930check_cedit()
4931{
4932 int n;
4933
4934 if (*p_cedit == NUL)
4935 cedit_key = -1;
4936 else
4937 {
4938 n = string_to_key(p_cedit);
4939 if (vim_isprintc(n))
4940 return e_invarg;
4941 cedit_key = n;
4942 }
4943 return NULL;
4944}
4945#endif
4946
4947#ifdef FEAT_TITLE
4948/*
4949 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4950 * maketitle() to create and display it.
4951 * When switching the title or icon off, call mch_restore_title() to get
4952 * the old value back.
4953 */
4954 static void
4955did_set_title(icon)
4956 int icon; /* Did set icon instead of title */
4957{
4958 if (starting != NO_SCREEN
4959#ifdef FEAT_GUI
4960 && !gui.starting
4961#endif
4962 )
4963 {
4964 maketitle();
4965 if (icon)
4966 {
4967 if (!p_icon)
4968 mch_restore_title(2);
4969 }
4970 else
4971 {
4972 if (!p_title)
4973 mch_restore_title(1);
4974 }
4975 }
4976}
4977#endif
4978
4979/*
4980 * set_options_bin - called when 'bin' changes value.
4981 */
4982 void
4983set_options_bin(oldval, newval, opt_flags)
4984 int oldval;
4985 int newval;
4986 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4987{
4988 /*
4989 * The option values that are changed when 'bin' changes are
4990 * copied when 'bin is set and restored when 'bin' is reset.
4991 */
4992 if (newval)
4993 {
4994 if (!oldval) /* switched on */
4995 {
4996 if (!(opt_flags & OPT_GLOBAL))
4997 {
4998 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4999 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5000 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5001 curbuf->b_p_et_nobin = curbuf->b_p_et;
5002 }
5003 if (!(opt_flags & OPT_LOCAL))
5004 {
5005 p_tw_nobin = p_tw;
5006 p_wm_nobin = p_wm;
5007 p_ml_nobin = p_ml;
5008 p_et_nobin = p_et;
5009 }
5010 }
5011
5012 if (!(opt_flags & OPT_GLOBAL))
5013 {
5014 curbuf->b_p_tw = 0; /* no automatic line wrap */
5015 curbuf->b_p_wm = 0; /* no automatic line wrap */
5016 curbuf->b_p_ml = 0; /* no modelines */
5017 curbuf->b_p_et = 0; /* no expandtab */
5018 }
5019 if (!(opt_flags & OPT_LOCAL))
5020 {
5021 p_tw = 0;
5022 p_wm = 0;
5023 p_ml = FALSE;
5024 p_et = FALSE;
5025 p_bin = TRUE; /* needed when called for the "-b" argument */
5026 }
5027 }
5028 else if (oldval) /* switched off */
5029 {
5030 if (!(opt_flags & OPT_GLOBAL))
5031 {
5032 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5033 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5034 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5035 curbuf->b_p_et = curbuf->b_p_et_nobin;
5036 }
5037 if (!(opt_flags & OPT_LOCAL))
5038 {
5039 p_tw = p_tw_nobin;
5040 p_wm = p_wm_nobin;
5041 p_ml = p_ml_nobin;
5042 p_et = p_et_nobin;
5043 }
5044 }
5045}
5046
5047#ifdef FEAT_VIMINFO
5048/*
5049 * Find the parameter represented by the given character (eg ', :, ", or /),
5050 * and return its associated value in the 'viminfo' string.
5051 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005052 * If the parameter is not specified in the string or there is no following
5053 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005054 */
5055 int
5056get_viminfo_parameter(type)
5057 int type;
5058{
5059 char_u *p;
5060
5061 p = find_viminfo_parameter(type);
5062 if (p != NULL && VIM_ISDIGIT(*p))
5063 return atoi((char *)p);
5064 return -1;
5065}
5066
5067/*
5068 * Find the parameter represented by the given character (eg ''', ':', '"', or
5069 * '/') in the 'viminfo' option and return a pointer to the string after it.
5070 * Return NULL if the parameter is not specified in the string.
5071 */
5072 char_u *
5073find_viminfo_parameter(type)
5074 int type;
5075{
5076 char_u *p;
5077
5078 for (p = p_viminfo; *p; ++p)
5079 {
5080 if (*p == type)
5081 return p + 1;
5082 if (*p == 'n') /* 'n' is always the last one */
5083 break;
5084 p = vim_strchr(p, ','); /* skip until next ',' */
5085 if (p == NULL) /* hit the end without finding parameter */
5086 break;
5087 }
5088 return NULL;
5089}
5090#endif
5091
5092/*
5093 * Expand environment variables for some string options.
5094 * These string options cannot be indirect!
5095 * If "val" is NULL expand the current value of the option.
5096 * Return pointer to NameBuff, or NULL when not expanded.
5097 */
5098 static char_u *
5099option_expand(opt_idx, val)
5100 int opt_idx;
5101 char_u *val;
5102{
5103 /* if option doesn't need expansion nothing to do */
5104 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5105 return NULL;
5106
5107 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5108 * expand_env() would truncate the string. */
5109 if (val != NULL && STRLEN(val) > MAXPATHL)
5110 return NULL;
5111
5112 if (val == NULL)
5113 val = *(char_u **)options[opt_idx].var;
5114
5115 /*
5116 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5117 * Escape spaces when expanding 'tags', they are used to separate file
5118 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005119 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 */
5121 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005122 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005123#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005124 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5125#endif
5126 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5128 return NULL;
5129
5130 return NameBuff;
5131}
5132
5133/*
5134 * After setting various option values: recompute variables that depend on
5135 * option values.
5136 */
5137 static void
5138didset_options()
5139{
5140 /* initialize the table for 'iskeyword' et.al. */
5141 (void)init_chartab();
5142
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005143#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005144 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5147#ifdef FEAT_SESSION
5148 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5149 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5150#endif
5151#ifdef FEAT_FOLDING
5152 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5153#endif
5154 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5155#ifdef FEAT_VIRTUALEDIT
5156 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5157#endif
5158#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5159 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5160#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005161#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005162 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005163 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005164 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5167 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5168#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005169#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5171#endif
5172#ifdef FEAT_CMDWIN
5173 /* set cedit_key */
5174 (void)check_cedit();
5175#endif
5176}
5177
5178/*
5179 * Check for string options that are NULL (normally only termcap options).
5180 */
5181 void
5182check_options()
5183{
5184 int opt_idx;
5185
5186 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5187 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5188 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5189}
5190
5191/*
5192 * Check string options in a buffer for NULL value.
5193 */
5194 void
5195check_buf_options(buf)
5196 buf_T *buf;
5197{
5198#if defined(FEAT_QUICKFIX)
5199 check_string_option(&buf->b_p_bh);
5200 check_string_option(&buf->b_p_bt);
5201#endif
5202#ifdef FEAT_MBYTE
5203 check_string_option(&buf->b_p_fenc);
5204#endif
5205 check_string_option(&buf->b_p_ff);
5206#ifdef FEAT_FIND_ID
5207 check_string_option(&buf->b_p_def);
5208 check_string_option(&buf->b_p_inc);
5209# ifdef FEAT_EVAL
5210 check_string_option(&buf->b_p_inex);
5211# endif
5212#endif
5213#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5214 check_string_option(&buf->b_p_inde);
5215 check_string_option(&buf->b_p_indk);
5216#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005217#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5218 check_string_option(&buf->b_p_bexpr);
5219#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005220#if defined(FEAT_CRYPT)
5221 check_string_option(&buf->b_p_cm);
5222#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005223#if defined(FEAT_EVAL)
5224 check_string_option(&buf->b_p_fex);
5225#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226#ifdef FEAT_CRYPT
5227 check_string_option(&buf->b_p_key);
5228#endif
5229 check_string_option(&buf->b_p_kp);
5230 check_string_option(&buf->b_p_mps);
5231 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005232 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 check_string_option(&buf->b_p_isk);
5234#ifdef FEAT_COMMENTS
5235 check_string_option(&buf->b_p_com);
5236#endif
5237#ifdef FEAT_FOLDING
5238 check_string_option(&buf->b_p_cms);
5239#endif
5240 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005241#ifdef FEAT_TEXTOBJ
5242 check_string_option(&buf->b_p_qe);
5243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244#ifdef FEAT_SYN_HL
5245 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005246#endif
5247#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005248 check_string_option(&buf->b_s.b_p_spc);
5249 check_string_option(&buf->b_s.b_p_spf);
5250 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251#endif
5252#ifdef FEAT_SEARCHPATH
5253 check_string_option(&buf->b_p_sua);
5254#endif
5255#ifdef FEAT_CINDENT
5256 check_string_option(&buf->b_p_cink);
5257 check_string_option(&buf->b_p_cino);
5258#endif
5259#ifdef FEAT_AUTOCMD
5260 check_string_option(&buf->b_p_ft);
5261#endif
5262#ifdef FEAT_OSFILETYPE
5263 check_string_option(&buf->b_p_oft);
5264#endif
5265#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5266 check_string_option(&buf->b_p_cinw);
5267#endif
5268#ifdef FEAT_INS_EXPAND
5269 check_string_option(&buf->b_p_cpt);
5270#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005271#ifdef FEAT_COMPL_FUNC
5272 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005273 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275#ifdef FEAT_KEYMAP
5276 check_string_option(&buf->b_p_keymap);
5277#endif
5278#ifdef FEAT_QUICKFIX
5279 check_string_option(&buf->b_p_gp);
5280 check_string_option(&buf->b_p_mp);
5281 check_string_option(&buf->b_p_efm);
5282#endif
5283 check_string_option(&buf->b_p_ep);
5284 check_string_option(&buf->b_p_path);
5285 check_string_option(&buf->b_p_tags);
5286#ifdef FEAT_INS_EXPAND
5287 check_string_option(&buf->b_p_dict);
5288 check_string_option(&buf->b_p_tsr);
5289#endif
5290}
5291
5292/*
5293 * Free the string allocated for an option.
5294 * Checks for the string being empty_option. This may happen if we're out of
5295 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5296 * check_options().
5297 * Does NOT check for P_ALLOCED flag!
5298 */
5299 void
5300free_string_option(p)
5301 char_u *p;
5302{
5303 if (p != empty_option)
5304 vim_free(p);
5305}
5306
5307 void
5308clear_string_option(pp)
5309 char_u **pp;
5310{
5311 if (*pp != empty_option)
5312 vim_free(*pp);
5313 *pp = empty_option;
5314}
5315
5316 static void
5317check_string_option(pp)
5318 char_u **pp;
5319{
5320 if (*pp == NULL)
5321 *pp = empty_option;
5322}
5323
5324/*
5325 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5326 */
5327 void
5328set_term_option_alloced(p)
5329 char_u **p;
5330{
5331 int opt_idx;
5332
5333 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5334 if (options[opt_idx].var == (char_u *)p)
5335 {
5336 options[opt_idx].flags |= P_ALLOCED;
5337 return;
5338 }
5339 return; /* cannot happen: didn't find it! */
5340}
5341
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005342#if defined(FEAT_EVAL) || defined(PROTO)
5343/*
5344 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5345 * Return FALSE when it wasn't.
5346 * Return -1 for an unknown option.
5347 */
5348 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005349was_set_insecurely(opt, opt_flags)
5350 char_u *opt;
5351 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005352{
5353 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005354 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005355
5356 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005357 {
5358 flagp = insecure_flag(idx, opt_flags);
5359 return (*flagp & P_INSECURE) != 0;
5360 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005361 EMSG2(_(e_intern2), "was_set_insecurely()");
5362 return -1;
5363}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005364
5365/*
5366 * Get a pointer to the flags used for the P_INSECURE flag of option
5367 * "opt_idx". For some local options a local flags field is used.
5368 */
5369 static long_u *
5370insecure_flag(opt_idx, opt_flags)
5371 int opt_idx;
5372 int opt_flags;
5373{
5374 if (opt_flags & OPT_LOCAL)
5375 switch ((int)options[opt_idx].indir)
5376 {
5377#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005378 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005379#endif
5380#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005381# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005382 case PV_FDE: return &curwin->w_p_fde_flags;
5383 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005384# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005385# ifdef FEAT_BEVAL
5386 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5387# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005388# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005389 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005390# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005391 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005392# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005393 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005394# endif
5395#endif
5396 }
5397
5398 /* Nothing special, return global flags field. */
5399 return &options[opt_idx].flags;
5400}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005401#endif
5402
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005403#ifdef FEAT_TITLE
5404static void redraw_titles __ARGS((void));
5405
5406/*
5407 * Redraw the window title and/or tab page text later.
5408 */
5409static void redraw_titles()
5410{
5411 need_maketitle = TRUE;
5412# ifdef FEAT_WINDOWS
5413 redraw_tabline = TRUE;
5414# endif
5415}
5416#endif
5417
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418/*
5419 * Set a string option to a new value (without checking the effect).
5420 * The string is copied into allocated memory.
5421 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005422 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005423 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424 */
5425 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005426set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427 char_u *name;
5428 int opt_idx;
5429 char_u *val;
5430 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005431 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432{
5433 char_u *s;
5434 char_u **varp;
5435 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005436 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005437
Bram Moolenaar89d40322006-08-29 15:30:07 +00005438 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005440 idx = findoption(name);
5441 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005442 {
5443 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446 }
5447
Bram Moolenaar89d40322006-08-29 15:30:07 +00005448 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449 return;
5450
5451 s = vim_strsave(val);
5452 if (s != NULL)
5453 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005454 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005455 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005456 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457 free_string_option(*varp);
5458 *varp = s;
5459
5460 /* For buffer/window local option may also set the global value. */
5461 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005462 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463
Bram Moolenaar89d40322006-08-29 15:30:07 +00005464 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465
5466 /* When setting both values of a global option with a local value,
5467 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005468 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469 {
5470 free_string_option(*varp);
5471 *varp = empty_option;
5472 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005473# ifdef FEAT_EVAL
5474 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005475 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005476 set_sid == 0 ? current_SID : set_sid);
5477# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 }
5479}
5480
5481/*
5482 * Set global value for string option when it's a local option.
5483 */
5484 static void
5485set_string_option_global(opt_idx, varp)
5486 int opt_idx; /* option index */
5487 char_u **varp; /* pointer to option variable */
5488{
5489 char_u **p, *s;
5490
5491 /* the global value is always allocated */
5492 if (options[opt_idx].var == VAR_WIN)
5493 p = (char_u **)GLOBAL_WO(varp);
5494 else
5495 p = (char_u **)options[opt_idx].var;
5496 if (options[opt_idx].indir != PV_NONE
5497 && p != varp
5498 && (s = vim_strsave(*varp)) != NULL)
5499 {
5500 free_string_option(*p);
5501 *p = s;
5502 }
5503}
5504
5505/*
5506 * Set a string option to a new value, and handle the effects.
5507 */
5508 static void
5509set_string_option(opt_idx, value, opt_flags)
5510 int opt_idx;
5511 char_u *value;
5512 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5513{
5514 char_u *s;
5515 char_u **varp;
5516 char_u *oldval;
5517
5518 if (options[opt_idx].var == NULL) /* don't set hidden option */
5519 return;
5520
5521 s = vim_strsave(value);
5522 if (s != NULL)
5523 {
5524 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5525 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005526 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 ? OPT_GLOBAL : OPT_LOCAL)
5528 : opt_flags);
5529 oldval = *varp;
5530 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005531 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5532 opt_flags) == NULL)
5533 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534 }
5535}
5536
5537/*
5538 * Handle string options that need some action to perform when changed.
5539 * Returns NULL for success, or an error message for an error.
5540 */
5541 static char_u *
5542did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5543 opt_flags)
5544 int opt_idx; /* index in options[] table */
5545 char_u **varp; /* pointer to the option variable */
5546 int new_value_alloced; /* new value was allocated */
5547 char_u *oldval; /* previous value of the option */
5548 char_u *errbuf; /* buffer for errors, or NULL */
5549 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5550{
5551 char_u *errmsg = NULL;
5552 char_u *s, *p;
5553 int did_chartab = FALSE;
5554 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005555 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005556#ifdef FEAT_GUI
5557 /* set when changing an option that only requires a redraw in the GUI */
5558 int redraw_gui_only = FALSE;
5559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560
5561 /* Get the global option to compare with, otherwise we would have to check
5562 * two values for all local options. */
5563 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5564
5565 /* Disallow changing some options from secure mode */
5566 if ((secure
5567#ifdef HAVE_SANDBOX
5568 || sandbox != 0
5569#endif
5570 ) && (options[opt_idx].flags & P_SECURE))
5571 {
5572 errmsg = e_secure;
5573 }
5574
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005575 /* Check for a "normal" file name in some options. Disallow a path
5576 * separator (slash and/or backslash), wildcards and characters that are
5577 * often illegal in a file name. */
5578 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005579 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005580 {
5581 errmsg = e_invarg;
5582 }
5583
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 /* 'term' */
5585 else if (varp == &T_NAME)
5586 {
5587 if (T_NAME[0] == NUL)
5588 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5589#ifdef FEAT_GUI
5590 if (gui.in_use)
5591 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5592 else if (term_is_gui(T_NAME))
5593 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5594#endif
5595 else if (set_termname(T_NAME) == FAIL)
5596 errmsg = (char_u *)N_("E522: Not found in termcap");
5597 else
5598 /* Screen colors may have changed. */
5599 redraw_later_clear();
5600 }
5601
5602 /* 'backupcopy' */
5603 else if (varp == &p_bkc)
5604 {
5605 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5606 errmsg = e_invarg;
5607 if (((bkc_flags & BKC_AUTO) != 0)
5608 + ((bkc_flags & BKC_YES) != 0)
5609 + ((bkc_flags & BKC_NO) != 0) != 1)
5610 {
5611 /* Must have exactly one of "auto", "yes" and "no". */
5612 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5613 errmsg = e_invarg;
5614 }
5615 }
5616
5617 /* 'backupext' and 'patchmode' */
5618 else if (varp == &p_bex || varp == &p_pm)
5619 {
5620 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5621 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5622 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5623 }
5624
5625 /*
5626 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5627 * If the new option is invalid, use old value. 'lisp' option: refill
5628 * chartab[] for '-' char
5629 */
5630 else if ( varp == &p_isi
5631 || varp == &(curbuf->b_p_isk)
5632 || varp == &p_isp
5633 || varp == &p_isf)
5634 {
5635 if (init_chartab() == FAIL)
5636 {
5637 did_chartab = TRUE; /* need to restore it below */
5638 errmsg = e_invarg; /* error in value */
5639 }
5640 }
5641
5642 /* 'helpfile' */
5643 else if (varp == &p_hf)
5644 {
5645 /* May compute new values for $VIM and $VIMRUNTIME */
5646 if (didset_vim)
5647 {
5648 vim_setenv((char_u *)"VIM", (char_u *)"");
5649 didset_vim = FALSE;
5650 }
5651 if (didset_vimruntime)
5652 {
5653 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5654 didset_vimruntime = FALSE;
5655 }
5656 }
5657
Bram Moolenaar1a384422010-07-14 19:53:30 +02005658#ifdef FEAT_SYN_HL
5659 /* 'colorcolumn' */
5660 else if (varp == &curwin->w_p_cc)
5661 errmsg = check_colorcolumn(curwin);
5662#endif
5663
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664#ifdef FEAT_MULTI_LANG
5665 /* 'helplang' */
5666 else if (varp == &p_hlg)
5667 {
5668 /* Check for "", "ab", "ab,cd", etc. */
5669 for (s = p_hlg; *s != NUL; s += 3)
5670 {
5671 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5672 {
5673 errmsg = e_invarg;
5674 break;
5675 }
5676 if (s[2] == NUL)
5677 break;
5678 }
5679 }
5680#endif
5681
5682 /* 'highlight' */
5683 else if (varp == &p_hl)
5684 {
5685 if (highlight_changed() == FAIL)
5686 errmsg = e_invarg; /* invalid flags */
5687 }
5688
5689 /* 'nrformats' */
5690 else if (gvarp == &p_nf)
5691 {
5692 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5693 errmsg = e_invarg;
5694 }
5695
5696#ifdef FEAT_SESSION
5697 /* 'sessionoptions' */
5698 else if (varp == &p_ssop)
5699 {
5700 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5701 errmsg = e_invarg;
5702 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5703 {
5704 /* Don't allow both "sesdir" and "curdir". */
5705 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5706 errmsg = e_invarg;
5707 }
5708 }
5709 /* 'viewoptions' */
5710 else if (varp == &p_vop)
5711 {
5712 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5713 errmsg = e_invarg;
5714 }
5715#endif
5716
5717 /* 'scrollopt' */
5718#ifdef FEAT_SCROLLBIND
5719 else if (varp == &p_sbo)
5720 {
5721 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5722 errmsg = e_invarg;
5723 }
5724#endif
5725
5726 /* 'ambiwidth' */
5727#ifdef FEAT_MBYTE
5728 else if (varp == &p_ambw)
5729 {
5730 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5731 errmsg = e_invarg;
5732 }
5733#endif
5734
5735 /* 'background' */
5736 else if (varp == &p_bg)
5737 {
5738 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5739 {
5740#ifdef FEAT_EVAL
5741 int dark = (*p_bg == 'd');
5742#endif
5743
5744 init_highlight(FALSE, FALSE);
5745
5746#ifdef FEAT_EVAL
5747 if (dark != (*p_bg == 'd')
5748 && get_var_value((char_u *)"g:colors_name") != NULL)
5749 {
5750 /* The color scheme must have set 'background' back to another
5751 * value, that's not what we want here. Disable the color
5752 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005753 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754 free_string_option(p_bg);
5755 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5756 check_string_option(&p_bg);
5757 init_highlight(FALSE, FALSE);
5758 }
5759#endif
5760 }
5761 else
5762 errmsg = e_invarg;
5763 }
5764
5765 /* 'wildmode' */
5766 else if (varp == &p_wim)
5767 {
5768 if (check_opt_wim() == FAIL)
5769 errmsg = e_invarg;
5770 }
5771
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005772#ifdef FEAT_CMDL_COMPL
5773 /* 'wildoptions' */
5774 else if (varp == &p_wop)
5775 {
5776 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5777 errmsg = e_invarg;
5778 }
5779#endif
5780
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781#ifdef FEAT_WAK
5782 /* 'winaltkeys' */
5783 else if (varp == &p_wak)
5784 {
5785 if (*p_wak == NUL
5786 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5787 errmsg = e_invarg;
5788# ifdef FEAT_MENU
5789# ifdef FEAT_GUI_MOTIF
5790 else if (gui.in_use)
5791 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5792# else
5793# ifdef FEAT_GUI_GTK
5794 else if (gui.in_use)
5795 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5796# endif
5797# endif
5798# endif
5799 }
5800#endif
5801
5802#ifdef FEAT_AUTOCMD
5803 /* 'eventignore' */
5804 else if (varp == &p_ei)
5805 {
5806 if (check_ei() == FAIL)
5807 errmsg = e_invarg;
5808 }
5809#endif
5810
5811#ifdef FEAT_MBYTE
5812 /* 'encoding' and 'fileencoding' */
5813 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5814 {
5815 if (gvarp == &p_fenc)
5816 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005817 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818 errmsg = e_modifiable;
5819 else if (vim_strchr(*varp, ',') != NULL)
5820 /* No comma allowed in 'fileencoding'; catches confusing it
5821 * with 'fileencodings'. */
5822 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005824 {
5825# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005827 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005829 /* Add 'fileencoding' to the swap file. */
5830 ml_setflags(curbuf);
5831 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832 }
5833 if (errmsg == NULL)
5834 {
5835 /* canonize the value, so that STRCMP() can be used on it */
5836 p = enc_canonize(*varp);
5837 if (p != NULL)
5838 {
5839 vim_free(*varp);
5840 *varp = p;
5841 }
5842 if (varp == &p_enc)
5843 {
5844 errmsg = mb_init();
5845# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005846 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847# endif
5848 }
5849 }
5850
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005851# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5853 {
5854 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5855 if (STRCMP(p_tenc, "utf-8") != 0)
5856 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5857 }
5858# endif
5859
5860 if (errmsg == NULL)
5861 {
5862# ifdef FEAT_KEYMAP
5863 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5864 * (with another encoding). */
5865 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5866 (void)keymap_init();
5867# endif
5868
5869 /* When 'termencoding' is not empty and 'encoding' changes or when
5870 * 'termencoding' changes, need to setup for keyboard input and
5871 * display output conversion. */
5872 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5873 {
5874 convert_setup(&input_conv, p_tenc, p_enc);
5875 convert_setup(&output_conv, p_enc, p_tenc);
5876 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005877
5878# if defined(WIN3264) && defined(FEAT_MBYTE)
5879 /* $HOME may have characters in active code page. */
5880 if (varp == &p_enc)
5881 init_homedir();
5882# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 }
5884 }
5885#endif
5886
5887#if defined(FEAT_POSTSCRIPT)
5888 else if (varp == &p_penc)
5889 {
5890 /* Canonize printencoding if VIM standard one */
5891 p = enc_canonize(p_penc);
5892 if (p != NULL)
5893 {
5894 vim_free(p_penc);
5895 p_penc = p;
5896 }
5897 else
5898 {
5899 /* Ensure lower case and '-' for '_' */
5900 for (s = p_penc; *s != NUL; s++)
5901 {
5902 if (*s == '_')
5903 *s = '-';
5904 else
5905 *s = TOLOWER_ASC(*s);
5906 }
5907 }
5908 }
5909#endif
5910
Bram Moolenaar9372a112005-12-06 19:59:18 +00005911#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 else if (varp == &p_imak)
5913 {
5914 if (gui.in_use && !im_xim_isvalid_imactivate())
5915 errmsg = e_invarg;
5916 }
5917#endif
5918
5919#ifdef FEAT_KEYMAP
5920 else if (varp == &curbuf->b_p_keymap)
5921 {
5922 /* load or unload key mapping tables */
5923 errmsg = keymap_init();
5924
Bram Moolenaarfab06232009-03-04 03:13:35 +00005925 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005927 if (*curbuf->b_p_keymap != NUL)
5928 {
5929 /* Installed a new keymap, switch on using it. */
5930 curbuf->b_p_iminsert = B_IMODE_LMAP;
5931 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5932 curbuf->b_p_imsearch = B_IMODE_LMAP;
5933 }
5934 else
5935 {
5936 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5937 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5938 curbuf->b_p_iminsert = B_IMODE_NONE;
5939 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5940 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5941 }
5942 if ((opt_flags & OPT_LOCAL) == 0)
5943 {
5944 set_iminsert_global();
5945 set_imsearch_global();
5946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947# ifdef FEAT_WINDOWS
5948 status_redraw_curbuf();
5949# endif
5950 }
5951 }
5952#endif
5953
5954 /* 'fileformat' */
5955 else if (gvarp == &p_ff)
5956 {
5957 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5958 errmsg = e_modifiable;
5959 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5960 errmsg = e_invarg;
5961 else
5962 {
5963 /* may also change 'textmode' */
5964 if (get_fileformat(curbuf) == EOL_DOS)
5965 curbuf->b_p_tx = TRUE;
5966 else
5967 curbuf->b_p_tx = FALSE;
5968#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005969 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005971 /* update flag in swap file */
5972 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005973 /* Redraw needed when switching to/from "mac": a CR in the text
5974 * will be displayed differently. */
5975 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5976 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977 }
5978 }
5979
5980 /* 'fileformats' */
5981 else if (varp == &p_ffs)
5982 {
5983 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5984 errmsg = e_invarg;
5985 else
5986 {
5987 /* also change 'textauto' */
5988 if (*p_ffs == NUL)
5989 p_ta = FALSE;
5990 else
5991 p_ta = TRUE;
5992 }
5993 }
5994
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005995#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996 /* 'cryptkey' */
5997 else if (gvarp == &p_key)
5998 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02005999# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000 /* Make sure the ":set" command doesn't show the new value in the
6001 * history. */
6002 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006003# endif
6004 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6005 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006006 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6007 }
6008
6009 else if (gvarp == &p_cm)
6010 {
6011 if (opt_flags & OPT_LOCAL)
6012 p = curbuf->b_p_cm;
6013 else
6014 p = p_cm;
6015 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6016 errmsg = e_invarg;
6017 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6018 errmsg = e_invarg;
6019 else
6020 {
6021 /* When setting the global value to empty, make it "zip". */
6022 if (*p_cm == NUL)
6023 {
6024 if (new_value_alloced)
6025 free_string_option(p_cm);
6026 p_cm = vim_strsave((char_u *)"zip");
6027 new_value_alloced = TRUE;
6028 }
6029
6030 /* Need to update the swapfile when the effective method changed.
6031 * Set "s" to the effective old value, "p" to the effective new
6032 * method and compare. */
6033 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6034 s = p_cm; /* was previously using the global value */
6035 else
6036 s = oldval;
6037 if (*curbuf->b_p_cm == NUL)
6038 p = p_cm; /* is now using the global value */
6039 else
6040 p = curbuf->b_p_cm;
6041 if (STRCMP(s, p) != 0)
6042 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6043 crypt_method_from_string(s));
6044
6045 /* If the global value changes need to update the swapfile for all
6046 * buffers using that value. */
6047 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6048 {
6049 buf_T *buf;
6050
6051 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6052 if (buf != curbuf && *buf->b_p_cm == NUL)
6053 ml_set_crypt_key(buf, buf->b_p_key,
6054 crypt_method_from_string(oldval));
6055 }
6056 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006057 }
6058#endif
6059
6060 /* 'matchpairs' */
6061 else if (gvarp == &p_mps)
6062 {
6063 /* Check for "x:y,x:y" */
6064 for (p = *varp; *p != NUL; p += 4)
6065 {
6066 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6067 {
6068 errmsg = e_invarg;
6069 break;
6070 }
6071 if (p[3] == NUL)
6072 break;
6073 }
6074 }
6075
6076#ifdef FEAT_COMMENTS
6077 /* 'comments' */
6078 else if (gvarp == &p_com)
6079 {
6080 for (s = *varp; *s; )
6081 {
6082 while (*s && *s != ':')
6083 {
6084 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6085 && !VIM_ISDIGIT(*s) && *s != '-')
6086 {
6087 errmsg = illegal_char(errbuf, *s);
6088 break;
6089 }
6090 ++s;
6091 }
6092 if (*s++ == NUL)
6093 errmsg = (char_u *)N_("E524: Missing colon");
6094 else if (*s == ',' || *s == NUL)
6095 errmsg = (char_u *)N_("E525: Zero length string");
6096 if (errmsg != NULL)
6097 break;
6098 while (*s && *s != ',')
6099 {
6100 if (*s == '\\' && s[1] != NUL)
6101 ++s;
6102 ++s;
6103 }
6104 s = skip_to_option_part(s);
6105 }
6106 }
6107#endif
6108
6109 /* 'listchars' */
6110 else if (varp == &p_lcs)
6111 {
6112 errmsg = set_chars_option(varp);
6113 }
6114
6115#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6116 /* 'fillchars' */
6117 else if (varp == &p_fcs)
6118 {
6119 errmsg = set_chars_option(varp);
6120 }
6121#endif
6122
6123#ifdef FEAT_CMDWIN
6124 /* 'cedit' */
6125 else if (varp == &p_cedit)
6126 {
6127 errmsg = check_cedit();
6128 }
6129#endif
6130
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006131 /* 'verbosefile' */
6132 else if (varp == &p_vfile)
6133 {
6134 verbose_stop();
6135 if (*p_vfile != NUL && verbose_open() == FAIL)
6136 errmsg = e_invarg;
6137 }
6138
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139#ifdef FEAT_VIMINFO
6140 /* 'viminfo' */
6141 else if (varp == &p_viminfo)
6142 {
6143 for (s = p_viminfo; *s;)
6144 {
6145 /* Check it's a valid character */
6146 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6147 {
6148 errmsg = illegal_char(errbuf, *s);
6149 break;
6150 }
6151 if (*s == 'n') /* name is always last one */
6152 {
6153 break;
6154 }
6155 else if (*s == 'r') /* skip until next ',' */
6156 {
6157 while (*++s && *s != ',')
6158 ;
6159 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006160 else if (*s == '%')
6161 {
6162 /* optional number */
6163 while (vim_isdigit(*++s))
6164 ;
6165 }
6166 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006167 ++s; /* no extra chars */
6168 else /* must have a number */
6169 {
6170 while (vim_isdigit(*++s))
6171 ;
6172
6173 if (!VIM_ISDIGIT(*(s - 1)))
6174 {
6175 if (errbuf != NULL)
6176 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006177 sprintf((char *)errbuf,
6178 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 transchar_byte(*(s - 1)));
6180 errmsg = errbuf;
6181 }
6182 else
6183 errmsg = (char_u *)"";
6184 break;
6185 }
6186 }
6187 if (*s == ',')
6188 ++s;
6189 else if (*s)
6190 {
6191 if (errbuf != NULL)
6192 errmsg = (char_u *)N_("E527: Missing comma");
6193 else
6194 errmsg = (char_u *)"";
6195 break;
6196 }
6197 }
6198 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6199 errmsg = (char_u *)N_("E528: Must specify a ' value");
6200 }
6201#endif /* FEAT_VIMINFO */
6202
6203 /* terminal options */
6204 else if (istermoption(&options[opt_idx]) && full_screen)
6205 {
6206 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6207 if (varp == &T_CCO)
6208 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006209 int colors = atoi((char *)T_CCO);
6210
6211 /* Only reinitialize colors if t_Co value has really changed to
6212 * avoid expensive reload of colorscheme if t_Co is set to the
6213 * same value multiple times. */
6214 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006216 t_colors = colors;
6217 if (t_colors <= 1)
6218 {
6219 if (new_value_alloced)
6220 vim_free(T_CCO);
6221 T_CCO = empty_option;
6222 }
6223 /* We now have a different color setup, initialize it again. */
6224 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 }
6227 ttest(FALSE);
6228 if (varp == &T_ME)
6229 {
6230 out_str(T_ME);
6231 redraw_later(CLEAR);
6232#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6233 /* Since t_me has been set, this probably means that the user
6234 * wants to use this as default colors. Need to reset default
6235 * background/foreground colors. */
6236 mch_set_normal_colors();
6237#endif
6238 }
6239 }
6240
6241#ifdef FEAT_LINEBREAK
6242 /* 'showbreak' */
6243 else if (varp == &p_sbr)
6244 {
6245 for (s = p_sbr; *s; )
6246 {
6247 if (ptr2cells(s) != 1)
6248 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006249 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 }
6251 }
6252#endif
6253
6254#ifdef FEAT_GUI
6255 /* 'guifont' */
6256 else if (varp == &p_guifont)
6257 {
6258 if (gui.in_use)
6259 {
6260 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006261# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262 /*
6263 * Put up a font dialog and let the user select a new value.
6264 * If this is cancelled go back to the old value but don't
6265 * give an error message.
6266 */
6267 if (STRCMP(p, "*") == 0)
6268 {
6269 p = gui_mch_font_dialog(oldval);
6270
6271 if (new_value_alloced)
6272 free_string_option(p_guifont);
6273
6274 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6275 new_value_alloced = TRUE;
6276 }
6277# endif
6278 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6279 {
6280# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6281 if (STRCMP(p_guifont, "*") == 0)
6282 {
6283 /* Dialog was cancelled: Keep the old value without giving
6284 * an error message. */
6285 if (new_value_alloced)
6286 free_string_option(p_guifont);
6287 p_guifont = vim_strsave(oldval);
6288 new_value_alloced = TRUE;
6289 }
6290 else
6291# endif
6292 errmsg = (char_u *)N_("E596: Invalid font(s)");
6293 }
6294 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006295 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 }
6297# ifdef FEAT_XFONTSET
6298 else if (varp == &p_guifontset)
6299 {
6300 if (STRCMP(p_guifontset, "*") == 0)
6301 errmsg = (char_u *)N_("E597: can't select fontset");
6302 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6303 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006304 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 }
6306# endif
6307# ifdef FEAT_MBYTE
6308 else if (varp == &p_guifontwide)
6309 {
6310 if (STRCMP(p_guifontwide, "*") == 0)
6311 errmsg = (char_u *)N_("E533: can't select wide font");
6312 else if (gui_get_wide_font() == FAIL)
6313 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006314 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 }
6316# endif
6317#endif
6318
6319#ifdef CURSOR_SHAPE
6320 /* 'guicursor' */
6321 else if (varp == &p_guicursor)
6322 errmsg = parse_shape_opt(SHAPE_CURSOR);
6323#endif
6324
6325#ifdef FEAT_MOUSESHAPE
6326 /* 'mouseshape' */
6327 else if (varp == &p_mouseshape)
6328 {
6329 errmsg = parse_shape_opt(SHAPE_MOUSE);
6330 update_mouseshape(-1);
6331 }
6332#endif
6333
6334#ifdef FEAT_PRINTER
6335 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006336 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006337# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006338 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006339 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006340# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341#endif
6342
6343#ifdef FEAT_LANGMAP
6344 /* 'langmap' */
6345 else if (varp == &p_langmap)
6346 langmap_set();
6347#endif
6348
6349#ifdef FEAT_LINEBREAK
6350 /* 'breakat' */
6351 else if (varp == &p_breakat)
6352 fill_breakat_flags();
6353#endif
6354
6355#ifdef FEAT_TITLE
6356 /* 'titlestring' and 'iconstring' */
6357 else if (varp == &p_titlestring || varp == &p_iconstring)
6358 {
6359# ifdef FEAT_STL_OPT
6360 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6361
6362 /* NULL => statusline syntax */
6363 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6364 stl_syntax |= flagval;
6365 else
6366 stl_syntax &= ~flagval;
6367# endif
6368 did_set_title(varp == &p_iconstring);
6369
6370 }
6371#endif
6372
6373#ifdef FEAT_GUI
6374 /* 'guioptions' */
6375 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006376 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006378 redraw_gui_only = TRUE;
6379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380#endif
6381
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006382#if defined(FEAT_GUI_TABLINE)
6383 /* 'guitablabel' */
6384 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006385 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006386 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006387 redraw_gui_only = TRUE;
6388 }
6389 /* 'guitabtooltip' */
6390 else if (varp == &p_gtt)
6391 {
6392 redraw_gui_only = TRUE;
6393 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006394#endif
6395
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6397 /* 'ttymouse' */
6398 else if (varp == &p_ttym)
6399 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006400 /* Switch the mouse off before changing the escape sequences used for
6401 * that. */
6402 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6404 errmsg = e_invarg;
6405 else
6406 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006407 if (termcap_active)
6408 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409 }
6410#endif
6411
6412#ifdef FEAT_VISUAL
6413 /* 'selection' */
6414 else if (varp == &p_sel)
6415 {
6416 if (*p_sel == NUL
6417 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6418 errmsg = e_invarg;
6419 }
6420
6421 /* 'selectmode' */
6422 else if (varp == &p_slm)
6423 {
6424 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6425 errmsg = e_invarg;
6426 }
6427#endif
6428
6429#ifdef FEAT_BROWSE
6430 /* 'browsedir' */
6431 else if (varp == &p_bsdir)
6432 {
6433 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6434 && !mch_isdir(p_bsdir))
6435 errmsg = e_invarg;
6436 }
6437#endif
6438
6439#ifdef FEAT_VISUAL
6440 /* 'keymodel' */
6441 else if (varp == &p_km)
6442 {
6443 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6444 errmsg = e_invarg;
6445 else
6446 {
6447 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6448 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6449 }
6450 }
6451#endif
6452
6453 /* 'mousemodel' */
6454 else if (varp == &p_mousem)
6455 {
6456 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6457 errmsg = e_invarg;
6458#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6459 else if (*p_mousem != *oldval)
6460 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6461 * to create or delete the popup menus. */
6462 gui_motif_update_mousemodel(root_menu);
6463#endif
6464 }
6465
6466 /* 'switchbuf' */
6467 else if (varp == &p_swb)
6468 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006469 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 errmsg = e_invarg;
6471 }
6472
6473 /* 'debug' */
6474 else if (varp == &p_debug)
6475 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006476 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 errmsg = e_invarg;
6478 }
6479
6480 /* 'display' */
6481 else if (varp == &p_dy)
6482 {
6483 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6484 errmsg = e_invarg;
6485 else
6486 (void)init_chartab();
6487
6488 }
6489
6490#ifdef FEAT_VERTSPLIT
6491 /* 'eadirection' */
6492 else if (varp == &p_ead)
6493 {
6494 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6495 errmsg = e_invarg;
6496 }
6497#endif
6498
6499#ifdef FEAT_CLIPBOARD
6500 /* 'clipboard' */
6501 else if (varp == &p_cb)
6502 errmsg = check_clipboard_option();
6503#endif
6504
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006505#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006506 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6507 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006508 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006509 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006510 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006511 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006512
Bram Moolenaar860cae12010-06-05 23:22:07 +02006513 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006514 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006515 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6516 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006517 ".add") != 0))
6518 errmsg = e_invarg;
6519 }
6520
6521 if (errmsg == NULL)
6522 {
6523 FOR_ALL_WINDOWS(wp)
6524 if (wp->w_buffer == curbuf && wp->w_p_spell)
6525 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006526 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006527# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006528 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006529# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006530 }
6531 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006532 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006533 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006534 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006535 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006536 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006537 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006538 /* 'spellsuggest' */
6539 else if (varp == &p_sps)
6540 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006541 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006542 errmsg = e_invarg;
6543 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006544 /* 'mkspellmem' */
6545 else if (varp == &p_msm)
6546 {
6547 if (spell_check_msm() != OK)
6548 errmsg = e_invarg;
6549 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006550#endif
6551
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552#ifdef FEAT_QUICKFIX
6553 /* When 'bufhidden' is set, check for valid value. */
6554 else if (gvarp == &p_bh)
6555 {
6556 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6557 errmsg = e_invarg;
6558 }
6559
6560 /* When 'buftype' is set, check for valid value. */
6561 else if (gvarp == &p_bt)
6562 {
6563 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6564 errmsg = e_invarg;
6565 else
6566 {
6567# ifdef FEAT_WINDOWS
6568 if (curwin->w_status_height)
6569 {
6570 curwin->w_redr_status = TRUE;
6571 redraw_later(VALID);
6572 }
6573# endif
6574 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006575# ifdef FEAT_TITLE
6576 redraw_titles();
6577# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579 }
6580#endif
6581
6582#ifdef FEAT_STL_OPT
6583 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006584 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 {
6586 int wid;
6587
6588 if (varp == &p_ruf) /* reset ru_wid first */
6589 ru_wid = 0;
6590 s = *varp;
6591 if (varp == &p_ruf && *s == '%')
6592 {
6593 /* set ru_wid if 'ruf' starts with "%99(" */
6594 if (*++s == '-') /* ignore a '-' */
6595 s++;
6596 wid = getdigits(&s);
6597 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6598 ru_wid = wid;
6599 else
6600 errmsg = check_stl_option(p_ruf);
6601 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006602 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006603 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006605 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 comp_col();
6607 }
6608#endif
6609
6610#ifdef FEAT_INS_EXPAND
6611 /* check if it is a valid value for 'complete' -- Acevedo */
6612 else if (gvarp == &p_cpt)
6613 {
6614 for (s = *varp; *s;)
6615 {
6616 while(*s == ',' || *s == ' ')
6617 s++;
6618 if (!*s)
6619 break;
6620 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6621 {
6622 errmsg = illegal_char(errbuf, *s);
6623 break;
6624 }
6625 if (*++s != NUL && *s != ',' && *s != ' ')
6626 {
6627 if (s[-1] == 'k' || s[-1] == 's')
6628 {
6629 /* skip optional filename after 'k' and 's' */
6630 while (*s && *s != ',' && *s != ' ')
6631 {
6632 if (*s == '\\')
6633 ++s;
6634 ++s;
6635 }
6636 }
6637 else
6638 {
6639 if (errbuf != NULL)
6640 {
6641 sprintf((char *)errbuf,
6642 _("E535: Illegal character after <%c>"),
6643 *--s);
6644 errmsg = errbuf;
6645 }
6646 else
6647 errmsg = (char_u *)"";
6648 break;
6649 }
6650 }
6651 }
6652 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006653
6654 /* 'completeopt' */
6655 else if (varp == &p_cot)
6656 {
6657 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6658 errmsg = e_invarg;
6659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660#endif /* FEAT_INS_EXPAND */
6661
6662
6663#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6664 else if (varp == &p_toolbar)
6665 {
6666 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6667 &toolbar_flags, TRUE) != OK)
6668 errmsg = e_invarg;
6669 else
6670 {
6671 out_flush();
6672 gui_mch_show_toolbar((toolbar_flags &
6673 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6674 }
6675 }
6676#endif
6677
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006678#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679 /* 'toolbariconsize': GTK+ 2 only */
6680 else if (varp == &p_tbis)
6681 {
6682 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6683 errmsg = e_invarg;
6684 else
6685 {
6686 out_flush();
6687 gui_mch_show_toolbar((toolbar_flags &
6688 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6689 }
6690 }
6691#endif
6692
6693 /* 'pastetoggle': translate key codes like in a mapping */
6694 else if (varp == &p_pt)
6695 {
6696 if (*p_pt)
6697 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006698 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 if (p != NULL)
6700 {
6701 if (new_value_alloced)
6702 free_string_option(p_pt);
6703 p_pt = p;
6704 new_value_alloced = TRUE;
6705 }
6706 }
6707 }
6708
6709 /* 'backspace' */
6710 else if (varp == &p_bs)
6711 {
6712 if (VIM_ISDIGIT(*p_bs))
6713 {
6714 if (*p_bs >'2' || p_bs[1] != NUL)
6715 errmsg = e_invarg;
6716 }
6717 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6718 errmsg = e_invarg;
6719 }
6720
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006721#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 /* 'casemap' */
6723 else if (varp == &p_cmp)
6724 {
6725 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6726 errmsg = e_invarg;
6727 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729
6730#ifdef FEAT_DIFF
6731 /* 'diffopt' */
6732 else if (varp == &p_dip)
6733 {
6734 if (diffopt_changed() == FAIL)
6735 errmsg = e_invarg;
6736 }
6737#endif
6738
6739#ifdef FEAT_FOLDING
6740 /* 'foldmethod' */
6741 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6742 {
6743 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6744 || *curwin->w_p_fdm == NUL)
6745 errmsg = e_invarg;
6746 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006747 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006749 if (foldmethodIsDiff(curwin))
6750 newFoldLevel();
6751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752 }
6753# ifdef FEAT_EVAL
6754 /* 'foldexpr' */
6755 else if (varp == &curwin->w_p_fde)
6756 {
6757 if (foldmethodIsExpr(curwin))
6758 foldUpdateAll(curwin);
6759 }
6760# endif
6761 /* 'foldmarker' */
6762 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6763 {
6764 p = vim_strchr(*varp, ',');
6765 if (p == NULL)
6766 errmsg = (char_u *)N_("E536: comma required");
6767 else if (p == *varp || p[1] == NUL)
6768 errmsg = e_invarg;
6769 else if (foldmethodIsMarker(curwin))
6770 foldUpdateAll(curwin);
6771 }
6772 /* 'commentstring' */
6773 else if (gvarp == &p_cms)
6774 {
6775 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6776 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6777 }
6778 /* 'foldopen' */
6779 else if (varp == &p_fdo)
6780 {
6781 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6782 errmsg = e_invarg;
6783 }
6784 /* 'foldclose' */
6785 else if (varp == &p_fcl)
6786 {
6787 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6788 errmsg = e_invarg;
6789 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006790 /* 'foldignore' */
6791 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6792 {
6793 if (foldmethodIsIndent(curwin))
6794 foldUpdateAll(curwin);
6795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796#endif
6797
6798#ifdef FEAT_VIRTUALEDIT
6799 /* 'virtualedit' */
6800 else if (varp == &p_ve)
6801 {
6802 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6803 errmsg = e_invarg;
6804 else if (STRCMP(p_ve, oldval) != 0)
6805 {
6806 /* Recompute cursor position in case the new 've' setting
6807 * changes something. */
6808 validate_virtcol();
6809 coladvance(curwin->w_virtcol);
6810 }
6811 }
6812#endif
6813
6814#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6815 else if (varp == &p_csqf)
6816 {
6817 if (p_csqf != NULL)
6818 {
6819 p = p_csqf;
6820 while (*p != NUL)
6821 {
6822 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6823 || p[1] == NUL
6824 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6825 || (p[2] != NUL && p[2] != ','))
6826 {
6827 errmsg = e_invarg;
6828 break;
6829 }
6830 else if (p[2] == NUL)
6831 break;
6832 else
6833 p += 3;
6834 }
6835 }
6836 }
6837#endif
6838
6839 /* Options that are a list of flags. */
6840 else
6841 {
6842 p = NULL;
6843 if (varp == &p_ww)
6844 p = (char_u *)WW_ALL;
6845 if (varp == &p_shm)
6846 p = (char_u *)SHM_ALL;
6847 else if (varp == &(p_cpo))
6848 p = (char_u *)CPO_ALL;
6849 else if (varp == &(curbuf->b_p_fo))
6850 p = (char_u *)FO_ALL;
6851 else if (varp == &p_mouse)
6852 {
6853#ifdef FEAT_MOUSE
6854 p = (char_u *)MOUSE_ALL;
6855#else
6856 if (*p_mouse != NUL)
6857 errmsg = (char_u *)N_("E538: No mouse support");
6858#endif
6859 }
6860#if defined(FEAT_GUI)
6861 else if (varp == &p_go)
6862 p = (char_u *)GO_ALL;
6863#endif
6864 if (p != NULL)
6865 {
6866 for (s = *varp; *s; ++s)
6867 if (vim_strchr(p, *s) == NULL)
6868 {
6869 errmsg = illegal_char(errbuf, *s);
6870 break;
6871 }
6872 }
6873 }
6874
6875 /*
6876 * If error detected, restore the previous value.
6877 */
6878 if (errmsg != NULL)
6879 {
6880 if (new_value_alloced)
6881 free_string_option(*varp);
6882 *varp = oldval;
6883 /*
6884 * When resetting some values, need to act on it.
6885 */
6886 if (did_chartab)
6887 (void)init_chartab();
6888 if (varp == &p_hl)
6889 (void)highlight_changed();
6890 }
6891 else
6892 {
6893#ifdef FEAT_EVAL
6894 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006895 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896#endif
6897 /*
6898 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006899 * Use "free_oldval", because recursiveness may change the flags under
6900 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006902 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 free_string_option(oldval);
6904 if (new_value_alloced)
6905 options[opt_idx].flags |= P_ALLOCED;
6906 else
6907 options[opt_idx].flags &= ~P_ALLOCED;
6908
6909 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006910 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 {
6912 /* global option with local value set to use global value; free
6913 * the local value and make it empty */
6914 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6915 free_string_option(*(char_u **)p);
6916 *(char_u **)p = empty_option;
6917 }
6918
6919 /* May set global value for local option. */
6920 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6921 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006922
6923#ifdef FEAT_AUTOCMD
6924 /*
6925 * Trigger the autocommand only after setting the flags.
6926 */
6927# ifdef FEAT_SYN_HL
6928 /* When 'syntax' is set, load the syntax of that name */
6929 if (varp == &(curbuf->b_p_syn))
6930 {
6931 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6932 curbuf->b_fname, TRUE, curbuf);
6933 }
6934# endif
6935 else if (varp == &(curbuf->b_p_ft))
6936 {
6937 /* 'filetype' is set, trigger the FileType autocommand */
6938 did_filetype = TRUE;
6939 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6940 curbuf->b_fname, TRUE, curbuf);
6941 }
6942#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006943#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006944 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006945 {
6946 char_u fname[200];
6947
6948 /*
6949 * Source the spell/LANG.vim in 'runtimepath'.
6950 * They could set 'spellcapcheck' depending on the language.
6951 * Use the first name in 'spelllang' up to '_region' or
6952 * '.encoding'.
6953 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006954 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006955 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6956 break;
6957 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006958 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006959 source_runtime(fname, TRUE);
6960 }
6961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962 }
6963
6964#ifdef FEAT_MOUSE
6965 if (varp == &p_mouse)
6966 {
6967# ifdef FEAT_MOUSE_TTY
6968 if (*p_mouse == NUL)
6969 mch_setmouse(FALSE); /* switch mouse off */
6970 else
6971# endif
6972 setmouse(); /* in case 'mouse' changed */
6973 }
6974#endif
6975
6976 if (curwin->w_curswant != MAXCOL)
6977 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006978#ifdef FEAT_GUI
6979 /* check redraw when it's not a GUI option or the GUI is active. */
6980 if (!redraw_gui_only || gui.in_use)
6981#endif
6982 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983
6984 return errmsg;
6985}
6986
Bram Moolenaar1a384422010-07-14 19:53:30 +02006987#ifdef FEAT_SYN_HL
6988/*
6989 * Simple int comparison function for use with qsort()
6990 */
6991 static int
6992int_cmp(a, b)
6993 const void *a;
6994 const void *b;
6995{
6996 return *(const int *)a - *(const int *)b;
6997}
6998
6999/*
7000 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7001 * Returns error message, NULL if it's OK.
7002 */
7003 char_u *
7004check_colorcolumn(wp)
7005 win_T *wp;
7006{
7007 char_u *s;
7008 int col;
7009 int count = 0;
7010 int color_cols[256];
7011 int i;
7012 int j = 0;
7013
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007014 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007015 {
7016 if (*s == '-' || *s == '+')
7017 {
7018 /* -N and +N: add to 'textwidth' */
7019 col = (*s == '-') ? -1 : 1;
7020 ++s;
7021 if (!VIM_ISDIGIT(*s))
7022 return e_invarg;
7023 col = col * getdigits(&s);
7024 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007025 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007026 col += wp->w_buffer->b_p_tw;
7027 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007028 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007029 }
7030 else if (VIM_ISDIGIT(*s))
7031 col = getdigits(&s);
7032 else
7033 return e_invarg;
7034 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007035skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007036 if (*s == NUL)
7037 break;
7038 if (*s != ',')
7039 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007040 if (*++s == NUL)
7041 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007042 }
7043
7044 vim_free(wp->w_p_cc_cols);
7045 if (count == 0)
7046 wp->w_p_cc_cols = NULL;
7047 else
7048 {
7049 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7050 if (wp->w_p_cc_cols != NULL)
7051 {
7052 /* sort the columns for faster usage on screen redraw inside
7053 * win_line() */
7054 qsort(color_cols, count, sizeof(int), int_cmp);
7055
7056 for (i = 0; i < count; ++i)
7057 /* skip duplicates */
7058 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7059 wp->w_p_cc_cols[j++] = color_cols[i];
7060 wp->w_p_cc_cols[j] = -1; /* end marker */
7061 }
7062 }
7063
7064 return NULL; /* no error */
7065}
7066#endif
7067
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068/*
7069 * Handle setting 'listchars' or 'fillchars'.
7070 * Returns error message, NULL if it's OK.
7071 */
7072 static char_u *
7073set_chars_option(varp)
7074 char_u **varp;
7075{
7076 int round, i, len, entries;
7077 char_u *p, *s;
7078 int c1, c2 = 0;
7079 struct charstab
7080 {
7081 int *cp;
7082 char *name;
7083 };
7084#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7085 static struct charstab filltab[] =
7086 {
7087 {&fill_stl, "stl"},
7088 {&fill_stlnc, "stlnc"},
7089 {&fill_vert, "vert"},
7090 {&fill_fold, "fold"},
7091 {&fill_diff, "diff"},
7092 };
7093#endif
7094 static struct charstab lcstab[] =
7095 {
7096 {&lcs_eol, "eol"},
7097 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007098 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 {&lcs_prec, "precedes"},
7100 {&lcs_tab2, "tab"},
7101 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007102#ifdef FEAT_CONCEAL
7103 {&lcs_conceal, "conceal"},
7104#else
7105 {NULL, "conceal"},
7106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107 };
7108 struct charstab *tab;
7109
7110#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7111 if (varp == &p_lcs)
7112#endif
7113 {
7114 tab = lcstab;
7115 entries = sizeof(lcstab) / sizeof(struct charstab);
7116 }
7117#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7118 else
7119 {
7120 tab = filltab;
7121 entries = sizeof(filltab) / sizeof(struct charstab);
7122 }
7123#endif
7124
7125 /* first round: check for valid value, second round: assign values */
7126 for (round = 0; round <= 1; ++round)
7127 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007128 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 {
7130 /* After checking that the value is valid: set defaults: space for
7131 * 'fillchars', NUL for 'listchars' */
7132 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007133 if (tab[i].cp != NULL)
7134 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 if (varp == &p_lcs)
7136 lcs_tab1 = NUL;
7137#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7138 else
7139 fill_diff = '-';
7140#endif
7141 }
7142 p = *varp;
7143 while (*p)
7144 {
7145 for (i = 0; i < entries; ++i)
7146 {
7147 len = (int)STRLEN(tab[i].name);
7148 if (STRNCMP(p, tab[i].name, len) == 0
7149 && p[len] == ':'
7150 && p[len + 1] != NUL)
7151 {
7152 s = p + len + 1;
7153#ifdef FEAT_MBYTE
7154 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007155 if (mb_char2cells(c1) > 1)
7156 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157#else
7158 c1 = *s++;
7159#endif
7160 if (tab[i].cp == &lcs_tab2)
7161 {
7162 if (*s == NUL)
7163 continue;
7164#ifdef FEAT_MBYTE
7165 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007166 if (mb_char2cells(c2) > 1)
7167 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168#else
7169 c2 = *s++;
7170#endif
7171 }
7172 if (*s == ',' || *s == NUL)
7173 {
7174 if (round)
7175 {
7176 if (tab[i].cp == &lcs_tab2)
7177 {
7178 lcs_tab1 = c1;
7179 lcs_tab2 = c2;
7180 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007181 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007182 *(tab[i].cp) = c1;
7183
7184 }
7185 p = s;
7186 break;
7187 }
7188 }
7189 }
7190
7191 if (i == entries)
7192 return e_invarg;
7193 if (*p == ',')
7194 ++p;
7195 }
7196 }
7197
7198 return NULL; /* no error */
7199}
7200
7201#ifdef FEAT_STL_OPT
7202/*
7203 * Check validity of options with the 'statusline' format.
7204 * Return error message or NULL.
7205 */
7206 char_u *
7207check_stl_option(s)
7208 char_u *s;
7209{
7210 int itemcnt = 0;
7211 int groupdepth = 0;
7212 static char_u errbuf[80];
7213
7214 while (*s && itemcnt < STL_MAX_ITEM)
7215 {
7216 /* Check for valid keys after % sequences */
7217 while (*s && *s != '%')
7218 s++;
7219 if (!*s)
7220 break;
7221 s++;
7222 if (*s != '%' && *s != ')')
7223 ++itemcnt;
7224 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7225 {
7226 s++;
7227 continue;
7228 }
7229 if (*s == ')')
7230 {
7231 s++;
7232 if (--groupdepth < 0)
7233 break;
7234 continue;
7235 }
7236 if (*s == '-')
7237 s++;
7238 while (VIM_ISDIGIT(*s))
7239 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007240 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241 continue;
7242 if (*s == '.')
7243 {
7244 s++;
7245 while (*s && VIM_ISDIGIT(*s))
7246 s++;
7247 }
7248 if (*s == '(')
7249 {
7250 groupdepth++;
7251 continue;
7252 }
7253 if (vim_strchr(STL_ALL, *s) == NULL)
7254 {
7255 return illegal_char(errbuf, *s);
7256 }
7257 if (*s == '{')
7258 {
7259 s++;
7260 while (*s != '}' && *s)
7261 s++;
7262 if (*s != '}')
7263 return (char_u *)N_("E540: Unclosed expression sequence");
7264 }
7265 }
7266 if (itemcnt >= STL_MAX_ITEM)
7267 return (char_u *)N_("E541: too many items");
7268 if (groupdepth != 0)
7269 return (char_u *)N_("E542: unbalanced groups");
7270 return NULL;
7271}
7272#endif
7273
7274#ifdef FEAT_CLIPBOARD
7275/*
7276 * Extract the items in the 'clipboard' option and set global values.
7277 */
7278 static char_u *
7279check_clipboard_option()
7280{
7281 int new_unnamed = FALSE;
7282 int new_autoselect = FALSE;
7283 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007284 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 regprog_T *new_exclude_prog = NULL;
7286 char_u *errmsg = NULL;
7287 char_u *p;
7288
7289 for (p = p_cb; *p != NUL; )
7290 {
7291 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7292 {
7293 new_unnamed = TRUE;
7294 p += 7;
7295 }
7296 else if (STRNCMP(p, "autoselect", 10) == 0
7297 && (p[10] == ',' || p[10] == NUL))
7298 {
7299 new_autoselect = TRUE;
7300 p += 10;
7301 }
7302 else if (STRNCMP(p, "autoselectml", 12) == 0
7303 && (p[12] == ',' || p[12] == NUL))
7304 {
7305 new_autoselectml = TRUE;
7306 p += 12;
7307 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007308 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7309 {
7310 new_html = TRUE;
7311 p += 4;
7312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7314 {
7315 p += 8;
7316 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7317 if (new_exclude_prog == NULL)
7318 errmsg = e_invarg;
7319 break;
7320 }
7321 else
7322 {
7323 errmsg = e_invarg;
7324 break;
7325 }
7326 if (*p == ',')
7327 ++p;
7328 }
7329 if (errmsg == NULL)
7330 {
7331 clip_unnamed = new_unnamed;
7332 clip_autoselect = new_autoselect;
7333 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007334 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 vim_free(clip_exclude_prog);
7336 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007337#ifdef FEAT_GUI_GTK
7338 if (gui.in_use)
7339 {
7340 gui_gtk_set_selection_targets();
7341 gui_gtk_set_dnd_targets();
7342 }
7343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 }
7345 else
7346 vim_free(new_exclude_prog);
7347
7348 return errmsg;
7349}
7350#endif
7351
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007352#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007353/*
7354 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7355 * Return error message when failed, NULL when OK.
7356 */
7357 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007358compile_cap_prog(synblock)
7359 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007360{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007361 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007362 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007363
Bram Moolenaar860cae12010-06-05 23:22:07 +02007364 if (*synblock->b_p_spc == NUL)
7365 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007366 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007367 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007368 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007369 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007370 if (re != NULL)
7371 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007372 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7373 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007374 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007375 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007376 return e_invarg;
7377 }
7378 vim_free(re);
7379 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007380 }
7381
7382 vim_free(rp);
7383 return NULL;
7384}
7385#endif
7386
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007387#if defined(FEAT_EVAL) || defined(PROTO)
7388/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007389 * Set the scriptID for an option, taking care of setting the buffer- or
7390 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007391 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007392 static void
7393set_option_scriptID_idx(opt_idx, opt_flags, id)
7394 int opt_idx;
7395 int opt_flags;
7396 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007397{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007398 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7399 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007400
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007401 /* Remember where the option was set. For local options need to do that
7402 * in the buffer or window structure. */
7403 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007404 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007405 if (both || (opt_flags & OPT_LOCAL))
7406 {
7407 if (indir & PV_BUF)
7408 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7409 else if (indir & PV_WIN)
7410 curwin->w_p_scriptID[indir & PV_MASK] = id;
7411 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007412}
7413#endif
7414
Bram Moolenaar071d4272004-06-13 20:20:40 +00007415/*
7416 * Set the value of a boolean option, and take care of side effects.
7417 * Returns NULL for success, or an error message for an error.
7418 */
7419 static char_u *
7420set_bool_option(opt_idx, varp, value, opt_flags)
7421 int opt_idx; /* index in options[] table */
7422 char_u *varp; /* pointer to the option variable */
7423 int value; /* new value */
7424 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7425{
7426 int old_value = *(int *)varp;
7427
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 /* Disallow changing some options from secure mode */
7429 if ((secure
7430#ifdef HAVE_SANDBOX
7431 || sandbox != 0
7432#endif
7433 ) && (options[opt_idx].flags & P_SECURE))
7434 return e_secure;
7435
7436 *(int *)varp = value; /* set the new value */
7437#ifdef FEAT_EVAL
7438 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007439 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440#endif
7441
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007442#ifdef FEAT_GUI
7443 need_mouse_correct = TRUE;
7444#endif
7445
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 /* May set global value for local option. */
7447 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7448 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7449
7450 /*
7451 * Handle side effects of changing a bool option.
7452 */
7453
7454 /* 'compatible' */
7455 if ((int *)varp == &p_cp)
7456 {
7457 compatible_set();
7458 }
7459
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007460 /* 'list', 'number' */
7461 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007462 || (int *)varp == &curwin->w_p_nu
7463 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007464 {
7465 if (curwin->w_curswant != MAXCOL)
7466 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007467
7468 /* If 'number' is set, reset 'relativenumber'. */
7469 /* If 'relativenumber' is set, reset 'number'. */
7470 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7471 curwin->w_p_rnu = FALSE;
7472 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7473 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007474 }
7475
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476 else if ((int *)varp == &curbuf->b_p_ro)
7477 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007478 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7480 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007481
7482 /* when 'readonly' is set may give W10 again */
7483 if (curbuf->b_p_ro)
7484 curbuf->b_did_warn = FALSE;
7485
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007487 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488#endif
7489 }
7490
Bram Moolenaar370df582010-06-22 05:16:38 +02007491#if defined(FEAT_TITLE) || defined(FEAT_CONCEAL)
7492 /* when 'modifiable' is changed, redraw the window title and
7493 * update current line for concealable items */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007495 {
Bram Moolenaar370df582010-06-22 05:16:38 +02007496# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007497 redraw_titles();
Bram Moolenaar370df582010-06-22 05:16:38 +02007498# endif
7499# ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02007500 if (curwin->w_p_conc > 0)
Bram Moolenaar370df582010-06-22 05:16:38 +02007501 update_single_line(curwin, curwin->w_cursor.lnum);
7502# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007503 }
Bram Moolenaar370df582010-06-22 05:16:38 +02007504#endif
7505#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 /* when 'endofline' is changed, redraw the window title */
7507 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007508 {
7509 redraw_titles();
7510 }
7511# ifdef FEAT_MBYTE
7512 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007513 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007514 {
7515 redraw_titles();
7516 }
7517# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518#endif
7519
7520 /* when 'bin' is set also set some other options */
7521 else if ((int *)varp == &curbuf->b_p_bin)
7522 {
7523 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7524#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007525 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526#endif
7527 }
7528
7529#ifdef FEAT_AUTOCMD
7530 /* when 'buflisted' changes, trigger autocommands */
7531 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7532 {
7533 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7534 NULL, NULL, TRUE, curbuf);
7535 }
7536#endif
7537
7538 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7539 else if ((int *)varp == &curbuf->b_p_swf)
7540 {
7541 if (curbuf->b_p_swf && p_uc)
7542 ml_open_file(curbuf); /* create the swap file */
7543 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007544 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7545 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 mf_close_file(curbuf, TRUE); /* remove the swap file */
7547 }
7548
7549 /* when 'terse' is set change 'shortmess' */
7550 else if ((int *)varp == &p_terse)
7551 {
7552 char_u *p;
7553
7554 p = vim_strchr(p_shm, SHM_SEARCH);
7555
7556 /* insert 's' in p_shm */
7557 if (p_terse && p == NULL)
7558 {
7559 STRCPY(IObuff, p_shm);
7560 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007561 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 }
7563 /* remove 's' from p_shm */
7564 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007565 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007566 }
7567
7568 /* when 'paste' is set or reset also change other options */
7569 else if ((int *)varp == &p_paste)
7570 {
7571 paste_option_changed();
7572 }
7573
7574 /* when 'insertmode' is set from an autocommand need to do work here */
7575 else if ((int *)varp == &p_im)
7576 {
7577 if (p_im)
7578 {
7579 if ((State & INSERT) == 0)
7580 need_start_insertmode = TRUE;
7581 stop_insert_mode = FALSE;
7582 }
7583 else
7584 {
7585 need_start_insertmode = FALSE;
7586 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007587 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 clear_cmdline = TRUE; /* remove "(insert)" */
7589 restart_edit = 0;
7590 }
7591 }
7592
7593 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7594 else if ((int *)varp == &p_ic && p_hls)
7595 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007596 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 }
7598
7599#ifdef FEAT_SEARCH_EXTRA
7600 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7601 else if ((int *)varp == &p_hls)
7602 {
7603 no_hlsearch = FALSE;
7604 }
7605#endif
7606
7607#ifdef FEAT_SCROLLBIND
7608 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7609 * at the end of normal_cmd() */
7610 else if ((int *)varp == &curwin->w_p_scb)
7611 {
7612 if (curwin->w_p_scb)
7613 do_check_scrollbind(FALSE);
7614 }
7615#endif
7616
7617#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7618 /* There can be only one window with 'previewwindow' set. */
7619 else if ((int *)varp == &curwin->w_p_pvw)
7620 {
7621 if (curwin->w_p_pvw)
7622 {
7623 win_T *win;
7624
7625 for (win = firstwin; win != NULL; win = win->w_next)
7626 if (win->w_p_pvw && win != curwin)
7627 {
7628 curwin->w_p_pvw = FALSE;
7629 return (char_u *)N_("E590: A preview window already exists");
7630 }
7631 }
7632 }
7633#endif
7634
7635 /* when 'textmode' is set or reset also change 'fileformat' */
7636 else if ((int *)varp == &curbuf->b_p_tx)
7637 {
7638 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7639 }
7640
7641 /* when 'textauto' is set or reset also change 'fileformats' */
7642 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643 set_string_option_direct((char_u *)"ffs", -1,
7644 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007645 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646
7647 /*
7648 * When 'lisp' option changes include/exclude '-' in
7649 * keyword characters.
7650 */
7651#ifdef FEAT_LISP
7652 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7653 {
7654 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7655 }
7656#endif
7657
7658#ifdef FEAT_TITLE
7659 /* when 'title' changed, may need to change the title; same for 'icon' */
7660 else if ((int *)varp == &p_title)
7661 {
7662 did_set_title(FALSE);
7663 }
7664
7665 else if ((int *)varp == &p_icon)
7666 {
7667 did_set_title(TRUE);
7668 }
7669#endif
7670
7671 else if ((int *)varp == &curbuf->b_changed)
7672 {
7673 if (!value)
7674 save_file_ff(curbuf); /* Buffer is unchanged */
7675#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007676 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677#endif
7678#ifdef FEAT_AUTOCMD
7679 modified_was_set = value;
7680#endif
7681 }
7682
7683#ifdef BACKSLASH_IN_FILENAME
7684 else if ((int *)varp == &p_ssl)
7685 {
7686 if (p_ssl)
7687 {
7688 psepc = '/';
7689 psepcN = '\\';
7690 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 }
7692 else
7693 {
7694 psepc = '\\';
7695 psepcN = '/';
7696 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007697 }
7698
7699 /* need to adjust the file name arguments and buffer names. */
7700 buflist_slash_adjust();
7701 alist_slash_adjust();
7702# ifdef FEAT_EVAL
7703 scriptnames_slash_adjust();
7704# endif
7705 }
7706#endif
7707
7708 /* If 'wrap' is set, set w_leftcol to zero. */
7709 else if ((int *)varp == &curwin->w_p_wrap)
7710 {
7711 if (curwin->w_p_wrap)
7712 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007713 if (curwin->w_curswant != MAXCOL)
7714 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 }
7716
7717#ifdef FEAT_WINDOWS
7718 else if ((int *)varp == &p_ea)
7719 {
7720 if (p_ea && !old_value)
7721 win_equal(curwin, FALSE, 0);
7722 }
7723#endif
7724
7725 else if ((int *)varp == &p_wiv)
7726 {
7727 /*
7728 * When 'weirdinvert' changed, set/reset 't_xs'.
7729 * Then set 'weirdinvert' according to value of 't_xs'.
7730 */
7731 if (p_wiv && !old_value)
7732 T_XS = (char_u *)"y";
7733 else if (!p_wiv && old_value)
7734 T_XS = empty_option;
7735 p_wiv = (*T_XS != NUL);
7736 }
7737
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007738#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 else if ((int *)varp == &p_beval)
7740 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 if (p_beval == TRUE)
7742 gui_mch_enable_beval_area(balloonEval);
7743 else
7744 gui_mch_disable_beval_area(balloonEval);
7745 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007748#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 else if ((int *)varp == &p_acd)
7750 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007751 /* Change directories when the 'acd' option is set now. */
7752 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753 }
7754#endif
7755
7756#ifdef FEAT_DIFF
7757 /* 'diff' */
7758 else if ((int *)varp == &curwin->w_p_diff)
7759 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007760 /* May add or remove the buffer from the list of diff buffers. */
7761 diff_buf_adjust(curwin);
7762# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 if (foldmethodIsDiff(curwin))
7764 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007765# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 }
7767#endif
7768
7769#ifdef USE_IM_CONTROL
7770 /* 'imdisable' */
7771 else if ((int *)varp == &p_imdisable)
7772 {
7773 /* Only de-activate it here, it will be enabled when changing mode. */
7774 if (p_imdisable)
7775 im_set_active(FALSE);
7776 }
7777#endif
7778
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007779#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007780 /* 'spell' */
7781 else if ((int *)varp == &curwin->w_p_spell)
7782 {
7783 if (curwin->w_p_spell)
7784 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007785 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007786 if (errmsg != NULL)
7787 EMSG(_(errmsg));
7788 }
7789 }
7790#endif
7791
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792#ifdef FEAT_FKMAP
7793 else if ((int *)varp == &p_altkeymap)
7794 {
7795 if (old_value != p_altkeymap)
7796 {
7797 if (!p_altkeymap)
7798 {
7799 p_hkmap = p_fkmap;
7800 p_fkmap = 0;
7801 }
7802 else
7803 {
7804 p_fkmap = p_hkmap;
7805 p_hkmap = 0;
7806 }
7807 (void)init_chartab();
7808 }
7809 }
7810
7811 /*
7812 * In case some second language keymapping options have changed, check
7813 * and correct the setting in a consistent way.
7814 */
7815
7816 /*
7817 * If hkmap or fkmap are set, reset Arabic keymapping.
7818 */
7819 if ((p_hkmap || p_fkmap) && p_altkeymap)
7820 {
7821 p_altkeymap = p_fkmap;
7822# ifdef FEAT_ARABIC
7823 curwin->w_p_arab = FALSE;
7824# endif
7825 (void)init_chartab();
7826 }
7827
7828 /*
7829 * If hkmap set, reset Farsi keymapping.
7830 */
7831 if (p_hkmap && p_altkeymap)
7832 {
7833 p_altkeymap = 0;
7834 p_fkmap = 0;
7835# ifdef FEAT_ARABIC
7836 curwin->w_p_arab = FALSE;
7837# endif
7838 (void)init_chartab();
7839 }
7840
7841 /*
7842 * If fkmap set, reset Hebrew keymapping.
7843 */
7844 if (p_fkmap && !p_altkeymap)
7845 {
7846 p_altkeymap = 1;
7847 p_hkmap = 0;
7848# ifdef FEAT_ARABIC
7849 curwin->w_p_arab = FALSE;
7850# endif
7851 (void)init_chartab();
7852 }
7853#endif
7854
7855#ifdef FEAT_ARABIC
7856 if ((int *)varp == &curwin->w_p_arab)
7857 {
7858 if (curwin->w_p_arab)
7859 {
7860 /*
7861 * 'arabic' is set, handle various sub-settings.
7862 */
7863 if (!p_tbidi)
7864 {
7865 /* set rightleft mode */
7866 if (!curwin->w_p_rl)
7867 {
7868 curwin->w_p_rl = TRUE;
7869 changed_window_setting();
7870 }
7871
7872 /* Enable Arabic shaping (major part of what Arabic requires) */
7873 if (!p_arshape)
7874 {
7875 p_arshape = TRUE;
7876 redraw_later_clear();
7877 }
7878 }
7879
7880 /* Arabic requires a utf-8 encoding, inform the user if its not
7881 * set. */
7882 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007883 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007884 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7885
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007886 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007887 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7888#ifdef FEAT_EVAL
7889 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7890#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892
7893# ifdef FEAT_MBYTE
7894 /* set 'delcombine' */
7895 p_deco = TRUE;
7896# endif
7897
7898# ifdef FEAT_KEYMAP
7899 /* Force-set the necessary keymap for arabic */
7900 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7901 OPT_LOCAL);
7902# endif
7903# ifdef FEAT_FKMAP
7904 p_altkeymap = 0;
7905 p_hkmap = 0;
7906 p_fkmap = 0;
7907 (void)init_chartab();
7908# endif
7909 }
7910 else
7911 {
7912 /*
7913 * 'arabic' is reset, handle various sub-settings.
7914 */
7915 if (!p_tbidi)
7916 {
7917 /* reset rightleft mode */
7918 if (curwin->w_p_rl)
7919 {
7920 curwin->w_p_rl = FALSE;
7921 changed_window_setting();
7922 }
7923
7924 /* 'arabicshape' isn't reset, it is a global option and
7925 * another window may still need it "on". */
7926 }
7927
7928 /* 'delcombine' isn't reset, it is a global option and another
7929 * window may still want it "on". */
7930
7931# ifdef FEAT_KEYMAP
7932 /* Revert to the default keymap */
7933 curbuf->b_p_iminsert = B_IMODE_NONE;
7934 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7935# endif
7936 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007937 if (curwin->w_curswant != MAXCOL)
7938 curwin->w_set_curswant = TRUE;
7939 }
7940
7941 else if ((int *)varp == &p_arshape)
7942 {
7943 if (curwin->w_curswant != MAXCOL)
7944 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 }
7946#endif
7947
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007948#ifdef FEAT_LINEBREAK
7949 if ((int *)varp == &curwin->w_p_lbr)
7950 {
7951 if (curwin->w_curswant != MAXCOL)
7952 curwin->w_set_curswant = TRUE;
7953 }
7954#endif
7955
7956#ifdef FEAT_RIGHTLEFT
7957 if ((int *)varp == &curwin->w_p_rl)
7958 {
7959 if (curwin->w_curswant != MAXCOL)
7960 curwin->w_set_curswant = TRUE;
7961 }
7962#endif
7963
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 /*
7965 * End of handling side effects for bool options.
7966 */
7967
7968 options[opt_idx].flags |= P_WAS_SET;
7969
7970 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007971
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 check_redraw(options[opt_idx].flags);
7973
7974 return NULL;
7975}
7976
7977/*
7978 * Set the value of a number option, and take care of side effects.
7979 * Returns NULL for success, or an error message for an error.
7980 */
7981 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007982set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 int opt_idx; /* index in options[] table */
7984 char_u *varp; /* pointer to the option variable */
7985 long value; /* new value */
7986 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007987 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7989 OPT_MODELINE */
7990{
7991 char_u *errmsg = NULL;
7992 long old_value = *(long *)varp;
7993 long old_Rows = Rows; /* remember old Rows */
7994 long old_Columns = Columns; /* remember old Columns */
7995 long *pp = (long *)varp;
7996
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007997 /* Disallow changing some options from secure mode. */
7998 if ((secure
7999#ifdef HAVE_SANDBOX
8000 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008002 ) && (options[opt_idx].flags & P_SECURE))
8003 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004
8005 *pp = value;
8006#ifdef FEAT_EVAL
8007 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008008 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008010#ifdef FEAT_GUI
8011 need_mouse_correct = TRUE;
8012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013
8014 if (curbuf->b_p_sw <= 0)
8015 {
8016 errmsg = e_positive;
8017 curbuf->b_p_sw = curbuf->b_p_ts;
8018 }
8019
8020 /*
8021 * Number options that need some action when changed
8022 */
8023#ifdef FEAT_WINDOWS
8024 if (pp == &p_wh || pp == &p_hh)
8025 {
8026 if (p_wh < 1)
8027 {
8028 errmsg = e_positive;
8029 p_wh = 1;
8030 }
8031 if (p_wmh > p_wh)
8032 {
8033 errmsg = e_winheight;
8034 p_wh = p_wmh;
8035 }
8036 if (p_hh < 0)
8037 {
8038 errmsg = e_positive;
8039 p_hh = 0;
8040 }
8041
8042 /* Change window height NOW */
8043 if (lastwin != firstwin)
8044 {
8045 if (pp == &p_wh && curwin->w_height < p_wh)
8046 win_setheight((int)p_wh);
8047 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8048 win_setheight((int)p_hh);
8049 }
8050 }
8051
8052 /* 'winminheight' */
8053 else if (pp == &p_wmh)
8054 {
8055 if (p_wmh < 0)
8056 {
8057 errmsg = e_positive;
8058 p_wmh = 0;
8059 }
8060 if (p_wmh > p_wh)
8061 {
8062 errmsg = e_winheight;
8063 p_wmh = p_wh;
8064 }
8065 win_setminheight();
8066 }
8067
8068# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008069 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 {
8071 if (p_wiw < 1)
8072 {
8073 errmsg = e_positive;
8074 p_wiw = 1;
8075 }
8076 if (p_wmw > p_wiw)
8077 {
8078 errmsg = e_winwidth;
8079 p_wiw = p_wmw;
8080 }
8081
8082 /* Change window width NOW */
8083 if (lastwin != firstwin && curwin->w_width < p_wiw)
8084 win_setwidth((int)p_wiw);
8085 }
8086
8087 /* 'winminwidth' */
8088 else if (pp == &p_wmw)
8089 {
8090 if (p_wmw < 0)
8091 {
8092 errmsg = e_positive;
8093 p_wmw = 0;
8094 }
8095 if (p_wmw > p_wiw)
8096 {
8097 errmsg = e_winwidth;
8098 p_wmw = p_wiw;
8099 }
8100 win_setminheight();
8101 }
8102# endif
8103
8104#endif
8105
8106#ifdef FEAT_WINDOWS
8107 /* (re)set last window status line */
8108 else if (pp == &p_ls)
8109 {
8110 last_status(FALSE);
8111 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008112
8113 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008114 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008115 {
8116 shell_new_rows(); /* recompute window positions and heights */
8117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118#endif
8119
8120#ifdef FEAT_GUI
8121 else if (pp == &p_linespace)
8122 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008123 /* Recompute gui.char_height and resize the Vim window to keep the
8124 * same number of lines. */
8125 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008126 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 }
8128#endif
8129
8130#ifdef FEAT_FOLDING
8131 /* 'foldlevel' */
8132 else if (pp == &curwin->w_p_fdl)
8133 {
8134 if (curwin->w_p_fdl < 0)
8135 curwin->w_p_fdl = 0;
8136 newFoldLevel();
8137 }
8138
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008139 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140 else if (pp == &curwin->w_p_fml)
8141 {
8142 foldUpdateAll(curwin);
8143 }
8144
8145 /* 'foldnestmax' */
8146 else if (pp == &curwin->w_p_fdn)
8147 {
8148 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8149 foldUpdateAll(curwin);
8150 }
8151
8152 /* 'foldcolumn' */
8153 else if (pp == &curwin->w_p_fdc)
8154 {
8155 if (curwin->w_p_fdc < 0)
8156 {
8157 errmsg = e_positive;
8158 curwin->w_p_fdc = 0;
8159 }
8160 else if (curwin->w_p_fdc > 12)
8161 {
8162 errmsg = e_invarg;
8163 curwin->w_p_fdc = 12;
8164 }
8165 }
8166
8167 /* 'shiftwidth' or 'tabstop' */
8168 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8169 {
8170 if (foldmethodIsIndent(curwin))
8171 foldUpdateAll(curwin);
8172 }
8173#endif /* FEAT_FOLDING */
8174
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008175#ifdef FEAT_MBYTE
8176 /* 'maxcombine' */
8177 else if (pp == &p_mco)
8178 {
8179 if (p_mco > MAX_MCO)
8180 p_mco = MAX_MCO;
8181 else if (p_mco < 0)
8182 p_mco = 0;
8183 screenclear(); /* will re-allocate the screen */
8184 }
8185#endif
8186
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 else if (pp == &curbuf->b_p_iminsert)
8188 {
8189 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8190 {
8191 errmsg = e_invarg;
8192 curbuf->b_p_iminsert = B_IMODE_NONE;
8193 }
8194 p_iminsert = curbuf->b_p_iminsert;
8195 if (termcap_active) /* don't do this in the alternate screen */
8196 showmode();
8197#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8198 /* Show/unshow value of 'keymap' in status lines. */
8199 status_redraw_curbuf();
8200#endif
8201 }
8202
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008203 else if (pp == &p_window)
8204 {
8205 if (p_window < 1)
8206 p_window = 1;
8207 else if (p_window >= Rows)
8208 p_window = Rows - 1;
8209 }
8210
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 else if (pp == &curbuf->b_p_imsearch)
8212 {
8213 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8214 {
8215 errmsg = e_invarg;
8216 curbuf->b_p_imsearch = B_IMODE_NONE;
8217 }
8218 p_imsearch = curbuf->b_p_imsearch;
8219 }
8220
8221#ifdef FEAT_TITLE
8222 /* if 'titlelen' has changed, redraw the title */
8223 else if (pp == &p_titlelen)
8224 {
8225 if (p_titlelen < 0)
8226 {
8227 errmsg = e_positive;
8228 p_titlelen = 85;
8229 }
8230 if (starting != NO_SCREEN && old_value != p_titlelen)
8231 need_maketitle = TRUE;
8232 }
8233#endif
8234
8235 /* if p_ch changed value, change the command line height */
8236 else if (pp == &p_ch)
8237 {
8238 if (p_ch < 1)
8239 {
8240 errmsg = e_positive;
8241 p_ch = 1;
8242 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008243 if (p_ch > Rows - min_rows() + 1)
8244 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245
8246 /* Only compute the new window layout when startup has been
8247 * completed. Otherwise the frame sizes may be wrong. */
8248 if (p_ch != old_value && full_screen
8249#ifdef FEAT_GUI
8250 && !gui.starting
8251#endif
8252 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008253 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 }
8255
8256 /* when 'updatecount' changes from zero to non-zero, open swap files */
8257 else if (pp == &p_uc)
8258 {
8259 if (p_uc < 0)
8260 {
8261 errmsg = e_positive;
8262 p_uc = 100;
8263 }
8264 if (p_uc && !old_value)
8265 ml_open_files();
8266 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008267#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008268 else if (pp == &curwin->w_p_conc)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008269 {
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008270 if (curwin->w_p_conc < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008271 {
8272 errmsg = e_positive;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008273 curwin->w_p_conc = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008274 }
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008275 else if (curwin->w_p_conc > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008276 {
8277 errmsg = e_invarg;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008278 curwin->w_p_conc = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008279 }
8280 }
8281#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008282#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008283 else if (pp == &p_mzq)
8284 mzvim_reset_timer();
8285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286
8287 /* sync undo before 'undolevels' changes */
8288 else if (pp == &p_ul)
8289 {
8290 /* use the old value, otherwise u_sync() may not work properly */
8291 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008292 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 p_ul = value;
8294 }
8295
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008296#ifdef FEAT_LINEBREAK
8297 /* 'numberwidth' must be positive */
8298 else if (pp == &curwin->w_p_nuw)
8299 {
8300 if (curwin->w_p_nuw < 1)
8301 {
8302 errmsg = e_positive;
8303 curwin->w_p_nuw = 1;
8304 }
8305 if (curwin->w_p_nuw > 10)
8306 {
8307 errmsg = e_invarg;
8308 curwin->w_p_nuw = 10;
8309 }
8310 curwin->w_nrwidth_line_count = 0;
8311 }
8312#endif
8313
Bram Moolenaar1a384422010-07-14 19:53:30 +02008314 else if (pp == &curbuf->b_p_tw)
8315 {
8316 if (curbuf->b_p_tw < 0)
8317 {
8318 errmsg = e_positive;
8319 curbuf->b_p_tw = 0;
8320 }
8321#ifdef FEAT_SYN_HL
8322# ifdef FEAT_WINDOWS
8323 {
8324 win_T *wp;
8325 tabpage_T *tp;
8326
8327 FOR_ALL_TAB_WINDOWS(tp, wp)
8328 check_colorcolumn(wp);
8329 }
8330# else
8331 check_colorcolumn(curwin);
8332# endif
8333#endif
8334 }
8335
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336 /*
8337 * Check the bounds for numeric options here
8338 */
8339 if (Rows < min_rows() && full_screen)
8340 {
8341 if (errbuf != NULL)
8342 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008343 vim_snprintf((char *)errbuf, errbuflen,
8344 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 errmsg = errbuf;
8346 }
8347 Rows = min_rows();
8348 }
8349 if (Columns < MIN_COLUMNS && full_screen)
8350 {
8351 if (errbuf != NULL)
8352 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008353 vim_snprintf((char *)errbuf, errbuflen,
8354 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355 errmsg = errbuf;
8356 }
8357 Columns = MIN_COLUMNS;
8358 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008359 /* Limit the values to avoid an overflow in Rows * Columns. */
8360 if (Columns > 10000)
8361 Columns = 10000;
8362 if (Rows > 1000)
8363 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364
8365#ifdef DJGPP
8366 /* avoid a crash by checking for a too large value of 'columns' */
8367 if (old_Columns != Columns && full_screen && term_console)
8368 mch_check_columns();
8369#endif
8370
8371 /*
8372 * If the screen (shell) height has been changed, assume it is the
8373 * physical screenheight.
8374 */
8375 if (old_Rows != Rows || old_Columns != Columns)
8376 {
8377 /* Changing the screen size is not allowed while updating the screen. */
8378 if (updating_screen)
8379 *pp = old_value;
8380 else if (full_screen
8381#ifdef FEAT_GUI
8382 && !gui.starting
8383#endif
8384 )
8385 set_shellsize((int)Columns, (int)Rows, TRUE);
8386 else
8387 {
8388 /* Postpone the resizing; check the size and cmdline position for
8389 * messages. */
8390 check_shellsize();
8391 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8392 cmdline_row = Rows - p_ch;
8393 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008394 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008395 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 }
8397
8398 if (curbuf->b_p_sts < 0)
8399 {
8400 errmsg = e_positive;
8401 curbuf->b_p_sts = 0;
8402 }
8403 if (curbuf->b_p_ts <= 0)
8404 {
8405 errmsg = e_positive;
8406 curbuf->b_p_ts = 8;
8407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 if (p_tm < 0)
8409 {
8410 errmsg = e_positive;
8411 p_tm = 0;
8412 }
8413 if ((curwin->w_p_scr <= 0
8414 || (curwin->w_p_scr > curwin->w_height
8415 && curwin->w_height > 0))
8416 && full_screen)
8417 {
8418 if (pp == &(curwin->w_p_scr))
8419 {
8420 if (curwin->w_p_scr != 0)
8421 errmsg = e_scroll;
8422 win_comp_scroll(curwin);
8423 }
8424 /* If 'scroll' became invalid because of a side effect silently adjust
8425 * it. */
8426 else if (curwin->w_p_scr <= 0)
8427 curwin->w_p_scr = 1;
8428 else /* curwin->w_p_scr > curwin->w_height */
8429 curwin->w_p_scr = curwin->w_height;
8430 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008431 if (p_hi < 0)
8432 {
8433 errmsg = e_positive;
8434 p_hi = 0;
8435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 if (p_report < 0)
8437 {
8438 errmsg = e_positive;
8439 p_report = 1;
8440 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008441 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442 {
8443 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8444 p_sj = Rows / 2;
8445 else
8446 {
8447 errmsg = e_scroll;
8448 p_sj = 1;
8449 }
8450 }
8451 if (p_so < 0 && full_screen)
8452 {
8453 errmsg = e_scroll;
8454 p_so = 0;
8455 }
8456 if (p_siso < 0 && full_screen)
8457 {
8458 errmsg = e_positive;
8459 p_siso = 0;
8460 }
8461#ifdef FEAT_CMDWIN
8462 if (p_cwh < 1)
8463 {
8464 errmsg = e_positive;
8465 p_cwh = 1;
8466 }
8467#endif
8468 if (p_ut < 0)
8469 {
8470 errmsg = e_positive;
8471 p_ut = 2000;
8472 }
8473 if (p_ss < 0)
8474 {
8475 errmsg = e_positive;
8476 p_ss = 0;
8477 }
8478
8479 /* May set global value for local option. */
8480 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8481 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8482
8483 options[opt_idx].flags |= P_WAS_SET;
8484
8485 comp_col(); /* in case 'columns' or 'ls' changed */
8486 if (curwin->w_curswant != MAXCOL)
8487 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8488 check_redraw(options[opt_idx].flags);
8489
8490 return errmsg;
8491}
8492
8493/*
8494 * Called after an option changed: check if something needs to be redrawn.
8495 */
8496 static void
8497check_redraw(flags)
8498 long_u flags;
8499{
8500 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8501 int clear = (flags & P_RCLR) == P_RCLR;
8502 int all = ((flags & P_RALL) == P_RALL || clear);
8503
8504#ifdef FEAT_WINDOWS
8505 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8506 status_redraw_all();
8507#endif
8508
8509 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8510 changed_window_setting();
8511 if (flags & P_RBUF)
8512 redraw_curbuf_later(NOT_VALID);
8513 if (clear)
8514 redraw_all_later(CLEAR);
8515 else if (all)
8516 redraw_all_later(NOT_VALID);
8517}
8518
8519/*
8520 * Find index for option 'arg'.
8521 * Return -1 if not found.
8522 */
8523 static int
8524findoption(arg)
8525 char_u *arg;
8526{
8527 int opt_idx;
8528 char *s, *p;
8529 static short quick_tab[27] = {0, 0}; /* quick access table */
8530 int is_term_opt;
8531
8532 /*
8533 * For first call: Initialize the quick-access table.
8534 * It contains the index for the first option that starts with a certain
8535 * letter. There are 26 letters, plus the first "t_" option.
8536 */
8537 if (quick_tab[1] == 0)
8538 {
8539 p = options[0].fullname;
8540 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8541 {
8542 if (s[0] != p[0])
8543 {
8544 if (s[0] == 't' && s[1] == '_')
8545 quick_tab[26] = opt_idx;
8546 else
8547 quick_tab[CharOrdLow(s[0])] = opt_idx;
8548 }
8549 p = s;
8550 }
8551 }
8552
8553 /*
8554 * Check for name starting with an illegal character.
8555 */
8556#ifdef EBCDIC
8557 if (!islower(arg[0]))
8558#else
8559 if (arg[0] < 'a' || arg[0] > 'z')
8560#endif
8561 return -1;
8562
8563 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8564 if (is_term_opt)
8565 opt_idx = quick_tab[26];
8566 else
8567 opt_idx = quick_tab[CharOrdLow(arg[0])];
8568 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8569 {
8570 if (STRCMP(arg, s) == 0) /* match full name */
8571 break;
8572 }
8573 if (s == NULL && !is_term_opt)
8574 {
8575 opt_idx = quick_tab[CharOrdLow(arg[0])];
8576 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8577 {
8578 s = options[opt_idx].shortname;
8579 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8580 break;
8581 s = NULL;
8582 }
8583 }
8584 if (s == NULL)
8585 opt_idx = -1;
8586 return opt_idx;
8587}
8588
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008589#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590/*
8591 * Get the value for an option.
8592 *
8593 * Returns:
8594 * Number or Toggle option: 1, *numval gets value.
8595 * String option: 0, *stringval gets allocated string.
8596 * Hidden Number or Toggle option: -1.
8597 * hidden String option: -2.
8598 * unknown option: -3.
8599 */
8600 int
8601get_option_value(name, numval, stringval, opt_flags)
8602 char_u *name;
8603 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008604 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 int opt_flags;
8606{
8607 int opt_idx;
8608 char_u *varp;
8609
8610 opt_idx = findoption(name);
8611 if (opt_idx < 0) /* unknown option */
8612 return -3;
8613
8614 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8615
8616 if (options[opt_idx].flags & P_STRING)
8617 {
8618 if (varp == NULL) /* hidden option */
8619 return -2;
8620 if (stringval != NULL)
8621 {
8622#ifdef FEAT_CRYPT
8623 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008624 if ((char_u **)varp == &curbuf->b_p_key
8625 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626 *stringval = vim_strsave((char_u *)"*****");
8627 else
8628#endif
8629 *stringval = vim_strsave(*(char_u **)(varp));
8630 }
8631 return 0;
8632 }
8633
8634 if (varp == NULL) /* hidden option */
8635 return -1;
8636 if (options[opt_idx].flags & P_NUM)
8637 *numval = *(long *)varp;
8638 else
8639 {
8640 /* Special case: 'modified' is b_changed, but we also want to consider
8641 * it set when 'ff' or 'fenc' changed. */
8642 if ((int *)varp == &curbuf->b_changed)
8643 *numval = curbufIsChanged();
8644 else
8645 *numval = *(int *)varp;
8646 }
8647 return 1;
8648}
8649#endif
8650
8651/*
8652 * Set the value of option "name".
8653 * Use "string" for string options, use "number" for other options.
8654 */
8655 void
8656set_option_value(name, number, string, opt_flags)
8657 char_u *name;
8658 long number;
8659 char_u *string;
8660 int opt_flags; /* OPT_LOCAL or 0 (both) */
8661{
8662 int opt_idx;
8663 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008664 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665
8666 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008667 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 EMSG2(_("E355: Unknown option: %s"), name);
8669 else
8670 {
8671 flags = options[opt_idx].flags;
8672#ifdef HAVE_SANDBOX
8673 /* Disallow changing some options in the sandbox */
8674 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008675 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008677 return;
8678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008680 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681 set_string_option(opt_idx, string, opt_flags);
8682 else
8683 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008684 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 if (varp != NULL) /* hidden option is not changed */
8686 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008687 if (number == 0 && string != NULL)
8688 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008689 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008690
8691 /* Either we are given a string or we are setting option
8692 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008693 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008694 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008695 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008696 {
8697 /* There's another character after zeros or the string
8698 * is empty. In both cases, we are trying to set a
8699 * num option using a string. */
8700 EMSG3(_("E521: Number required: &%s = '%s'"),
8701 name, string);
8702 return; /* do nothing as we hit an error */
8703
8704 }
8705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008707 (void)set_num_option(opt_idx, varp, number,
8708 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008710 (void)set_bool_option(opt_idx, varp, (int)number,
8711 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712 }
8713 }
8714 }
8715}
8716
8717/*
8718 * Get the terminal code for a terminal option.
8719 * Returns NULL when not found.
8720 */
8721 char_u *
8722get_term_code(tname)
8723 char_u *tname;
8724{
8725 int opt_idx;
8726 char_u *varp;
8727
8728 if (tname[0] != 't' || tname[1] != '_' ||
8729 tname[2] == NUL || tname[3] == NUL)
8730 return NULL;
8731 if ((opt_idx = findoption(tname)) >= 0)
8732 {
8733 varp = get_varp(&(options[opt_idx]));
8734 if (varp != NULL)
8735 varp = *(char_u **)(varp);
8736 return varp;
8737 }
8738 return find_termcode(tname + 2);
8739}
8740
8741 char_u *
8742get_highlight_default()
8743{
8744 int i;
8745
8746 i = findoption((char_u *)"hl");
8747 if (i >= 0)
8748 return options[i].def_val[VI_DEFAULT];
8749 return (char_u *)NULL;
8750}
8751
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008752#if defined(FEAT_MBYTE) || defined(PROTO)
8753 char_u *
8754get_encoding_default()
8755{
8756 int i;
8757
8758 i = findoption((char_u *)"enc");
8759 if (i >= 0)
8760 return options[i].def_val[VI_DEFAULT];
8761 return (char_u *)NULL;
8762}
8763#endif
8764
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765/*
8766 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8767 */
8768 static int
8769find_key_option(arg)
8770 char_u *arg;
8771{
8772 int key;
8773 int modifiers;
8774
8775 /*
8776 * Don't use get_special_key_code() for t_xx, we don't want it to call
8777 * add_termcap_entry().
8778 */
8779 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8780 key = TERMCAP2KEY(arg[2], arg[3]);
8781 else
8782 {
8783 --arg; /* put arg at the '<' */
8784 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008785 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 if (modifiers) /* can't handle modifiers here */
8787 key = 0;
8788 }
8789 return key;
8790}
8791
8792/*
8793 * if 'all' == 0: show changed options
8794 * if 'all' == 1: show all normal options
8795 * if 'all' == 2: show all terminal options
8796 */
8797 static void
8798showoptions(all, opt_flags)
8799 int all;
8800 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8801{
8802 struct vimoption *p;
8803 int col;
8804 int isterm;
8805 char_u *varp;
8806 struct vimoption **items;
8807 int item_count;
8808 int run;
8809 int row, rows;
8810 int cols;
8811 int i;
8812 int len;
8813
8814#define INC 20
8815#define GAP 3
8816
8817 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8818 PARAM_COUNT));
8819 if (items == NULL)
8820 return;
8821
8822 /* Highlight title */
8823 if (all == 2)
8824 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8825 else if (opt_flags & OPT_GLOBAL)
8826 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8827 else if (opt_flags & OPT_LOCAL)
8828 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8829 else
8830 MSG_PUTS_TITLE(_("\n--- Options ---"));
8831
8832 /*
8833 * do the loop two times:
8834 * 1. display the short items
8835 * 2. display the long items (only strings and numbers)
8836 */
8837 for (run = 1; run <= 2 && !got_int; ++run)
8838 {
8839 /*
8840 * collect the items in items[]
8841 */
8842 item_count = 0;
8843 for (p = &options[0]; p->fullname != NULL; p++)
8844 {
8845 varp = NULL;
8846 isterm = istermoption(p);
8847 if (opt_flags != 0)
8848 {
8849 if (p->indir != PV_NONE && !isterm)
8850 varp = get_varp_scope(p, opt_flags);
8851 }
8852 else
8853 varp = get_varp(p);
8854 if (varp != NULL
8855 && ((all == 2 && isterm)
8856 || (all == 1 && !isterm)
8857 || (all == 0 && !optval_default(p, varp))))
8858 {
8859 if (p->flags & P_BOOL)
8860 len = 1; /* a toggle option fits always */
8861 else
8862 {
8863 option_value2string(p, opt_flags);
8864 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8865 }
8866 if ((len <= INC - GAP && run == 1) ||
8867 (len > INC - GAP && run == 2))
8868 items[item_count++] = p;
8869 }
8870 }
8871
8872 /*
8873 * display the items
8874 */
8875 if (run == 1)
8876 {
8877 cols = (Columns + GAP - 3) / INC;
8878 if (cols == 0)
8879 cols = 1;
8880 rows = (item_count + cols - 1) / cols;
8881 }
8882 else /* run == 2 */
8883 rows = item_count;
8884 for (row = 0; row < rows && !got_int; ++row)
8885 {
8886 msg_putchar('\n'); /* go to next line */
8887 if (got_int) /* 'q' typed in more */
8888 break;
8889 col = 0;
8890 for (i = row; i < item_count; i += rows)
8891 {
8892 msg_col = col; /* make columns */
8893 showoneopt(items[i], opt_flags);
8894 col += INC;
8895 }
8896 out_flush();
8897 ui_breakcheck();
8898 }
8899 }
8900 vim_free(items);
8901}
8902
8903/*
8904 * Return TRUE if option "p" has its default value.
8905 */
8906 static int
8907optval_default(p, varp)
8908 struct vimoption *p;
8909 char_u *varp;
8910{
8911 int dvi;
8912
8913 if (varp == NULL)
8914 return TRUE; /* hidden option is always at default */
8915 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8916 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008917 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008919 /* the cast to long is required for Manx C, long_i is
8920 * needed for MSVC */
8921 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 /* P_STRING */
8923 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8924}
8925
8926/*
8927 * showoneopt: show the value of one option
8928 * must not be called with a hidden option!
8929 */
8930 static void
8931showoneopt(p, opt_flags)
8932 struct vimoption *p;
8933 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8934{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008935 char_u *varp;
8936 int save_silent = silent_mode;
8937
8938 silent_mode = FALSE;
8939 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940
8941 varp = get_varp_scope(p, opt_flags);
8942
8943 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8944 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8945 ? !curbufIsChanged() : !*(int *)varp))
8946 MSG_PUTS("no");
8947 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8948 MSG_PUTS("--");
8949 else
8950 MSG_PUTS(" ");
8951 MSG_PUTS(p->fullname);
8952 if (!(p->flags & P_BOOL))
8953 {
8954 msg_putchar('=');
8955 /* put value string in NameBuff */
8956 option_value2string(p, opt_flags);
8957 msg_outtrans(NameBuff);
8958 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008959
8960 silent_mode = save_silent;
8961 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962}
8963
8964/*
8965 * Write modified options as ":set" commands to a file.
8966 *
8967 * There are three values for "opt_flags":
8968 * OPT_GLOBAL: Write global option values and fresh values of
8969 * buffer-local options (used for start of a session
8970 * file).
8971 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8972 * curwin (used for a vimrc file).
8973 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8974 * and local values for window-local options of
8975 * curwin. Local values are also written when at the
8976 * default value, because a modeline or autocommand
8977 * may have set them when doing ":edit file" and the
8978 * user has set them back at the default or fresh
8979 * value.
8980 * When "local_only" is TRUE, don't write fresh
8981 * values, only local values (for ":mkview").
8982 * (fresh value = value used for a new buffer or window for a local option).
8983 *
8984 * Return FAIL on error, OK otherwise.
8985 */
8986 int
8987makeset(fd, opt_flags, local_only)
8988 FILE *fd;
8989 int opt_flags;
8990 int local_only;
8991{
8992 struct vimoption *p;
8993 char_u *varp; /* currently used value */
8994 char_u *varp_fresh; /* local value */
8995 char_u *varp_local = NULL; /* fresh value */
8996 char *cmd;
8997 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008998 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999
9000 /*
9001 * The options that don't have a default (terminal name, columns, lines)
9002 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009003 * Do the loop over "options[]" twice: once for options with the
9004 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009005 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009006 for (pri = 1; pri >= 0; --pri)
9007 {
9008 for (p = &options[0]; !istermoption(p); p++)
9009 if (!(p->flags & P_NO_MKRC)
9010 && !istermoption(p)
9011 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009012 {
9013 /* skip global option when only doing locals */
9014 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9015 continue;
9016
9017 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9018 * file, they are always buffer-specific. */
9019 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9020 continue;
9021
9022 /* Global values are only written when not at the default value. */
9023 varp = get_varp_scope(p, opt_flags);
9024 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9025 continue;
9026
9027 round = 2;
9028 if (p->indir != PV_NONE)
9029 {
9030 if (p->var == VAR_WIN)
9031 {
9032 /* skip window-local option when only doing globals */
9033 if (!(opt_flags & OPT_LOCAL))
9034 continue;
9035 /* When fresh value of window-local option is not at the
9036 * default, need to write it too. */
9037 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9038 {
9039 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9040 if (!optval_default(p, varp_fresh))
9041 {
9042 round = 1;
9043 varp_local = varp;
9044 varp = varp_fresh;
9045 }
9046 }
9047 }
9048 }
9049
9050 /* Round 1: fresh value for window-local options.
9051 * Round 2: other values */
9052 for ( ; round <= 2; varp = varp_local, ++round)
9053 {
9054 if (round == 1 || (opt_flags & OPT_GLOBAL))
9055 cmd = "set";
9056 else
9057 cmd = "setlocal";
9058
9059 if (p->flags & P_BOOL)
9060 {
9061 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9062 return FAIL;
9063 }
9064 else if (p->flags & P_NUM)
9065 {
9066 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9067 return FAIL;
9068 }
9069 else /* P_STRING */
9070 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009071#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9072 int do_endif = FALSE;
9073
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 /* Don't set 'syntax' and 'filetype' again if the value is
9075 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009076 if (
9077# if defined(FEAT_SYN_HL)
9078 p->indir == PV_SYN
9079# if defined(FEAT_AUTOCMD)
9080 ||
9081# endif
9082# endif
9083# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009084 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009085# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009086 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 {
9088 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9089 *(char_u **)(varp)) < 0
9090 || put_eol(fd) < 0)
9091 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009092 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009093 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9096 (p->flags & P_EXPAND) != 0) == FAIL)
9097 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009098#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9099 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 {
9101 if (put_line(fd, "endif") == FAIL)
9102 return FAIL;
9103 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009104#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 }
9106 }
9107 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009108 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 return OK;
9110}
9111
9112#if defined(FEAT_FOLDING) || defined(PROTO)
9113/*
9114 * Generate set commands for the local fold options only. Used when
9115 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9116 */
9117 int
9118makefoldset(fd)
9119 FILE *fd;
9120{
9121 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9122# ifdef FEAT_EVAL
9123 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9124 == FAIL
9125# endif
9126 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9127 == FAIL
9128 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9129 == FAIL
9130 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9131 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9132 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9133 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9134 )
9135 return FAIL;
9136
9137 return OK;
9138}
9139#endif
9140
9141 static int
9142put_setstring(fd, cmd, name, valuep, expand)
9143 FILE *fd;
9144 char *cmd;
9145 char *name;
9146 char_u **valuep;
9147 int expand;
9148{
9149 char_u *s;
9150 char_u buf[MAXPATHL];
9151
9152 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9153 return FAIL;
9154 if (*valuep != NULL)
9155 {
9156 /* Output 'pastetoggle' as key names. For other
9157 * options some characters have to be escaped with
9158 * CTRL-V or backslash */
9159 if (valuep == &p_pt)
9160 {
9161 s = *valuep;
9162 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009163 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164 return FAIL;
9165 }
9166 else if (expand)
9167 {
9168 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9169 if (put_escstr(fd, buf, 2) == FAIL)
9170 return FAIL;
9171 }
9172 else if (put_escstr(fd, *valuep, 2) == FAIL)
9173 return FAIL;
9174 }
9175 if (put_eol(fd) < 0)
9176 return FAIL;
9177 return OK;
9178}
9179
9180 static int
9181put_setnum(fd, cmd, name, valuep)
9182 FILE *fd;
9183 char *cmd;
9184 char *name;
9185 long *valuep;
9186{
9187 long wc;
9188
9189 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9190 return FAIL;
9191 if (wc_use_keyname((char_u *)valuep, &wc))
9192 {
9193 /* print 'wildchar' and 'wildcharm' as a key name */
9194 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9195 return FAIL;
9196 }
9197 else if (fprintf(fd, "%ld", *valuep) < 0)
9198 return FAIL;
9199 if (put_eol(fd) < 0)
9200 return FAIL;
9201 return OK;
9202}
9203
9204 static int
9205put_setbool(fd, cmd, name, value)
9206 FILE *fd;
9207 char *cmd;
9208 char *name;
9209 int value;
9210{
Bram Moolenaar893de922007-10-02 18:40:57 +00009211 if (value < 0) /* global/local option using global value */
9212 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9214 || put_eol(fd) < 0)
9215 return FAIL;
9216 return OK;
9217}
9218
9219/*
9220 * Clear all the terminal options.
9221 * If the option has been allocated, free the memory.
9222 * Terminal options are never hidden or indirect.
9223 */
9224 void
9225clear_termoptions()
9226{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 /*
9228 * Reset a few things before clearing the old options. This may cause
9229 * outputting a few things that the terminal doesn't understand, but the
9230 * screen will be cleared later, so this is OK.
9231 */
9232#ifdef FEAT_MOUSE_TTY
9233 mch_setmouse(FALSE); /* switch mouse off */
9234#endif
9235#ifdef FEAT_TITLE
9236 mch_restore_title(3); /* restore window titles */
9237#endif
9238#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9239 /* When starting the GUI close the display opened for the clipboard.
9240 * After restoring the title, because that will need the display. */
9241 if (gui.starting)
9242 clear_xterm_clip();
9243#endif
9244#ifdef WIN3264
9245 /*
9246 * Check if this is allowed now.
9247 */
9248 if (can_end_termcap_mode(FALSE) == TRUE)
9249#endif
9250 stoptermcap(); /* stop termcap mode */
9251
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009252 free_termoptions();
9253}
9254
9255 void
9256free_termoptions()
9257{
9258 struct vimoption *p;
9259
Bram Moolenaar071d4272004-06-13 20:20:40 +00009260 for (p = &options[0]; p->fullname != NULL; p++)
9261 if (istermoption(p))
9262 {
9263 if (p->flags & P_ALLOCED)
9264 free_string_option(*(char_u **)(p->var));
9265 if (p->flags & P_DEF_ALLOCED)
9266 free_string_option(p->def_val[VI_DEFAULT]);
9267 *(char_u **)(p->var) = empty_option;
9268 p->def_val[VI_DEFAULT] = empty_option;
9269 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9270 }
9271 clear_termcodes();
9272}
9273
9274/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009275 * Free the string for one term option, if it was allocated.
9276 * Set the string to empty_option and clear allocated flag.
9277 * "var" points to the option value.
9278 */
9279 void
9280free_one_termoption(var)
9281 char_u *var;
9282{
9283 struct vimoption *p;
9284
9285 for (p = &options[0]; p->fullname != NULL; p++)
9286 if (p->var == var)
9287 {
9288 if (p->flags & P_ALLOCED)
9289 free_string_option(*(char_u **)(p->var));
9290 *(char_u **)(p->var) = empty_option;
9291 p->flags &= ~P_ALLOCED;
9292 break;
9293 }
9294}
9295
9296/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297 * Set the terminal option defaults to the current value.
9298 * Used after setting the terminal name.
9299 */
9300 void
9301set_term_defaults()
9302{
9303 struct vimoption *p;
9304
9305 for (p = &options[0]; p->fullname != NULL; p++)
9306 {
9307 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9308 {
9309 if (p->flags & P_DEF_ALLOCED)
9310 {
9311 free_string_option(p->def_val[VI_DEFAULT]);
9312 p->flags &= ~P_DEF_ALLOCED;
9313 }
9314 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9315 if (p->flags & P_ALLOCED)
9316 {
9317 p->flags |= P_DEF_ALLOCED;
9318 p->flags &= ~P_ALLOCED; /* don't free the value now */
9319 }
9320 }
9321 }
9322}
9323
9324/*
9325 * return TRUE if 'p' starts with 't_'
9326 */
9327 static int
9328istermoption(p)
9329 struct vimoption *p;
9330{
9331 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9332}
9333
9334/*
9335 * Compute columns for ruler and shown command. 'sc_col' is also used to
9336 * decide what the maximum length of a message on the status line can be.
9337 * If there is a status line for the last window, 'sc_col' is independent
9338 * of 'ru_col'.
9339 */
9340
9341#define COL_RULER 17 /* columns needed by standard ruler */
9342
9343 void
9344comp_col()
9345{
9346#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9347 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9348
9349 sc_col = 0;
9350 ru_col = 0;
9351 if (p_ru)
9352 {
9353#ifdef FEAT_STL_OPT
9354 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9355#else
9356 ru_col = COL_RULER + 1;
9357#endif
9358 /* no last status line, adjust sc_col */
9359 if (!last_has_status)
9360 sc_col = ru_col;
9361 }
9362 if (p_sc)
9363 {
9364 sc_col += SHOWCMD_COLS;
9365 if (!p_ru || last_has_status) /* no need for separating space */
9366 ++sc_col;
9367 }
9368 sc_col = Columns - sc_col;
9369 ru_col = Columns - ru_col;
9370 if (sc_col <= 0) /* screen too narrow, will become a mess */
9371 sc_col = 1;
9372 if (ru_col <= 0)
9373 ru_col = 1;
9374#else
9375 sc_col = Columns;
9376 ru_col = Columns;
9377#endif
9378}
9379
9380/*
9381 * Get pointer to option variable, depending on local or global scope.
9382 */
9383 static char_u *
9384get_varp_scope(p, opt_flags)
9385 struct vimoption *p;
9386 int opt_flags;
9387{
9388 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9389 {
9390 if (p->var == VAR_WIN)
9391 return (char_u *)GLOBAL_WO(get_varp(p));
9392 return p->var;
9393 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009394 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009395 {
9396 switch ((int)p->indir)
9397 {
9398#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009399 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9400 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9401 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009403 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9404 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9405 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009406 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009407 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009409 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9410 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411#endif
9412#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009413 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9414 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009415#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009416#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9417 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9418#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009419#if defined(FEAT_CRYPT)
9420 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9421#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009422#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009423 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009424#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 }
9426 return NULL; /* "cannot happen" */
9427 }
9428 return get_varp(p);
9429}
9430
9431/*
9432 * Get pointer to option variable.
9433 */
9434 static char_u *
9435get_varp(p)
9436 struct vimoption *p;
9437{
9438 /* hidden option, always return NULL */
9439 if (p->var == NULL)
9440 return NULL;
9441
9442 switch ((int)p->indir)
9443 {
9444 case PV_NONE: return p->var;
9445
9446 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009447 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009448 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009449 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009450 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009451 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009452 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009453 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009455 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9457#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009458 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009460 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9462#endif
9463#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009464 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009466 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9468#endif
9469#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009470 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009471 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009472 case PV_GP: return *curbuf->b_p_gp != NUL
9473 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9474 case PV_MP: return *curbuf->b_p_mp != NUL
9475 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009477#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9478 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9479 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9480#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009481#if defined(FEAT_CRYPT)
9482 case PV_CM: return *curbuf->b_p_cm != NUL
9483 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9484#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009485#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009486 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009487 ? (char_u *)&(curwin->w_p_stl) : p->var;
9488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489
9490#ifdef FEAT_ARABIC
9491 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9492#endif
9493 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009494#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009495 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9496#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009497#ifdef FEAT_SYN_HL
9498 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9499 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009500 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009501#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009502#ifdef FEAT_DIFF
9503 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9504#endif
9505#ifdef FEAT_FOLDING
9506 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9507 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9508 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9509 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9510 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9511 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9512 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9513# ifdef FEAT_EVAL
9514 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9515 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9516# endif
9517 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9518#endif
9519 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009520 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009521#ifdef FEAT_LINEBREAK
9522 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9523#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009524#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009525 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9526#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009527#ifdef FEAT_VERTSPLIT
9528 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9531 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9532#endif
9533#ifdef FEAT_RIGHTLEFT
9534 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9535 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9536#endif
9537 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9538 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9539#ifdef FEAT_LINEBREAK
9540 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9541#endif
9542#ifdef FEAT_SCROLLBIND
9543 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9544#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009545#ifdef FEAT_CURSORBIND
9546 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9547#endif
9548#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02009549 case PV_CONCEAL: return (char_u *)&(curwin->w_p_conc);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551
9552 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9553 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9554#ifdef FEAT_MBYTE
9555 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9556#endif
9557#if defined(FEAT_QUICKFIX)
9558 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9559 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9560#endif
9561 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9562 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9563#ifdef FEAT_CINDENT
9564 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9565 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9566 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9567#endif
9568#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9569 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9570#endif
9571#ifdef FEAT_COMMENTS
9572 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9573#endif
9574#ifdef FEAT_FOLDING
9575 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9576#endif
9577#ifdef FEAT_INS_EXPAND
9578 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9579#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009580#ifdef FEAT_COMPL_FUNC
9581 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009582 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009584 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9585 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9586#ifdef FEAT_MBYTE
9587 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9588#endif
9589 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9590#ifdef FEAT_AUTOCMD
9591 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9592#endif
9593 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009594 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009595 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9596 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9597 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9598 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9599#ifdef FEAT_FIND_ID
9600# ifdef FEAT_EVAL
9601 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9602# endif
9603#endif
9604#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9605 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9606 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9607#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009608#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009609 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611#ifdef FEAT_CRYPT
9612 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9613#endif
9614#ifdef FEAT_LISP
9615 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9616#endif
9617 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9618 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9619 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9620 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9621 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9622#ifdef FEAT_OSFILETYPE
9623 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9624#endif
9625 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009626#ifdef FEAT_TEXTOBJ
9627 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9630#ifdef FEAT_SMARTINDENT
9631 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9632#endif
9633#ifndef SHORT_FNAME
9634 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9635#endif
9636 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9637#ifdef FEAT_SEARCHPATH
9638 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9639#endif
9640 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9641#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009642 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009643 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9644#endif
9645#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009646 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9647 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9648 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009649#endif
9650 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9651 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9652 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9653 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009654#ifdef FEAT_PERSISTENT_UNDO
9655 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9658#ifdef FEAT_KEYMAP
9659 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9660#endif
9661 default: EMSG(_("E356: get_varp ERROR"));
9662 }
9663 /* always return a valid pointer to avoid a crash! */
9664 return (char_u *)&(curbuf->b_p_wm);
9665}
9666
9667/*
9668 * Get the value of 'equalprg', either the buffer-local one or the global one.
9669 */
9670 char_u *
9671get_equalprg()
9672{
9673 if (*curbuf->b_p_ep == NUL)
9674 return p_ep;
9675 return curbuf->b_p_ep;
9676}
9677
9678#if defined(FEAT_WINDOWS) || defined(PROTO)
9679/*
9680 * Copy options from one window to another.
9681 * Used when splitting a window.
9682 */
9683 void
9684win_copy_options(wp_from, wp_to)
9685 win_T *wp_from;
9686 win_T *wp_to;
9687{
9688 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9689 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9690# ifdef FEAT_RIGHTLEFT
9691# ifdef FEAT_FKMAP
9692 /* Is this right? */
9693 wp_to->w_farsi = wp_from->w_farsi;
9694# endif
9695# endif
9696}
9697#endif
9698
9699/*
9700 * Copy the options from one winopt_T to another.
9701 * Doesn't free the old option values in "to", use clear_winopt() for that.
9702 * The 'scroll' option is not copied, because it depends on the window height.
9703 * The 'previewwindow' option is reset, there can be only one preview window.
9704 */
9705 void
9706copy_winopt(from, to)
9707 winopt_T *from;
9708 winopt_T *to;
9709{
9710#ifdef FEAT_ARABIC
9711 to->wo_arab = from->wo_arab;
9712#endif
9713 to->wo_list = from->wo_list;
9714 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009715 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009716#ifdef FEAT_LINEBREAK
9717 to->wo_nuw = from->wo_nuw;
9718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719#ifdef FEAT_RIGHTLEFT
9720 to->wo_rl = from->wo_rl;
9721 to->wo_rlc = vim_strsave(from->wo_rlc);
9722#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009723#ifdef FEAT_STL_OPT
9724 to->wo_stl = vim_strsave(from->wo_stl);
9725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 to->wo_wrap = from->wo_wrap;
9727#ifdef FEAT_LINEBREAK
9728 to->wo_lbr = from->wo_lbr;
9729#endif
9730#ifdef FEAT_SCROLLBIND
9731 to->wo_scb = from->wo_scb;
9732#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009733#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009734 to->wo_spell = from->wo_spell;
9735#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009736#ifdef FEAT_SYN_HL
9737 to->wo_cuc = from->wo_cuc;
9738 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009739 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741#ifdef FEAT_DIFF
9742 to->wo_diff = from->wo_diff;
9743#endif
9744#ifdef FEAT_FOLDING
9745 to->wo_fdc = from->wo_fdc;
9746 to->wo_fen = from->wo_fen;
9747 to->wo_fdi = vim_strsave(from->wo_fdi);
9748 to->wo_fml = from->wo_fml;
9749 to->wo_fdl = from->wo_fdl;
9750 to->wo_fdm = vim_strsave(from->wo_fdm);
9751 to->wo_fdn = from->wo_fdn;
9752# ifdef FEAT_EVAL
9753 to->wo_fde = vim_strsave(from->wo_fde);
9754 to->wo_fdt = vim_strsave(from->wo_fdt);
9755# endif
9756 to->wo_fmr = vim_strsave(from->wo_fmr);
9757#endif
9758 check_winopt(to); /* don't want NULL pointers */
9759}
9760
9761/*
9762 * Check string options in a window for a NULL value.
9763 */
9764 void
9765check_win_options(win)
9766 win_T *win;
9767{
9768 check_winopt(&win->w_onebuf_opt);
9769 check_winopt(&win->w_allbuf_opt);
9770}
9771
9772/*
9773 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9774 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775 void
9776check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009777 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009778{
9779#ifdef FEAT_FOLDING
9780 check_string_option(&wop->wo_fdi);
9781 check_string_option(&wop->wo_fdm);
9782# ifdef FEAT_EVAL
9783 check_string_option(&wop->wo_fde);
9784 check_string_option(&wop->wo_fdt);
9785# endif
9786 check_string_option(&wop->wo_fmr);
9787#endif
9788#ifdef FEAT_RIGHTLEFT
9789 check_string_option(&wop->wo_rlc);
9790#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009791#ifdef FEAT_STL_OPT
9792 check_string_option(&wop->wo_stl);
9793#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009794#ifdef FEAT_SYN_HL
9795 check_string_option(&wop->wo_cc);
9796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797}
9798
9799/*
9800 * Free the allocated memory inside a winopt_T.
9801 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802 void
9803clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009804 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805{
9806#ifdef FEAT_FOLDING
9807 clear_string_option(&wop->wo_fdi);
9808 clear_string_option(&wop->wo_fdm);
9809# ifdef FEAT_EVAL
9810 clear_string_option(&wop->wo_fde);
9811 clear_string_option(&wop->wo_fdt);
9812# endif
9813 clear_string_option(&wop->wo_fmr);
9814#endif
9815#ifdef FEAT_RIGHTLEFT
9816 clear_string_option(&wop->wo_rlc);
9817#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009818#ifdef FEAT_STL_OPT
9819 clear_string_option(&wop->wo_stl);
9820#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009821#ifdef FEAT_SYN_HL
9822 clear_string_option(&wop->wo_cc);
9823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824}
9825
9826/*
9827 * Copy global option values to local options for one buffer.
9828 * Used when creating a new buffer and sometimes when entering a buffer.
9829 * flags:
9830 * BCO_ENTER We will enter the buf buffer.
9831 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9832 * appropriate.
9833 * BCO_NOHELP Don't copy the values to a help buffer.
9834 */
9835 void
9836buf_copy_options(buf, flags)
9837 buf_T *buf;
9838 int flags;
9839{
9840 int should_copy = TRUE;
9841 char_u *save_p_isk = NULL; /* init for GCC */
9842 int dont_do_help;
9843 int did_isk = FALSE;
9844
9845 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009846 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847 */
9848 if (buf == NULL || !buf_valid(buf))
9849 return;
9850
9851 /*
9852 * Skip this when the option defaults have not been set yet. Happens when
9853 * main() allocates the first buffer.
9854 */
9855 if (p_cpo != NULL)
9856 {
9857 /*
9858 * Always copy when entering and 'cpo' contains 'S'.
9859 * Don't copy when already initialized.
9860 * Don't copy when 'cpo' contains 's' and not entering.
9861 * 'S' BCO_ENTER initialized 's' should_copy
9862 * yes yes X X TRUE
9863 * yes no yes X FALSE
9864 * no X yes X FALSE
9865 * X no no yes FALSE
9866 * X no no no TRUE
9867 * no yes no X TRUE
9868 */
9869 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9870 && (buf->b_p_initialized
9871 || (!(flags & BCO_ENTER)
9872 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9873 should_copy = FALSE;
9874
9875 if (should_copy || (flags & BCO_ALWAYS))
9876 {
9877 /* Don't copy the options specific to a help buffer when
9878 * BCO_NOHELP is given or the options were initialized already
9879 * (jumping back to a help file with CTRL-T or CTRL-O) */
9880 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9881 || buf->b_p_initialized;
9882 if (dont_do_help) /* don't free b_p_isk */
9883 {
9884 save_p_isk = buf->b_p_isk;
9885 buf->b_p_isk = NULL;
9886 }
9887 /*
9888 * Always free the allocated strings.
9889 * If not already initialized, set 'readonly' and copy 'fileformat'.
9890 */
9891 if (!buf->b_p_initialized)
9892 {
9893 free_buf_options(buf, TRUE);
9894 buf->b_p_ro = FALSE; /* don't copy readonly */
9895 buf->b_p_tx = p_tx;
9896#ifdef FEAT_MBYTE
9897 buf->b_p_fenc = vim_strsave(p_fenc);
9898#endif
9899 buf->b_p_ff = vim_strsave(p_ff);
9900#if defined(FEAT_QUICKFIX)
9901 buf->b_p_bh = empty_option;
9902 buf->b_p_bt = empty_option;
9903#endif
9904 }
9905 else
9906 free_buf_options(buf, FALSE);
9907
9908 buf->b_p_ai = p_ai;
9909 buf->b_p_ai_nopaste = p_ai_nopaste;
9910 buf->b_p_sw = p_sw;
9911 buf->b_p_tw = p_tw;
9912 buf->b_p_tw_nopaste = p_tw_nopaste;
9913 buf->b_p_tw_nobin = p_tw_nobin;
9914 buf->b_p_wm = p_wm;
9915 buf->b_p_wm_nopaste = p_wm_nopaste;
9916 buf->b_p_wm_nobin = p_wm_nobin;
9917 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009918#ifdef FEAT_MBYTE
9919 buf->b_p_bomb = p_bomb;
9920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 buf->b_p_et = p_et;
9922 buf->b_p_et_nobin = p_et_nobin;
9923 buf->b_p_ml = p_ml;
9924 buf->b_p_ml_nobin = p_ml_nobin;
9925 buf->b_p_inf = p_inf;
9926 buf->b_p_swf = p_swf;
9927#ifdef FEAT_INS_EXPAND
9928 buf->b_p_cpt = vim_strsave(p_cpt);
9929#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009930#ifdef FEAT_COMPL_FUNC
9931 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009932 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934 buf->b_p_sts = p_sts;
9935 buf->b_p_sts_nopaste = p_sts_nopaste;
9936#ifndef SHORT_FNAME
9937 buf->b_p_sn = p_sn;
9938#endif
9939#ifdef FEAT_COMMENTS
9940 buf->b_p_com = vim_strsave(p_com);
9941#endif
9942#ifdef FEAT_FOLDING
9943 buf->b_p_cms = vim_strsave(p_cms);
9944#endif
9945 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009946 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947 buf->b_p_nf = vim_strsave(p_nf);
9948 buf->b_p_mps = vim_strsave(p_mps);
9949#ifdef FEAT_SMARTINDENT
9950 buf->b_p_si = p_si;
9951#endif
9952 buf->b_p_ci = p_ci;
9953#ifdef FEAT_CINDENT
9954 buf->b_p_cin = p_cin;
9955 buf->b_p_cink = vim_strsave(p_cink);
9956 buf->b_p_cino = vim_strsave(p_cino);
9957#endif
9958#ifdef FEAT_AUTOCMD
9959 /* Don't copy 'filetype', it must be detected */
9960 buf->b_p_ft = empty_option;
9961#endif
9962#ifdef FEAT_OSFILETYPE
9963 buf->b_p_oft = vim_strsave(p_oft);
9964#endif
9965 buf->b_p_pi = p_pi;
9966#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9967 buf->b_p_cinw = vim_strsave(p_cinw);
9968#endif
9969#ifdef FEAT_LISP
9970 buf->b_p_lisp = p_lisp;
9971#endif
9972#ifdef FEAT_SYN_HL
9973 /* Don't copy 'syntax', it must be set */
9974 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009975 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009976#endif
9977#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009978 buf->b_s.b_p_spc = vim_strsave(p_spf);
9979 (void)compile_cap_prog(&buf->b_s);
9980 buf->b_s.b_p_spf = vim_strsave(p_spf);
9981 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009982#endif
9983#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9984 buf->b_p_inde = vim_strsave(p_inde);
9985 buf->b_p_indk = vim_strsave(p_indk);
9986#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009987#if defined(FEAT_EVAL)
9988 buf->b_p_fex = vim_strsave(p_fex);
9989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990#ifdef FEAT_CRYPT
9991 buf->b_p_key = vim_strsave(p_key);
9992#endif
9993#ifdef FEAT_SEARCHPATH
9994 buf->b_p_sua = vim_strsave(p_sua);
9995#endif
9996#ifdef FEAT_KEYMAP
9997 buf->b_p_keymap = vim_strsave(p_keymap);
9998 buf->b_kmap_state |= KEYMAP_INIT;
9999#endif
10000 /* This isn't really an option, but copying the langmap and IME
10001 * state from the current buffer is better than resetting it. */
10002 buf->b_p_iminsert = p_iminsert;
10003 buf->b_p_imsearch = p_imsearch;
10004
10005 /* options that are normally global but also have a local value
10006 * are not copied, start using the global value */
10007 buf->b_p_ar = -1;
10008#ifdef FEAT_QUICKFIX
10009 buf->b_p_gp = empty_option;
10010 buf->b_p_mp = empty_option;
10011 buf->b_p_efm = empty_option;
10012#endif
10013 buf->b_p_ep = empty_option;
10014 buf->b_p_kp = empty_option;
10015 buf->b_p_path = empty_option;
10016 buf->b_p_tags = empty_option;
10017#ifdef FEAT_FIND_ID
10018 buf->b_p_def = empty_option;
10019 buf->b_p_inc = empty_option;
10020# ifdef FEAT_EVAL
10021 buf->b_p_inex = vim_strsave(p_inex);
10022# endif
10023#endif
10024#ifdef FEAT_INS_EXPAND
10025 buf->b_p_dict = empty_option;
10026 buf->b_p_tsr = empty_option;
10027#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010028#ifdef FEAT_TEXTOBJ
10029 buf->b_p_qe = vim_strsave(p_qe);
10030#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010031#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10032 buf->b_p_bexpr = empty_option;
10033#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010034#if defined(FEAT_CRYPT)
10035 buf->b_p_cm = empty_option;
10036#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010037#ifdef FEAT_PERSISTENT_UNDO
10038 buf->b_p_udf = p_udf;
10039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040
10041 /*
10042 * Don't copy the options set by ex_help(), use the saved values,
10043 * when going from a help buffer to a non-help buffer.
10044 * Don't touch these at all when BCO_NOHELP is used and going from
10045 * or to a help buffer.
10046 */
10047 if (dont_do_help)
10048 buf->b_p_isk = save_p_isk;
10049 else
10050 {
10051 buf->b_p_isk = vim_strsave(p_isk);
10052 did_isk = TRUE;
10053 buf->b_p_ts = p_ts;
10054 buf->b_help = FALSE;
10055#ifdef FEAT_QUICKFIX
10056 if (buf->b_p_bt[0] == 'h')
10057 clear_string_option(&buf->b_p_bt);
10058#endif
10059 buf->b_p_ma = p_ma;
10060 }
10061 }
10062
10063 /*
10064 * When the options should be copied (ignoring BCO_ALWAYS), set the
10065 * flag that indicates that the options have been initialized.
10066 */
10067 if (should_copy)
10068 buf->b_p_initialized = TRUE;
10069 }
10070
10071 check_buf_options(buf); /* make sure we don't have NULLs */
10072 if (did_isk)
10073 (void)buf_init_chartab(buf, FALSE);
10074}
10075
10076/*
10077 * Reset the 'modifiable' option and its default value.
10078 */
10079 void
10080reset_modifiable()
10081{
10082 int opt_idx;
10083
10084 curbuf->b_p_ma = FALSE;
10085 p_ma = FALSE;
10086 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010087 if (opt_idx >= 0)
10088 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010089}
10090
10091/*
10092 * Set the global value for 'iminsert' to the local value.
10093 */
10094 void
10095set_iminsert_global()
10096{
10097 p_iminsert = curbuf->b_p_iminsert;
10098}
10099
10100/*
10101 * Set the global value for 'imsearch' to the local value.
10102 */
10103 void
10104set_imsearch_global()
10105{
10106 p_imsearch = curbuf->b_p_imsearch;
10107}
10108
10109#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10110static int expand_option_idx = -1;
10111static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10112static int expand_option_flags = 0;
10113
10114 void
10115set_context_in_set_cmd(xp, arg, opt_flags)
10116 expand_T *xp;
10117 char_u *arg;
10118 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10119{
10120 int nextchar;
10121 long_u flags = 0; /* init for GCC */
10122 int opt_idx = 0; /* init for GCC */
10123 char_u *p;
10124 char_u *s;
10125 int is_term_option = FALSE;
10126 int key;
10127
10128 expand_option_flags = opt_flags;
10129
10130 xp->xp_context = EXPAND_SETTINGS;
10131 if (*arg == NUL)
10132 {
10133 xp->xp_pattern = arg;
10134 return;
10135 }
10136 p = arg + STRLEN(arg) - 1;
10137 if (*p == ' ' && *(p - 1) != '\\')
10138 {
10139 xp->xp_pattern = p + 1;
10140 return;
10141 }
10142 while (p > arg)
10143 {
10144 s = p;
10145 /* count number of backslashes before ' ' or ',' */
10146 if (*p == ' ' || *p == ',')
10147 {
10148 while (s > arg && *(s - 1) == '\\')
10149 --s;
10150 }
10151 /* break at a space with an even number of backslashes */
10152 if (*p == ' ' && ((p - s) & 1) == 0)
10153 {
10154 ++p;
10155 break;
10156 }
10157 --p;
10158 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010159 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 {
10161 xp->xp_context = EXPAND_BOOL_SETTINGS;
10162 p += 2;
10163 }
10164 if (STRNCMP(p, "inv", 3) == 0)
10165 {
10166 xp->xp_context = EXPAND_BOOL_SETTINGS;
10167 p += 3;
10168 }
10169 xp->xp_pattern = arg = p;
10170 if (*arg == '<')
10171 {
10172 while (*p != '>')
10173 if (*p++ == NUL) /* expand terminal option name */
10174 return;
10175 key = get_special_key_code(arg + 1);
10176 if (key == 0) /* unknown name */
10177 {
10178 xp->xp_context = EXPAND_NOTHING;
10179 return;
10180 }
10181 nextchar = *++p;
10182 is_term_option = TRUE;
10183 expand_option_name[2] = KEY2TERMCAP0(key);
10184 expand_option_name[3] = KEY2TERMCAP1(key);
10185 }
10186 else
10187 {
10188 if (p[0] == 't' && p[1] == '_')
10189 {
10190 p += 2;
10191 if (*p != NUL)
10192 ++p;
10193 if (*p == NUL)
10194 return; /* expand option name */
10195 nextchar = *++p;
10196 is_term_option = TRUE;
10197 expand_option_name[2] = p[-2];
10198 expand_option_name[3] = p[-1];
10199 }
10200 else
10201 {
10202 /* Allow * wildcard */
10203 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10204 p++;
10205 if (*p == NUL)
10206 return;
10207 nextchar = *p;
10208 *p = NUL;
10209 opt_idx = findoption(arg);
10210 *p = nextchar;
10211 if (opt_idx == -1 || options[opt_idx].var == NULL)
10212 {
10213 xp->xp_context = EXPAND_NOTHING;
10214 return;
10215 }
10216 flags = options[opt_idx].flags;
10217 if (flags & P_BOOL)
10218 {
10219 xp->xp_context = EXPAND_NOTHING;
10220 return;
10221 }
10222 }
10223 }
10224 /* handle "-=" and "+=" */
10225 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10226 {
10227 ++p;
10228 nextchar = '=';
10229 }
10230 if ((nextchar != '=' && nextchar != ':')
10231 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10232 {
10233 xp->xp_context = EXPAND_UNSUCCESSFUL;
10234 return;
10235 }
10236 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10237 {
10238 xp->xp_context = EXPAND_OLD_SETTING;
10239 if (is_term_option)
10240 expand_option_idx = -1;
10241 else
10242 expand_option_idx = opt_idx;
10243 xp->xp_pattern = p + 1;
10244 return;
10245 }
10246 xp->xp_context = EXPAND_NOTHING;
10247 if (is_term_option || (flags & P_NUM))
10248 return;
10249
10250 xp->xp_pattern = p + 1;
10251
10252 if (flags & P_EXPAND)
10253 {
10254 p = options[opt_idx].var;
10255 if (p == (char_u *)&p_bdir
10256 || p == (char_u *)&p_dir
10257 || p == (char_u *)&p_path
10258 || p == (char_u *)&p_rtp
10259#ifdef FEAT_SEARCHPATH
10260 || p == (char_u *)&p_cdpath
10261#endif
10262#ifdef FEAT_SESSION
10263 || p == (char_u *)&p_vdir
10264#endif
10265 )
10266 {
10267 xp->xp_context = EXPAND_DIRECTORIES;
10268 if (p == (char_u *)&p_path
10269#ifdef FEAT_SEARCHPATH
10270 || p == (char_u *)&p_cdpath
10271#endif
10272 )
10273 xp->xp_backslash = XP_BS_THREE;
10274 else
10275 xp->xp_backslash = XP_BS_ONE;
10276 }
10277 else
10278 {
10279 xp->xp_context = EXPAND_FILES;
10280 /* for 'tags' need three backslashes for a space */
10281 if (p == (char_u *)&p_tags)
10282 xp->xp_backslash = XP_BS_THREE;
10283 else
10284 xp->xp_backslash = XP_BS_ONE;
10285 }
10286 }
10287
10288 /* For an option that is a list of file names, find the start of the
10289 * last file name. */
10290 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10291 {
10292 /* count number of backslashes before ' ' or ',' */
10293 if (*p == ' ' || *p == ',')
10294 {
10295 s = p;
10296 while (s > xp->xp_pattern && *(s - 1) == '\\')
10297 --s;
10298 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10299 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10300 {
10301 xp->xp_pattern = p + 1;
10302 break;
10303 }
10304 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010305
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010306#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010307 /* for 'spellsuggest' start at "file:" */
10308 if (options[opt_idx].var == (char_u *)&p_sps
10309 && STRNCMP(p, "file:", 5) == 0)
10310 {
10311 xp->xp_pattern = p + 5;
10312 break;
10313 }
10314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 }
10316
10317 return;
10318}
10319
10320 int
10321ExpandSettings(xp, regmatch, num_file, file)
10322 expand_T *xp;
10323 regmatch_T *regmatch;
10324 int *num_file;
10325 char_u ***file;
10326{
10327 int num_normal = 0; /* Nr of matching non-term-code settings */
10328 int num_term = 0; /* Nr of matching terminal code settings */
10329 int opt_idx;
10330 int match;
10331 int count = 0;
10332 char_u *str;
10333 int loop;
10334 int is_term_opt;
10335 char_u name_buf[MAX_KEY_NAME_LEN];
10336 static char *(names[]) = {"all", "termcap"};
10337 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10338
10339 /* do this loop twice:
10340 * loop == 0: count the number of matching options
10341 * loop == 1: copy the matching options into allocated memory
10342 */
10343 for (loop = 0; loop <= 1; ++loop)
10344 {
10345 regmatch->rm_ic = ic;
10346 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10347 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010348 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10349 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010350 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10351 {
10352 if (loop == 0)
10353 num_normal++;
10354 else
10355 (*file)[count++] = vim_strsave((char_u *)names[match]);
10356 }
10357 }
10358 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10359 opt_idx++)
10360 {
10361 if (options[opt_idx].var == NULL)
10362 continue;
10363 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10364 && !(options[opt_idx].flags & P_BOOL))
10365 continue;
10366 is_term_opt = istermoption(&options[opt_idx]);
10367 if (is_term_opt && num_normal > 0)
10368 continue;
10369 match = FALSE;
10370 if (vim_regexec(regmatch, str, (colnr_T)0)
10371 || (options[opt_idx].shortname != NULL
10372 && vim_regexec(regmatch,
10373 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10374 match = TRUE;
10375 else if (is_term_opt)
10376 {
10377 name_buf[0] = '<';
10378 name_buf[1] = 't';
10379 name_buf[2] = '_';
10380 name_buf[3] = str[2];
10381 name_buf[4] = str[3];
10382 name_buf[5] = '>';
10383 name_buf[6] = NUL;
10384 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10385 {
10386 match = TRUE;
10387 str = name_buf;
10388 }
10389 }
10390 if (match)
10391 {
10392 if (loop == 0)
10393 {
10394 if (is_term_opt)
10395 num_term++;
10396 else
10397 num_normal++;
10398 }
10399 else
10400 (*file)[count++] = vim_strsave(str);
10401 }
10402 }
10403 /*
10404 * Check terminal key codes, these are not in the option table
10405 */
10406 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10407 {
10408 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10409 {
10410 if (!isprint(str[0]) || !isprint(str[1]))
10411 continue;
10412
10413 name_buf[0] = 't';
10414 name_buf[1] = '_';
10415 name_buf[2] = str[0];
10416 name_buf[3] = str[1];
10417 name_buf[4] = NUL;
10418
10419 match = FALSE;
10420 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10421 match = TRUE;
10422 else
10423 {
10424 name_buf[0] = '<';
10425 name_buf[1] = 't';
10426 name_buf[2] = '_';
10427 name_buf[3] = str[0];
10428 name_buf[4] = str[1];
10429 name_buf[5] = '>';
10430 name_buf[6] = NUL;
10431
10432 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10433 match = TRUE;
10434 }
10435 if (match)
10436 {
10437 if (loop == 0)
10438 num_term++;
10439 else
10440 (*file)[count++] = vim_strsave(name_buf);
10441 }
10442 }
10443
10444 /*
10445 * Check special key names.
10446 */
10447 regmatch->rm_ic = TRUE; /* ignore case here */
10448 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10449 {
10450 name_buf[0] = '<';
10451 STRCPY(name_buf + 1, str);
10452 STRCAT(name_buf, ">");
10453
10454 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10455 {
10456 if (loop == 0)
10457 num_term++;
10458 else
10459 (*file)[count++] = vim_strsave(name_buf);
10460 }
10461 }
10462 }
10463 if (loop == 0)
10464 {
10465 if (num_normal > 0)
10466 *num_file = num_normal;
10467 else if (num_term > 0)
10468 *num_file = num_term;
10469 else
10470 return OK;
10471 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10472 if (*file == NULL)
10473 {
10474 *file = (char_u **)"";
10475 return FAIL;
10476 }
10477 }
10478 }
10479 return OK;
10480}
10481
10482 int
10483ExpandOldSetting(num_file, file)
10484 int *num_file;
10485 char_u ***file;
10486{
10487 char_u *var = NULL; /* init for GCC */
10488 char_u *buf;
10489
10490 *num_file = 0;
10491 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10492 if (*file == NULL)
10493 return FAIL;
10494
10495 /*
10496 * For a terminal key code expand_option_idx is < 0.
10497 */
10498 if (expand_option_idx < 0)
10499 {
10500 var = find_termcode(expand_option_name + 2);
10501 if (var == NULL)
10502 expand_option_idx = findoption(expand_option_name);
10503 }
10504
10505 if (expand_option_idx >= 0)
10506 {
10507 /* put string of option value in NameBuff */
10508 option_value2string(&options[expand_option_idx], expand_option_flags);
10509 var = NameBuff;
10510 }
10511 else if (var == NULL)
10512 var = (char_u *)"";
10513
10514 /* A backslash is required before some characters. This is the reverse of
10515 * what happens in do_set(). */
10516 buf = vim_strsave_escaped(var, escape_chars);
10517
10518 if (buf == NULL)
10519 {
10520 vim_free(*file);
10521 *file = NULL;
10522 return FAIL;
10523 }
10524
10525#ifdef BACKSLASH_IN_FILENAME
10526 /* For MS-Windows et al. we don't double backslashes at the start and
10527 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010528 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 if (var[0] == '\\' && var[1] == '\\'
10530 && expand_option_idx >= 0
10531 && (options[expand_option_idx].flags & P_EXPAND)
10532 && vim_isfilec(var[2])
10533 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010534 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#endif
10536
10537 *file[0] = buf;
10538 *num_file = 1;
10539 return OK;
10540}
10541#endif
10542
10543/*
10544 * Get the value for the numeric or string option *opp in a nice format into
10545 * NameBuff[]. Must not be called with a hidden option!
10546 */
10547 static void
10548option_value2string(opp, opt_flags)
10549 struct vimoption *opp;
10550 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10551{
10552 char_u *varp;
10553
10554 varp = get_varp_scope(opp, opt_flags);
10555
10556 if (opp->flags & P_NUM)
10557 {
10558 long wc = 0;
10559
10560 if (wc_use_keyname(varp, &wc))
10561 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10562 else if (wc != 0)
10563 STRCPY(NameBuff, transchar((int)wc));
10564 else
10565 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10566 }
10567 else /* P_STRING */
10568 {
10569 varp = *(char_u **)(varp);
10570 if (varp == NULL) /* just in case */
10571 NameBuff[0] = NUL;
10572#ifdef FEAT_CRYPT
10573 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010574 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 STRCPY(NameBuff, "*****");
10576#endif
10577 else if (opp->flags & P_EXPAND)
10578 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10579 /* Translate 'pastetoggle' into special key names */
10580 else if ((char_u **)opp->var == &p_pt)
10581 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10582 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010583 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 }
10585}
10586
10587/*
10588 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10589 * printed as a keyname.
10590 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10591 */
10592 static int
10593wc_use_keyname(varp, wcp)
10594 char_u *varp;
10595 long *wcp;
10596{
10597 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10598 {
10599 *wcp = *(long *)varp;
10600 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10601 return TRUE;
10602 }
10603 return FALSE;
10604}
10605
10606#ifdef FEAT_LANGMAP
10607/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010608 * Any character has an equivalent 'langmap' character. This is used for
10609 * keyboards that have a special language mode that sends characters above
10610 * 128 (although other characters can be translated too). The "to" field is a
10611 * Vim command character. This avoids having to switch the keyboard back to
10612 * ASCII mode when leaving Insert mode.
10613 *
10614 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10615 * commands.
10616 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10617 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10618 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010620# ifdef FEAT_MBYTE
10621/*
10622 * With multi-byte support use growarray for 'langmap' chars >= 256
10623 */
10624typedef struct
10625{
10626 int from;
10627 int to;
10628} langmap_entry_T;
10629
10630static garray_T langmap_mapga;
10631static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010632
10633/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010634 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10635 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010637 static void
10638langmap_set_entry(from, to)
10639 int from;
10640 int to;
10641{
10642 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010643 int a = 0;
10644 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010645
10646 /* Do a binary search for an existing entry. */
10647 while (a != b)
10648 {
10649 int i = (a + b) / 2;
10650 int d = entries[i].from - from;
10651
10652 if (d == 0)
10653 {
10654 entries[i].to = to;
10655 return;
10656 }
10657 if (d < 0)
10658 a = i + 1;
10659 else
10660 b = i;
10661 }
10662
10663 if (ga_grow(&langmap_mapga, 1) != OK)
10664 return; /* out of memory */
10665
10666 /* insert new entry at position "a" */
10667 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10668 mch_memmove(entries + 1, entries,
10669 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10670 ++langmap_mapga.ga_len;
10671 entries[0].from = from;
10672 entries[0].to = to;
10673}
10674
10675/*
10676 * Apply 'langmap' to multi-byte character "c" and return the result.
10677 */
10678 int
10679langmap_adjust_mb(c)
10680 int c;
10681{
10682 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10683 int a = 0;
10684 int b = langmap_mapga.ga_len;
10685
10686 while (a != b)
10687 {
10688 int i = (a + b) / 2;
10689 int d = entries[i].from - c;
10690
10691 if (d == 0)
10692 return entries[i].to; /* found matching entry */
10693 if (d < 0)
10694 a = i + 1;
10695 else
10696 b = i;
10697 }
10698 return c; /* no entry found, return "c" unmodified */
10699}
10700# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701
10702 static void
10703langmap_init()
10704{
10705 int i;
10706
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010707 for (i = 0; i < 256; i++)
10708 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10709# ifdef FEAT_MBYTE
10710 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10711# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712}
10713
10714/*
10715 * Called when langmap option is set; the language map can be
10716 * changed at any time!
10717 */
10718 static void
10719langmap_set()
10720{
10721 char_u *p;
10722 char_u *p2;
10723 int from, to;
10724
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010725#ifdef FEAT_MBYTE
10726 ga_clear(&langmap_mapga); /* clear the previous map first */
10727#endif
10728 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729
10730 for (p = p_langmap; p[0] != NUL; )
10731 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010732 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10733 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 {
10735 if (p2[0] == '\\' && p2[1] != NUL)
10736 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 }
10738 if (p2[0] == ';')
10739 ++p2; /* abcd;ABCD form, p2 points to A */
10740 else
10741 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10742 while (p[0])
10743 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010744 if (p[0] == ',')
10745 {
10746 ++p;
10747 break;
10748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749 if (p[0] == '\\' && p[1] != NUL)
10750 ++p;
10751#ifdef FEAT_MBYTE
10752 from = (*mb_ptr2char)(p);
10753#else
10754 from = p[0];
10755#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010756 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 if (p2 == NULL)
10758 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010759 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010760 if (p[0] != ',')
10761 {
10762 if (p[0] == '\\')
10763 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010765 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010767 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010769 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 }
10771 else
10772 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010773 if (p2[0] != ',')
10774 {
10775 if (p2[0] == '\\')
10776 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010778 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010780 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783 }
10784 if (to == NUL)
10785 {
10786 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10787 transchar(from));
10788 return;
10789 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010790
10791#ifdef FEAT_MBYTE
10792 if (from >= 256)
10793 langmap_set_entry(from, to);
10794 else
10795#endif
10796 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797
10798 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010799 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010800 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010802 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 if (*p == ';')
10804 {
10805 p = p2;
10806 if (p[0] != NUL)
10807 {
10808 if (p[0] != ',')
10809 {
10810 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10811 return;
10812 }
10813 ++p;
10814 }
10815 break;
10816 }
10817 }
10818 }
10819 }
10820}
10821#endif
10822
10823/*
10824 * Return TRUE if format option 'x' is in effect.
10825 * Take care of no formatting when 'paste' is set.
10826 */
10827 int
10828has_format_option(x)
10829 int x;
10830{
10831 if (p_paste)
10832 return FALSE;
10833 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10834}
10835
10836/*
10837 * Return TRUE if "x" is present in 'shortmess' option, or
10838 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10839 */
10840 int
10841shortmess(x)
10842 int x;
10843{
10844 return ( vim_strchr(p_shm, x) != NULL
10845 || (vim_strchr(p_shm, 'a') != NULL
10846 && vim_strchr((char_u *)SHM_A, x) != NULL));
10847}
10848
10849/*
10850 * paste_option_changed() - Called after p_paste was set or reset.
10851 */
10852 static void
10853paste_option_changed()
10854{
10855 static int old_p_paste = FALSE;
10856 static int save_sm = 0;
10857#ifdef FEAT_CMDL_INFO
10858 static int save_ru = 0;
10859#endif
10860#ifdef FEAT_RIGHTLEFT
10861 static int save_ri = 0;
10862 static int save_hkmap = 0;
10863#endif
10864 buf_T *buf;
10865
10866 if (p_paste)
10867 {
10868 /*
10869 * Paste switched from off to on.
10870 * Save the current values, so they can be restored later.
10871 */
10872 if (!old_p_paste)
10873 {
10874 /* save options for each buffer */
10875 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10876 {
10877 buf->b_p_tw_nopaste = buf->b_p_tw;
10878 buf->b_p_wm_nopaste = buf->b_p_wm;
10879 buf->b_p_sts_nopaste = buf->b_p_sts;
10880 buf->b_p_ai_nopaste = buf->b_p_ai;
10881 }
10882
10883 /* save global options */
10884 save_sm = p_sm;
10885#ifdef FEAT_CMDL_INFO
10886 save_ru = p_ru;
10887#endif
10888#ifdef FEAT_RIGHTLEFT
10889 save_ri = p_ri;
10890 save_hkmap = p_hkmap;
10891#endif
10892 /* save global values for local buffer options */
10893 p_tw_nopaste = p_tw;
10894 p_wm_nopaste = p_wm;
10895 p_sts_nopaste = p_sts;
10896 p_ai_nopaste = p_ai;
10897 }
10898
10899 /*
10900 * Always set the option values, also when 'paste' is set when it is
10901 * already on.
10902 */
10903 /* set options for each buffer */
10904 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10905 {
10906 buf->b_p_tw = 0; /* textwidth is 0 */
10907 buf->b_p_wm = 0; /* wrapmargin is 0 */
10908 buf->b_p_sts = 0; /* softtabstop is 0 */
10909 buf->b_p_ai = 0; /* no auto-indent */
10910 }
10911
10912 /* set global options */
10913 p_sm = 0; /* no showmatch */
10914#ifdef FEAT_CMDL_INFO
10915# ifdef FEAT_WINDOWS
10916 if (p_ru)
10917 status_redraw_all(); /* redraw to remove the ruler */
10918# endif
10919 p_ru = 0; /* no ruler */
10920#endif
10921#ifdef FEAT_RIGHTLEFT
10922 p_ri = 0; /* no reverse insert */
10923 p_hkmap = 0; /* no Hebrew keyboard */
10924#endif
10925 /* set global values for local buffer options */
10926 p_tw = 0;
10927 p_wm = 0;
10928 p_sts = 0;
10929 p_ai = 0;
10930 }
10931
10932 /*
10933 * Paste switched from on to off: Restore saved values.
10934 */
10935 else if (old_p_paste)
10936 {
10937 /* restore options for each buffer */
10938 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10939 {
10940 buf->b_p_tw = buf->b_p_tw_nopaste;
10941 buf->b_p_wm = buf->b_p_wm_nopaste;
10942 buf->b_p_sts = buf->b_p_sts_nopaste;
10943 buf->b_p_ai = buf->b_p_ai_nopaste;
10944 }
10945
10946 /* restore global options */
10947 p_sm = save_sm;
10948#ifdef FEAT_CMDL_INFO
10949# ifdef FEAT_WINDOWS
10950 if (p_ru != save_ru)
10951 status_redraw_all(); /* redraw to draw the ruler */
10952# endif
10953 p_ru = save_ru;
10954#endif
10955#ifdef FEAT_RIGHTLEFT
10956 p_ri = save_ri;
10957 p_hkmap = save_hkmap;
10958#endif
10959 /* set global values for local buffer options */
10960 p_tw = p_tw_nopaste;
10961 p_wm = p_wm_nopaste;
10962 p_sts = p_sts_nopaste;
10963 p_ai = p_ai_nopaste;
10964 }
10965
10966 old_p_paste = p_paste;
10967}
10968
10969/*
10970 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10971 *
10972 * Reset 'compatible' and set the values for options that didn't get set yet
10973 * to the Vim defaults.
10974 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010975 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 */
10977 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010978vimrc_found(fname, envname)
10979 char_u *fname;
10980 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010982 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010983 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010984 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010985
10986 if (!option_was_set((char_u *)"cp"))
10987 {
10988 p_cp = FALSE;
10989 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10990 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10991 set_option_default(opt_idx, OPT_FREE, FALSE);
10992 didset_options();
10993 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010994
10995 if (fname != NULL)
10996 {
10997 p = vim_getenv(envname, &dofree);
10998 if (p == NULL)
10999 {
11000 /* Set $MYVIMRC to the first vimrc file found. */
11001 p = FullName_save(fname, FALSE);
11002 if (p != NULL)
11003 {
11004 vim_setenv(envname, p);
11005 vim_free(p);
11006 }
11007 }
11008 else if (dofree)
11009 vim_free(p);
11010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011}
11012
11013/*
11014 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11015 */
11016 void
11017change_compatible(on)
11018 int on;
11019{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011020 int opt_idx;
11021
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022 if (p_cp != on)
11023 {
11024 p_cp = on;
11025 compatible_set();
11026 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011027 opt_idx = findoption((char_u *)"cp");
11028 if (opt_idx >= 0)
11029 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030}
11031
11032/*
11033 * Return TRUE when option "name" has been set.
11034 */
11035 int
11036option_was_set(name)
11037 char_u *name;
11038{
11039 int idx;
11040
11041 idx = findoption(name);
11042 if (idx < 0) /* unknown option */
11043 return FALSE;
11044 if (options[idx].flags & P_WAS_SET)
11045 return TRUE;
11046 return FALSE;
11047}
11048
11049/*
11050 * compatible_set() - Called when 'compatible' has been set or unset.
11051 *
11052 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11053 * flag) to a Vi compatible value.
11054 * When 'compatible' is unset: Set all options that have a different default
11055 * for Vim (without the P_VI_DEF flag) to that default.
11056 */
11057 static void
11058compatible_set()
11059{
11060 int opt_idx;
11061
11062 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11063 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11064 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11065 set_option_default(opt_idx, OPT_FREE, p_cp);
11066 didset_options();
11067}
11068
11069#ifdef FEAT_LINEBREAK
11070
11071# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11072 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011073 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074# endif
11075
11076/*
11077 * fill_breakat_flags() -- called when 'breakat' changes value.
11078 */
11079 static void
11080fill_breakat_flags()
11081{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011082 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 int i;
11084
11085 for (i = 0; i < 256; i++)
11086 breakat_flags[i] = FALSE;
11087
11088 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011089 for (p = p_breakat; *p; p++)
11090 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091}
11092
11093# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011094 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095# endif
11096
11097#endif
11098
11099/*
11100 * Check an option that can be a range of string values.
11101 *
11102 * Return OK for correct value, FAIL otherwise.
11103 * Empty is always OK.
11104 */
11105 static int
11106check_opt_strings(val, values, list)
11107 char_u *val;
11108 char **values;
11109 int list; /* when TRUE: accept a list of values */
11110{
11111 return opt_strings_flags(val, values, NULL, list);
11112}
11113
11114/*
11115 * Handle an option that can be a range of string values.
11116 * Set a flag in "*flagp" for each string present.
11117 *
11118 * Return OK for correct value, FAIL otherwise.
11119 * Empty is always OK.
11120 */
11121 static int
11122opt_strings_flags(val, values, flagp, list)
11123 char_u *val; /* new value */
11124 char **values; /* array of valid string values */
11125 unsigned *flagp;
11126 int list; /* when TRUE: accept a list of values */
11127{
11128 int i;
11129 int len;
11130 unsigned new_flags = 0;
11131
11132 while (*val)
11133 {
11134 for (i = 0; ; ++i)
11135 {
11136 if (values[i] == NULL) /* val not found in values[] */
11137 return FAIL;
11138
11139 len = (int)STRLEN(values[i]);
11140 if (STRNCMP(values[i], val, len) == 0
11141 && ((list && val[len] == ',') || val[len] == NUL))
11142 {
11143 val += len + (val[len] == ',');
11144 new_flags |= (1 << i);
11145 break; /* check next item in val list */
11146 }
11147 }
11148 }
11149 if (flagp != NULL)
11150 *flagp = new_flags;
11151
11152 return OK;
11153}
11154
11155/*
11156 * Read the 'wildmode' option, fill wim_flags[].
11157 */
11158 static int
11159check_opt_wim()
11160{
11161 char_u new_wim_flags[4];
11162 char_u *p;
11163 int i;
11164 int idx = 0;
11165
11166 for (i = 0; i < 4; ++i)
11167 new_wim_flags[i] = 0;
11168
11169 for (p = p_wim; *p; ++p)
11170 {
11171 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11172 ;
11173 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11174 return FAIL;
11175 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11176 new_wim_flags[idx] |= WIM_LONGEST;
11177 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11178 new_wim_flags[idx] |= WIM_FULL;
11179 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11180 new_wim_flags[idx] |= WIM_LIST;
11181 else
11182 return FAIL;
11183 p += i;
11184 if (*p == NUL)
11185 break;
11186 if (*p == ',')
11187 {
11188 if (idx == 3)
11189 return FAIL;
11190 ++idx;
11191 }
11192 }
11193
11194 /* fill remaining entries with last flag */
11195 while (idx < 3)
11196 {
11197 new_wim_flags[idx + 1] = new_wim_flags[idx];
11198 ++idx;
11199 }
11200
11201 /* only when there are no errors, wim_flags[] is changed */
11202 for (i = 0; i < 4; ++i)
11203 wim_flags[i] = new_wim_flags[i];
11204 return OK;
11205}
11206
11207/*
11208 * Check if backspacing over something is allowed.
11209 */
11210 int
11211can_bs(what)
11212 int what; /* BS_INDENT, BS_EOL or BS_START */
11213{
11214 switch (*p_bs)
11215 {
11216 case '2': return TRUE;
11217 case '1': return (what != BS_START);
11218 case '0': return FALSE;
11219 }
11220 return vim_strchr(p_bs, what) != NULL;
11221}
11222
11223/*
11224 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11225 * the file must be considered changed when the value is different.
11226 */
11227 void
11228save_file_ff(buf)
11229 buf_T *buf;
11230{
11231 buf->b_start_ffc = *buf->b_p_ff;
11232 buf->b_start_eol = buf->b_p_eol;
11233#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011234 buf->b_start_bomb = buf->b_p_bomb;
11235
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 /* Only use free/alloc when necessary, they take time. */
11237 if (buf->b_start_fenc == NULL
11238 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11239 {
11240 vim_free(buf->b_start_fenc);
11241 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11242 }
11243#endif
11244}
11245
11246/*
11247 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11248 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011249 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11250 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011251 * Don't consider a new, empty buffer to be changed.
11252 */
11253 int
11254file_ff_differs(buf)
11255 buf_T *buf;
11256{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011257 /* In a buffer that was never loaded the options are not valid. */
11258 if (buf->b_flags & BF_NEVERLOADED)
11259 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260 if ((buf->b_flags & BF_NEW)
11261 && buf->b_ml.ml_line_count == 1
11262 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11263 return FALSE;
11264 if (buf->b_start_ffc != *buf->b_p_ff)
11265 return TRUE;
11266 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11267 return TRUE;
11268#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011269 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11270 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271 if (buf->b_start_fenc == NULL)
11272 return (*buf->b_p_fenc != NUL);
11273 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11274#else
11275 return FALSE;
11276#endif
11277}
11278
11279/*
11280 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11281 */
11282 int
11283check_ff_value(p)
11284 char_u *p;
11285{
11286 return check_opt_strings(p, p_ff_values, FALSE);
11287}