blob: f16c4ba44f2a58bb4256d45544ac75b9b259845c [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 Moolenaar9c449722010-07-20 18:44:27 +02007491#ifdef FEAT_GUI
7492 else if ((int *)varp == &p_mh)
7493 {
7494 if (!p_mh)
7495 gui_mch_mousehide(FALSE);
7496 }
7497#endif
7498
Bram Moolenaar370df582010-06-22 05:16:38 +02007499#if defined(FEAT_TITLE) || defined(FEAT_CONCEAL)
7500 /* when 'modifiable' is changed, redraw the window title and
7501 * update current line for concealable items */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007503 {
Bram Moolenaar370df582010-06-22 05:16:38 +02007504# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007505 redraw_titles();
Bram Moolenaar370df582010-06-22 05:16:38 +02007506# endif
7507# ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02007508 if (curwin->w_p_conc > 0)
Bram Moolenaar370df582010-06-22 05:16:38 +02007509 update_single_line(curwin, curwin->w_cursor.lnum);
7510# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007511 }
Bram Moolenaar370df582010-06-22 05:16:38 +02007512#endif
7513#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 /* when 'endofline' is changed, redraw the window title */
7515 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007516 {
7517 redraw_titles();
7518 }
7519# ifdef FEAT_MBYTE
7520 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007521 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007522 {
7523 redraw_titles();
7524 }
7525# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526#endif
7527
7528 /* when 'bin' is set also set some other options */
7529 else if ((int *)varp == &curbuf->b_p_bin)
7530 {
7531 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7532#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007533 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534#endif
7535 }
7536
7537#ifdef FEAT_AUTOCMD
7538 /* when 'buflisted' changes, trigger autocommands */
7539 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7540 {
7541 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7542 NULL, NULL, TRUE, curbuf);
7543 }
7544#endif
7545
7546 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7547 else if ((int *)varp == &curbuf->b_p_swf)
7548 {
7549 if (curbuf->b_p_swf && p_uc)
7550 ml_open_file(curbuf); /* create the swap file */
7551 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007552 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7553 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554 mf_close_file(curbuf, TRUE); /* remove the swap file */
7555 }
7556
7557 /* when 'terse' is set change 'shortmess' */
7558 else if ((int *)varp == &p_terse)
7559 {
7560 char_u *p;
7561
7562 p = vim_strchr(p_shm, SHM_SEARCH);
7563
7564 /* insert 's' in p_shm */
7565 if (p_terse && p == NULL)
7566 {
7567 STRCPY(IObuff, p_shm);
7568 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007569 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 }
7571 /* remove 's' from p_shm */
7572 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007573 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 }
7575
7576 /* when 'paste' is set or reset also change other options */
7577 else if ((int *)varp == &p_paste)
7578 {
7579 paste_option_changed();
7580 }
7581
7582 /* when 'insertmode' is set from an autocommand need to do work here */
7583 else if ((int *)varp == &p_im)
7584 {
7585 if (p_im)
7586 {
7587 if ((State & INSERT) == 0)
7588 need_start_insertmode = TRUE;
7589 stop_insert_mode = FALSE;
7590 }
7591 else
7592 {
7593 need_start_insertmode = FALSE;
7594 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007595 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596 clear_cmdline = TRUE; /* remove "(insert)" */
7597 restart_edit = 0;
7598 }
7599 }
7600
7601 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7602 else if ((int *)varp == &p_ic && p_hls)
7603 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007604 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605 }
7606
7607#ifdef FEAT_SEARCH_EXTRA
7608 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7609 else if ((int *)varp == &p_hls)
7610 {
7611 no_hlsearch = FALSE;
7612 }
7613#endif
7614
7615#ifdef FEAT_SCROLLBIND
7616 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7617 * at the end of normal_cmd() */
7618 else if ((int *)varp == &curwin->w_p_scb)
7619 {
7620 if (curwin->w_p_scb)
7621 do_check_scrollbind(FALSE);
7622 }
7623#endif
7624
7625#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7626 /* There can be only one window with 'previewwindow' set. */
7627 else if ((int *)varp == &curwin->w_p_pvw)
7628 {
7629 if (curwin->w_p_pvw)
7630 {
7631 win_T *win;
7632
7633 for (win = firstwin; win != NULL; win = win->w_next)
7634 if (win->w_p_pvw && win != curwin)
7635 {
7636 curwin->w_p_pvw = FALSE;
7637 return (char_u *)N_("E590: A preview window already exists");
7638 }
7639 }
7640 }
7641#endif
7642
7643 /* when 'textmode' is set or reset also change 'fileformat' */
7644 else if ((int *)varp == &curbuf->b_p_tx)
7645 {
7646 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7647 }
7648
7649 /* when 'textauto' is set or reset also change 'fileformats' */
7650 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 set_string_option_direct((char_u *)"ffs", -1,
7652 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007653 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654
7655 /*
7656 * When 'lisp' option changes include/exclude '-' in
7657 * keyword characters.
7658 */
7659#ifdef FEAT_LISP
7660 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7661 {
7662 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7663 }
7664#endif
7665
7666#ifdef FEAT_TITLE
7667 /* when 'title' changed, may need to change the title; same for 'icon' */
7668 else if ((int *)varp == &p_title)
7669 {
7670 did_set_title(FALSE);
7671 }
7672
7673 else if ((int *)varp == &p_icon)
7674 {
7675 did_set_title(TRUE);
7676 }
7677#endif
7678
7679 else if ((int *)varp == &curbuf->b_changed)
7680 {
7681 if (!value)
7682 save_file_ff(curbuf); /* Buffer is unchanged */
7683#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007684 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685#endif
7686#ifdef FEAT_AUTOCMD
7687 modified_was_set = value;
7688#endif
7689 }
7690
7691#ifdef BACKSLASH_IN_FILENAME
7692 else if ((int *)varp == &p_ssl)
7693 {
7694 if (p_ssl)
7695 {
7696 psepc = '/';
7697 psepcN = '\\';
7698 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 }
7700 else
7701 {
7702 psepc = '\\';
7703 psepcN = '/';
7704 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 }
7706
7707 /* need to adjust the file name arguments and buffer names. */
7708 buflist_slash_adjust();
7709 alist_slash_adjust();
7710# ifdef FEAT_EVAL
7711 scriptnames_slash_adjust();
7712# endif
7713 }
7714#endif
7715
7716 /* If 'wrap' is set, set w_leftcol to zero. */
7717 else if ((int *)varp == &curwin->w_p_wrap)
7718 {
7719 if (curwin->w_p_wrap)
7720 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007721 if (curwin->w_curswant != MAXCOL)
7722 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 }
7724
7725#ifdef FEAT_WINDOWS
7726 else if ((int *)varp == &p_ea)
7727 {
7728 if (p_ea && !old_value)
7729 win_equal(curwin, FALSE, 0);
7730 }
7731#endif
7732
7733 else if ((int *)varp == &p_wiv)
7734 {
7735 /*
7736 * When 'weirdinvert' changed, set/reset 't_xs'.
7737 * Then set 'weirdinvert' according to value of 't_xs'.
7738 */
7739 if (p_wiv && !old_value)
7740 T_XS = (char_u *)"y";
7741 else if (!p_wiv && old_value)
7742 T_XS = empty_option;
7743 p_wiv = (*T_XS != NUL);
7744 }
7745
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007746#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 else if ((int *)varp == &p_beval)
7748 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 if (p_beval == TRUE)
7750 gui_mch_enable_beval_area(balloonEval);
7751 else
7752 gui_mch_disable_beval_area(balloonEval);
7753 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007756#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 else if ((int *)varp == &p_acd)
7758 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007759 /* Change directories when the 'acd' option is set now. */
7760 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 }
7762#endif
7763
7764#ifdef FEAT_DIFF
7765 /* 'diff' */
7766 else if ((int *)varp == &curwin->w_p_diff)
7767 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007768 /* May add or remove the buffer from the list of diff buffers. */
7769 diff_buf_adjust(curwin);
7770# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771 if (foldmethodIsDiff(curwin))
7772 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007773# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 }
7775#endif
7776
7777#ifdef USE_IM_CONTROL
7778 /* 'imdisable' */
7779 else if ((int *)varp == &p_imdisable)
7780 {
7781 /* Only de-activate it here, it will be enabled when changing mode. */
7782 if (p_imdisable)
7783 im_set_active(FALSE);
7784 }
7785#endif
7786
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007787#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007788 /* 'spell' */
7789 else if ((int *)varp == &curwin->w_p_spell)
7790 {
7791 if (curwin->w_p_spell)
7792 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007793 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007794 if (errmsg != NULL)
7795 EMSG(_(errmsg));
7796 }
7797 }
7798#endif
7799
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800#ifdef FEAT_FKMAP
7801 else if ((int *)varp == &p_altkeymap)
7802 {
7803 if (old_value != p_altkeymap)
7804 {
7805 if (!p_altkeymap)
7806 {
7807 p_hkmap = p_fkmap;
7808 p_fkmap = 0;
7809 }
7810 else
7811 {
7812 p_fkmap = p_hkmap;
7813 p_hkmap = 0;
7814 }
7815 (void)init_chartab();
7816 }
7817 }
7818
7819 /*
7820 * In case some second language keymapping options have changed, check
7821 * and correct the setting in a consistent way.
7822 */
7823
7824 /*
7825 * If hkmap or fkmap are set, reset Arabic keymapping.
7826 */
7827 if ((p_hkmap || p_fkmap) && p_altkeymap)
7828 {
7829 p_altkeymap = p_fkmap;
7830# ifdef FEAT_ARABIC
7831 curwin->w_p_arab = FALSE;
7832# endif
7833 (void)init_chartab();
7834 }
7835
7836 /*
7837 * If hkmap set, reset Farsi keymapping.
7838 */
7839 if (p_hkmap && p_altkeymap)
7840 {
7841 p_altkeymap = 0;
7842 p_fkmap = 0;
7843# ifdef FEAT_ARABIC
7844 curwin->w_p_arab = FALSE;
7845# endif
7846 (void)init_chartab();
7847 }
7848
7849 /*
7850 * If fkmap set, reset Hebrew keymapping.
7851 */
7852 if (p_fkmap && !p_altkeymap)
7853 {
7854 p_altkeymap = 1;
7855 p_hkmap = 0;
7856# ifdef FEAT_ARABIC
7857 curwin->w_p_arab = FALSE;
7858# endif
7859 (void)init_chartab();
7860 }
7861#endif
7862
7863#ifdef FEAT_ARABIC
7864 if ((int *)varp == &curwin->w_p_arab)
7865 {
7866 if (curwin->w_p_arab)
7867 {
7868 /*
7869 * 'arabic' is set, handle various sub-settings.
7870 */
7871 if (!p_tbidi)
7872 {
7873 /* set rightleft mode */
7874 if (!curwin->w_p_rl)
7875 {
7876 curwin->w_p_rl = TRUE;
7877 changed_window_setting();
7878 }
7879
7880 /* Enable Arabic shaping (major part of what Arabic requires) */
7881 if (!p_arshape)
7882 {
7883 p_arshape = TRUE;
7884 redraw_later_clear();
7885 }
7886 }
7887
7888 /* Arabic requires a utf-8 encoding, inform the user if its not
7889 * set. */
7890 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007891 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007892 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7893
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007894 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007895 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7896#ifdef FEAT_EVAL
7897 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7898#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900
7901# ifdef FEAT_MBYTE
7902 /* set 'delcombine' */
7903 p_deco = TRUE;
7904# endif
7905
7906# ifdef FEAT_KEYMAP
7907 /* Force-set the necessary keymap for arabic */
7908 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7909 OPT_LOCAL);
7910# endif
7911# ifdef FEAT_FKMAP
7912 p_altkeymap = 0;
7913 p_hkmap = 0;
7914 p_fkmap = 0;
7915 (void)init_chartab();
7916# endif
7917 }
7918 else
7919 {
7920 /*
7921 * 'arabic' is reset, handle various sub-settings.
7922 */
7923 if (!p_tbidi)
7924 {
7925 /* reset rightleft mode */
7926 if (curwin->w_p_rl)
7927 {
7928 curwin->w_p_rl = FALSE;
7929 changed_window_setting();
7930 }
7931
7932 /* 'arabicshape' isn't reset, it is a global option and
7933 * another window may still need it "on". */
7934 }
7935
7936 /* 'delcombine' isn't reset, it is a global option and another
7937 * window may still want it "on". */
7938
7939# ifdef FEAT_KEYMAP
7940 /* Revert to the default keymap */
7941 curbuf->b_p_iminsert = B_IMODE_NONE;
7942 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7943# endif
7944 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007945 if (curwin->w_curswant != MAXCOL)
7946 curwin->w_set_curswant = TRUE;
7947 }
7948
7949 else if ((int *)varp == &p_arshape)
7950 {
7951 if (curwin->w_curswant != MAXCOL)
7952 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954#endif
7955
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007956#ifdef FEAT_LINEBREAK
7957 if ((int *)varp == &curwin->w_p_lbr)
7958 {
7959 if (curwin->w_curswant != MAXCOL)
7960 curwin->w_set_curswant = TRUE;
7961 }
7962#endif
7963
7964#ifdef FEAT_RIGHTLEFT
7965 if ((int *)varp == &curwin->w_p_rl)
7966 {
7967 if (curwin->w_curswant != MAXCOL)
7968 curwin->w_set_curswant = TRUE;
7969 }
7970#endif
7971
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 /*
7973 * End of handling side effects for bool options.
7974 */
7975
7976 options[opt_idx].flags |= P_WAS_SET;
7977
7978 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007979
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 check_redraw(options[opt_idx].flags);
7981
7982 return NULL;
7983}
7984
7985/*
7986 * Set the value of a number option, and take care of side effects.
7987 * Returns NULL for success, or an error message for an error.
7988 */
7989 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007990set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 int opt_idx; /* index in options[] table */
7992 char_u *varp; /* pointer to the option variable */
7993 long value; /* new value */
7994 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007995 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7997 OPT_MODELINE */
7998{
7999 char_u *errmsg = NULL;
8000 long old_value = *(long *)varp;
8001 long old_Rows = Rows; /* remember old Rows */
8002 long old_Columns = Columns; /* remember old Columns */
8003 long *pp = (long *)varp;
8004
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008005 /* Disallow changing some options from secure mode. */
8006 if ((secure
8007#ifdef HAVE_SANDBOX
8008 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008010 ) && (options[opt_idx].flags & P_SECURE))
8011 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012
8013 *pp = value;
8014#ifdef FEAT_EVAL
8015 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008016 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008018#ifdef FEAT_GUI
8019 need_mouse_correct = TRUE;
8020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021
8022 if (curbuf->b_p_sw <= 0)
8023 {
8024 errmsg = e_positive;
8025 curbuf->b_p_sw = curbuf->b_p_ts;
8026 }
8027
8028 /*
8029 * Number options that need some action when changed
8030 */
8031#ifdef FEAT_WINDOWS
8032 if (pp == &p_wh || pp == &p_hh)
8033 {
8034 if (p_wh < 1)
8035 {
8036 errmsg = e_positive;
8037 p_wh = 1;
8038 }
8039 if (p_wmh > p_wh)
8040 {
8041 errmsg = e_winheight;
8042 p_wh = p_wmh;
8043 }
8044 if (p_hh < 0)
8045 {
8046 errmsg = e_positive;
8047 p_hh = 0;
8048 }
8049
8050 /* Change window height NOW */
8051 if (lastwin != firstwin)
8052 {
8053 if (pp == &p_wh && curwin->w_height < p_wh)
8054 win_setheight((int)p_wh);
8055 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8056 win_setheight((int)p_hh);
8057 }
8058 }
8059
8060 /* 'winminheight' */
8061 else if (pp == &p_wmh)
8062 {
8063 if (p_wmh < 0)
8064 {
8065 errmsg = e_positive;
8066 p_wmh = 0;
8067 }
8068 if (p_wmh > p_wh)
8069 {
8070 errmsg = e_winheight;
8071 p_wmh = p_wh;
8072 }
8073 win_setminheight();
8074 }
8075
8076# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008077 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008078 {
8079 if (p_wiw < 1)
8080 {
8081 errmsg = e_positive;
8082 p_wiw = 1;
8083 }
8084 if (p_wmw > p_wiw)
8085 {
8086 errmsg = e_winwidth;
8087 p_wiw = p_wmw;
8088 }
8089
8090 /* Change window width NOW */
8091 if (lastwin != firstwin && curwin->w_width < p_wiw)
8092 win_setwidth((int)p_wiw);
8093 }
8094
8095 /* 'winminwidth' */
8096 else if (pp == &p_wmw)
8097 {
8098 if (p_wmw < 0)
8099 {
8100 errmsg = e_positive;
8101 p_wmw = 0;
8102 }
8103 if (p_wmw > p_wiw)
8104 {
8105 errmsg = e_winwidth;
8106 p_wmw = p_wiw;
8107 }
8108 win_setminheight();
8109 }
8110# endif
8111
8112#endif
8113
8114#ifdef FEAT_WINDOWS
8115 /* (re)set last window status line */
8116 else if (pp == &p_ls)
8117 {
8118 last_status(FALSE);
8119 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008120
8121 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008122 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008123 {
8124 shell_new_rows(); /* recompute window positions and heights */
8125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126#endif
8127
8128#ifdef FEAT_GUI
8129 else if (pp == &p_linespace)
8130 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008131 /* Recompute gui.char_height and resize the Vim window to keep the
8132 * same number of lines. */
8133 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008134 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 }
8136#endif
8137
8138#ifdef FEAT_FOLDING
8139 /* 'foldlevel' */
8140 else if (pp == &curwin->w_p_fdl)
8141 {
8142 if (curwin->w_p_fdl < 0)
8143 curwin->w_p_fdl = 0;
8144 newFoldLevel();
8145 }
8146
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008147 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 else if (pp == &curwin->w_p_fml)
8149 {
8150 foldUpdateAll(curwin);
8151 }
8152
8153 /* 'foldnestmax' */
8154 else if (pp == &curwin->w_p_fdn)
8155 {
8156 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8157 foldUpdateAll(curwin);
8158 }
8159
8160 /* 'foldcolumn' */
8161 else if (pp == &curwin->w_p_fdc)
8162 {
8163 if (curwin->w_p_fdc < 0)
8164 {
8165 errmsg = e_positive;
8166 curwin->w_p_fdc = 0;
8167 }
8168 else if (curwin->w_p_fdc > 12)
8169 {
8170 errmsg = e_invarg;
8171 curwin->w_p_fdc = 12;
8172 }
8173 }
8174
8175 /* 'shiftwidth' or 'tabstop' */
8176 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8177 {
8178 if (foldmethodIsIndent(curwin))
8179 foldUpdateAll(curwin);
8180 }
8181#endif /* FEAT_FOLDING */
8182
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008183#ifdef FEAT_MBYTE
8184 /* 'maxcombine' */
8185 else if (pp == &p_mco)
8186 {
8187 if (p_mco > MAX_MCO)
8188 p_mco = MAX_MCO;
8189 else if (p_mco < 0)
8190 p_mco = 0;
8191 screenclear(); /* will re-allocate the screen */
8192 }
8193#endif
8194
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 else if (pp == &curbuf->b_p_iminsert)
8196 {
8197 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8198 {
8199 errmsg = e_invarg;
8200 curbuf->b_p_iminsert = B_IMODE_NONE;
8201 }
8202 p_iminsert = curbuf->b_p_iminsert;
8203 if (termcap_active) /* don't do this in the alternate screen */
8204 showmode();
8205#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8206 /* Show/unshow value of 'keymap' in status lines. */
8207 status_redraw_curbuf();
8208#endif
8209 }
8210
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008211 else if (pp == &p_window)
8212 {
8213 if (p_window < 1)
8214 p_window = 1;
8215 else if (p_window >= Rows)
8216 p_window = Rows - 1;
8217 }
8218
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 else if (pp == &curbuf->b_p_imsearch)
8220 {
8221 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8222 {
8223 errmsg = e_invarg;
8224 curbuf->b_p_imsearch = B_IMODE_NONE;
8225 }
8226 p_imsearch = curbuf->b_p_imsearch;
8227 }
8228
8229#ifdef FEAT_TITLE
8230 /* if 'titlelen' has changed, redraw the title */
8231 else if (pp == &p_titlelen)
8232 {
8233 if (p_titlelen < 0)
8234 {
8235 errmsg = e_positive;
8236 p_titlelen = 85;
8237 }
8238 if (starting != NO_SCREEN && old_value != p_titlelen)
8239 need_maketitle = TRUE;
8240 }
8241#endif
8242
8243 /* if p_ch changed value, change the command line height */
8244 else if (pp == &p_ch)
8245 {
8246 if (p_ch < 1)
8247 {
8248 errmsg = e_positive;
8249 p_ch = 1;
8250 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008251 if (p_ch > Rows - min_rows() + 1)
8252 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253
8254 /* Only compute the new window layout when startup has been
8255 * completed. Otherwise the frame sizes may be wrong. */
8256 if (p_ch != old_value && full_screen
8257#ifdef FEAT_GUI
8258 && !gui.starting
8259#endif
8260 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008261 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008262 }
8263
8264 /* when 'updatecount' changes from zero to non-zero, open swap files */
8265 else if (pp == &p_uc)
8266 {
8267 if (p_uc < 0)
8268 {
8269 errmsg = e_positive;
8270 p_uc = 100;
8271 }
8272 if (p_uc && !old_value)
8273 ml_open_files();
8274 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008275#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008276 else if (pp == &curwin->w_p_conc)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008277 {
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008278 if (curwin->w_p_conc < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008279 {
8280 errmsg = e_positive;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008281 curwin->w_p_conc = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008282 }
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008283 else if (curwin->w_p_conc > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008284 {
8285 errmsg = e_invarg;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02008286 curwin->w_p_conc = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008287 }
8288 }
8289#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008290#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008291 else if (pp == &p_mzq)
8292 mzvim_reset_timer();
8293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294
8295 /* sync undo before 'undolevels' changes */
8296 else if (pp == &p_ul)
8297 {
8298 /* use the old value, otherwise u_sync() may not work properly */
8299 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008300 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 p_ul = value;
8302 }
8303
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008304#ifdef FEAT_LINEBREAK
8305 /* 'numberwidth' must be positive */
8306 else if (pp == &curwin->w_p_nuw)
8307 {
8308 if (curwin->w_p_nuw < 1)
8309 {
8310 errmsg = e_positive;
8311 curwin->w_p_nuw = 1;
8312 }
8313 if (curwin->w_p_nuw > 10)
8314 {
8315 errmsg = e_invarg;
8316 curwin->w_p_nuw = 10;
8317 }
8318 curwin->w_nrwidth_line_count = 0;
8319 }
8320#endif
8321
Bram Moolenaar1a384422010-07-14 19:53:30 +02008322 else if (pp == &curbuf->b_p_tw)
8323 {
8324 if (curbuf->b_p_tw < 0)
8325 {
8326 errmsg = e_positive;
8327 curbuf->b_p_tw = 0;
8328 }
8329#ifdef FEAT_SYN_HL
8330# ifdef FEAT_WINDOWS
8331 {
8332 win_T *wp;
8333 tabpage_T *tp;
8334
8335 FOR_ALL_TAB_WINDOWS(tp, wp)
8336 check_colorcolumn(wp);
8337 }
8338# else
8339 check_colorcolumn(curwin);
8340# endif
8341#endif
8342 }
8343
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344 /*
8345 * Check the bounds for numeric options here
8346 */
8347 if (Rows < min_rows() && full_screen)
8348 {
8349 if (errbuf != NULL)
8350 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008351 vim_snprintf((char *)errbuf, errbuflen,
8352 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 errmsg = errbuf;
8354 }
8355 Rows = min_rows();
8356 }
8357 if (Columns < MIN_COLUMNS && full_screen)
8358 {
8359 if (errbuf != NULL)
8360 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008361 vim_snprintf((char *)errbuf, errbuflen,
8362 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 errmsg = errbuf;
8364 }
8365 Columns = MIN_COLUMNS;
8366 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008367 /* Limit the values to avoid an overflow in Rows * Columns. */
8368 if (Columns > 10000)
8369 Columns = 10000;
8370 if (Rows > 1000)
8371 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
8373#ifdef DJGPP
8374 /* avoid a crash by checking for a too large value of 'columns' */
8375 if (old_Columns != Columns && full_screen && term_console)
8376 mch_check_columns();
8377#endif
8378
8379 /*
8380 * If the screen (shell) height has been changed, assume it is the
8381 * physical screenheight.
8382 */
8383 if (old_Rows != Rows || old_Columns != Columns)
8384 {
8385 /* Changing the screen size is not allowed while updating the screen. */
8386 if (updating_screen)
8387 *pp = old_value;
8388 else if (full_screen
8389#ifdef FEAT_GUI
8390 && !gui.starting
8391#endif
8392 )
8393 set_shellsize((int)Columns, (int)Rows, TRUE);
8394 else
8395 {
8396 /* Postpone the resizing; check the size and cmdline position for
8397 * messages. */
8398 check_shellsize();
8399 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8400 cmdline_row = Rows - p_ch;
8401 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008402 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008403 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 }
8405
8406 if (curbuf->b_p_sts < 0)
8407 {
8408 errmsg = e_positive;
8409 curbuf->b_p_sts = 0;
8410 }
8411 if (curbuf->b_p_ts <= 0)
8412 {
8413 errmsg = e_positive;
8414 curbuf->b_p_ts = 8;
8415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 if (p_tm < 0)
8417 {
8418 errmsg = e_positive;
8419 p_tm = 0;
8420 }
8421 if ((curwin->w_p_scr <= 0
8422 || (curwin->w_p_scr > curwin->w_height
8423 && curwin->w_height > 0))
8424 && full_screen)
8425 {
8426 if (pp == &(curwin->w_p_scr))
8427 {
8428 if (curwin->w_p_scr != 0)
8429 errmsg = e_scroll;
8430 win_comp_scroll(curwin);
8431 }
8432 /* If 'scroll' became invalid because of a side effect silently adjust
8433 * it. */
8434 else if (curwin->w_p_scr <= 0)
8435 curwin->w_p_scr = 1;
8436 else /* curwin->w_p_scr > curwin->w_height */
8437 curwin->w_p_scr = curwin->w_height;
8438 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008439 if (p_hi < 0)
8440 {
8441 errmsg = e_positive;
8442 p_hi = 0;
8443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 if (p_report < 0)
8445 {
8446 errmsg = e_positive;
8447 p_report = 1;
8448 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008449 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 {
8451 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8452 p_sj = Rows / 2;
8453 else
8454 {
8455 errmsg = e_scroll;
8456 p_sj = 1;
8457 }
8458 }
8459 if (p_so < 0 && full_screen)
8460 {
8461 errmsg = e_scroll;
8462 p_so = 0;
8463 }
8464 if (p_siso < 0 && full_screen)
8465 {
8466 errmsg = e_positive;
8467 p_siso = 0;
8468 }
8469#ifdef FEAT_CMDWIN
8470 if (p_cwh < 1)
8471 {
8472 errmsg = e_positive;
8473 p_cwh = 1;
8474 }
8475#endif
8476 if (p_ut < 0)
8477 {
8478 errmsg = e_positive;
8479 p_ut = 2000;
8480 }
8481 if (p_ss < 0)
8482 {
8483 errmsg = e_positive;
8484 p_ss = 0;
8485 }
8486
8487 /* May set global value for local option. */
8488 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8489 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8490
8491 options[opt_idx].flags |= P_WAS_SET;
8492
8493 comp_col(); /* in case 'columns' or 'ls' changed */
8494 if (curwin->w_curswant != MAXCOL)
8495 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8496 check_redraw(options[opt_idx].flags);
8497
8498 return errmsg;
8499}
8500
8501/*
8502 * Called after an option changed: check if something needs to be redrawn.
8503 */
8504 static void
8505check_redraw(flags)
8506 long_u flags;
8507{
8508 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8509 int clear = (flags & P_RCLR) == P_RCLR;
8510 int all = ((flags & P_RALL) == P_RALL || clear);
8511
8512#ifdef FEAT_WINDOWS
8513 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8514 status_redraw_all();
8515#endif
8516
8517 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8518 changed_window_setting();
8519 if (flags & P_RBUF)
8520 redraw_curbuf_later(NOT_VALID);
8521 if (clear)
8522 redraw_all_later(CLEAR);
8523 else if (all)
8524 redraw_all_later(NOT_VALID);
8525}
8526
8527/*
8528 * Find index for option 'arg'.
8529 * Return -1 if not found.
8530 */
8531 static int
8532findoption(arg)
8533 char_u *arg;
8534{
8535 int opt_idx;
8536 char *s, *p;
8537 static short quick_tab[27] = {0, 0}; /* quick access table */
8538 int is_term_opt;
8539
8540 /*
8541 * For first call: Initialize the quick-access table.
8542 * It contains the index for the first option that starts with a certain
8543 * letter. There are 26 letters, plus the first "t_" option.
8544 */
8545 if (quick_tab[1] == 0)
8546 {
8547 p = options[0].fullname;
8548 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8549 {
8550 if (s[0] != p[0])
8551 {
8552 if (s[0] == 't' && s[1] == '_')
8553 quick_tab[26] = opt_idx;
8554 else
8555 quick_tab[CharOrdLow(s[0])] = opt_idx;
8556 }
8557 p = s;
8558 }
8559 }
8560
8561 /*
8562 * Check for name starting with an illegal character.
8563 */
8564#ifdef EBCDIC
8565 if (!islower(arg[0]))
8566#else
8567 if (arg[0] < 'a' || arg[0] > 'z')
8568#endif
8569 return -1;
8570
8571 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8572 if (is_term_opt)
8573 opt_idx = quick_tab[26];
8574 else
8575 opt_idx = quick_tab[CharOrdLow(arg[0])];
8576 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8577 {
8578 if (STRCMP(arg, s) == 0) /* match full name */
8579 break;
8580 }
8581 if (s == NULL && !is_term_opt)
8582 {
8583 opt_idx = quick_tab[CharOrdLow(arg[0])];
8584 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8585 {
8586 s = options[opt_idx].shortname;
8587 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8588 break;
8589 s = NULL;
8590 }
8591 }
8592 if (s == NULL)
8593 opt_idx = -1;
8594 return opt_idx;
8595}
8596
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008597#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598/*
8599 * Get the value for an option.
8600 *
8601 * Returns:
8602 * Number or Toggle option: 1, *numval gets value.
8603 * String option: 0, *stringval gets allocated string.
8604 * Hidden Number or Toggle option: -1.
8605 * hidden String option: -2.
8606 * unknown option: -3.
8607 */
8608 int
8609get_option_value(name, numval, stringval, opt_flags)
8610 char_u *name;
8611 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008612 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613 int opt_flags;
8614{
8615 int opt_idx;
8616 char_u *varp;
8617
8618 opt_idx = findoption(name);
8619 if (opt_idx < 0) /* unknown option */
8620 return -3;
8621
8622 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8623
8624 if (options[opt_idx].flags & P_STRING)
8625 {
8626 if (varp == NULL) /* hidden option */
8627 return -2;
8628 if (stringval != NULL)
8629 {
8630#ifdef FEAT_CRYPT
8631 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008632 if ((char_u **)varp == &curbuf->b_p_key
8633 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634 *stringval = vim_strsave((char_u *)"*****");
8635 else
8636#endif
8637 *stringval = vim_strsave(*(char_u **)(varp));
8638 }
8639 return 0;
8640 }
8641
8642 if (varp == NULL) /* hidden option */
8643 return -1;
8644 if (options[opt_idx].flags & P_NUM)
8645 *numval = *(long *)varp;
8646 else
8647 {
8648 /* Special case: 'modified' is b_changed, but we also want to consider
8649 * it set when 'ff' or 'fenc' changed. */
8650 if ((int *)varp == &curbuf->b_changed)
8651 *numval = curbufIsChanged();
8652 else
8653 *numval = *(int *)varp;
8654 }
8655 return 1;
8656}
8657#endif
8658
8659/*
8660 * Set the value of option "name".
8661 * Use "string" for string options, use "number" for other options.
8662 */
8663 void
8664set_option_value(name, number, string, opt_flags)
8665 char_u *name;
8666 long number;
8667 char_u *string;
8668 int opt_flags; /* OPT_LOCAL or 0 (both) */
8669{
8670 int opt_idx;
8671 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008672 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673
8674 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008675 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 EMSG2(_("E355: Unknown option: %s"), name);
8677 else
8678 {
8679 flags = options[opt_idx].flags;
8680#ifdef HAVE_SANDBOX
8681 /* Disallow changing some options in the sandbox */
8682 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008683 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008685 return;
8686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008688 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689 set_string_option(opt_idx, string, opt_flags);
8690 else
8691 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008692 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 if (varp != NULL) /* hidden option is not changed */
8694 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008695 if (number == 0 && string != NULL)
8696 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008697 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008698
8699 /* Either we are given a string or we are setting option
8700 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008701 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008702 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008703 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008704 {
8705 /* There's another character after zeros or the string
8706 * is empty. In both cases, we are trying to set a
8707 * num option using a string. */
8708 EMSG3(_("E521: Number required: &%s = '%s'"),
8709 name, string);
8710 return; /* do nothing as we hit an error */
8711
8712 }
8713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008715 (void)set_num_option(opt_idx, varp, number,
8716 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008718 (void)set_bool_option(opt_idx, varp, (int)number,
8719 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 }
8721 }
8722 }
8723}
8724
8725/*
8726 * Get the terminal code for a terminal option.
8727 * Returns NULL when not found.
8728 */
8729 char_u *
8730get_term_code(tname)
8731 char_u *tname;
8732{
8733 int opt_idx;
8734 char_u *varp;
8735
8736 if (tname[0] != 't' || tname[1] != '_' ||
8737 tname[2] == NUL || tname[3] == NUL)
8738 return NULL;
8739 if ((opt_idx = findoption(tname)) >= 0)
8740 {
8741 varp = get_varp(&(options[opt_idx]));
8742 if (varp != NULL)
8743 varp = *(char_u **)(varp);
8744 return varp;
8745 }
8746 return find_termcode(tname + 2);
8747}
8748
8749 char_u *
8750get_highlight_default()
8751{
8752 int i;
8753
8754 i = findoption((char_u *)"hl");
8755 if (i >= 0)
8756 return options[i].def_val[VI_DEFAULT];
8757 return (char_u *)NULL;
8758}
8759
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008760#if defined(FEAT_MBYTE) || defined(PROTO)
8761 char_u *
8762get_encoding_default()
8763{
8764 int i;
8765
8766 i = findoption((char_u *)"enc");
8767 if (i >= 0)
8768 return options[i].def_val[VI_DEFAULT];
8769 return (char_u *)NULL;
8770}
8771#endif
8772
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773/*
8774 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8775 */
8776 static int
8777find_key_option(arg)
8778 char_u *arg;
8779{
8780 int key;
8781 int modifiers;
8782
8783 /*
8784 * Don't use get_special_key_code() for t_xx, we don't want it to call
8785 * add_termcap_entry().
8786 */
8787 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8788 key = TERMCAP2KEY(arg[2], arg[3]);
8789 else
8790 {
8791 --arg; /* put arg at the '<' */
8792 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008793 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794 if (modifiers) /* can't handle modifiers here */
8795 key = 0;
8796 }
8797 return key;
8798}
8799
8800/*
8801 * if 'all' == 0: show changed options
8802 * if 'all' == 1: show all normal options
8803 * if 'all' == 2: show all terminal options
8804 */
8805 static void
8806showoptions(all, opt_flags)
8807 int all;
8808 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8809{
8810 struct vimoption *p;
8811 int col;
8812 int isterm;
8813 char_u *varp;
8814 struct vimoption **items;
8815 int item_count;
8816 int run;
8817 int row, rows;
8818 int cols;
8819 int i;
8820 int len;
8821
8822#define INC 20
8823#define GAP 3
8824
8825 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8826 PARAM_COUNT));
8827 if (items == NULL)
8828 return;
8829
8830 /* Highlight title */
8831 if (all == 2)
8832 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8833 else if (opt_flags & OPT_GLOBAL)
8834 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8835 else if (opt_flags & OPT_LOCAL)
8836 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8837 else
8838 MSG_PUTS_TITLE(_("\n--- Options ---"));
8839
8840 /*
8841 * do the loop two times:
8842 * 1. display the short items
8843 * 2. display the long items (only strings and numbers)
8844 */
8845 for (run = 1; run <= 2 && !got_int; ++run)
8846 {
8847 /*
8848 * collect the items in items[]
8849 */
8850 item_count = 0;
8851 for (p = &options[0]; p->fullname != NULL; p++)
8852 {
8853 varp = NULL;
8854 isterm = istermoption(p);
8855 if (opt_flags != 0)
8856 {
8857 if (p->indir != PV_NONE && !isterm)
8858 varp = get_varp_scope(p, opt_flags);
8859 }
8860 else
8861 varp = get_varp(p);
8862 if (varp != NULL
8863 && ((all == 2 && isterm)
8864 || (all == 1 && !isterm)
8865 || (all == 0 && !optval_default(p, varp))))
8866 {
8867 if (p->flags & P_BOOL)
8868 len = 1; /* a toggle option fits always */
8869 else
8870 {
8871 option_value2string(p, opt_flags);
8872 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8873 }
8874 if ((len <= INC - GAP && run == 1) ||
8875 (len > INC - GAP && run == 2))
8876 items[item_count++] = p;
8877 }
8878 }
8879
8880 /*
8881 * display the items
8882 */
8883 if (run == 1)
8884 {
8885 cols = (Columns + GAP - 3) / INC;
8886 if (cols == 0)
8887 cols = 1;
8888 rows = (item_count + cols - 1) / cols;
8889 }
8890 else /* run == 2 */
8891 rows = item_count;
8892 for (row = 0; row < rows && !got_int; ++row)
8893 {
8894 msg_putchar('\n'); /* go to next line */
8895 if (got_int) /* 'q' typed in more */
8896 break;
8897 col = 0;
8898 for (i = row; i < item_count; i += rows)
8899 {
8900 msg_col = col; /* make columns */
8901 showoneopt(items[i], opt_flags);
8902 col += INC;
8903 }
8904 out_flush();
8905 ui_breakcheck();
8906 }
8907 }
8908 vim_free(items);
8909}
8910
8911/*
8912 * Return TRUE if option "p" has its default value.
8913 */
8914 static int
8915optval_default(p, varp)
8916 struct vimoption *p;
8917 char_u *varp;
8918{
8919 int dvi;
8920
8921 if (varp == NULL)
8922 return TRUE; /* hidden option is always at default */
8923 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8924 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008925 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008927 /* the cast to long is required for Manx C, long_i is
8928 * needed for MSVC */
8929 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930 /* P_STRING */
8931 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8932}
8933
8934/*
8935 * showoneopt: show the value of one option
8936 * must not be called with a hidden option!
8937 */
8938 static void
8939showoneopt(p, opt_flags)
8940 struct vimoption *p;
8941 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8942{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008943 char_u *varp;
8944 int save_silent = silent_mode;
8945
8946 silent_mode = FALSE;
8947 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948
8949 varp = get_varp_scope(p, opt_flags);
8950
8951 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8952 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8953 ? !curbufIsChanged() : !*(int *)varp))
8954 MSG_PUTS("no");
8955 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8956 MSG_PUTS("--");
8957 else
8958 MSG_PUTS(" ");
8959 MSG_PUTS(p->fullname);
8960 if (!(p->flags & P_BOOL))
8961 {
8962 msg_putchar('=');
8963 /* put value string in NameBuff */
8964 option_value2string(p, opt_flags);
8965 msg_outtrans(NameBuff);
8966 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008967
8968 silent_mode = save_silent;
8969 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970}
8971
8972/*
8973 * Write modified options as ":set" commands to a file.
8974 *
8975 * There are three values for "opt_flags":
8976 * OPT_GLOBAL: Write global option values and fresh values of
8977 * buffer-local options (used for start of a session
8978 * file).
8979 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8980 * curwin (used for a vimrc file).
8981 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8982 * and local values for window-local options of
8983 * curwin. Local values are also written when at the
8984 * default value, because a modeline or autocommand
8985 * may have set them when doing ":edit file" and the
8986 * user has set them back at the default or fresh
8987 * value.
8988 * When "local_only" is TRUE, don't write fresh
8989 * values, only local values (for ":mkview").
8990 * (fresh value = value used for a new buffer or window for a local option).
8991 *
8992 * Return FAIL on error, OK otherwise.
8993 */
8994 int
8995makeset(fd, opt_flags, local_only)
8996 FILE *fd;
8997 int opt_flags;
8998 int local_only;
8999{
9000 struct vimoption *p;
9001 char_u *varp; /* currently used value */
9002 char_u *varp_fresh; /* local value */
9003 char_u *varp_local = NULL; /* fresh value */
9004 char *cmd;
9005 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009006 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009007
9008 /*
9009 * The options that don't have a default (terminal name, columns, lines)
9010 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009011 * Do the loop over "options[]" twice: once for options with the
9012 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009014 for (pri = 1; pri >= 0; --pri)
9015 {
9016 for (p = &options[0]; !istermoption(p); p++)
9017 if (!(p->flags & P_NO_MKRC)
9018 && !istermoption(p)
9019 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020 {
9021 /* skip global option when only doing locals */
9022 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9023 continue;
9024
9025 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9026 * file, they are always buffer-specific. */
9027 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9028 continue;
9029
9030 /* Global values are only written when not at the default value. */
9031 varp = get_varp_scope(p, opt_flags);
9032 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9033 continue;
9034
9035 round = 2;
9036 if (p->indir != PV_NONE)
9037 {
9038 if (p->var == VAR_WIN)
9039 {
9040 /* skip window-local option when only doing globals */
9041 if (!(opt_flags & OPT_LOCAL))
9042 continue;
9043 /* When fresh value of window-local option is not at the
9044 * default, need to write it too. */
9045 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9046 {
9047 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9048 if (!optval_default(p, varp_fresh))
9049 {
9050 round = 1;
9051 varp_local = varp;
9052 varp = varp_fresh;
9053 }
9054 }
9055 }
9056 }
9057
9058 /* Round 1: fresh value for window-local options.
9059 * Round 2: other values */
9060 for ( ; round <= 2; varp = varp_local, ++round)
9061 {
9062 if (round == 1 || (opt_flags & OPT_GLOBAL))
9063 cmd = "set";
9064 else
9065 cmd = "setlocal";
9066
9067 if (p->flags & P_BOOL)
9068 {
9069 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9070 return FAIL;
9071 }
9072 else if (p->flags & P_NUM)
9073 {
9074 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9075 return FAIL;
9076 }
9077 else /* P_STRING */
9078 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009079#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9080 int do_endif = FALSE;
9081
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 /* Don't set 'syntax' and 'filetype' again if the value is
9083 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009084 if (
9085# if defined(FEAT_SYN_HL)
9086 p->indir == PV_SYN
9087# if defined(FEAT_AUTOCMD)
9088 ||
9089# endif
9090# endif
9091# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009092 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009093# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009094 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 {
9096 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9097 *(char_u **)(varp)) < 0
9098 || put_eol(fd) < 0)
9099 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009100 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9104 (p->flags & P_EXPAND) != 0) == FAIL)
9105 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009106#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9107 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108 {
9109 if (put_line(fd, "endif") == FAIL)
9110 return FAIL;
9111 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 }
9114 }
9115 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 return OK;
9118}
9119
9120#if defined(FEAT_FOLDING) || defined(PROTO)
9121/*
9122 * Generate set commands for the local fold options only. Used when
9123 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9124 */
9125 int
9126makefoldset(fd)
9127 FILE *fd;
9128{
9129 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9130# ifdef FEAT_EVAL
9131 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9132 == FAIL
9133# endif
9134 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9135 == FAIL
9136 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9137 == FAIL
9138 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9139 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9140 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9141 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9142 )
9143 return FAIL;
9144
9145 return OK;
9146}
9147#endif
9148
9149 static int
9150put_setstring(fd, cmd, name, valuep, expand)
9151 FILE *fd;
9152 char *cmd;
9153 char *name;
9154 char_u **valuep;
9155 int expand;
9156{
9157 char_u *s;
9158 char_u buf[MAXPATHL];
9159
9160 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9161 return FAIL;
9162 if (*valuep != NULL)
9163 {
9164 /* Output 'pastetoggle' as key names. For other
9165 * options some characters have to be escaped with
9166 * CTRL-V or backslash */
9167 if (valuep == &p_pt)
9168 {
9169 s = *valuep;
9170 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009171 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 return FAIL;
9173 }
9174 else if (expand)
9175 {
9176 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9177 if (put_escstr(fd, buf, 2) == FAIL)
9178 return FAIL;
9179 }
9180 else if (put_escstr(fd, *valuep, 2) == FAIL)
9181 return FAIL;
9182 }
9183 if (put_eol(fd) < 0)
9184 return FAIL;
9185 return OK;
9186}
9187
9188 static int
9189put_setnum(fd, cmd, name, valuep)
9190 FILE *fd;
9191 char *cmd;
9192 char *name;
9193 long *valuep;
9194{
9195 long wc;
9196
9197 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9198 return FAIL;
9199 if (wc_use_keyname((char_u *)valuep, &wc))
9200 {
9201 /* print 'wildchar' and 'wildcharm' as a key name */
9202 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9203 return FAIL;
9204 }
9205 else if (fprintf(fd, "%ld", *valuep) < 0)
9206 return FAIL;
9207 if (put_eol(fd) < 0)
9208 return FAIL;
9209 return OK;
9210}
9211
9212 static int
9213put_setbool(fd, cmd, name, value)
9214 FILE *fd;
9215 char *cmd;
9216 char *name;
9217 int value;
9218{
Bram Moolenaar893de922007-10-02 18:40:57 +00009219 if (value < 0) /* global/local option using global value */
9220 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9222 || put_eol(fd) < 0)
9223 return FAIL;
9224 return OK;
9225}
9226
9227/*
9228 * Clear all the terminal options.
9229 * If the option has been allocated, free the memory.
9230 * Terminal options are never hidden or indirect.
9231 */
9232 void
9233clear_termoptions()
9234{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235 /*
9236 * Reset a few things before clearing the old options. This may cause
9237 * outputting a few things that the terminal doesn't understand, but the
9238 * screen will be cleared later, so this is OK.
9239 */
9240#ifdef FEAT_MOUSE_TTY
9241 mch_setmouse(FALSE); /* switch mouse off */
9242#endif
9243#ifdef FEAT_TITLE
9244 mch_restore_title(3); /* restore window titles */
9245#endif
9246#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9247 /* When starting the GUI close the display opened for the clipboard.
9248 * After restoring the title, because that will need the display. */
9249 if (gui.starting)
9250 clear_xterm_clip();
9251#endif
9252#ifdef WIN3264
9253 /*
9254 * Check if this is allowed now.
9255 */
9256 if (can_end_termcap_mode(FALSE) == TRUE)
9257#endif
9258 stoptermcap(); /* stop termcap mode */
9259
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009260 free_termoptions();
9261}
9262
9263 void
9264free_termoptions()
9265{
9266 struct vimoption *p;
9267
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268 for (p = &options[0]; p->fullname != NULL; p++)
9269 if (istermoption(p))
9270 {
9271 if (p->flags & P_ALLOCED)
9272 free_string_option(*(char_u **)(p->var));
9273 if (p->flags & P_DEF_ALLOCED)
9274 free_string_option(p->def_val[VI_DEFAULT]);
9275 *(char_u **)(p->var) = empty_option;
9276 p->def_val[VI_DEFAULT] = empty_option;
9277 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9278 }
9279 clear_termcodes();
9280}
9281
9282/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009283 * Free the string for one term option, if it was allocated.
9284 * Set the string to empty_option and clear allocated flag.
9285 * "var" points to the option value.
9286 */
9287 void
9288free_one_termoption(var)
9289 char_u *var;
9290{
9291 struct vimoption *p;
9292
9293 for (p = &options[0]; p->fullname != NULL; p++)
9294 if (p->var == var)
9295 {
9296 if (p->flags & P_ALLOCED)
9297 free_string_option(*(char_u **)(p->var));
9298 *(char_u **)(p->var) = empty_option;
9299 p->flags &= ~P_ALLOCED;
9300 break;
9301 }
9302}
9303
9304/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 * Set the terminal option defaults to the current value.
9306 * Used after setting the terminal name.
9307 */
9308 void
9309set_term_defaults()
9310{
9311 struct vimoption *p;
9312
9313 for (p = &options[0]; p->fullname != NULL; p++)
9314 {
9315 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9316 {
9317 if (p->flags & P_DEF_ALLOCED)
9318 {
9319 free_string_option(p->def_val[VI_DEFAULT]);
9320 p->flags &= ~P_DEF_ALLOCED;
9321 }
9322 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9323 if (p->flags & P_ALLOCED)
9324 {
9325 p->flags |= P_DEF_ALLOCED;
9326 p->flags &= ~P_ALLOCED; /* don't free the value now */
9327 }
9328 }
9329 }
9330}
9331
9332/*
9333 * return TRUE if 'p' starts with 't_'
9334 */
9335 static int
9336istermoption(p)
9337 struct vimoption *p;
9338{
9339 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9340}
9341
9342/*
9343 * Compute columns for ruler and shown command. 'sc_col' is also used to
9344 * decide what the maximum length of a message on the status line can be.
9345 * If there is a status line for the last window, 'sc_col' is independent
9346 * of 'ru_col'.
9347 */
9348
9349#define COL_RULER 17 /* columns needed by standard ruler */
9350
9351 void
9352comp_col()
9353{
9354#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9355 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9356
9357 sc_col = 0;
9358 ru_col = 0;
9359 if (p_ru)
9360 {
9361#ifdef FEAT_STL_OPT
9362 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9363#else
9364 ru_col = COL_RULER + 1;
9365#endif
9366 /* no last status line, adjust sc_col */
9367 if (!last_has_status)
9368 sc_col = ru_col;
9369 }
9370 if (p_sc)
9371 {
9372 sc_col += SHOWCMD_COLS;
9373 if (!p_ru || last_has_status) /* no need for separating space */
9374 ++sc_col;
9375 }
9376 sc_col = Columns - sc_col;
9377 ru_col = Columns - ru_col;
9378 if (sc_col <= 0) /* screen too narrow, will become a mess */
9379 sc_col = 1;
9380 if (ru_col <= 0)
9381 ru_col = 1;
9382#else
9383 sc_col = Columns;
9384 ru_col = Columns;
9385#endif
9386}
9387
9388/*
9389 * Get pointer to option variable, depending on local or global scope.
9390 */
9391 static char_u *
9392get_varp_scope(p, opt_flags)
9393 struct vimoption *p;
9394 int opt_flags;
9395{
9396 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9397 {
9398 if (p->var == VAR_WIN)
9399 return (char_u *)GLOBAL_WO(get_varp(p));
9400 return p->var;
9401 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009402 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 {
9404 switch ((int)p->indir)
9405 {
9406#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009407 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9408 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9409 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009411 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9412 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9413 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009414 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009415 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009417 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9418 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419#endif
9420#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009421 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9422 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009424#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9425 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9426#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009427#if defined(FEAT_CRYPT)
9428 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9429#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009430#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009431 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 }
9434 return NULL; /* "cannot happen" */
9435 }
9436 return get_varp(p);
9437}
9438
9439/*
9440 * Get pointer to option variable.
9441 */
9442 static char_u *
9443get_varp(p)
9444 struct vimoption *p;
9445{
9446 /* hidden option, always return NULL */
9447 if (p->var == NULL)
9448 return NULL;
9449
9450 switch ((int)p->indir)
9451 {
9452 case PV_NONE: return p->var;
9453
9454 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009455 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009457 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009459 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009461 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009463 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9465#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009466 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009468 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9470#endif
9471#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009472 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009474 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9476#endif
9477#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009478 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009480 case PV_GP: return *curbuf->b_p_gp != NUL
9481 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9482 case PV_MP: return *curbuf->b_p_mp != NUL
9483 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009485#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9486 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9487 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9488#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009489#if defined(FEAT_CRYPT)
9490 case PV_CM: return *curbuf->b_p_cm != NUL
9491 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9492#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009493#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009494 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009495 ? (char_u *)&(curwin->w_p_stl) : p->var;
9496#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497
9498#ifdef FEAT_ARABIC
9499 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9500#endif
9501 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009502#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009503 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9504#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009505#ifdef FEAT_SYN_HL
9506 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9507 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009508 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009510#ifdef FEAT_DIFF
9511 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9512#endif
9513#ifdef FEAT_FOLDING
9514 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9515 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9516 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9517 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9518 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9519 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9520 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9521# ifdef FEAT_EVAL
9522 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9523 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9524# endif
9525 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9526#endif
9527 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009528 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009529#ifdef FEAT_LINEBREAK
9530 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9531#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009532#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9534#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009535#ifdef FEAT_VERTSPLIT
9536 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009538#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9539 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9540#endif
9541#ifdef FEAT_RIGHTLEFT
9542 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9543 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9544#endif
9545 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9546 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9547#ifdef FEAT_LINEBREAK
9548 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9549#endif
9550#ifdef FEAT_SCROLLBIND
9551 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9552#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009553#ifdef FEAT_CURSORBIND
9554 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9555#endif
9556#ifdef FEAT_CONCEAL
Bram Moolenaarc400cb92010-07-19 19:52:13 +02009557 case PV_CONCEAL: return (char_u *)&(curwin->w_p_conc);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559
9560 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9561 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9562#ifdef FEAT_MBYTE
9563 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9564#endif
9565#if defined(FEAT_QUICKFIX)
9566 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9567 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9568#endif
9569 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9570 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9571#ifdef FEAT_CINDENT
9572 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9573 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9574 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9575#endif
9576#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9577 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9578#endif
9579#ifdef FEAT_COMMENTS
9580 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9581#endif
9582#ifdef FEAT_FOLDING
9583 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9584#endif
9585#ifdef FEAT_INS_EXPAND
9586 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9587#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009588#ifdef FEAT_COMPL_FUNC
9589 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009590 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9593 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9594#ifdef FEAT_MBYTE
9595 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9596#endif
9597 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9598#ifdef FEAT_AUTOCMD
9599 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9600#endif
9601 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009602 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9604 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9605 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9606 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9607#ifdef FEAT_FIND_ID
9608# ifdef FEAT_EVAL
9609 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9610# endif
9611#endif
9612#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9613 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9614 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9615#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009616#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009617 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009619#ifdef FEAT_CRYPT
9620 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9621#endif
9622#ifdef FEAT_LISP
9623 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9624#endif
9625 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9626 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9627 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9628 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9629 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9630#ifdef FEAT_OSFILETYPE
9631 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9632#endif
9633 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009634#ifdef FEAT_TEXTOBJ
9635 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9638#ifdef FEAT_SMARTINDENT
9639 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9640#endif
9641#ifndef SHORT_FNAME
9642 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9643#endif
9644 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9645#ifdef FEAT_SEARCHPATH
9646 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9647#endif
9648 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9649#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009650 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009651 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9652#endif
9653#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009654 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9655 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9656 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657#endif
9658 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9659 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9660 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9661 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009662#ifdef FEAT_PERSISTENT_UNDO
9663 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009665 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9666#ifdef FEAT_KEYMAP
9667 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9668#endif
9669 default: EMSG(_("E356: get_varp ERROR"));
9670 }
9671 /* always return a valid pointer to avoid a crash! */
9672 return (char_u *)&(curbuf->b_p_wm);
9673}
9674
9675/*
9676 * Get the value of 'equalprg', either the buffer-local one or the global one.
9677 */
9678 char_u *
9679get_equalprg()
9680{
9681 if (*curbuf->b_p_ep == NUL)
9682 return p_ep;
9683 return curbuf->b_p_ep;
9684}
9685
9686#if defined(FEAT_WINDOWS) || defined(PROTO)
9687/*
9688 * Copy options from one window to another.
9689 * Used when splitting a window.
9690 */
9691 void
9692win_copy_options(wp_from, wp_to)
9693 win_T *wp_from;
9694 win_T *wp_to;
9695{
9696 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9697 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9698# ifdef FEAT_RIGHTLEFT
9699# ifdef FEAT_FKMAP
9700 /* Is this right? */
9701 wp_to->w_farsi = wp_from->w_farsi;
9702# endif
9703# endif
9704}
9705#endif
9706
9707/*
9708 * Copy the options from one winopt_T to another.
9709 * Doesn't free the old option values in "to", use clear_winopt() for that.
9710 * The 'scroll' option is not copied, because it depends on the window height.
9711 * The 'previewwindow' option is reset, there can be only one preview window.
9712 */
9713 void
9714copy_winopt(from, to)
9715 winopt_T *from;
9716 winopt_T *to;
9717{
9718#ifdef FEAT_ARABIC
9719 to->wo_arab = from->wo_arab;
9720#endif
9721 to->wo_list = from->wo_list;
9722 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009723 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009724#ifdef FEAT_LINEBREAK
9725 to->wo_nuw = from->wo_nuw;
9726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727#ifdef FEAT_RIGHTLEFT
9728 to->wo_rl = from->wo_rl;
9729 to->wo_rlc = vim_strsave(from->wo_rlc);
9730#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009731#ifdef FEAT_STL_OPT
9732 to->wo_stl = vim_strsave(from->wo_stl);
9733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 to->wo_wrap = from->wo_wrap;
9735#ifdef FEAT_LINEBREAK
9736 to->wo_lbr = from->wo_lbr;
9737#endif
9738#ifdef FEAT_SCROLLBIND
9739 to->wo_scb = from->wo_scb;
9740#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009741#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009742 to->wo_spell = from->wo_spell;
9743#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009744#ifdef FEAT_SYN_HL
9745 to->wo_cuc = from->wo_cuc;
9746 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009747 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009748#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749#ifdef FEAT_DIFF
9750 to->wo_diff = from->wo_diff;
9751#endif
9752#ifdef FEAT_FOLDING
9753 to->wo_fdc = from->wo_fdc;
9754 to->wo_fen = from->wo_fen;
9755 to->wo_fdi = vim_strsave(from->wo_fdi);
9756 to->wo_fml = from->wo_fml;
9757 to->wo_fdl = from->wo_fdl;
9758 to->wo_fdm = vim_strsave(from->wo_fdm);
9759 to->wo_fdn = from->wo_fdn;
9760# ifdef FEAT_EVAL
9761 to->wo_fde = vim_strsave(from->wo_fde);
9762 to->wo_fdt = vim_strsave(from->wo_fdt);
9763# endif
9764 to->wo_fmr = vim_strsave(from->wo_fmr);
9765#endif
9766 check_winopt(to); /* don't want NULL pointers */
9767}
9768
9769/*
9770 * Check string options in a window for a NULL value.
9771 */
9772 void
9773check_win_options(win)
9774 win_T *win;
9775{
9776 check_winopt(&win->w_onebuf_opt);
9777 check_winopt(&win->w_allbuf_opt);
9778}
9779
9780/*
9781 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9782 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 void
9784check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009785 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786{
9787#ifdef FEAT_FOLDING
9788 check_string_option(&wop->wo_fdi);
9789 check_string_option(&wop->wo_fdm);
9790# ifdef FEAT_EVAL
9791 check_string_option(&wop->wo_fde);
9792 check_string_option(&wop->wo_fdt);
9793# endif
9794 check_string_option(&wop->wo_fmr);
9795#endif
9796#ifdef FEAT_RIGHTLEFT
9797 check_string_option(&wop->wo_rlc);
9798#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009799#ifdef FEAT_STL_OPT
9800 check_string_option(&wop->wo_stl);
9801#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009802#ifdef FEAT_SYN_HL
9803 check_string_option(&wop->wo_cc);
9804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805}
9806
9807/*
9808 * Free the allocated memory inside a winopt_T.
9809 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 void
9811clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009812 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009813{
9814#ifdef FEAT_FOLDING
9815 clear_string_option(&wop->wo_fdi);
9816 clear_string_option(&wop->wo_fdm);
9817# ifdef FEAT_EVAL
9818 clear_string_option(&wop->wo_fde);
9819 clear_string_option(&wop->wo_fdt);
9820# endif
9821 clear_string_option(&wop->wo_fmr);
9822#endif
9823#ifdef FEAT_RIGHTLEFT
9824 clear_string_option(&wop->wo_rlc);
9825#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009826#ifdef FEAT_STL_OPT
9827 clear_string_option(&wop->wo_stl);
9828#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009829#ifdef FEAT_SYN_HL
9830 clear_string_option(&wop->wo_cc);
9831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832}
9833
9834/*
9835 * Copy global option values to local options for one buffer.
9836 * Used when creating a new buffer and sometimes when entering a buffer.
9837 * flags:
9838 * BCO_ENTER We will enter the buf buffer.
9839 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9840 * appropriate.
9841 * BCO_NOHELP Don't copy the values to a help buffer.
9842 */
9843 void
9844buf_copy_options(buf, flags)
9845 buf_T *buf;
9846 int flags;
9847{
9848 int should_copy = TRUE;
9849 char_u *save_p_isk = NULL; /* init for GCC */
9850 int dont_do_help;
9851 int did_isk = FALSE;
9852
9853 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009854 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009855 */
9856 if (buf == NULL || !buf_valid(buf))
9857 return;
9858
9859 /*
9860 * Skip this when the option defaults have not been set yet. Happens when
9861 * main() allocates the first buffer.
9862 */
9863 if (p_cpo != NULL)
9864 {
9865 /*
9866 * Always copy when entering and 'cpo' contains 'S'.
9867 * Don't copy when already initialized.
9868 * Don't copy when 'cpo' contains 's' and not entering.
9869 * 'S' BCO_ENTER initialized 's' should_copy
9870 * yes yes X X TRUE
9871 * yes no yes X FALSE
9872 * no X yes X FALSE
9873 * X no no yes FALSE
9874 * X no no no TRUE
9875 * no yes no X TRUE
9876 */
9877 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9878 && (buf->b_p_initialized
9879 || (!(flags & BCO_ENTER)
9880 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9881 should_copy = FALSE;
9882
9883 if (should_copy || (flags & BCO_ALWAYS))
9884 {
9885 /* Don't copy the options specific to a help buffer when
9886 * BCO_NOHELP is given or the options were initialized already
9887 * (jumping back to a help file with CTRL-T or CTRL-O) */
9888 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9889 || buf->b_p_initialized;
9890 if (dont_do_help) /* don't free b_p_isk */
9891 {
9892 save_p_isk = buf->b_p_isk;
9893 buf->b_p_isk = NULL;
9894 }
9895 /*
9896 * Always free the allocated strings.
9897 * If not already initialized, set 'readonly' and copy 'fileformat'.
9898 */
9899 if (!buf->b_p_initialized)
9900 {
9901 free_buf_options(buf, TRUE);
9902 buf->b_p_ro = FALSE; /* don't copy readonly */
9903 buf->b_p_tx = p_tx;
9904#ifdef FEAT_MBYTE
9905 buf->b_p_fenc = vim_strsave(p_fenc);
9906#endif
9907 buf->b_p_ff = vim_strsave(p_ff);
9908#if defined(FEAT_QUICKFIX)
9909 buf->b_p_bh = empty_option;
9910 buf->b_p_bt = empty_option;
9911#endif
9912 }
9913 else
9914 free_buf_options(buf, FALSE);
9915
9916 buf->b_p_ai = p_ai;
9917 buf->b_p_ai_nopaste = p_ai_nopaste;
9918 buf->b_p_sw = p_sw;
9919 buf->b_p_tw = p_tw;
9920 buf->b_p_tw_nopaste = p_tw_nopaste;
9921 buf->b_p_tw_nobin = p_tw_nobin;
9922 buf->b_p_wm = p_wm;
9923 buf->b_p_wm_nopaste = p_wm_nopaste;
9924 buf->b_p_wm_nobin = p_wm_nobin;
9925 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009926#ifdef FEAT_MBYTE
9927 buf->b_p_bomb = p_bomb;
9928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929 buf->b_p_et = p_et;
9930 buf->b_p_et_nobin = p_et_nobin;
9931 buf->b_p_ml = p_ml;
9932 buf->b_p_ml_nobin = p_ml_nobin;
9933 buf->b_p_inf = p_inf;
9934 buf->b_p_swf = p_swf;
9935#ifdef FEAT_INS_EXPAND
9936 buf->b_p_cpt = vim_strsave(p_cpt);
9937#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009938#ifdef FEAT_COMPL_FUNC
9939 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009940 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942 buf->b_p_sts = p_sts;
9943 buf->b_p_sts_nopaste = p_sts_nopaste;
9944#ifndef SHORT_FNAME
9945 buf->b_p_sn = p_sn;
9946#endif
9947#ifdef FEAT_COMMENTS
9948 buf->b_p_com = vim_strsave(p_com);
9949#endif
9950#ifdef FEAT_FOLDING
9951 buf->b_p_cms = vim_strsave(p_cms);
9952#endif
9953 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009954 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 buf->b_p_nf = vim_strsave(p_nf);
9956 buf->b_p_mps = vim_strsave(p_mps);
9957#ifdef FEAT_SMARTINDENT
9958 buf->b_p_si = p_si;
9959#endif
9960 buf->b_p_ci = p_ci;
9961#ifdef FEAT_CINDENT
9962 buf->b_p_cin = p_cin;
9963 buf->b_p_cink = vim_strsave(p_cink);
9964 buf->b_p_cino = vim_strsave(p_cino);
9965#endif
9966#ifdef FEAT_AUTOCMD
9967 /* Don't copy 'filetype', it must be detected */
9968 buf->b_p_ft = empty_option;
9969#endif
9970#ifdef FEAT_OSFILETYPE
9971 buf->b_p_oft = vim_strsave(p_oft);
9972#endif
9973 buf->b_p_pi = p_pi;
9974#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9975 buf->b_p_cinw = vim_strsave(p_cinw);
9976#endif
9977#ifdef FEAT_LISP
9978 buf->b_p_lisp = p_lisp;
9979#endif
9980#ifdef FEAT_SYN_HL
9981 /* Don't copy 'syntax', it must be set */
9982 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009983 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009984#endif
9985#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009986 buf->b_s.b_p_spc = vim_strsave(p_spf);
9987 (void)compile_cap_prog(&buf->b_s);
9988 buf->b_s.b_p_spf = vim_strsave(p_spf);
9989 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990#endif
9991#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9992 buf->b_p_inde = vim_strsave(p_inde);
9993 buf->b_p_indk = vim_strsave(p_indk);
9994#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009995#if defined(FEAT_EVAL)
9996 buf->b_p_fex = vim_strsave(p_fex);
9997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998#ifdef FEAT_CRYPT
9999 buf->b_p_key = vim_strsave(p_key);
10000#endif
10001#ifdef FEAT_SEARCHPATH
10002 buf->b_p_sua = vim_strsave(p_sua);
10003#endif
10004#ifdef FEAT_KEYMAP
10005 buf->b_p_keymap = vim_strsave(p_keymap);
10006 buf->b_kmap_state |= KEYMAP_INIT;
10007#endif
10008 /* This isn't really an option, but copying the langmap and IME
10009 * state from the current buffer is better than resetting it. */
10010 buf->b_p_iminsert = p_iminsert;
10011 buf->b_p_imsearch = p_imsearch;
10012
10013 /* options that are normally global but also have a local value
10014 * are not copied, start using the global value */
10015 buf->b_p_ar = -1;
10016#ifdef FEAT_QUICKFIX
10017 buf->b_p_gp = empty_option;
10018 buf->b_p_mp = empty_option;
10019 buf->b_p_efm = empty_option;
10020#endif
10021 buf->b_p_ep = empty_option;
10022 buf->b_p_kp = empty_option;
10023 buf->b_p_path = empty_option;
10024 buf->b_p_tags = empty_option;
10025#ifdef FEAT_FIND_ID
10026 buf->b_p_def = empty_option;
10027 buf->b_p_inc = empty_option;
10028# ifdef FEAT_EVAL
10029 buf->b_p_inex = vim_strsave(p_inex);
10030# endif
10031#endif
10032#ifdef FEAT_INS_EXPAND
10033 buf->b_p_dict = empty_option;
10034 buf->b_p_tsr = empty_option;
10035#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010036#ifdef FEAT_TEXTOBJ
10037 buf->b_p_qe = vim_strsave(p_qe);
10038#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010039#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10040 buf->b_p_bexpr = empty_option;
10041#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010042#if defined(FEAT_CRYPT)
10043 buf->b_p_cm = empty_option;
10044#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010045#ifdef FEAT_PERSISTENT_UNDO
10046 buf->b_p_udf = p_udf;
10047#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010048
10049 /*
10050 * Don't copy the options set by ex_help(), use the saved values,
10051 * when going from a help buffer to a non-help buffer.
10052 * Don't touch these at all when BCO_NOHELP is used and going from
10053 * or to a help buffer.
10054 */
10055 if (dont_do_help)
10056 buf->b_p_isk = save_p_isk;
10057 else
10058 {
10059 buf->b_p_isk = vim_strsave(p_isk);
10060 did_isk = TRUE;
10061 buf->b_p_ts = p_ts;
10062 buf->b_help = FALSE;
10063#ifdef FEAT_QUICKFIX
10064 if (buf->b_p_bt[0] == 'h')
10065 clear_string_option(&buf->b_p_bt);
10066#endif
10067 buf->b_p_ma = p_ma;
10068 }
10069 }
10070
10071 /*
10072 * When the options should be copied (ignoring BCO_ALWAYS), set the
10073 * flag that indicates that the options have been initialized.
10074 */
10075 if (should_copy)
10076 buf->b_p_initialized = TRUE;
10077 }
10078
10079 check_buf_options(buf); /* make sure we don't have NULLs */
10080 if (did_isk)
10081 (void)buf_init_chartab(buf, FALSE);
10082}
10083
10084/*
10085 * Reset the 'modifiable' option and its default value.
10086 */
10087 void
10088reset_modifiable()
10089{
10090 int opt_idx;
10091
10092 curbuf->b_p_ma = FALSE;
10093 p_ma = FALSE;
10094 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010095 if (opt_idx >= 0)
10096 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097}
10098
10099/*
10100 * Set the global value for 'iminsert' to the local value.
10101 */
10102 void
10103set_iminsert_global()
10104{
10105 p_iminsert = curbuf->b_p_iminsert;
10106}
10107
10108/*
10109 * Set the global value for 'imsearch' to the local value.
10110 */
10111 void
10112set_imsearch_global()
10113{
10114 p_imsearch = curbuf->b_p_imsearch;
10115}
10116
10117#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10118static int expand_option_idx = -1;
10119static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10120static int expand_option_flags = 0;
10121
10122 void
10123set_context_in_set_cmd(xp, arg, opt_flags)
10124 expand_T *xp;
10125 char_u *arg;
10126 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10127{
10128 int nextchar;
10129 long_u flags = 0; /* init for GCC */
10130 int opt_idx = 0; /* init for GCC */
10131 char_u *p;
10132 char_u *s;
10133 int is_term_option = FALSE;
10134 int key;
10135
10136 expand_option_flags = opt_flags;
10137
10138 xp->xp_context = EXPAND_SETTINGS;
10139 if (*arg == NUL)
10140 {
10141 xp->xp_pattern = arg;
10142 return;
10143 }
10144 p = arg + STRLEN(arg) - 1;
10145 if (*p == ' ' && *(p - 1) != '\\')
10146 {
10147 xp->xp_pattern = p + 1;
10148 return;
10149 }
10150 while (p > arg)
10151 {
10152 s = p;
10153 /* count number of backslashes before ' ' or ',' */
10154 if (*p == ' ' || *p == ',')
10155 {
10156 while (s > arg && *(s - 1) == '\\')
10157 --s;
10158 }
10159 /* break at a space with an even number of backslashes */
10160 if (*p == ' ' && ((p - s) & 1) == 0)
10161 {
10162 ++p;
10163 break;
10164 }
10165 --p;
10166 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010167 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 {
10169 xp->xp_context = EXPAND_BOOL_SETTINGS;
10170 p += 2;
10171 }
10172 if (STRNCMP(p, "inv", 3) == 0)
10173 {
10174 xp->xp_context = EXPAND_BOOL_SETTINGS;
10175 p += 3;
10176 }
10177 xp->xp_pattern = arg = p;
10178 if (*arg == '<')
10179 {
10180 while (*p != '>')
10181 if (*p++ == NUL) /* expand terminal option name */
10182 return;
10183 key = get_special_key_code(arg + 1);
10184 if (key == 0) /* unknown name */
10185 {
10186 xp->xp_context = EXPAND_NOTHING;
10187 return;
10188 }
10189 nextchar = *++p;
10190 is_term_option = TRUE;
10191 expand_option_name[2] = KEY2TERMCAP0(key);
10192 expand_option_name[3] = KEY2TERMCAP1(key);
10193 }
10194 else
10195 {
10196 if (p[0] == 't' && p[1] == '_')
10197 {
10198 p += 2;
10199 if (*p != NUL)
10200 ++p;
10201 if (*p == NUL)
10202 return; /* expand option name */
10203 nextchar = *++p;
10204 is_term_option = TRUE;
10205 expand_option_name[2] = p[-2];
10206 expand_option_name[3] = p[-1];
10207 }
10208 else
10209 {
10210 /* Allow * wildcard */
10211 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10212 p++;
10213 if (*p == NUL)
10214 return;
10215 nextchar = *p;
10216 *p = NUL;
10217 opt_idx = findoption(arg);
10218 *p = nextchar;
10219 if (opt_idx == -1 || options[opt_idx].var == NULL)
10220 {
10221 xp->xp_context = EXPAND_NOTHING;
10222 return;
10223 }
10224 flags = options[opt_idx].flags;
10225 if (flags & P_BOOL)
10226 {
10227 xp->xp_context = EXPAND_NOTHING;
10228 return;
10229 }
10230 }
10231 }
10232 /* handle "-=" and "+=" */
10233 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10234 {
10235 ++p;
10236 nextchar = '=';
10237 }
10238 if ((nextchar != '=' && nextchar != ':')
10239 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10240 {
10241 xp->xp_context = EXPAND_UNSUCCESSFUL;
10242 return;
10243 }
10244 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10245 {
10246 xp->xp_context = EXPAND_OLD_SETTING;
10247 if (is_term_option)
10248 expand_option_idx = -1;
10249 else
10250 expand_option_idx = opt_idx;
10251 xp->xp_pattern = p + 1;
10252 return;
10253 }
10254 xp->xp_context = EXPAND_NOTHING;
10255 if (is_term_option || (flags & P_NUM))
10256 return;
10257
10258 xp->xp_pattern = p + 1;
10259
10260 if (flags & P_EXPAND)
10261 {
10262 p = options[opt_idx].var;
10263 if (p == (char_u *)&p_bdir
10264 || p == (char_u *)&p_dir
10265 || p == (char_u *)&p_path
10266 || p == (char_u *)&p_rtp
10267#ifdef FEAT_SEARCHPATH
10268 || p == (char_u *)&p_cdpath
10269#endif
10270#ifdef FEAT_SESSION
10271 || p == (char_u *)&p_vdir
10272#endif
10273 )
10274 {
10275 xp->xp_context = EXPAND_DIRECTORIES;
10276 if (p == (char_u *)&p_path
10277#ifdef FEAT_SEARCHPATH
10278 || p == (char_u *)&p_cdpath
10279#endif
10280 )
10281 xp->xp_backslash = XP_BS_THREE;
10282 else
10283 xp->xp_backslash = XP_BS_ONE;
10284 }
10285 else
10286 {
10287 xp->xp_context = EXPAND_FILES;
10288 /* for 'tags' need three backslashes for a space */
10289 if (p == (char_u *)&p_tags)
10290 xp->xp_backslash = XP_BS_THREE;
10291 else
10292 xp->xp_backslash = XP_BS_ONE;
10293 }
10294 }
10295
10296 /* For an option that is a list of file names, find the start of the
10297 * last file name. */
10298 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10299 {
10300 /* count number of backslashes before ' ' or ',' */
10301 if (*p == ' ' || *p == ',')
10302 {
10303 s = p;
10304 while (s > xp->xp_pattern && *(s - 1) == '\\')
10305 --s;
10306 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10307 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10308 {
10309 xp->xp_pattern = p + 1;
10310 break;
10311 }
10312 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010313
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010314#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010315 /* for 'spellsuggest' start at "file:" */
10316 if (options[opt_idx].var == (char_u *)&p_sps
10317 && STRNCMP(p, "file:", 5) == 0)
10318 {
10319 xp->xp_pattern = p + 5;
10320 break;
10321 }
10322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323 }
10324
10325 return;
10326}
10327
10328 int
10329ExpandSettings(xp, regmatch, num_file, file)
10330 expand_T *xp;
10331 regmatch_T *regmatch;
10332 int *num_file;
10333 char_u ***file;
10334{
10335 int num_normal = 0; /* Nr of matching non-term-code settings */
10336 int num_term = 0; /* Nr of matching terminal code settings */
10337 int opt_idx;
10338 int match;
10339 int count = 0;
10340 char_u *str;
10341 int loop;
10342 int is_term_opt;
10343 char_u name_buf[MAX_KEY_NAME_LEN];
10344 static char *(names[]) = {"all", "termcap"};
10345 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10346
10347 /* do this loop twice:
10348 * loop == 0: count the number of matching options
10349 * loop == 1: copy the matching options into allocated memory
10350 */
10351 for (loop = 0; loop <= 1; ++loop)
10352 {
10353 regmatch->rm_ic = ic;
10354 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10355 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010356 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10357 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10359 {
10360 if (loop == 0)
10361 num_normal++;
10362 else
10363 (*file)[count++] = vim_strsave((char_u *)names[match]);
10364 }
10365 }
10366 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10367 opt_idx++)
10368 {
10369 if (options[opt_idx].var == NULL)
10370 continue;
10371 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10372 && !(options[opt_idx].flags & P_BOOL))
10373 continue;
10374 is_term_opt = istermoption(&options[opt_idx]);
10375 if (is_term_opt && num_normal > 0)
10376 continue;
10377 match = FALSE;
10378 if (vim_regexec(regmatch, str, (colnr_T)0)
10379 || (options[opt_idx].shortname != NULL
10380 && vim_regexec(regmatch,
10381 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10382 match = TRUE;
10383 else if (is_term_opt)
10384 {
10385 name_buf[0] = '<';
10386 name_buf[1] = 't';
10387 name_buf[2] = '_';
10388 name_buf[3] = str[2];
10389 name_buf[4] = str[3];
10390 name_buf[5] = '>';
10391 name_buf[6] = NUL;
10392 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10393 {
10394 match = TRUE;
10395 str = name_buf;
10396 }
10397 }
10398 if (match)
10399 {
10400 if (loop == 0)
10401 {
10402 if (is_term_opt)
10403 num_term++;
10404 else
10405 num_normal++;
10406 }
10407 else
10408 (*file)[count++] = vim_strsave(str);
10409 }
10410 }
10411 /*
10412 * Check terminal key codes, these are not in the option table
10413 */
10414 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10415 {
10416 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10417 {
10418 if (!isprint(str[0]) || !isprint(str[1]))
10419 continue;
10420
10421 name_buf[0] = 't';
10422 name_buf[1] = '_';
10423 name_buf[2] = str[0];
10424 name_buf[3] = str[1];
10425 name_buf[4] = NUL;
10426
10427 match = FALSE;
10428 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10429 match = TRUE;
10430 else
10431 {
10432 name_buf[0] = '<';
10433 name_buf[1] = 't';
10434 name_buf[2] = '_';
10435 name_buf[3] = str[0];
10436 name_buf[4] = str[1];
10437 name_buf[5] = '>';
10438 name_buf[6] = NUL;
10439
10440 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10441 match = TRUE;
10442 }
10443 if (match)
10444 {
10445 if (loop == 0)
10446 num_term++;
10447 else
10448 (*file)[count++] = vim_strsave(name_buf);
10449 }
10450 }
10451
10452 /*
10453 * Check special key names.
10454 */
10455 regmatch->rm_ic = TRUE; /* ignore case here */
10456 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10457 {
10458 name_buf[0] = '<';
10459 STRCPY(name_buf + 1, str);
10460 STRCAT(name_buf, ">");
10461
10462 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10463 {
10464 if (loop == 0)
10465 num_term++;
10466 else
10467 (*file)[count++] = vim_strsave(name_buf);
10468 }
10469 }
10470 }
10471 if (loop == 0)
10472 {
10473 if (num_normal > 0)
10474 *num_file = num_normal;
10475 else if (num_term > 0)
10476 *num_file = num_term;
10477 else
10478 return OK;
10479 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10480 if (*file == NULL)
10481 {
10482 *file = (char_u **)"";
10483 return FAIL;
10484 }
10485 }
10486 }
10487 return OK;
10488}
10489
10490 int
10491ExpandOldSetting(num_file, file)
10492 int *num_file;
10493 char_u ***file;
10494{
10495 char_u *var = NULL; /* init for GCC */
10496 char_u *buf;
10497
10498 *num_file = 0;
10499 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10500 if (*file == NULL)
10501 return FAIL;
10502
10503 /*
10504 * For a terminal key code expand_option_idx is < 0.
10505 */
10506 if (expand_option_idx < 0)
10507 {
10508 var = find_termcode(expand_option_name + 2);
10509 if (var == NULL)
10510 expand_option_idx = findoption(expand_option_name);
10511 }
10512
10513 if (expand_option_idx >= 0)
10514 {
10515 /* put string of option value in NameBuff */
10516 option_value2string(&options[expand_option_idx], expand_option_flags);
10517 var = NameBuff;
10518 }
10519 else if (var == NULL)
10520 var = (char_u *)"";
10521
10522 /* A backslash is required before some characters. This is the reverse of
10523 * what happens in do_set(). */
10524 buf = vim_strsave_escaped(var, escape_chars);
10525
10526 if (buf == NULL)
10527 {
10528 vim_free(*file);
10529 *file = NULL;
10530 return FAIL;
10531 }
10532
10533#ifdef BACKSLASH_IN_FILENAME
10534 /* For MS-Windows et al. we don't double backslashes at the start and
10535 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010536 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 if (var[0] == '\\' && var[1] == '\\'
10538 && expand_option_idx >= 0
10539 && (options[expand_option_idx].flags & P_EXPAND)
10540 && vim_isfilec(var[2])
10541 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010542 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543#endif
10544
10545 *file[0] = buf;
10546 *num_file = 1;
10547 return OK;
10548}
10549#endif
10550
10551/*
10552 * Get the value for the numeric or string option *opp in a nice format into
10553 * NameBuff[]. Must not be called with a hidden option!
10554 */
10555 static void
10556option_value2string(opp, opt_flags)
10557 struct vimoption *opp;
10558 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10559{
10560 char_u *varp;
10561
10562 varp = get_varp_scope(opp, opt_flags);
10563
10564 if (opp->flags & P_NUM)
10565 {
10566 long wc = 0;
10567
10568 if (wc_use_keyname(varp, &wc))
10569 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10570 else if (wc != 0)
10571 STRCPY(NameBuff, transchar((int)wc));
10572 else
10573 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10574 }
10575 else /* P_STRING */
10576 {
10577 varp = *(char_u **)(varp);
10578 if (varp == NULL) /* just in case */
10579 NameBuff[0] = NUL;
10580#ifdef FEAT_CRYPT
10581 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010582 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 STRCPY(NameBuff, "*****");
10584#endif
10585 else if (opp->flags & P_EXPAND)
10586 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10587 /* Translate 'pastetoggle' into special key names */
10588 else if ((char_u **)opp->var == &p_pt)
10589 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10590 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010591 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 }
10593}
10594
10595/*
10596 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10597 * printed as a keyname.
10598 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10599 */
10600 static int
10601wc_use_keyname(varp, wcp)
10602 char_u *varp;
10603 long *wcp;
10604{
10605 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10606 {
10607 *wcp = *(long *)varp;
10608 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10609 return TRUE;
10610 }
10611 return FALSE;
10612}
10613
10614#ifdef FEAT_LANGMAP
10615/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010616 * Any character has an equivalent 'langmap' character. This is used for
10617 * keyboards that have a special language mode that sends characters above
10618 * 128 (although other characters can be translated too). The "to" field is a
10619 * Vim command character. This avoids having to switch the keyboard back to
10620 * ASCII mode when leaving Insert mode.
10621 *
10622 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10623 * commands.
10624 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10625 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10626 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010628# ifdef FEAT_MBYTE
10629/*
10630 * With multi-byte support use growarray for 'langmap' chars >= 256
10631 */
10632typedef struct
10633{
10634 int from;
10635 int to;
10636} langmap_entry_T;
10637
10638static garray_T langmap_mapga;
10639static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640
10641/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010642 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10643 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010645 static void
10646langmap_set_entry(from, to)
10647 int from;
10648 int to;
10649{
10650 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010651 int a = 0;
10652 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010653
10654 /* Do a binary search for an existing entry. */
10655 while (a != b)
10656 {
10657 int i = (a + b) / 2;
10658 int d = entries[i].from - from;
10659
10660 if (d == 0)
10661 {
10662 entries[i].to = to;
10663 return;
10664 }
10665 if (d < 0)
10666 a = i + 1;
10667 else
10668 b = i;
10669 }
10670
10671 if (ga_grow(&langmap_mapga, 1) != OK)
10672 return; /* out of memory */
10673
10674 /* insert new entry at position "a" */
10675 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10676 mch_memmove(entries + 1, entries,
10677 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10678 ++langmap_mapga.ga_len;
10679 entries[0].from = from;
10680 entries[0].to = to;
10681}
10682
10683/*
10684 * Apply 'langmap' to multi-byte character "c" and return the result.
10685 */
10686 int
10687langmap_adjust_mb(c)
10688 int c;
10689{
10690 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10691 int a = 0;
10692 int b = langmap_mapga.ga_len;
10693
10694 while (a != b)
10695 {
10696 int i = (a + b) / 2;
10697 int d = entries[i].from - c;
10698
10699 if (d == 0)
10700 return entries[i].to; /* found matching entry */
10701 if (d < 0)
10702 a = i + 1;
10703 else
10704 b = i;
10705 }
10706 return c; /* no entry found, return "c" unmodified */
10707}
10708# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709
10710 static void
10711langmap_init()
10712{
10713 int i;
10714
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010715 for (i = 0; i < 256; i++)
10716 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10717# ifdef FEAT_MBYTE
10718 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10719# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720}
10721
10722/*
10723 * Called when langmap option is set; the language map can be
10724 * changed at any time!
10725 */
10726 static void
10727langmap_set()
10728{
10729 char_u *p;
10730 char_u *p2;
10731 int from, to;
10732
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010733#ifdef FEAT_MBYTE
10734 ga_clear(&langmap_mapga); /* clear the previous map first */
10735#endif
10736 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737
10738 for (p = p_langmap; p[0] != NUL; )
10739 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010740 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10741 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010742 {
10743 if (p2[0] == '\\' && p2[1] != NUL)
10744 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745 }
10746 if (p2[0] == ';')
10747 ++p2; /* abcd;ABCD form, p2 points to A */
10748 else
10749 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10750 while (p[0])
10751 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010752 if (p[0] == ',')
10753 {
10754 ++p;
10755 break;
10756 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 if (p[0] == '\\' && p[1] != NUL)
10758 ++p;
10759#ifdef FEAT_MBYTE
10760 from = (*mb_ptr2char)(p);
10761#else
10762 from = p[0];
10763#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010764 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765 if (p2 == NULL)
10766 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010767 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010768 if (p[0] != ',')
10769 {
10770 if (p[0] == '\\')
10771 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010773 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010775 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778 }
10779 else
10780 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010781 if (p2[0] != ',')
10782 {
10783 if (p2[0] == '\\')
10784 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010786 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010788 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791 }
10792 if (to == NUL)
10793 {
10794 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10795 transchar(from));
10796 return;
10797 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010798
10799#ifdef FEAT_MBYTE
10800 if (from >= 256)
10801 langmap_set_entry(from, to);
10802 else
10803#endif
10804 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805
10806 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010807 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010808 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010810 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 if (*p == ';')
10812 {
10813 p = p2;
10814 if (p[0] != NUL)
10815 {
10816 if (p[0] != ',')
10817 {
10818 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10819 return;
10820 }
10821 ++p;
10822 }
10823 break;
10824 }
10825 }
10826 }
10827 }
10828}
10829#endif
10830
10831/*
10832 * Return TRUE if format option 'x' is in effect.
10833 * Take care of no formatting when 'paste' is set.
10834 */
10835 int
10836has_format_option(x)
10837 int x;
10838{
10839 if (p_paste)
10840 return FALSE;
10841 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10842}
10843
10844/*
10845 * Return TRUE if "x" is present in 'shortmess' option, or
10846 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10847 */
10848 int
10849shortmess(x)
10850 int x;
10851{
10852 return ( vim_strchr(p_shm, x) != NULL
10853 || (vim_strchr(p_shm, 'a') != NULL
10854 && vim_strchr((char_u *)SHM_A, x) != NULL));
10855}
10856
10857/*
10858 * paste_option_changed() - Called after p_paste was set or reset.
10859 */
10860 static void
10861paste_option_changed()
10862{
10863 static int old_p_paste = FALSE;
10864 static int save_sm = 0;
10865#ifdef FEAT_CMDL_INFO
10866 static int save_ru = 0;
10867#endif
10868#ifdef FEAT_RIGHTLEFT
10869 static int save_ri = 0;
10870 static int save_hkmap = 0;
10871#endif
10872 buf_T *buf;
10873
10874 if (p_paste)
10875 {
10876 /*
10877 * Paste switched from off to on.
10878 * Save the current values, so they can be restored later.
10879 */
10880 if (!old_p_paste)
10881 {
10882 /* save options for each buffer */
10883 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10884 {
10885 buf->b_p_tw_nopaste = buf->b_p_tw;
10886 buf->b_p_wm_nopaste = buf->b_p_wm;
10887 buf->b_p_sts_nopaste = buf->b_p_sts;
10888 buf->b_p_ai_nopaste = buf->b_p_ai;
10889 }
10890
10891 /* save global options */
10892 save_sm = p_sm;
10893#ifdef FEAT_CMDL_INFO
10894 save_ru = p_ru;
10895#endif
10896#ifdef FEAT_RIGHTLEFT
10897 save_ri = p_ri;
10898 save_hkmap = p_hkmap;
10899#endif
10900 /* save global values for local buffer options */
10901 p_tw_nopaste = p_tw;
10902 p_wm_nopaste = p_wm;
10903 p_sts_nopaste = p_sts;
10904 p_ai_nopaste = p_ai;
10905 }
10906
10907 /*
10908 * Always set the option values, also when 'paste' is set when it is
10909 * already on.
10910 */
10911 /* set options for each buffer */
10912 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10913 {
10914 buf->b_p_tw = 0; /* textwidth is 0 */
10915 buf->b_p_wm = 0; /* wrapmargin is 0 */
10916 buf->b_p_sts = 0; /* softtabstop is 0 */
10917 buf->b_p_ai = 0; /* no auto-indent */
10918 }
10919
10920 /* set global options */
10921 p_sm = 0; /* no showmatch */
10922#ifdef FEAT_CMDL_INFO
10923# ifdef FEAT_WINDOWS
10924 if (p_ru)
10925 status_redraw_all(); /* redraw to remove the ruler */
10926# endif
10927 p_ru = 0; /* no ruler */
10928#endif
10929#ifdef FEAT_RIGHTLEFT
10930 p_ri = 0; /* no reverse insert */
10931 p_hkmap = 0; /* no Hebrew keyboard */
10932#endif
10933 /* set global values for local buffer options */
10934 p_tw = 0;
10935 p_wm = 0;
10936 p_sts = 0;
10937 p_ai = 0;
10938 }
10939
10940 /*
10941 * Paste switched from on to off: Restore saved values.
10942 */
10943 else if (old_p_paste)
10944 {
10945 /* restore options for each buffer */
10946 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10947 {
10948 buf->b_p_tw = buf->b_p_tw_nopaste;
10949 buf->b_p_wm = buf->b_p_wm_nopaste;
10950 buf->b_p_sts = buf->b_p_sts_nopaste;
10951 buf->b_p_ai = buf->b_p_ai_nopaste;
10952 }
10953
10954 /* restore global options */
10955 p_sm = save_sm;
10956#ifdef FEAT_CMDL_INFO
10957# ifdef FEAT_WINDOWS
10958 if (p_ru != save_ru)
10959 status_redraw_all(); /* redraw to draw the ruler */
10960# endif
10961 p_ru = save_ru;
10962#endif
10963#ifdef FEAT_RIGHTLEFT
10964 p_ri = save_ri;
10965 p_hkmap = save_hkmap;
10966#endif
10967 /* set global values for local buffer options */
10968 p_tw = p_tw_nopaste;
10969 p_wm = p_wm_nopaste;
10970 p_sts = p_sts_nopaste;
10971 p_ai = p_ai_nopaste;
10972 }
10973
10974 old_p_paste = p_paste;
10975}
10976
10977/*
10978 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10979 *
10980 * Reset 'compatible' and set the values for options that didn't get set yet
10981 * to the Vim defaults.
10982 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010983 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010984 */
10985 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010986vimrc_found(fname, envname)
10987 char_u *fname;
10988 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010990 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010991 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010992 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010993
10994 if (!option_was_set((char_u *)"cp"))
10995 {
10996 p_cp = FALSE;
10997 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10998 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10999 set_option_default(opt_idx, OPT_FREE, FALSE);
11000 didset_options();
11001 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011002
11003 if (fname != NULL)
11004 {
11005 p = vim_getenv(envname, &dofree);
11006 if (p == NULL)
11007 {
11008 /* Set $MYVIMRC to the first vimrc file found. */
11009 p = FullName_save(fname, FALSE);
11010 if (p != NULL)
11011 {
11012 vim_setenv(envname, p);
11013 vim_free(p);
11014 }
11015 }
11016 else if (dofree)
11017 vim_free(p);
11018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019}
11020
11021/*
11022 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11023 */
11024 void
11025change_compatible(on)
11026 int on;
11027{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011028 int opt_idx;
11029
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030 if (p_cp != on)
11031 {
11032 p_cp = on;
11033 compatible_set();
11034 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011035 opt_idx = findoption((char_u *)"cp");
11036 if (opt_idx >= 0)
11037 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038}
11039
11040/*
11041 * Return TRUE when option "name" has been set.
11042 */
11043 int
11044option_was_set(name)
11045 char_u *name;
11046{
11047 int idx;
11048
11049 idx = findoption(name);
11050 if (idx < 0) /* unknown option */
11051 return FALSE;
11052 if (options[idx].flags & P_WAS_SET)
11053 return TRUE;
11054 return FALSE;
11055}
11056
11057/*
11058 * compatible_set() - Called when 'compatible' has been set or unset.
11059 *
11060 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11061 * flag) to a Vi compatible value.
11062 * When 'compatible' is unset: Set all options that have a different default
11063 * for Vim (without the P_VI_DEF flag) to that default.
11064 */
11065 static void
11066compatible_set()
11067{
11068 int opt_idx;
11069
11070 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11071 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11072 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11073 set_option_default(opt_idx, OPT_FREE, p_cp);
11074 didset_options();
11075}
11076
11077#ifdef FEAT_LINEBREAK
11078
11079# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11080 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011081 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082# endif
11083
11084/*
11085 * fill_breakat_flags() -- called when 'breakat' changes value.
11086 */
11087 static void
11088fill_breakat_flags()
11089{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011090 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 int i;
11092
11093 for (i = 0; i < 256; i++)
11094 breakat_flags[i] = FALSE;
11095
11096 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011097 for (p = p_breakat; *p; p++)
11098 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099}
11100
11101# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011102 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103# endif
11104
11105#endif
11106
11107/*
11108 * Check an option that can be a range of string values.
11109 *
11110 * Return OK for correct value, FAIL otherwise.
11111 * Empty is always OK.
11112 */
11113 static int
11114check_opt_strings(val, values, list)
11115 char_u *val;
11116 char **values;
11117 int list; /* when TRUE: accept a list of values */
11118{
11119 return opt_strings_flags(val, values, NULL, list);
11120}
11121
11122/*
11123 * Handle an option that can be a range of string values.
11124 * Set a flag in "*flagp" for each string present.
11125 *
11126 * Return OK for correct value, FAIL otherwise.
11127 * Empty is always OK.
11128 */
11129 static int
11130opt_strings_flags(val, values, flagp, list)
11131 char_u *val; /* new value */
11132 char **values; /* array of valid string values */
11133 unsigned *flagp;
11134 int list; /* when TRUE: accept a list of values */
11135{
11136 int i;
11137 int len;
11138 unsigned new_flags = 0;
11139
11140 while (*val)
11141 {
11142 for (i = 0; ; ++i)
11143 {
11144 if (values[i] == NULL) /* val not found in values[] */
11145 return FAIL;
11146
11147 len = (int)STRLEN(values[i]);
11148 if (STRNCMP(values[i], val, len) == 0
11149 && ((list && val[len] == ',') || val[len] == NUL))
11150 {
11151 val += len + (val[len] == ',');
11152 new_flags |= (1 << i);
11153 break; /* check next item in val list */
11154 }
11155 }
11156 }
11157 if (flagp != NULL)
11158 *flagp = new_flags;
11159
11160 return OK;
11161}
11162
11163/*
11164 * Read the 'wildmode' option, fill wim_flags[].
11165 */
11166 static int
11167check_opt_wim()
11168{
11169 char_u new_wim_flags[4];
11170 char_u *p;
11171 int i;
11172 int idx = 0;
11173
11174 for (i = 0; i < 4; ++i)
11175 new_wim_flags[i] = 0;
11176
11177 for (p = p_wim; *p; ++p)
11178 {
11179 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11180 ;
11181 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11182 return FAIL;
11183 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11184 new_wim_flags[idx] |= WIM_LONGEST;
11185 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11186 new_wim_flags[idx] |= WIM_FULL;
11187 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11188 new_wim_flags[idx] |= WIM_LIST;
11189 else
11190 return FAIL;
11191 p += i;
11192 if (*p == NUL)
11193 break;
11194 if (*p == ',')
11195 {
11196 if (idx == 3)
11197 return FAIL;
11198 ++idx;
11199 }
11200 }
11201
11202 /* fill remaining entries with last flag */
11203 while (idx < 3)
11204 {
11205 new_wim_flags[idx + 1] = new_wim_flags[idx];
11206 ++idx;
11207 }
11208
11209 /* only when there are no errors, wim_flags[] is changed */
11210 for (i = 0; i < 4; ++i)
11211 wim_flags[i] = new_wim_flags[i];
11212 return OK;
11213}
11214
11215/*
11216 * Check if backspacing over something is allowed.
11217 */
11218 int
11219can_bs(what)
11220 int what; /* BS_INDENT, BS_EOL or BS_START */
11221{
11222 switch (*p_bs)
11223 {
11224 case '2': return TRUE;
11225 case '1': return (what != BS_START);
11226 case '0': return FALSE;
11227 }
11228 return vim_strchr(p_bs, what) != NULL;
11229}
11230
11231/*
11232 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11233 * the file must be considered changed when the value is different.
11234 */
11235 void
11236save_file_ff(buf)
11237 buf_T *buf;
11238{
11239 buf->b_start_ffc = *buf->b_p_ff;
11240 buf->b_start_eol = buf->b_p_eol;
11241#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011242 buf->b_start_bomb = buf->b_p_bomb;
11243
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244 /* Only use free/alloc when necessary, they take time. */
11245 if (buf->b_start_fenc == NULL
11246 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11247 {
11248 vim_free(buf->b_start_fenc);
11249 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11250 }
11251#endif
11252}
11253
11254/*
11255 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11256 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011257 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11258 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259 * Don't consider a new, empty buffer to be changed.
11260 */
11261 int
11262file_ff_differs(buf)
11263 buf_T *buf;
11264{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011265 /* In a buffer that was never loaded the options are not valid. */
11266 if (buf->b_flags & BF_NEVERLOADED)
11267 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268 if ((buf->b_flags & BF_NEW)
11269 && buf->b_ml.ml_line_count == 1
11270 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11271 return FALSE;
11272 if (buf->b_start_ffc != *buf->b_p_ff)
11273 return TRUE;
11274 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11275 return TRUE;
11276#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011277 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11278 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279 if (buf->b_start_fenc == NULL)
11280 return (*buf->b_p_fenc != NUL);
11281 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11282#else
11283 return FALSE;
11284#endif
11285}
11286
11287/*
11288 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11289 */
11290 int
11291check_ff_value(p)
11292 char_u *p;
11293{
11294 return check_opt_strings(p, p_ff_values, FALSE);
11295}