blob: 718464951c79f3807383780df009644ce215c903 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#ifdef FEAT_COMPL_FUNC
144# define PV_OFU OPT_BUF(BV_OFU)
145#endif
146#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
147#define PV_PI OPT_BUF(BV_PI)
148#ifdef FEAT_TEXTOBJ
149# define PV_QE OPT_BUF(BV_QE)
150#endif
151#define PV_RO OPT_BUF(BV_RO)
152#ifdef FEAT_SMARTINDENT
153# define PV_SI OPT_BUF(BV_SI)
154#endif
155#ifndef SHORT_FNAME
156# define PV_SN OPT_BUF(BV_SN)
157#endif
158#ifdef FEAT_SYN_HL
159# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000160# define PV_SYN OPT_BUF(BV_SYN)
161#endif
162#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163# define PV_SPC OPT_BUF(BV_SPC)
164# define PV_SPF OPT_BUF(BV_SPF)
165# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166#endif
167#define PV_STS OPT_BUF(BV_STS)
168#ifdef FEAT_SEARCHPATH
169# define PV_SUA OPT_BUF(BV_SUA)
170#endif
171#define PV_SW OPT_BUF(BV_SW)
172#define PV_SWF OPT_BUF(BV_SWF)
173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
174#define PV_TS OPT_BUF(BV_TS)
175#define PV_TW OPT_BUF(BV_TW)
176#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200177#ifdef FEAT_PERSISTENT_UNDO
178# define PV_UDF OPT_BUF(BV_UDF)
179#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000181
182/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183 * Definition of the PV_ values for window-local options.
184 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186#define PV_LIST OPT_WIN(WV_LIST)
187#ifdef FEAT_ARABIC
188# define PV_ARAB OPT_WIN(WV_ARAB)
189#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000190#ifdef FEAT_DIFF
191# define PV_DIFF OPT_WIN(WV_DIFF)
192#endif
193#ifdef FEAT_FOLDING
194# define PV_FDC OPT_WIN(WV_FDC)
195# define PV_FEN OPT_WIN(WV_FEN)
196# define PV_FDI OPT_WIN(WV_FDI)
197# define PV_FDL OPT_WIN(WV_FDL)
198# define PV_FDM OPT_WIN(WV_FDM)
199# define PV_FML OPT_WIN(WV_FML)
200# define PV_FDN OPT_WIN(WV_FDN)
201# ifdef FEAT_EVAL
202# define PV_FDE OPT_WIN(WV_FDE)
203# define PV_FDT OPT_WIN(WV_FDT)
204# endif
205# define PV_FMR OPT_WIN(WV_FMR)
206#endif
207#ifdef FEAT_LINEBREAK
208# define PV_LBR OPT_WIN(WV_LBR)
209#endif
210#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200211#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000212#ifdef FEAT_LINEBREAK
213# define PV_NUW OPT_WIN(WV_NUW)
214#endif
215#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216# define PV_PVW OPT_WIN(WV_PVW)
217#endif
218#ifdef FEAT_RIGHTLEFT
219# define PV_RL OPT_WIN(WV_RL)
220# define PV_RLC OPT_WIN(WV_RLC)
221#endif
222#ifdef FEAT_SCROLLBIND
223# define PV_SCBIND OPT_WIN(WV_SCBIND)
224#endif
225#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000226#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_SPELL OPT_WIN(WV_SPELL)
228#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SYN_HL
230# define PV_CUC OPT_WIN(WV_CUC)
231# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200232# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234#ifdef FEAT_STL_OPT
235# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
236#endif
237#ifdef FEAT_WINDOWS
238# define PV_WFH OPT_WIN(WV_WFH)
239#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000240#ifdef FEAT_VERTSPLIT
241# define PV_WFW OPT_WIN(WV_WFW)
242#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200244#ifdef FEAT_CURSORBIND
245# define PV_CRBIND OPT_WIN(WV_CRBIND)
246#endif
247#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200248# define PV_COCU OPT_WIN(WV_COCU)
249# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251
252/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253typedef enum
254{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000255 PV_NONE = 0,
256 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257} idopt_T;
258
259/*
260 * Options local to a window have a value local to a buffer and global to all
261 * buffers. Indicate this by setting "var" to VAR_WIN.
262 */
263#define VAR_WIN ((char_u *)-1)
264
265/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000266 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267 * Only to be used in option.c!
268 */
269static int p_ai;
270static int p_bin;
271#ifdef FEAT_MBYTE
272static int p_bomb;
273#endif
274#if defined(FEAT_QUICKFIX)
275static char_u *p_bh;
276static char_u *p_bt;
277#endif
278static int p_bl;
279static int p_ci;
280#ifdef FEAT_CINDENT
281static int p_cin;
282static char_u *p_cink;
283static char_u *p_cino;
284#endif
285#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
286static char_u *p_cinw;
287#endif
288#ifdef FEAT_COMMENTS
289static char_u *p_com;
290#endif
291#ifdef FEAT_FOLDING
292static char_u *p_cms;
293#endif
294#ifdef FEAT_INS_EXPAND
295static char_u *p_cpt;
296#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000297#ifdef FEAT_COMPL_FUNC
298static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000299static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301static int p_eol;
302static int p_et;
303#ifdef FEAT_MBYTE
304static char_u *p_fenc;
305#endif
306static char_u *p_ff;
307static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000308static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309#ifdef FEAT_AUTOCMD
310static char_u *p_ft;
311#endif
312static long p_iminsert;
313static long p_imsearch;
314#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
315static char_u *p_inex;
316#endif
317#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
318static char_u *p_inde;
319static char_u *p_indk;
320#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000321#if defined(FEAT_EVAL)
322static char_u *p_fex;
323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324static int p_inf;
325static char_u *p_isk;
326#ifdef FEAT_CRYPT
327static char_u *p_key;
328#endif
329#ifdef FEAT_LISP
330static int p_lisp;
331#endif
332static int p_ml;
333static int p_ma;
334static int p_mod;
335static char_u *p_mps;
336static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338#ifdef FEAT_TEXTOBJ
339static char_u *p_qe;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_ro;
342#ifdef FEAT_SMARTINDENT
343static int p_si;
344#endif
345#ifndef SHORT_FNAME
346static int p_sn;
347#endif
348static long p_sts;
349#if defined(FEAT_SEARCHPATH)
350static char_u *p_sua;
351#endif
352static long p_sw;
353static int p_swf;
354#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000355static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000357#endif
358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000359static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000360static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000361static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362#endif
363static long p_ts;
364static long p_tw;
365static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200366#ifdef FEAT_PERSISTENT_UNDO
367static int p_udf;
368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static long p_wm;
370#ifdef FEAT_KEYMAP
371static char_u *p_keymap;
372#endif
373
374/* Saved values for when 'bin' is set. */
375static int p_et_nobin;
376static int p_ml_nobin;
377static long p_tw_nobin;
378static long p_wm_nobin;
379
380/* Saved values for when 'paste' is set */
381static long p_tw_nopaste;
382static long p_wm_nopaste;
383static long p_sts_nopaste;
384static int p_ai_nopaste;
385
386struct vimoption
387{
388 char *fullname; /* full option name */
389 char *shortname; /* permissible abbreviation */
390 long_u flags; /* see below */
391 char_u *var; /* global option: pointer to variable;
392 * window-local option: VAR_WIN;
393 * buffer-local option: global value */
394 idopt_T indir; /* global option: PV_NONE;
395 * local option: indirect option index */
396 char_u *def_val[2]; /* default values for variable (vi and vim) */
397#ifdef FEAT_EVAL
398 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000399# define SCRIPTID_INIT , 0
400#else
401# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402#endif
403};
404
405#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
406#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
407
408/*
409 * Flags
410 */
411#define P_BOOL 0x01 /* the option is boolean */
412#define P_NUM 0x02 /* the option is numeric */
413#define P_STRING 0x04 /* the option is a string */
414#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000415 must use free_string_option() when
416 assigning new value. Not set if default is
417 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
419 never be used for local or hidden options! */
420#define P_NODEFAULT 0x40 /* don't set to default value */
421#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
422 use vim_free() when assigning new value */
423#define P_WAS_SET 0x100 /* option has been set/reset */
424#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
425#define P_VI_DEF 0x400 /* Use Vi default for Vim */
426#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
427
428 /* when option changed, what to display: */
429#define P_RSTAT 0x1000 /* redraw status lines */
430#define P_RWIN 0x2000 /* redraw current window */
431#define P_RBUF 0x4000 /* redraw current buffer */
432#define P_RALL 0x6000 /* redraw all windows */
433#define P_RCLR 0x7000 /* clear and redraw all */
434
435#define P_COMMA 0x8000 /* comma separated list */
436#define P_NODUP 0x10000L/* don't allow duplicate strings */
437#define P_FLAGLIST 0x20000L/* list of single-char flags */
438
439#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
440#define P_GETTEXT 0x80000L/* expand default value with _() */
441#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000442#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000443#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000444#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
445 side effects) */
Bram Moolenaar865242e2010-07-14 21:12:05 +0200446#define P_NO_ML 0x1000000L/* not allowed in modeline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000448#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
449
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000450/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
451 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000452#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000453# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000454#else
455# define ISP_LATIN1 (char_u *)"@,161-255"
456#endif
457
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000458/* The 16 bit MS-DOS version is low on space, make the string as short as
459 * possible when compiling with few features. */
460#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
461 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200462 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200463# 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 +0000464#else
465# 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"
466#endif
467
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468/*
469 * options[] is initialized here.
470 * The order of the options MUST be alphabetic for ":set all" and findoption().
471 * All option names MUST start with a lowercase letter (for findoption()).
472 * Exception: "t_" options are at the end.
473 * The options with a NULL variable are 'hidden': a set command for them is
474 * ignored and they are not printed.
475 */
476static struct vimoption
477#ifdef FEAT_GUI_W16
478 _far
479#endif
480 options[] =
481{
482 {"aleph", "al", P_NUM|P_VI_DEF,
483#ifdef FEAT_RIGHTLEFT
484 (char_u *)&p_aleph, PV_NONE,
485#else
486 (char_u *)NULL, PV_NONE,
487#endif
488 {
489#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
490 (char_u *)128L,
491#else
492 (char_u *)224L,
493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000494 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
496#if defined(FEAT_GUI) && defined(MACOS_X)
497 (char_u *)&p_antialias, PV_NONE,
498 {(char_u *)FALSE, (char_u *)FALSE}
499#else
500 (char_u *)NULL, PV_NONE,
501 {(char_u *)FALSE, (char_u *)FALSE}
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
505#ifdef FEAT_ARABIC
506 (char_u *)VAR_WIN, PV_ARAB,
507#else
508 (char_u *)NULL, PV_NONE,
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
512#ifdef FEAT_ARABIC
513 (char_u *)&p_arshape, PV_NONE,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
519#ifdef FEAT_RIGHTLEFT
520 (char_u *)&p_ari, PV_NONE,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
526#ifdef FEAT_FKMAP
527 (char_u *)&p_altkeymap, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
533#if defined(FEAT_MBYTE)
534 (char_u *)&p_ambw, PV_NONE,
535 {(char_u *)"single", (char_u *)0L}
536#else
537 (char_u *)NULL, PV_NONE,
538 {(char_u *)0L, (char_u *)0L}
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000541#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"autochdir", "acd", P_BOOL|P_VI_DEF,
543 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545#endif
546 {"autoindent", "ai", P_BOOL|P_VI_DEF,
547 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autoprint", "ap", P_BOOL|P_VI_DEF,
550 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000553 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autowrite", "aw", P_BOOL|P_VI_DEF,
556 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autowriteall","awa", P_BOOL|P_VI_DEF,
559 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
562 (char_u *)&p_bg, PV_NONE,
563 {
564#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
565 (char_u *)"dark",
566#else
567 (char_u *)"light",
568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
571 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
574 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
577 (char_u *)&p_bkc, PV_NONE,
578#ifdef UNIX
579 {(char_u *)"yes", (char_u *)"auto"}
580#else
581 {(char_u *)"auto", (char_u *)"auto"}
582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
585 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000587 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)&p_bex, PV_NONE,
589 {
590#ifdef VMS
591 (char_u *)"_",
592#else
593 (char_u *)"~",
594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000595 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
597#ifdef FEAT_WILDIGN
598 (char_u *)&p_bsk, PV_NONE,
599 {(char_u *)"", (char_u *)0L}
600#else
601 (char_u *)NULL, PV_NONE,
602 {(char_u *)0L, (char_u *)0L}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605#ifdef FEAT_BEVAL
606 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
607 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
610 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000612# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000613 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000614 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000616# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#endif
618 {"beautify", "bf", P_BOOL|P_VI_DEF,
619 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
622 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
625#ifdef MSDOS
626 (char_u *)&p_biosk, PV_NONE,
627#else
628 (char_u *)NULL, PV_NONE,
629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
632#ifdef FEAT_MBYTE
633 (char_u *)&p_bomb, PV_BOMB,
634#else
635 (char_u *)NULL, PV_NONE,
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
639#ifdef FEAT_LINEBREAK
640 (char_u *)&p_breakat, PV_NONE,
641 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
648#ifdef FEAT_BROWSE
649 (char_u *)&p_bsdir, PV_NONE,
650 {(char_u *)"last", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
657#if defined(FEAT_QUICKFIX)
658 (char_u *)&p_bh, PV_BH,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
666 (char_u *)&p_bl, PV_BL,
667 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
670#if defined(FEAT_QUICKFIX)
671 (char_u *)&p_bt, PV_BT,
672 {(char_u *)"", (char_u *)0L}
673#else
674 (char_u *)NULL, PV_NONE,
675 {(char_u *)0L, (char_u *)0L}
676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000679#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 (char_u *)&p_cmp, PV_NONE,
681 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
688#ifdef FEAT_SEARCHPATH
689 (char_u *)&p_cdpath, PV_NONE,
690 {(char_u *)",,", (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"cedit", NULL, P_STRING,
697#ifdef FEAT_CMDWIN
698 (char_u *)&p_cedit, PV_NONE,
699 {(char_u *)"", (char_u *)CTRL_F_STR}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
706#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
707 (char_u *)&p_ccv, PV_NONE,
708 {(char_u *)"", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
715#ifdef FEAT_CINDENT
716 (char_u *)&p_cin, PV_CIN,
717#else
718 (char_u *)NULL, PV_NONE,
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
722#ifdef FEAT_CINDENT
723 (char_u *)&p_cink, PV_CINK,
724 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
725#else
726 (char_u *)NULL, PV_NONE,
727 {(char_u *)0L, (char_u *)0L}
728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
731#ifdef FEAT_CINDENT
732 (char_u *)&p_cino, PV_CINO,
733#else
734 (char_u *)NULL, PV_NONE,
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
738#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
739 (char_u *)&p_cinw, PV_CINW,
740 {(char_u *)"if,else,while,do,for,switch",
741 (char_u *)0L}
742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_CLIPBOARD
749 (char_u *)&p_cb, PV_NONE,
750# ifdef FEAT_XCLIPBOARD
751 {(char_u *)"autoselect,exclude:cons\\|linux",
752 (char_u *)0L}
753# else
754 {(char_u *)"", (char_u *)0L}
755# endif
756#else
757 (char_u *)NULL, PV_NONE,
758 {(char_u *)"", (char_u *)0L}
759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000760 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
762 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
765#ifdef FEAT_CMDWIN
766 (char_u *)&p_cwh, PV_NONE,
767#else
768 (char_u *)NULL, PV_NONE,
769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200771 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
772#ifdef FEAT_SYN_HL
773 (char_u *)VAR_WIN, PV_CC,
774#else
775 (char_u *)NULL, PV_NONE,
776#endif
777 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
779 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
782#ifdef FEAT_COMMENTS
783 (char_u *)&p_com, PV_COM,
784 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
792#ifdef FEAT_FOLDING
793 (char_u *)&p_cms, PV_CMS,
794 {(char_u *)"/*%s*/", (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000800 /* P_PRI_MKRC isn't needed here, optval_default()
801 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"compatible", "cp", P_BOOL|P_RALL,
803 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
806#ifdef FEAT_INS_EXPAND
807 (char_u *)&p_cpt, PV_CPT,
808 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)0L, (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200814 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200815#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200816 (char_u *)VAR_WIN, PV_COCU,
817 {(char_u *)"", (char_u *)NULL}
818#else
819 (char_u *)NULL, PV_NONE,
820 {(char_u *)NULL, (char_u *)0L}
821#endif
822 SCRIPTID_INIT},
823 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
824#ifdef FEAT_CONCEAL
825 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200826#else
827 (char_u *)NULL, PV_NONE,
828#endif
829 {(char_u *)0L, (char_u *)0L}
830 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000831 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
832#ifdef FEAT_COMPL_FUNC
833 (char_u *)&p_cfu, PV_CFU,
834 {(char_u *)"", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000840 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
841#ifdef FEAT_INS_EXPAND
842 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000843 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)0L, (char_u *)0L}
847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 {"confirm", "cf", P_BOOL|P_VI_DEF,
850#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
851 (char_u *)&p_confirm, PV_NONE,
852#else
853 (char_u *)NULL, PV_NONE,
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"conskey", "consk",P_BOOL|P_VI_DEF,
857#ifdef MSDOS
858 (char_u *)&p_consk, PV_NONE,
859#else
860 (char_u *)NULL, PV_NONE,
861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
864 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000865 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000866 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
867 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
869 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200870 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200871#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200872 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200873 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200874#else
875 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200877#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
880#ifdef FEAT_CSCOPE
881 (char_u *)&p_cspc, PV_NONE,
882#else
883 (char_u *)NULL, PV_NONE,
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
887#ifdef FEAT_CSCOPE
888 (char_u *)&p_csprg, PV_NONE,
889 {(char_u *)"cscope", (char_u *)0L}
890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
896#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
897 (char_u *)&p_csqf, PV_NONE,
898 {(char_u *)"", (char_u *)0L}
899#else
900 (char_u *)NULL, PV_NONE,
901 {(char_u *)0L, (char_u *)0L}
902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
905#ifdef FEAT_CSCOPE
906 (char_u *)&p_cst, PV_NONE,
907#else
908 (char_u *)NULL, PV_NONE,
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
912#ifdef FEAT_CSCOPE
913 (char_u *)&p_csto, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_csverbose, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200925 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
926#ifdef FEAT_CURSORBIND
927 (char_u *)VAR_WIN, PV_CRBIND,
928#else
929 (char_u *)NULL, PV_NONE,
930#endif
931 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000932 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
933#ifdef FEAT_SYN_HL
934 (char_u *)VAR_WIN, PV_CUC,
935#else
936 (char_u *)NULL, PV_NONE,
937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000939 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
940#ifdef FEAT_SYN_HL
941 (char_u *)VAR_WIN, PV_CUL,
942#else
943 (char_u *)NULL, PV_NONE,
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 {"debug", NULL, P_STRING|P_VI_DEF,
947 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000948 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
950#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000951 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000952 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953#else
954 (char_u *)NULL, PV_NONE,
955 {(char_u *)NULL, (char_u *)0L}
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
959#ifdef FEAT_MBYTE
960 (char_u *)&p_deco, PV_NONE,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000965 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
966#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000967 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
973#ifdef FEAT_DIFF
974 (char_u *)VAR_WIN, PV_DIFF,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
980#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
981 (char_u *)&p_dex, PV_NONE,
982 {(char_u *)"", (char_u *)0L}
983#else
984 (char_u *)NULL, PV_NONE,
985 {(char_u *)0L, (char_u *)0L}
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
989#ifdef FEAT_DIFF
990 (char_u *)&p_dip, PV_NONE,
991 {(char_u *)"filler", (char_u *)NULL}
992#else
993 (char_u *)NULL, PV_NONE,
994 {(char_u *)"", (char_u *)NULL}
995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
998#ifdef FEAT_DIGRAPHS
999 (char_u *)&p_dg, PV_NONE,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1005 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1008 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"eadirection", "ead", P_STRING|P_VI_DEF,
1011#ifdef FEAT_VERTSPLIT
1012 (char_u *)&p_ead, PV_NONE,
1013 {(char_u *)"both", (char_u *)0L}
1014#else
1015 (char_u *)NULL, PV_NONE,
1016 {(char_u *)NULL, (char_u *)0L}
1017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001018 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1020 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001022 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_MBYTE
1024 (char_u *)&p_enc, PV_NONE,
1025 {(char_u *)ENC_DFLT, (char_u *)0L}
1026#else
1027 (char_u *)NULL, PV_NONE,
1028 {(char_u *)0L, (char_u *)0L}
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1032 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1035 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001038 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1041 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1044#ifdef FEAT_QUICKFIX
1045 (char_u *)&p_ef, PV_NONE,
1046 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1047#else
1048 (char_u *)NULL, PV_NONE,
1049 {(char_u *)NULL, (char_u *)0L}
1050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1053#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001054 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056#else
1057 (char_u *)NULL, PV_NONE,
1058 {(char_u *)NULL, (char_u *)0L}
1059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"esckeys", "ek", P_BOOL|P_VIM,
1062 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1065#ifdef FEAT_AUTOCMD
1066 (char_u *)&p_ei, PV_NONE,
1067#else
1068 (char_u *)NULL, PV_NONE,
1069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1072 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1075 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1078#ifdef FEAT_MBYTE
1079 (char_u *)&p_fenc, PV_FENC,
1080 {(char_u *)"", (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)0L, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1087#ifdef FEAT_MBYTE
1088 (char_u *)&p_fencs, PV_NONE,
1089 {(char_u *)"ucs-bom", (char_u *)0L}
1090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)0L, (char_u *)0L}
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1096 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1099 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1101 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001102 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#ifdef FEAT_AUTOCMD
1104 (char_u *)&p_ft, PV_FT,
1105 {(char_u *)"", (char_u *)0L}
1106#else
1107 (char_u *)NULL, PV_NONE,
1108 {(char_u *)0L, (char_u *)0L}
1109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1112#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1113 (char_u *)&p_fcs, PV_NONE,
1114 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1115#else
1116 (char_u *)NULL, PV_NONE,
1117 {(char_u *)"", (char_u *)0L}
1118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1121#ifdef FEAT_FKMAP
1122 (char_u *)&p_fkmap, PV_NONE,
1123#else
1124 (char_u *)NULL, PV_NONE,
1125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"flash", "fl", P_BOOL|P_VI_DEF,
1128 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130#ifdef FEAT_FOLDING
1131 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1132 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1135 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1138 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1141# ifdef FEAT_EVAL
1142 (char_u *)VAR_WIN, PV_FDE,
1143 {(char_u *)"0", (char_u *)NULL}
1144# else
1145 (char_u *)NULL, PV_NONE,
1146 {(char_u *)NULL, (char_u *)0L}
1147# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001148 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1150 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001151 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1153 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1156 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1159 P_RWIN|P_COMMA|P_NODUP,
1160 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)"{{{,}}}", (char_u *)NULL}
1162 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1164 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1167 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1170 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1173 (char_u *)&p_fdo, PV_NONE,
1174 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1177# ifdef FEAT_EVAL
1178 (char_u *)VAR_WIN, PV_FDT,
1179 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001180# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181 (char_u *)NULL, PV_NONE,
1182 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001183# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001186 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001187#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001188 (char_u *)&p_fex, PV_FEX,
1189 {(char_u *)"", (char_u *)0L}
1190#else
1191 (char_u *)NULL, PV_NONE,
1192 {(char_u *)0L, (char_u *)0L}
1193#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1196 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1198 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001199 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1200 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1202 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1204 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001205 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001206 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1207#ifdef HAVE_FSYNC
1208 (char_u *)&p_fs, PV_NONE,
1209 {(char_u *)TRUE, (char_u *)0L}
1210#else
1211 (char_u *)NULL, PV_NONE,
1212 {(char_u *)FALSE, (char_u *)0L}
1213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1216 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"graphic", "gr", P_BOOL|P_VI_DEF,
1219 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1222#ifdef FEAT_QUICKFIX
1223 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001224 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225#else
1226 (char_u *)NULL, PV_NONE,
1227 {(char_u *)NULL, (char_u *)0L}
1228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1231#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001232 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 {
1234# ifdef WIN3264
1235 /* may be changed to "grep -n" in os_win32.c */
1236 (char_u *)"findstr /n",
1237# else
1238# ifdef UNIX
1239 /* Add an extra file name so that grep will always
1240 * insert a file name in the match line. */
1241 (char_u *)"grep -n $* /dev/null",
1242# else
1243# ifdef VMS
1244 (char_u *)"SEARCH/NUMBERS ",
1245# else
1246 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247# endif
1248# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001250 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1257#ifdef CURSOR_SHAPE
1258 (char_u *)&p_guicursor, PV_NONE,
1259 {
1260# ifdef FEAT_GUI
1261 (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",
1262# else /* MSDOS or Win32 console */
1263 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1264# endif
1265 (char_u *)0L}
1266#else
1267 (char_u *)NULL, PV_NONE,
1268 {(char_u *)NULL, (char_u *)0L}
1269#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1272#ifdef FEAT_GUI
1273 (char_u *)&p_guifont, PV_NONE,
1274 {(char_u *)"", (char_u *)0L}
1275#else
1276 (char_u *)NULL, PV_NONE,
1277 {(char_u *)NULL, (char_u *)0L}
1278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1281#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1282 (char_u *)&p_guifontset, PV_NONE,
1283 {(char_u *)"", (char_u *)0L}
1284#else
1285 (char_u *)NULL, PV_NONE,
1286 {(char_u *)NULL, (char_u *)0L}
1287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1290#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1291 (char_u *)&p_guifontwide, PV_NONE,
1292 {(char_u *)"", (char_u *)0L}
1293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001299#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 (char_u *)&p_ghr, PV_NONE,
1301#else
1302 (char_u *)NULL, PV_NONE,
1303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001304 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001306#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307 (char_u *)&p_go, PV_NONE,
1308# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001309 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001311 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312# endif
1313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 {"guipty", NULL, P_BOOL|P_VI_DEF,
1319#if defined(FEAT_GUI)
1320 (char_u *)&p_guipty, PV_NONE,
1321#else
1322 (char_u *)NULL, PV_NONE,
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001325 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001326#if defined(FEAT_GUI_TABLINE)
1327 (char_u *)&p_gtl, PV_NONE,
1328 {(char_u *)"", (char_u *)0L}
1329#else
1330 (char_u *)NULL, PV_NONE,
1331 {(char_u *)NULL, (char_u *)0L}
1332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001334 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001335#if defined(FEAT_GUI_TABLINE)
1336 (char_u *)&p_gtt, PV_NONE,
1337 {(char_u *)"", (char_u *)0L}
1338#else
1339 (char_u *)NULL, PV_NONE,
1340 {(char_u *)NULL, (char_u *)0L}
1341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1344 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001345 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1347 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"helpheight", "hh", P_NUM|P_VI_DEF,
1351#ifdef FEAT_WINDOWS
1352 (char_u *)&p_hh, PV_NONE,
1353#else
1354 (char_u *)NULL, PV_NONE,
1355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1358#ifdef FEAT_MULTI_LANG
1359 (char_u *)&p_hlg, PV_NONE,
1360 {(char_u *)"", (char_u *)0L}
1361#else
1362 (char_u *)NULL, PV_NONE,
1363 {(char_u *)0L, (char_u *)0L}
1364#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"hidden", "hid", P_BOOL|P_VI_DEF,
1367 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1370 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"history", "hi", P_NUM|P_VIM,
1374 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1377#ifdef FEAT_RIGHTLEFT
1378 (char_u *)&p_hkmap, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1384#ifdef FEAT_RIGHTLEFT
1385 (char_u *)&p_hkmapp, PV_NONE,
1386#else
1387 (char_u *)NULL, PV_NONE,
1388#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1391 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"icon", NULL, P_BOOL|P_VI_DEF,
1394#ifdef FEAT_TITLE
1395 (char_u *)&p_icon, PV_NONE,
1396#else
1397 (char_u *)NULL, PV_NONE,
1398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"iconstring", NULL, P_STRING|P_VI_DEF,
1401#ifdef FEAT_TITLE
1402 (char_u *)&p_iconstring, PV_NONE,
1403#else
1404 (char_u *)NULL, PV_NONE,
1405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1408 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001411#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 (char_u *)&p_imak, PV_NONE,
1413#else
1414 (char_u *)NULL, PV_NONE,
1415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1418#ifdef USE_IM_CONTROL
1419 (char_u *)&p_imcmdline, PV_NONE,
1420#else
1421 (char_u *)NULL, PV_NONE,
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1425#ifdef USE_IM_CONTROL
1426 (char_u *)&p_imdisable, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
1430#ifdef __sgi
1431 {(char_u *)TRUE, (char_u *)0L}
1432#else
1433 {(char_u *)FALSE, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"iminsert", "imi", P_NUM|P_VI_DEF,
1437 (char_u *)&p_iminsert, PV_IMI,
1438#ifdef B_IMODE_IM
1439 {(char_u *)B_IMODE_IM, (char_u *)0L}
1440#else
1441 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"imsearch", "ims", P_NUM|P_VI_DEF,
1445 (char_u *)&p_imsearch, PV_IMS,
1446#ifdef B_IMODE_IM
1447 {(char_u *)B_IMODE_IM, (char_u *)0L}
1448#else
1449 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1453#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001454 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1456#else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)0L, (char_u *)0L}
1459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1462#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1463 (char_u *)&p_inex, PV_INEX,
1464 {(char_u *)"", (char_u *)0L}
1465#else
1466 (char_u *)NULL, PV_NONE,
1467 {(char_u *)0L, (char_u *)0L}
1468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001469 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1471 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1474#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1475 (char_u *)&p_inde, PV_INDE,
1476 {(char_u *)"", (char_u *)0L}
1477#else
1478 (char_u *)NULL, PV_NONE,
1479 {(char_u *)0L, (char_u *)0L}
1480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001481 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1483#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1484 (char_u *)&p_indk, PV_INDK,
1485 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1486#else
1487 (char_u *)NULL, PV_NONE,
1488 {(char_u *)0L, (char_u *)0L}
1489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"infercase", "inf", P_BOOL|P_VI_DEF,
1492 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1495 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1498 (char_u *)&p_isf, PV_NONE,
1499 {
1500#ifdef BACKSLASH_IN_FILENAME
1501 /* Excluded are: & and ^ are special in cmd.exe
1502 * ( and ) are used in text separating fnames */
1503 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1504#else
1505# ifdef AMIGA
1506 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1507# else
1508# ifdef VMS
1509 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1510# else /* UNIX et al. */
1511# ifdef EBCDIC
1512 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1513# else
1514 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1515# endif
1516# endif
1517# endif
1518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1521 (char_u *)&p_isi, PV_NONE,
1522 {
1523#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1524 (char_u *)"@,48-57,_,128-167,224-235",
1525#else
1526# ifdef EBCDIC
1527 /* TODO: EBCDIC Check this! @ == isalpha()*/
1528 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1529 "112-120,128,140-142,156,158,172,"
1530 "174,186,191,203-207,219-225,235-239,"
1531 "251-254",
1532# else
1533 (char_u *)"@,48-57,_,192-255",
1534# endif
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1538 (char_u *)&p_isk, PV_ISK,
1539 {
1540#ifdef EBCDIC
1541 (char_u *)"@,240-249,_",
1542 /* TODO: EBCDIC Check this! @ == isalpha()*/
1543 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1544 "112-120,128,140-142,156,158,172,"
1545 "174,186,191,203-207,219-225,235-239,"
1546 "251-254",
1547#else
1548 (char_u *)"@,48-57,_",
1549# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1550 (char_u *)"@,48-57,_,128-167,224-235"
1551# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001552 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553# endif
1554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001555 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1557 (char_u *)&p_isp, PV_NONE,
1558 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001559#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1560 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 || defined(VMS)
1562 (char_u *)"@,~-255",
1563#else
1564# ifdef EBCDIC
1565 /* all chars above 63 are printable */
1566 (char_u *)"63-255",
1567# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001568 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569# endif
1570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1573 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1576#ifdef FEAT_CRYPT
1577 (char_u *)&p_key, PV_KEY,
1578 {(char_u *)"", (char_u *)0L}
1579#else
1580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)0L, (char_u *)0L}
1582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001584 {"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 +00001585#ifdef FEAT_KEYMAP
1586 (char_u *)&p_keymap, PV_KMAP,
1587 {(char_u *)"", (char_u *)0L}
1588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)"", (char_u *)0L}
1591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1594#ifdef FEAT_VISUAL
1595 (char_u *)&p_km, PV_NONE,
1596#else
1597 (char_u *)NULL, PV_NONE,
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001601 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {
1603#if defined(MSDOS) || defined(MSWIN)
1604 (char_u *)":help",
1605#else
1606#ifdef VMS
1607 (char_u *)"help",
1608#else
1609# if defined(OS2)
1610 (char_u *)"view /",
1611# else
1612# ifdef USEMAN_S
1613 (char_u *)"man -s",
1614# else
1615 (char_u *)"man",
1616# endif
1617# endif
1618#endif
1619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001620 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1622#ifdef FEAT_LANGMAP
1623 (char_u *)&p_langmap, PV_NONE,
1624 {(char_u *)"", /* unmatched } */
1625#else
1626 (char_u *)NULL, PV_NONE,
1627 {(char_u *)NULL,
1628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001629 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001630 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1632 (char_u *)&p_lm, PV_NONE,
1633#else
1634 (char_u *)NULL, PV_NONE,
1635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001636 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1638#ifdef FEAT_WINDOWS
1639 (char_u *)&p_ls, PV_NONE,
1640#else
1641 (char_u *)NULL, PV_NONE,
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1645 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1648#ifdef FEAT_LINEBREAK
1649 (char_u *)VAR_WIN, PV_LBR,
1650#else
1651 (char_u *)NULL, PV_NONE,
1652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1655 (char_u *)&Rows, PV_NONE,
1656 {
1657#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1658 (char_u *)25L,
1659#else
1660 (char_u *)24L,
1661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1664#ifdef FEAT_GUI
1665 (char_u *)&p_linespace, PV_NONE,
1666#else
1667 (char_u *)NULL, PV_NONE,
1668#endif
1669#ifdef FEAT_GUI_W32
1670 {(char_u *)1L, (char_u *)0L}
1671#else
1672 {(char_u *)0L, (char_u *)0L}
1673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001674 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 {"lisp", NULL, P_BOOL|P_VI_DEF,
1676#ifdef FEAT_LISP
1677 (char_u *)&p_lisp, PV_LISP,
1678#else
1679 (char_u *)NULL, PV_NONE,
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1683#ifdef FEAT_LISP
1684 (char_u *)&p_lispwords, PV_NONE,
1685 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1686#else
1687 (char_u *)NULL, PV_NONE,
1688 {(char_u *)"", (char_u *)0L}
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1692 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1695 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1698 (char_u *)&p_lpl, 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#ifdef FEAT_GUI_MAC
1701 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1702 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"magic", NULL, P_BOOL|P_VI_DEF,
1706 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001708 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#ifdef FEAT_QUICKFIX
1710 (char_u *)&p_mef, PV_NONE,
1711 {(char_u *)"", (char_u *)0L}
1712#else
1713 (char_u *)NULL, PV_NONE,
1714 {(char_u *)NULL, (char_u *)0L}
1715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1718#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001719 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720# ifdef VMS
1721 {(char_u *)"MMS", (char_u *)0L}
1722# else
1723 {(char_u *)"make", (char_u *)0L}
1724# endif
1725#else
1726 (char_u *)NULL, PV_NONE,
1727 {(char_u *)NULL, (char_u *)0L}
1728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1731 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"matchtime", "mat", P_NUM|P_VI_DEF,
1735 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001737 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1738#ifdef FEAT_MBYTE
1739 (char_u *)&p_mco, PV_NONE,
1740#else
1741 (char_u *)NULL, PV_NONE,
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1745#ifdef FEAT_EVAL
1746 (char_u *)&p_mfd, PV_NONE,
1747#else
1748 (char_u *)NULL, PV_NONE,
1749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1752 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"maxmem", "mm", P_NUM|P_VI_DEF,
1755 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1757 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001758 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1759 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1762 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1764 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {"menuitems", "mis", P_NUM|P_VI_DEF,
1766#ifdef FEAT_MENU
1767 (char_u *)&p_mis, PV_NONE,
1768#else
1769 (char_u *)NULL, PV_NONE,
1770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"mesg", NULL, P_BOOL|P_VI_DEF,
1773 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001775 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001776#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001777 (char_u *)&p_msm, PV_NONE,
1778 {(char_u *)"460000,2000,500", (char_u *)0L}
1779#else
1780 (char_u *)NULL, PV_NONE,
1781 {(char_u *)0L, (char_u *)0L}
1782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"modeline", "ml", P_BOOL|P_VIM,
1785 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"modelines", "mls", P_NUM|P_VI_DEF,
1788 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1791 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1794 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"more", NULL, P_BOOL|P_VIM,
1797 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1800 (char_u *)&p_mouse, PV_NONE,
1801 {
1802#if defined(MSDOS) || defined(WIN3264)
1803 (char_u *)"a",
1804#else
1805 (char_u *)"",
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1809#ifdef FEAT_GUI
1810 (char_u *)&p_mousef, PV_NONE,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1816#ifdef FEAT_GUI
1817 (char_u *)&p_mh, PV_NONE,
1818#else
1819 (char_u *)NULL, PV_NONE,
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1823 (char_u *)&p_mousem, PV_NONE,
1824 {
1825#if defined(MSDOS) || defined(MSWIN)
1826 (char_u *)"popup",
1827#else
1828# if defined(MACOS)
1829 (char_u *)"popup_setpos",
1830# else
1831 (char_u *)"extend",
1832# endif
1833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1836#ifdef FEAT_MOUSESHAPE
1837 (char_u *)&p_mouseshape, PV_NONE,
1838 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1839#else
1840 (char_u *)NULL, PV_NONE,
1841 {(char_u *)NULL, (char_u *)0L}
1842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1845 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001847 {"mzquantum", "mzq", P_NUM,
1848#ifdef FEAT_MZSCHEME
1849 (char_u *)&p_mzq, PV_NONE,
1850#else
1851 (char_u *)NULL, PV_NONE,
1852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"novice", NULL, P_BOOL|P_VI_DEF,
1855 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1858 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)"octal,hex", (char_u *)0L}
1860 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1862 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001864 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1865#ifdef FEAT_LINEBREAK
1866 (char_u *)VAR_WIN, PV_NUW,
1867#else
1868 (char_u *)NULL, PV_NONE,
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001871 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001872#ifdef FEAT_COMPL_FUNC
1873 (char_u *)&p_ofu, PV_OFU,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)0L, (char_u *)0L}
1878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"open", NULL, P_BOOL|P_VI_DEF,
1881 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001883 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1884#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1885 (char_u *)&p_odev, PV_NONE,
1886#else
1887 (char_u *)NULL, PV_NONE,
1888#endif
1889 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001891 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1892 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"optimize", "opt", P_BOOL|P_VI_DEF,
1895 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001899 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"paragraphs", "para", P_STRING|P_VI_DEF,
1901 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001902 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001903 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001904 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1908 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1911#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1912 (char_u *)&p_pex, PV_NONE,
1913 {(char_u *)"", (char_u *)0L}
1914#else
1915 (char_u *)NULL, PV_NONE,
1916 {(char_u *)0L, (char_u *)0L}
1917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001919 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001923 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {
1925#if defined AMIGA || defined MSDOS || defined MSWIN
1926 (char_u *)".,,",
1927#else
1928# if defined(__EMX__)
1929 (char_u *)".,/emx/include,,",
1930# else /* Unix, probably */
1931 (char_u *)".,/usr/include,,",
1932# endif
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1936 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001938 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1940 (char_u *)&p_pvh, PV_NONE,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1946#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1947 (char_u *)VAR_WIN, PV_PVW,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001952 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953#ifdef FEAT_PRINTER
1954 (char_u *)&p_pdev, PV_NONE,
1955 {(char_u *)"", (char_u *)0L}
1956#else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)NULL, (char_u *)0L}
1959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"printencoding", "penc", P_STRING|P_VI_DEF,
1962#ifdef FEAT_POSTSCRIPT
1963 (char_u *)&p_penc, PV_NONE,
1964 {(char_u *)"", (char_u *)0L}
1965#else
1966 (char_u *)NULL, PV_NONE,
1967 {(char_u *)NULL, (char_u *)0L}
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1971#ifdef FEAT_POSTSCRIPT
1972 (char_u *)&p_pexpr, PV_NONE,
1973 {(char_u *)"", (char_u *)0L}
1974#else
1975 (char_u *)NULL, PV_NONE,
1976 {(char_u *)NULL, (char_u *)0L}
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"printfont", "pfn", P_STRING|P_VI_DEF,
1980#ifdef FEAT_PRINTER
1981 (char_u *)&p_pfn, PV_NONE,
1982 {
1983# ifdef MSWIN
1984 (char_u *)"Courier_New:h10",
1985# else
1986 (char_u *)"courier",
1987# endif
1988 (char_u *)0L}
1989#else
1990 (char_u *)NULL, PV_NONE,
1991 {(char_u *)NULL, (char_u *)0L}
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1995#ifdef FEAT_PRINTER
1996 (char_u *)&p_header, PV_NONE,
1997 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1998#else
1999 (char_u *)NULL, PV_NONE,
2000 {(char_u *)NULL, (char_u *)0L}
2001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002003 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2004#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2005 (char_u *)&p_pmcs, PV_NONE,
2006 {(char_u *)"", (char_u *)0L}
2007#else
2008 (char_u *)NULL, PV_NONE,
2009 {(char_u *)NULL, (char_u *)0L}
2010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002011 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002012 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2013#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2014 (char_u *)&p_pmfn, PV_NONE,
2015 {(char_u *)"", (char_u *)0L}
2016#else
2017 (char_u *)NULL, PV_NONE,
2018 {(char_u *)NULL, (char_u *)0L}
2019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2022#ifdef FEAT_PRINTER
2023 (char_u *)&p_popt, PV_NONE,
2024 {(char_u *)"", (char_u *)0L}
2025#else
2026 (char_u *)NULL, PV_NONE,
2027 {(char_u *)NULL, (char_u *)0L}
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002031 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002033 {"pumheight", "ph", P_NUM|P_VI_DEF,
2034#ifdef FEAT_INS_EXPAND
2035 (char_u *)&p_ph, PV_NONE,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002040 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2041#ifdef FEAT_TEXTOBJ
2042 (char_u *)&p_qe, PV_QE,
2043 {(char_u *)"\\", (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)NULL, (char_u *)0L}
2047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2050 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"redraw", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002055 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2056#ifdef FEAT_RELTIME
2057 (char_u *)&p_rdt, PV_NONE,
2058#else
2059 (char_u *)NULL, PV_NONE,
2060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002062 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2063 (char_u *)VAR_WIN, PV_RNU,
2064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 {"remap", NULL, P_BOOL|P_VI_DEF,
2066 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 {"report", NULL, P_NUM|P_VI_DEF,
2069 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2072#ifdef WIN3264
2073 (char_u *)&p_rs, PV_NONE,
2074#else
2075 (char_u *)NULL, PV_NONE,
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2079#ifdef FEAT_RIGHTLEFT
2080 (char_u *)&p_ri, PV_NONE,
2081#else
2082 (char_u *)NULL, PV_NONE,
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2086#ifdef FEAT_RIGHTLEFT
2087 (char_u *)VAR_WIN, PV_RL,
2088#else
2089 (char_u *)NULL, PV_NONE,
2090#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2093#ifdef FEAT_RIGHTLEFT
2094 (char_u *)VAR_WIN, PV_RLC,
2095 {(char_u *)"search", (char_u *)NULL}
2096#else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)NULL, (char_u *)0L}
2099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2102#ifdef FEAT_CMDL_INFO
2103 (char_u *)&p_ru, PV_NONE,
2104#else
2105 (char_u *)NULL, PV_NONE,
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2109#ifdef FEAT_STL_OPT
2110 (char_u *)&p_ruf, PV_NONE,
2111#else
2112 (char_u *)NULL, PV_NONE,
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2116 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2120 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2123#ifdef FEAT_SCROLLBIND
2124 (char_u *)VAR_WIN, PV_SCBIND,
2125#else
2126 (char_u *)NULL, PV_NONE,
2127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2130 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2133 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2136#ifdef FEAT_SCROLLBIND
2137 (char_u *)&p_sbo, PV_NONE,
2138 {(char_u *)"ver,jump", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)0L, (char_u *)0L}
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"sections", "sect", P_STRING|P_VI_DEF,
2145 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2147 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2149 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"selection", "sel", P_STRING|P_VI_DEF,
2152#ifdef FEAT_VISUAL
2153 (char_u *)&p_sel, PV_NONE,
2154#else
2155 (char_u *)NULL, PV_NONE,
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)"inclusive", (char_u *)0L}
2158 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2160#ifdef FEAT_VISUAL
2161 (char_u *)&p_slm, PV_NONE,
2162#else
2163 (char_u *)NULL, PV_NONE,
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2167#ifdef FEAT_SESSION
2168 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002169 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 (char_u *)0L}
2171#else
2172 (char_u *)NULL, PV_NONE,
2173 {(char_u *)0L, (char_u *)0L}
2174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2177 (char_u *)&p_sh, PV_NONE,
2178 {
2179#ifdef VMS
2180 (char_u *)"-",
2181#else
2182# if defined(MSDOS)
2183 (char_u *)"command",
2184# else
2185# if defined(WIN16)
2186 (char_u *)"command.com",
2187# else
2188# if defined(WIN3264)
2189 (char_u *)"", /* set in set_init_1() */
2190# else
2191# if defined(OS2)
2192 (char_u *)"cmd.exe",
2193# else
2194# if defined(ARCHIE)
2195 (char_u *)"gos",
2196# else
2197 (char_u *)"sh",
2198# endif
2199# endif
2200# endif
2201# endif
2202# endif
2203#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_shcf, PV_NONE,
2207 {
2208#if defined(MSDOS) || defined(MSWIN)
2209 (char_u *)"/c",
2210#else
2211# if defined(OS2)
2212 (char_u *)"/c",
2213# else
2214 (char_u *)"-c",
2215# endif
2216#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002217 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2219#ifdef FEAT_QUICKFIX
2220 (char_u *)&p_sp, PV_NONE,
2221 {
2222#if defined(UNIX) || defined(OS2)
2223# ifdef ARCHIE
2224 (char_u *)"2>",
2225# else
2226 (char_u *)"| tee",
2227# endif
2228#else
2229 (char_u *)">",
2230#endif
2231 (char_u *)0L}
2232#else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)0L, (char_u *)0L}
2235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2238 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2241 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2244#ifdef BACKSLASH_IN_FILENAME
2245 (char_u *)&p_ssl, PV_NONE,
2246#else
2247 (char_u *)NULL, PV_NONE,
2248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002250 {"shelltemp", "stmp", P_BOOL,
2251 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 {"shelltype", "st", P_NUM|P_VI_DEF,
2254#ifdef AMIGA
2255 (char_u *)&p_st, PV_NONE,
2256#else
2257 (char_u *)NULL, PV_NONE,
2258#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2261 (char_u *)&p_sxq, PV_NONE,
2262 {
2263#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2264 (char_u *)"\"",
2265#else
2266 (char_u *)"",
2267#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2270 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2273 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002274 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2276 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 {(char_u *)"", (char_u *)"filnxtToO"}
2278 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"shortname", "sn", P_BOOL|P_VI_DEF,
2280#ifdef SHORT_FNAME
2281 (char_u *)NULL, PV_NONE,
2282#else
2283 (char_u *)&p_sn, PV_SN,
2284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2287#ifdef FEAT_LINEBREAK
2288 (char_u *)&p_sbr, PV_NONE,
2289#else
2290 (char_u *)NULL, PV_NONE,
2291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"showcmd", "sc", P_BOOL|P_VIM,
2294#ifdef FEAT_CMDL_INFO
2295 (char_u *)&p_sc, PV_NONE,
2296#else
2297 (char_u *)NULL, PV_NONE,
2298#endif
2299 {(char_u *)FALSE,
2300#ifdef UNIX
2301 (char_u *)FALSE
2302#else
2303 (char_u *)TRUE
2304#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2307 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2310 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"showmode", "smd", P_BOOL|P_VIM,
2313 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002315 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2316#ifdef FEAT_WINDOWS
2317 (char_u *)&p_stal, PV_NONE,
2318#else
2319 (char_u *)NULL, PV_NONE,
2320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2323 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2326 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2329 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2332 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2335#ifdef FEAT_SMARTINDENT
2336 (char_u *)&p_si, PV_SI,
2337#else
2338 (char_u *)NULL, PV_NONE,
2339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2342 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2345 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2348 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002350 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002351#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002352 (char_u *)VAR_WIN, PV_SPELL,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002357 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002359 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002360 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002361#else
2362 (char_u *)NULL, PV_NONE,
2363 {(char_u *)0L, (char_u *)0L}
2364#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002366 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002367#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002368 (char_u *)&p_spf, PV_SPF,
2369 {(char_u *)"", (char_u *)0L}
2370#else
2371 (char_u *)NULL, PV_NONE,
2372 {(char_u *)0L, (char_u *)0L}
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002375 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002376#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002377 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002378 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002379#else
2380 (char_u *)NULL, PV_NONE,
2381 {(char_u *)0L, (char_u *)0L}
2382#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002384 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002385#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002386 (char_u *)&p_sps, PV_NONE,
2387 {(char_u *)"best", (char_u *)0L}
2388#else
2389 (char_u *)NULL, PV_NONE,
2390 {(char_u *)0L, (char_u *)0L}
2391#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2394#ifdef FEAT_WINDOWS
2395 (char_u *)&p_sb, PV_NONE,
2396#else
2397 (char_u *)NULL, PV_NONE,
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"splitright", "spr", P_BOOL|P_VI_DEF,
2401#ifdef FEAT_VERTSPLIT
2402 (char_u *)&p_spr, PV_NONE,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2408 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2411#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002412 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2418 (char_u *)&p_su, PV_NONE,
2419 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002422#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 (char_u *)&p_sua, PV_SUA,
2424 {(char_u *)"", (char_u *)0L}
2425#else
2426 (char_u *)NULL, PV_NONE,
2427 {(char_u *)0L, (char_u *)0L}
2428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2431 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"swapsync", "sws", P_STRING|P_VI_DEF,
2434 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2437 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002439 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2440#ifdef FEAT_SYN_HL
2441 (char_u *)&p_smc, PV_SMC,
2442 {(char_u *)3000L, (char_u *)0L}
2443#else
2444 (char_u *)NULL, PV_NONE,
2445 {(char_u *)0L, (char_u *)0L}
2446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002448 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449#ifdef FEAT_SYN_HL
2450 (char_u *)&p_syn, PV_SYN,
2451 {(char_u *)"", (char_u *)0L}
2452#else
2453 (char_u *)NULL, PV_NONE,
2454 {(char_u *)0L, (char_u *)0L}
2455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002457 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2458#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002459 (char_u *)&p_tal, PV_NONE,
2460#else
2461 (char_u *)NULL, PV_NONE,
2462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002464 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2465#ifdef FEAT_WINDOWS
2466 (char_u *)&p_tpm, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2472 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2475 (char_u *)&p_tbs, PV_NONE,
2476#ifdef VMS /* binary searching doesn't appear to work on VMS */
2477 {(char_u *)0L, (char_u *)0L}
2478#else
2479 {(char_u *)TRUE, (char_u *)0L}
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"taglength", "tl", P_NUM|P_VI_DEF,
2483 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002484 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"tagrelative", "tr", P_BOOL|P_VIM,
2486 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002487 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002489 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {
2491#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2492 (char_u *)"./tags,./TAGS,tags,TAGS",
2493#else
2494 (char_u *)"./tags,tags",
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2498 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2501 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2504#ifdef FEAT_ARABIC
2505 (char_u *)&p_tbidi, PV_NONE,
2506#else
2507 (char_u *)NULL, PV_NONE,
2508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2511#ifdef FEAT_MBYTE
2512 (char_u *)&p_tenc, PV_NONE,
2513 {(char_u *)"", (char_u *)0L}
2514#else
2515 (char_u *)NULL, PV_NONE,
2516 {(char_u *)0L, (char_u *)0L}
2517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"terse", NULL, P_BOOL|P_VI_DEF,
2520 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"textauto", "ta", P_BOOL|P_VIM,
2523 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2525 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2527 (char_u *)&p_tx, PV_TX,
2528 {
2529#ifdef USE_CRNL
2530 (char_u *)TRUE,
2531#else
2532 (char_u *)FALSE,
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002535 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2539#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002540 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541#else
2542 (char_u *)NULL, PV_NONE,
2543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2546 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"timeout", "to", P_BOOL|P_VI_DEF,
2549 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2552 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"title", NULL, P_BOOL|P_VI_DEF,
2555#ifdef FEAT_TITLE
2556 (char_u *)&p_title, PV_NONE,
2557#else
2558 (char_u *)NULL, PV_NONE,
2559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"titlelen", NULL, P_NUM|P_VI_DEF,
2562#ifdef FEAT_TITLE
2563 (char_u *)&p_titlelen, PV_NONE,
2564#else
2565 (char_u *)NULL, PV_NONE,
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002568 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569#ifdef FEAT_TITLE
2570 (char_u *)&p_titleold, PV_NONE,
2571 {(char_u *)N_("Thanks for flying Vim"),
2572 (char_u *)0L}
2573#else
2574 (char_u *)NULL, PV_NONE,
2575 {(char_u *)0L, (char_u *)0L}
2576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"titlestring", NULL, P_STRING|P_VI_DEF,
2579#ifdef FEAT_TITLE
2580 (char_u *)&p_titlestring, PV_NONE,
2581#else
2582 (char_u *)NULL, PV_NONE,
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2586 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2587 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)"icons,tooltips", (char_u *)0L}
2589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002591#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2593 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595#endif
2596 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2597 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2600 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2603 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2606 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2609#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2610 (char_u *)&p_ttym, PV_NONE,
2611#else
2612 (char_u *)NULL, PV_NONE,
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2616 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2619 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002621 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2622#ifdef FEAT_PERSISTENT_UNDO
2623 (char_u *)&p_udir, PV_NONE,
2624 {(char_u *)".", (char_u *)0L}
2625#else
2626 (char_u *)NULL, PV_NONE,
2627 {(char_u *)0L, (char_u *)0L}
2628#endif
2629 SCRIPTID_INIT},
2630 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2631#ifdef FEAT_PERSISTENT_UNDO
2632 (char_u *)&p_udf, PV_UDF,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
2636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"undolevels", "ul", P_NUM|P_VI_DEF,
2638 (char_u *)&p_ul, PV_NONE,
2639 {
2640#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2641 (char_u *)1000L,
2642#else
2643 (char_u *)100L,
2644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002646 {"undoreload", "ur", P_NUM|P_VI_DEF,
2647 (char_u *)&p_ur, PV_NONE,
2648 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"updatecount", "uc", P_NUM|P_VI_DEF,
2650 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"updatetime", "ut", P_NUM|P_VI_DEF,
2653 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"verbose", "vbs", P_NUM|P_VI_DEF,
2656 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002658 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2659 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2662#ifdef FEAT_SESSION
2663 (char_u *)&p_vdir, PV_NONE,
2664 {(char_u *)DFLT_VDIR, (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2671#ifdef FEAT_SESSION
2672 (char_u *)&p_vop, PV_NONE,
2673 {(char_u *)"folds,options,cursor", (char_u *)0L}
2674#else
2675 (char_u *)NULL, PV_NONE,
2676 {(char_u *)0L, (char_u *)0L}
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2680#ifdef FEAT_VIMINFO
2681 (char_u *)&p_viminfo, PV_NONE,
2682#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002683 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#else
2685# ifdef AMIGA
2686 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002687 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002689 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690# endif
2691#endif
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2698#ifdef FEAT_VIRTUALEDIT
2699 (char_u *)&p_ve, PV_NONE,
2700 {(char_u *)"", (char_u *)""}
2701#else
2702 (char_u *)NULL, PV_NONE,
2703 {(char_u *)0L, (char_u *)0L}
2704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2707 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"w300", NULL, P_NUM|P_VI_DEF,
2710 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"w1200", NULL, P_NUM|P_VI_DEF,
2713 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"w9600", NULL, P_NUM|P_VI_DEF,
2716 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"warn", NULL, P_BOOL|P_VI_DEF,
2719 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2722 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2725 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {"wildchar", "wc", P_NUM|P_VIM,
2728 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2730 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002731 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2735#ifdef FEAT_WILDIGN
2736 (char_u *)&p_wig, PV_NONE,
2737#else
2738 (char_u *)NULL, PV_NONE,
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002741 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2742 (char_u *)&p_wic, PV_NONE,
2743 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2745#ifdef FEAT_WILDMENU
2746 (char_u *)&p_wmnu, PV_NONE,
2747#else
2748 (char_u *)NULL, PV_NONE,
2749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2752 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002754 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2755#ifdef FEAT_CMDL_COMPL
2756 (char_u *)&p_wop, PV_NONE,
2757 {(char_u *)"", (char_u *)0L}
2758#else
2759 (char_u *)NULL, PV_NONE,
2760 {(char_u *)NULL, (char_u *)0L}
2761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2764#ifdef FEAT_WAK
2765 (char_u *)&p_wak, PV_NONE,
2766 {(char_u *)"menu", (char_u *)0L}
2767#else
2768 (char_u *)NULL, PV_NONE,
2769 {(char_u *)NULL, (char_u *)0L}
2770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002773 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"winheight", "wh", P_NUM|P_VI_DEF,
2776#ifdef FEAT_WINDOWS
2777 (char_u *)&p_wh, PV_NONE,
2778#else
2779 (char_u *)NULL, PV_NONE,
2780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002783#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 (char_u *)VAR_WIN, PV_WFH,
2785#else
2786 (char_u *)NULL, PV_NONE,
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002789 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2790#ifdef FEAT_VERTSPLIT
2791 (char_u *)VAR_WIN, PV_WFW,
2792#else
2793 (char_u *)NULL, PV_NONE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2797#ifdef FEAT_WINDOWS
2798 (char_u *)&p_wmh, PV_NONE,
2799#else
2800 (char_u *)NULL, PV_NONE,
2801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2804#ifdef FEAT_VERTSPLIT
2805 (char_u *)&p_wmw, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2811#ifdef FEAT_VERTSPLIT
2812 (char_u *)&p_wiw, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2818 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2821 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2824 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"write", NULL, P_BOOL|P_VI_DEF,
2827 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"writeany", "wa", P_BOOL|P_VI_DEF,
2830 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2833 (char_u *)&p_wb, PV_NONE,
2834 {
2835#ifdef FEAT_WRITEBACKUP
2836 (char_u *)TRUE,
2837#else
2838 (char_u *)FALSE,
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"writedelay", "wd", P_NUM|P_VI_DEF,
2842 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844
2845/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002846#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849
2850 p_term("t_AB", T_CAB)
2851 p_term("t_AF", T_CAF)
2852 p_term("t_AL", T_CAL)
2853 p_term("t_al", T_AL)
2854 p_term("t_bc", T_BC)
2855 p_term("t_cd", T_CD)
2856 p_term("t_ce", T_CE)
2857 p_term("t_cl", T_CL)
2858 p_term("t_cm", T_CM)
2859 p_term("t_Co", T_CCO)
2860 p_term("t_CS", T_CCS)
2861 p_term("t_cs", T_CS)
2862#ifdef FEAT_VERTSPLIT
2863 p_term("t_CV", T_CSV)
2864#endif
2865 p_term("t_ut", T_UT)
2866 p_term("t_da", T_DA)
2867 p_term("t_db", T_DB)
2868 p_term("t_DL", T_CDL)
2869 p_term("t_dl", T_DL)
2870 p_term("t_fs", T_FS)
2871 p_term("t_IE", T_CIE)
2872 p_term("t_IS", T_CIS)
2873 p_term("t_ke", T_KE)
2874 p_term("t_ks", T_KS)
2875 p_term("t_le", T_LE)
2876 p_term("t_mb", T_MB)
2877 p_term("t_md", T_MD)
2878 p_term("t_me", T_ME)
2879 p_term("t_mr", T_MR)
2880 p_term("t_ms", T_MS)
2881 p_term("t_nd", T_ND)
2882 p_term("t_op", T_OP)
2883 p_term("t_RI", T_CRI)
2884 p_term("t_RV", T_CRV)
2885 p_term("t_Sb", T_CSB)
2886 p_term("t_Sf", T_CSF)
2887 p_term("t_se", T_SE)
2888 p_term("t_so", T_SO)
2889 p_term("t_sr", T_SR)
2890 p_term("t_ts", T_TS)
2891 p_term("t_te", T_TE)
2892 p_term("t_ti", T_TI)
2893 p_term("t_ue", T_UE)
2894 p_term("t_us", T_US)
2895 p_term("t_vb", T_VB)
2896 p_term("t_ve", T_VE)
2897 p_term("t_vi", T_VI)
2898 p_term("t_vs", T_VS)
2899 p_term("t_WP", T_CWP)
2900 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002901 p_term("t_SI", T_CSI)
2902 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 p_term("t_xs", T_XS)
2904 p_term("t_ZH", T_CZH)
2905 p_term("t_ZR", T_CZR)
2906
2907/* terminal key codes are not in here */
2908
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 /* end marker */
2910 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911};
2912
2913#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2914
2915#ifdef FEAT_MBYTE
2916static char *(p_ambw_values[]) = {"single", "double", NULL};
2917#endif
2918static char *(p_bg_values[]) = {"light", "dark", NULL};
2919static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2920static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002921#ifdef FEAT_CRYPT
2922static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2923#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002924#ifdef FEAT_CMDL_COMPL
2925static char *(p_wop_values[]) = {"tagfile", NULL};
2926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927#ifdef FEAT_WAK
2928static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2929#endif
2930static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2931#ifdef FEAT_VISUAL
2932static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2933static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2934#endif
2935#ifdef FEAT_VISUAL
2936static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2937#endif
2938#ifdef FEAT_BROWSE
2939static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2940#endif
2941#ifdef FEAT_SCROLLBIND
2942static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2943#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002944static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945#ifdef FEAT_VERTSPLIT
2946static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2947#endif
2948#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002949# ifdef FEAT_AUTOCMD
2950static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2951# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002953# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2955#endif
2956static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2957#ifdef FEAT_FOLDING
2958static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002959# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002961# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 NULL};
2963static char *(p_fcl_values[]) = {"all", NULL};
2964#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002965#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002966static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968
2969static void set_option_default __ARGS((int, int opt_flags, int compatible));
2970static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002971static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002972static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973static char_u *illegal_char __ARGS((char_u *, int));
2974static int string_to_key __ARGS((char_u *arg));
2975#ifdef FEAT_CMDWIN
2976static char_u *check_cedit __ARGS((void));
2977#endif
2978#ifdef FEAT_TITLE
2979static void did_set_title __ARGS((int icon));
2980#endif
2981static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2982static void didset_options __ARGS((void));
2983static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002984#if defined(FEAT_EVAL) || defined(PROTO)
2985static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2986#else
2987# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2990static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2991static 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));
2992static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02002993#ifdef FEAT_SYN_HL
2994static int int_cmp __ARGS((const void *a, const void *b));
2995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996#ifdef FEAT_CLIPBOARD
2997static char_u *check_clipboard_option __ARGS((void));
2998#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002999#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003000static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003001#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003002#ifdef FEAT_EVAL
3003static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3004#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003006static 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 +00003007static void check_redraw __ARGS((long_u flags));
3008static int findoption __ARGS((char_u *));
3009static int find_key_option __ARGS((char_u *));
3010static void showoptions __ARGS((int all, int opt_flags));
3011static int optval_default __ARGS((struct vimoption *, char_u *varp));
3012static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3013static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3014static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3015static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3016static int istermoption __ARGS((struct vimoption *));
3017static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3018static char_u *get_varp __ARGS((struct vimoption *));
3019static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3020static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3021#ifdef FEAT_LANGMAP
3022static void langmap_init __ARGS((void));
3023static void langmap_set __ARGS((void));
3024#endif
3025static void paste_option_changed __ARGS((void));
3026static void compatible_set __ARGS((void));
3027#ifdef FEAT_LINEBREAK
3028static void fill_breakat_flags __ARGS((void));
3029#endif
3030static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3031static int check_opt_strings __ARGS((char_u *val, char **values, int));
3032static int check_opt_wim __ARGS((void));
3033
3034/*
3035 * Initialize the options, first part.
3036 *
3037 * Called only once from main(), just after creating the first buffer.
3038 */
3039 void
3040set_init_1()
3041{
3042 char_u *p;
3043 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003044 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045
3046#ifdef FEAT_LANGMAP
3047 langmap_init();
3048#endif
3049
3050 /* Be Vi compatible by default */
3051 p_cp = TRUE;
3052
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003053 /* Use POSIX compatibility when $VIM_POSIX is set. */
3054 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003055 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003056 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003057 set_string_default("shm", (char_u *)"A");
3058 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003059
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 /*
3061 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003062 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003064 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3066# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003067 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003069 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003071 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072# endif
3073#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003074 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 set_string_default("sh", p);
3076
3077#ifdef FEAT_WILDIGN
3078 /*
3079 * Set the default for 'backupskip' to include environment variables for
3080 * temp files.
3081 */
3082 {
3083# ifdef UNIX
3084 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3085# else
3086 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3087# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003088 int len;
3089 garray_T ga;
3090 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091
3092 ga_init2(&ga, 1, 100);
3093 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3094 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003095 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096# ifdef UNIX
3097 if (*names[n] == NUL)
3098 p = (char_u *)"/tmp";
3099 else
3100# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003101 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 if (p != NULL && *p != NUL)
3103 {
3104 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003105 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 if (ga_grow(&ga, len) == OK)
3107 {
3108 if (ga.ga_len > 0)
3109 STRCAT(ga.ga_data, ",");
3110 STRCAT(ga.ga_data, p);
3111 add_pathsep(ga.ga_data);
3112 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 ga.ga_len += len;
3114 }
3115 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003116 if (mustfree)
3117 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 }
3119 if (ga.ga_data != NULL)
3120 {
3121 set_string_default("bsk", ga.ga_data);
3122 vim_free(ga.ga_data);
3123 }
3124 }
3125#endif
3126
3127 /*
3128 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3129 */
3130 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003131 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003133#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3134 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3135#endif
3136 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003138 /* Use amount of memory available at this moment. */
3139 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140#else
3141# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003142 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003143 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003145 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146# endif
3147#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003149 opt_idx = findoption((char_u *)"maxmem");
3150 if (opt_idx >= 0)
3151 {
3152#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3153 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3154 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3155#endif
3156 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3157 }
3158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 }
3160
3161#ifdef FEAT_GUI_W32
3162 /* force 'shortname' for Win32s */
3163 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003164 {
3165 opt_idx = findoption((char_u *)"shortname");
3166 if (opt_idx >= 0)
3167 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169#endif
3170
3171#ifdef FEAT_SEARCHPATH
3172 {
3173 char_u *cdpath;
3174 char_u *buf;
3175 int i;
3176 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003177 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178
3179 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003180 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 if (cdpath != NULL)
3182 {
3183 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3184 if (buf != NULL)
3185 {
3186 buf[0] = ','; /* start with ",", current dir first */
3187 j = 1;
3188 for (i = 0; cdpath[i] != NUL; ++i)
3189 {
3190 if (vim_ispathlistsep(cdpath[i]))
3191 buf[j++] = ',';
3192 else
3193 {
3194 if (cdpath[i] == ' ' || cdpath[i] == ',')
3195 buf[j++] = '\\';
3196 buf[j++] = cdpath[i];
3197 }
3198 }
3199 buf[j] = NUL;
3200 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003201 if (opt_idx >= 0)
3202 {
3203 options[opt_idx].def_val[VI_DEFAULT] = buf;
3204 options[opt_idx].flags |= P_DEF_ALLOCED;
3205 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003206 else
3207 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003209 if (mustfree)
3210 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 }
3212 }
3213#endif
3214
3215#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3216 /* Set print encoding on platforms that don't default to latin1 */
3217 set_string_default("penc",
3218# if defined(MSWIN) || defined(OS2)
3219 (char_u *)"cp1252"
3220# else
3221# ifdef VMS
3222 (char_u *)"dec-mcs"
3223# else
3224# ifdef EBCDIC
3225 (char_u *)"ebcdic-uk"
3226# else
3227# ifdef MAC
3228 (char_u *)"mac-roman"
3229# else /* HPUX */
3230 (char_u *)"hp-roman8"
3231# endif
3232# endif
3233# endif
3234# endif
3235 );
3236#endif
3237
3238#ifdef FEAT_POSTSCRIPT
3239 /* 'printexpr' must be allocated to be able to evaluate it. */
3240 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003241# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3242 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243# else
3244# ifdef VMS
3245 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3246
3247# else
3248 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3249# endif
3250# endif
3251 );
3252#endif
3253
3254 /*
3255 * Set all the options (except the terminal options) to their default
3256 * value. Also set the global value for local options.
3257 */
3258 set_options_default(0);
3259
3260#ifdef FEAT_GUI
3261 if (found_reverse_arg)
3262 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3263#endif
3264
3265 curbuf->b_p_initialized = TRUE;
3266 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3267 check_buf_options(curbuf);
3268 check_win_options(curwin);
3269 check_options();
3270
3271 /* Must be before option_expand(), because that one needs vim_isIDc() */
3272 didset_options();
3273
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003274#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003275 /* Use the current chartab for the generic chartab. */
3276 init_spell_chartab();
3277#endif
3278
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#ifdef FEAT_LINEBREAK
3280 /*
3281 * initialize the table for 'breakat'.
3282 */
3283 fill_breakat_flags();
3284#endif
3285
3286 /*
3287 * Expand environment variables and things like "~" for the defaults.
3288 * If option_expand() returns non-NULL the variable is expanded. This can
3289 * only happen for non-indirect options.
3290 * Also set the default to the expanded value, so ":set" does not list
3291 * them.
3292 * Don't set the P_ALLOCED flag, because we don't want to free the
3293 * default.
3294 */
3295 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3296 {
3297 if ((options[opt_idx].flags & P_GETTEXT)
3298 && options[opt_idx].var != NULL)
3299 p = (char_u *)_(*(char **)options[opt_idx].var);
3300 else
3301 p = option_expand(opt_idx, NULL);
3302 if (p != NULL && (p = vim_strsave(p)) != NULL)
3303 {
3304 *(char_u **)options[opt_idx].var = p;
3305 /* VIMEXP
3306 * Defaults for all expanded options are currently the same for Vi
3307 * and Vim. When this changes, add some code here! Also need to
3308 * split P_DEF_ALLOCED in two.
3309 */
3310 if (options[opt_idx].flags & P_DEF_ALLOCED)
3311 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3312 options[opt_idx].def_val[VI_DEFAULT] = p;
3313 options[opt_idx].flags |= P_DEF_ALLOCED;
3314 }
3315 }
3316
3317 /* Initialize the highlight_attr[] table. */
3318 highlight_changed();
3319
3320 save_file_ff(curbuf); /* Buffer is unchanged */
3321
3322 /* Parse default for 'wildmode' */
3323 check_opt_wim();
3324
3325#if defined(FEAT_ARABIC)
3326 /* Detect use of mlterm.
3327 * Mlterm is a terminal emulator akin to xterm that has some special
3328 * abilities (bidi namely).
3329 * NOTE: mlterm's author is being asked to 'set' a variable
3330 * instead of an environment variable due to inheritance.
3331 */
3332 if (mch_getenv((char_u *)"MLTERM") != NULL)
3333 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3334#endif
3335
3336#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3337 /* Parse default for 'fillchars'. */
3338 (void)set_chars_option(&p_fcs);
3339#endif
3340
3341#ifdef FEAT_CLIPBOARD
3342 /* Parse default for 'clipboard' */
3343 (void)check_clipboard_option();
3344#endif
3345
3346#ifdef FEAT_MBYTE
3347# if defined(WIN3264) && defined(FEAT_GETTEXT)
3348 /*
3349 * If $LANG isn't set, try to get a good value for it. This makes the
3350 * right language be used automatically. Don't do this for English.
3351 */
3352 if (mch_getenv((char_u *)"LANG") == NULL)
3353 {
3354 char buf[20];
3355
3356 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3357 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3358 * only the first two. */
3359 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3360 (LPTSTR)buf, 20);
3361 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3362 {
3363 /* There are a few exceptions (probably more) */
3364 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3365 STRCPY(buf, "zh_TW");
3366 else if (STRNICMP(buf, "chs", 3) == 0
3367 || STRNICMP(buf, "zhc", 3) == 0)
3368 STRCPY(buf, "zh_CN");
3369 else if (STRNICMP(buf, "jp", 2) == 0)
3370 STRCPY(buf, "ja");
3371 else
3372 buf[2] = NUL; /* truncate to two-letter code */
3373 vim_setenv("LANG", buf);
3374 }
3375 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003376# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003377# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003378 /* Moved to os_mac_conv.c to avoid dependency problems. */
3379 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003380# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381# endif
3382
3383 /* enc_locale() will try to find the encoding of the current locale. */
3384 p = enc_locale();
3385 if (p != NULL)
3386 {
3387 char_u *save_enc;
3388
3389 /* Try setting 'encoding' and check if the value is valid.
3390 * If not, go back to the default "latin1". */
3391 save_enc = p_enc;
3392 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003393 if (STRCMP(p_enc, "gb18030") == 0)
3394 {
3395 /* We don't support "gb18030", but "cp936" is a good substitute
3396 * for practical purposes, thus use that. It's not an alias to
3397 * still support conversion between gb18030 and utf-8. */
3398 p_enc = vim_strsave((char_u *)"cp936");
3399 vim_free(p);
3400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 if (mb_init() == NULL)
3402 {
3403 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003404 if (opt_idx >= 0)
3405 {
3406 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3407 options[opt_idx].flags |= P_DEF_ALLOCED;
3408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003410#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3411 || defined(VMS)
3412 if (STRCMP(p_enc, "latin1") == 0
3413# ifdef FEAT_MBYTE
3414 || enc_utf8
3415# endif
3416 )
3417 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003418 /* Adjust the default for 'isprint' and 'iskeyword' to match
3419 * latin1. Also set the defaults for when 'nocompatible' is
3420 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003421 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003422 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003423 set_string_option_direct((char_u *)"isk", -1,
3424 ISK_LATIN1, OPT_FREE, SID_NONE);
3425 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426 if (opt_idx >= 0)
3427 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003428 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003429 if (opt_idx >= 0)
3430 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003431 (void)init_chartab();
3432 }
3433#endif
3434
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435# if defined(WIN3264) && !defined(FEAT_GUI)
3436 /* Win32 console: When GetACP() returns a different value from
3437 * GetConsoleCP() set 'termencoding'. */
3438 if (GetACP() != GetConsoleCP())
3439 {
3440 char buf[50];
3441
3442 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3443 p_tenc = vim_strsave((char_u *)buf);
3444 if (p_tenc != NULL)
3445 {
3446 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003447 if (opt_idx >= 0)
3448 {
3449 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3450 options[opt_idx].flags |= P_DEF_ALLOCED;
3451 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 convert_setup(&input_conv, p_tenc, p_enc);
3453 convert_setup(&output_conv, p_enc, p_tenc);
3454 }
3455 else
3456 p_tenc = empty_option;
3457 }
3458# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003459# if defined(WIN3264) && defined(FEAT_MBYTE)
3460 /* $HOME may have characters in active code page. */
3461 init_homedir();
3462# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 }
3464 else
3465 {
3466 vim_free(p_enc);
3467 p_enc = save_enc;
3468 }
3469 }
3470#endif
3471
3472#ifdef FEAT_MULTI_LANG
3473 /* Set the default for 'helplang'. */
3474 set_helplang_default(get_mess_lang());
3475#endif
3476}
3477
3478/*
3479 * Set an option to its default value.
3480 * This does not take care of side effects!
3481 */
3482 static void
3483set_option_default(opt_idx, opt_flags, compatible)
3484 int opt_idx;
3485 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3486 int compatible; /* use Vi default value */
3487{
3488 char_u *varp; /* pointer to variable for current option */
3489 int dvi; /* index in def_val[] */
3490 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003491 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3493
3494 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3495 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003496 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 {
3498 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3499 if (flags & P_STRING)
3500 {
3501 /* Use set_string_option_direct() for local options to handle
3502 * freeing and allocating the value. */
3503 if (options[opt_idx].indir != PV_NONE)
3504 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003505 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 else
3507 {
3508 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3509 free_string_option(*(char_u **)(varp));
3510 *(char_u **)varp = options[opt_idx].def_val[dvi];
3511 options[opt_idx].flags &= ~P_ALLOCED;
3512 }
3513 }
3514 else if (flags & P_NUM)
3515 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003516 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 win_comp_scroll(curwin);
3518 else
3519 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003520 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 /* May also set global value for local option. */
3522 if (both)
3523 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3524 *(long *)varp;
3525 }
3526 }
3527 else /* P_BOOL */
3528 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003529 /* the cast to long is required for Manx C, long_i is needed for
3530 * MSVC */
3531 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003532#ifdef UNIX
3533 /* 'modeline' defaults to off for root */
3534 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3535 *(int *)varp = FALSE;
3536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 /* May also set global value for local option. */
3538 if (both)
3539 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3540 *(int *)varp;
3541 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003542
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003543 /* The default value is not insecure. */
3544 flagsp = insecure_flag(opt_idx, opt_flags);
3545 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 }
3547
3548#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003549 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550#endif
3551}
3552
3553/*
3554 * Set all options (except terminal options) to their default value.
3555 */
3556 static void
3557set_options_default(opt_flags)
3558 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3559{
3560 int i;
3561#ifdef FEAT_WINDOWS
3562 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003563 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564#endif
3565
3566 for (i = 0; !istermoption(&options[i]); i++)
3567 if (!(options[i].flags & P_NODEFAULT))
3568 set_option_default(i, opt_flags, p_cp);
3569
3570#ifdef FEAT_WINDOWS
3571 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003572 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 win_comp_scroll(wp);
3574#else
3575 win_comp_scroll(curwin);
3576#endif
3577}
3578
3579/*
3580 * Set the Vi-default value of a string option.
3581 * Used for 'sh', 'backupskip' and 'term'.
3582 */
3583 void
3584set_string_default(name, val)
3585 char *name;
3586 char_u *val;
3587{
3588 char_u *p;
3589 int opt_idx;
3590
3591 p = vim_strsave(val);
3592 if (p != NULL) /* we don't want a NULL */
3593 {
3594 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003595 if (opt_idx >= 0)
3596 {
3597 if (options[opt_idx].flags & P_DEF_ALLOCED)
3598 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3599 options[opt_idx].def_val[VI_DEFAULT] = p;
3600 options[opt_idx].flags |= P_DEF_ALLOCED;
3601 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 }
3603}
3604
3605/*
3606 * Set the Vi-default value of a number option.
3607 * Used for 'lines' and 'columns'.
3608 */
3609 void
3610set_number_default(name, val)
3611 char *name;
3612 long val;
3613{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003614 int opt_idx;
3615
3616 opt_idx = findoption((char_u *)name);
3617 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003618 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003619}
3620
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003621#if defined(EXITFREE) || defined(PROTO)
3622/*
3623 * Free all options.
3624 */
3625 void
3626free_all_options()
3627{
3628 int i;
3629
3630 for (i = 0; !istermoption(&options[i]); i++)
3631 {
3632 if (options[i].indir == PV_NONE)
3633 {
3634 /* global option: free value and default value. */
3635 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3636 free_string_option(*(char_u **)options[i].var);
3637 if (options[i].flags & P_DEF_ALLOCED)
3638 free_string_option(options[i].def_val[VI_DEFAULT]);
3639 }
3640 else if (options[i].var != VAR_WIN
3641 && (options[i].flags & P_STRING))
3642 /* buffer-local option: free global value */
3643 free_string_option(*(char_u **)options[i].var);
3644 }
3645}
3646#endif
3647
3648
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649/*
3650 * Initialize the options, part two: After getting Rows and Columns and
3651 * setting 'term'.
3652 */
3653 void
3654set_init_2()
3655{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003656 int idx;
3657
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658 /*
3659 * 'scroll' defaults to half the window height. Note that this default is
3660 * wrong when the window height changes.
3661 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003662 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003663 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003664 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003665 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666 comp_col();
3667
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003668 /*
3669 * 'window' is only for backwards compatibility with Vi.
3670 * Default is Rows - 1.
3671 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003672 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003673 p_window = Rows - 1;
3674 set_number_default("window", Rows - 1);
3675
Bram Moolenaarf740b292006-02-16 22:11:02 +00003676 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003678 /*
3679 * If 'background' wasn't set by the user, try guessing the value,
3680 * depending on the terminal name. Only need to check for terminals
3681 * with a dark background, that can handle color.
3682 */
3683 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003684 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3685 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003687 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003688 /* don't mark it as set, when starting the GUI it may be
3689 * changed again */
3690 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 }
3692#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003693
3694#ifdef CURSOR_SHAPE
3695 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3696#endif
3697#ifdef FEAT_MOUSESHAPE
3698 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3699#endif
3700#ifdef FEAT_PRINTER
3701 (void)parse_printoptions(); /* parse 'printoptions' default value */
3702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703}
3704
3705/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003706 * Return "dark" or "light" depending on the kind of terminal.
3707 * This is just guessing! Recognized are:
3708 * "linux" Linux console
3709 * "screen.linux" Linux console with screen
3710 * "cygwin" Cygwin shell
3711 * "putty" Putty program
3712 * We also check the COLORFGBG environment variable, which is set by
3713 * rxvt and derivatives. This variable contains either two or three
3714 * values separated by semicolons; we want the last value in either
3715 * case. If this value is 0-6 or 8, our background is dark.
3716 */
3717 static char_u *
3718term_bg_default()
3719{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003720#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3721 /* DOS console nearly always black */
3722 return (char_u *)"dark";
3723#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003724 char_u *p;
3725
Bram Moolenaarf740b292006-02-16 22:11:02 +00003726 if (STRCMP(T_NAME, "linux") == 0
3727 || STRCMP(T_NAME, "screen.linux") == 0
3728 || STRCMP(T_NAME, "cygwin") == 0
3729 || STRCMP(T_NAME, "putty") == 0
3730 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3731 && (p = vim_strrchr(p, ';')) != NULL
3732 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3733 && p[2] == NUL))
3734 return (char_u *)"dark";
3735 return (char_u *)"light";
3736#endif
3737}
3738
3739/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 * Initialize the options, part three: After reading the .vimrc
3741 */
3742 void
3743set_init_3()
3744{
3745#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3746/*
3747 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3748 * This is done after other initializations, where 'shell' might have been
3749 * set, but only if they have not been set before.
3750 */
3751 char_u *p;
3752 int idx_srr;
3753 int do_srr;
3754#ifdef FEAT_QUICKFIX
3755 int idx_sp;
3756 int do_sp;
3757#endif
3758
3759 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003760 if (idx_srr < 0)
3761 do_srr = FALSE;
3762 else
3763 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764#ifdef FEAT_QUICKFIX
3765 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003766 if (idx_sp < 0)
3767 do_sp = FALSE;
3768 else
3769 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770#endif
3771
3772 /*
3773 * Isolate the name of the shell:
3774 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3775 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003776 * But don't allow a space in the path, so that this works:
3777 * "/usr/bin/csh --rcfile ~/.cshrc"
3778 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003780#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 p = gettail(p_sh);
3782 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003783#else
3784 p = skiptowhite(p_sh);
3785 if (*p == NUL)
3786 {
3787 /* No white space, use the tail. */
3788 p = vim_strsave(gettail(p_sh));
3789 }
3790 else
3791 {
3792 char_u *p1, *p2;
3793
3794 /* Find the last path separator before the space. */
3795 p1 = p_sh;
3796 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3797 if (vim_ispathsep(*p2))
3798 p1 = p2 + 1;
3799 p = vim_strnsave(p1, (int)(p - p1));
3800 }
3801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 if (p != NULL)
3803 {
3804 /*
3805 * Default for p_sp is "| tee", for p_srr is ">".
3806 * For known shells it is changed here to include stderr.
3807 */
3808 if ( fnamecmp(p, "csh") == 0
3809 || fnamecmp(p, "tcsh") == 0
3810# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3811 || fnamecmp(p, "csh.exe") == 0
3812 || fnamecmp(p, "tcsh.exe") == 0
3813# endif
3814 )
3815 {
3816#if defined(FEAT_QUICKFIX)
3817 if (do_sp)
3818 {
3819# ifdef WIN3264
3820 p_sp = (char_u *)">&";
3821# else
3822 p_sp = (char_u *)"|& tee";
3823# endif
3824 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3825 }
3826#endif
3827 if (do_srr)
3828 {
3829 p_srr = (char_u *)">&";
3830 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3831 }
3832 }
3833 else
3834# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3835 if ( fnamecmp(p, "sh") == 0
3836 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003837 || fnamecmp(p, "mksh") == 0
3838 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003840 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 || fnamecmp(p, "bash") == 0
3842# ifdef WIN3264
3843 || fnamecmp(p, "cmd") == 0
3844 || fnamecmp(p, "sh.exe") == 0
3845 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003846 || fnamecmp(p, "mksh.exe") == 0
3847 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003849 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 || fnamecmp(p, "bash.exe") == 0
3851 || fnamecmp(p, "cmd.exe") == 0
3852# endif
3853 )
3854# endif
3855 {
3856#if defined(FEAT_QUICKFIX)
3857 if (do_sp)
3858 {
3859# ifdef WIN3264
3860 p_sp = (char_u *)">%s 2>&1";
3861# else
3862 p_sp = (char_u *)"2>&1| tee";
3863# endif
3864 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3865 }
3866#endif
3867 if (do_srr)
3868 {
3869 p_srr = (char_u *)">%s 2>&1";
3870 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3871 }
3872 }
3873 vim_free(p);
3874 }
3875#endif
3876
3877#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3878 /*
3879 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3880 * This is done after other initializations, where 'shell' might have been
3881 * set, but only if they have not been set before. Default for p_shcf is
3882 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3883 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3884 * command.com. And for Win32 we need to set p_sxq instead.
3885 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003886 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 {
3888 int idx3;
3889
3890 idx3 = findoption((char_u *)"shcf");
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_shcf = (char_u *)"-c";
3894 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3895 }
3896
3897# ifndef DJGPP
3898# ifdef WIN3264
3899 /* Somehow Win32 requires the quotes around the redirection too */
3900 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003901 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 {
3903 p_sxq = (char_u *)"\"";
3904 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3905 }
3906# else
3907 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003908 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 {
3910 p_shq = (char_u *)"\"";
3911 options[idx3].def_val[VI_DEFAULT] = p_shq;
3912 }
3913# endif
3914# endif
3915 }
3916#endif
3917
3918#ifdef FEAT_TITLE
3919 set_title_defaults();
3920#endif
3921}
3922
3923#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3924/*
3925 * When 'helplang' is still at its default value, set it to "lang".
3926 * Only the first two characters of "lang" are used.
3927 */
3928 void
3929set_helplang_default(lang)
3930 char_u *lang;
3931{
3932 int idx;
3933
3934 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3935 return;
3936 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003937 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 {
3939 if (options[idx].flags & P_ALLOCED)
3940 free_string_option(p_hlg);
3941 p_hlg = vim_strsave(lang);
3942 if (p_hlg == NULL)
3943 p_hlg = empty_option;
3944 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003945 {
3946 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3947 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3948 {
3949 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3950 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3951 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 options[idx].flags |= P_ALLOCED;
3955 }
3956}
3957#endif
3958
3959#ifdef FEAT_GUI
3960static char_u *gui_bg_default __ARGS((void));
3961
3962 static char_u *
3963gui_bg_default()
3964{
3965 if (gui_get_lightness(gui.back_pixel) < 127)
3966 return (char_u *)"dark";
3967 return (char_u *)"light";
3968}
3969
3970/*
3971 * Option initializations that can only be done after opening the GUI window.
3972 */
3973 void
3974init_gui_options()
3975{
3976 /* Set the 'background' option according to the lightness of the
3977 * background color, unless the user has set it already. */
3978 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3979 {
3980 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3981 highlight_changed();
3982 }
3983}
3984#endif
3985
3986#ifdef FEAT_TITLE
3987/*
3988 * 'title' and 'icon' only default to true if they have not been set or reset
3989 * in .vimrc and we can read the old value.
3990 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3991 * they can be reset. This reduces startup time when using X on a remote
3992 * machine.
3993 */
3994 void
3995set_title_defaults()
3996{
3997 int idx1;
3998 long val;
3999
4000 /*
4001 * If GUI is (going to be) used, we can always set the window title and
4002 * icon name. Saves a bit of time, because the X11 display server does
4003 * not need to be contacted.
4004 */
4005 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004006 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007 {
4008#ifdef FEAT_GUI
4009 if (gui.starting || gui.in_use)
4010 val = TRUE;
4011 else
4012#endif
4013 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004014 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 p_title = val;
4016 }
4017 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004018 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 {
4020#ifdef FEAT_GUI
4021 if (gui.starting || gui.in_use)
4022 val = TRUE;
4023 else
4024#endif
4025 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004026 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027 p_icon = val;
4028 }
4029}
4030#endif
4031
4032/*
4033 * Parse 'arg' for option settings.
4034 *
4035 * 'arg' may be IObuff, but only when no errors can be present and option
4036 * does not need to be expanded with option_expand().
4037 * "opt_flags":
4038 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004039 * OPT_GLOBAL for ":setglobal"
4040 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004042 * OPT_WINONLY to only set window-local options
4043 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 *
4045 * returns FAIL if an error is detected, OK otherwise
4046 */
4047 int
4048do_set(arg, opt_flags)
4049 char_u *arg; /* option string (may be written to!) */
4050 int opt_flags;
4051{
4052 int opt_idx;
4053 char_u *errmsg;
4054 char_u errbuf[80];
4055 char_u *startarg;
4056 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4057 int nextchar; /* next non-white char after option name */
4058 int afterchar; /* character just after option name */
4059 int len;
4060 int i;
4061 long value;
4062 int key;
4063 long_u flags; /* flags for current option */
4064 char_u *varp = NULL; /* pointer to variable for current option */
4065 int did_show = FALSE; /* already showed one value */
4066 int adding; /* "opt+=arg" */
4067 int prepending; /* "opt^=arg" */
4068 int removing; /* "opt-=arg" */
4069 int cp_val = 0;
4070 char_u key_name[2];
4071
4072 if (*arg == NUL)
4073 {
4074 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004075 did_show = TRUE;
4076 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 }
4078
4079 while (*arg != NUL) /* loop to process all options */
4080 {
4081 errmsg = NULL;
4082 startarg = arg; /* remember for error message */
4083
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004084 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4085 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 {
4087 /*
4088 * ":set all" show all options.
4089 * ":set all&" set all options to their default value.
4090 */
4091 arg += 3;
4092 if (*arg == '&')
4093 {
4094 ++arg;
4095 /* Only for :set command set global value of local options. */
4096 set_options_default(OPT_FREE | opt_flags);
4097 }
4098 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004099 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004101 did_show = TRUE;
4102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004104 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
4106 showoptions(2, opt_flags);
4107 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004108 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 arg += 7;
4110 }
4111 else
4112 {
4113 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004114 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 {
4116 prefix = 0;
4117 arg += 2;
4118 }
4119 else if (STRNCMP(arg, "inv", 3) == 0)
4120 {
4121 prefix = 2;
4122 arg += 3;
4123 }
4124
4125 /* find end of name */
4126 key = 0;
4127 if (*arg == '<')
4128 {
4129 nextchar = 0;
4130 opt_idx = -1;
4131 /* look out for <t_>;> */
4132 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4133 len = 5;
4134 else
4135 {
4136 len = 1;
4137 while (arg[len] != NUL && arg[len] != '>')
4138 ++len;
4139 }
4140 if (arg[len] != '>')
4141 {
4142 errmsg = e_invarg;
4143 goto skip;
4144 }
4145 arg[len] = NUL; /* put NUL after name */
4146 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4147 opt_idx = findoption(arg + 1);
4148 arg[len++] = '>'; /* restore '>' */
4149 if (opt_idx == -1)
4150 key = find_key_option(arg + 1);
4151 }
4152 else
4153 {
4154 len = 0;
4155 /*
4156 * The two characters after "t_" may not be alphanumeric.
4157 */
4158 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4159 len = 4;
4160 else
4161 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4162 ++len;
4163 nextchar = arg[len];
4164 arg[len] = NUL; /* put NUL after name */
4165 opt_idx = findoption(arg);
4166 arg[len] = nextchar; /* restore nextchar */
4167 if (opt_idx == -1)
4168 key = find_key_option(arg);
4169 }
4170
4171 /* remember character after option name */
4172 afterchar = arg[len];
4173
4174 /* skip white space, allow ":set ai ?" */
4175 while (vim_iswhite(arg[len]))
4176 ++len;
4177
4178 adding = FALSE;
4179 prepending = FALSE;
4180 removing = FALSE;
4181 if (arg[len] != NUL && arg[len + 1] == '=')
4182 {
4183 if (arg[len] == '+')
4184 {
4185 adding = TRUE; /* "+=" */
4186 ++len;
4187 }
4188 else if (arg[len] == '^')
4189 {
4190 prepending = TRUE; /* "^=" */
4191 ++len;
4192 }
4193 else if (arg[len] == '-')
4194 {
4195 removing = TRUE; /* "-=" */
4196 ++len;
4197 }
4198 }
4199 nextchar = arg[len];
4200
4201 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4202 {
4203 errmsg = (char_u *)N_("E518: Unknown option");
4204 goto skip;
4205 }
4206
4207 if (opt_idx >= 0)
4208 {
4209 if (options[opt_idx].var == NULL) /* hidden option: skip */
4210 {
4211 /* Only give an error message when requesting the value of
4212 * a hidden option, ignore setting it. */
4213 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4214 && (!(options[opt_idx].flags & P_BOOL)
4215 || nextchar == '?'))
4216 errmsg = (char_u *)N_("E519: Option not supported");
4217 goto skip;
4218 }
4219
4220 flags = options[opt_idx].flags;
4221 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4222 }
4223 else
4224 {
4225 flags = P_STRING;
4226 if (key < 0)
4227 {
4228 key_name[0] = KEY2TERMCAP0(key);
4229 key_name[1] = KEY2TERMCAP1(key);
4230 }
4231 else
4232 {
4233 key_name[0] = KS_KEY;
4234 key_name[1] = (key & 0xff);
4235 }
4236 }
4237
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004238 /* Skip all options that are not window-local (used when showing
4239 * an already loaded buffer in a window). */
4240 if ((opt_flags & OPT_WINONLY)
4241 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4242 goto skip;
4243
Bram Moolenaara3227e22006-03-08 21:32:40 +00004244 /* Skip all options that are window-local (used for :vimgrep). */
4245 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4246 && options[opt_idx].var == VAR_WIN)
4247 goto skip;
4248
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004249 /* Disallow changing some options from modelines. */
4250 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004252 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004253 {
4254 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4255 goto skip;
4256 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004257#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004258 /* In diff mode some options are overruled. This avoids that
4259 * 'foldmethod' becomes "marker" instead of "diff" and that
4260 * "wrap" gets set. */
4261 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004262 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004263 && (options[opt_idx].indir == PV_FDM
4264 || options[opt_idx].indir == PV_WRAP))
4265 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267 }
4268
4269#ifdef HAVE_SANDBOX
4270 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004271 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 {
4273 errmsg = (char_u *)_(e_sandbox);
4274 goto skip;
4275 }
4276#endif
4277
4278 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4279 {
4280 arg += len;
4281 cp_val = p_cp;
4282 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4283 {
4284 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4285 {
4286 cp_val = FALSE;
4287 arg += 3;
4288 }
4289 else /* "opt&vi": set to Vi default */
4290 {
4291 cp_val = TRUE;
4292 arg += 2;
4293 }
4294 }
4295 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4296 && arg[1] != NUL && !vim_iswhite(arg[1]))
4297 {
4298 errmsg = e_trailing;
4299 goto skip;
4300 }
4301 }
4302
4303 /*
4304 * allow '=' and ':' as MSDOS command.com allows only one
4305 * '=' character per "set" command line. grrr. (jw)
4306 */
4307 if (nextchar == '?'
4308 || (prefix == 1
4309 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4310 && !(flags & P_BOOL)))
4311 {
4312 /*
4313 * print value
4314 */
4315 if (did_show)
4316 msg_putchar('\n'); /* cursor below last one */
4317 else
4318 {
4319 gotocmdline(TRUE); /* cursor at status line */
4320 did_show = TRUE; /* remember that we did a line */
4321 }
4322 if (opt_idx >= 0)
4323 {
4324 showoneopt(&options[opt_idx], opt_flags);
4325#ifdef FEAT_EVAL
4326 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004327 {
4328 /* Mention where the option was last set. */
4329 if (varp == options[opt_idx].var)
4330 last_set_msg(options[opt_idx].scriptID);
4331 else if ((int)options[opt_idx].indir & PV_WIN)
4332 last_set_msg(curwin->w_p_scriptID[
4333 (int)options[opt_idx].indir & PV_MASK]);
4334 else if ((int)options[opt_idx].indir & PV_BUF)
4335 last_set_msg(curbuf->b_p_scriptID[
4336 (int)options[opt_idx].indir & PV_MASK]);
4337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338#endif
4339 }
4340 else
4341 {
4342 char_u *p;
4343
4344 p = find_termcode(key_name);
4345 if (p == NULL)
4346 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004347 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 goto skip;
4349 }
4350 else
4351 (void)show_one_termcode(key_name, p, TRUE);
4352 }
4353 if (nextchar != '?'
4354 && nextchar != NUL && !vim_iswhite(afterchar))
4355 errmsg = e_trailing;
4356 }
4357 else
4358 {
4359 if (flags & P_BOOL) /* boolean */
4360 {
4361 if (nextchar == '=' || nextchar == ':')
4362 {
4363 errmsg = e_invarg;
4364 goto skip;
4365 }
4366
4367 /*
4368 * ":set opt!": invert
4369 * ":set opt&": reset to default value
4370 * ":set opt<": reset to global value
4371 */
4372 if (nextchar == '!')
4373 value = *(int *)(varp) ^ 1;
4374 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004375 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 ((flags & P_VI_DEF) || cp_val)
4377 ? VI_DEFAULT : VIM_DEFAULT];
4378 else if (nextchar == '<')
4379 {
4380 /* For 'autoread' -1 means to use global value. */
4381 if ((int *)varp == &curbuf->b_p_ar
4382 && opt_flags == OPT_LOCAL)
4383 value = -1;
4384 else
4385 value = *(int *)get_varp_scope(&(options[opt_idx]),
4386 OPT_GLOBAL);
4387 }
4388 else
4389 {
4390 /*
4391 * ":set invopt": invert
4392 * ":set opt" or ":set noopt": set or reset
4393 */
4394 if (nextchar != NUL && !vim_iswhite(afterchar))
4395 {
4396 errmsg = e_trailing;
4397 goto skip;
4398 }
4399 if (prefix == 2) /* inv */
4400 value = *(int *)(varp) ^ 1;
4401 else
4402 value = prefix;
4403 }
4404
4405 errmsg = set_bool_option(opt_idx, varp, (int)value,
4406 opt_flags);
4407 }
4408 else /* numeric or string */
4409 {
4410 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4411 || prefix != 1)
4412 {
4413 errmsg = e_invarg;
4414 goto skip;
4415 }
4416
4417 if (flags & P_NUM) /* numeric */
4418 {
4419 /*
4420 * Different ways to set a number option:
4421 * & set to default value
4422 * < set to global value
4423 * <xx> accept special key codes for 'wildchar'
4424 * c accept any non-digit for 'wildchar'
4425 * [-]0-9 set number
4426 * other error
4427 */
4428 ++arg;
4429 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004430 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 ((flags & P_VI_DEF) || cp_val)
4432 ? VI_DEFAULT : VIM_DEFAULT];
4433 else if (nextchar == '<')
4434 value = *(long *)get_varp_scope(&(options[opt_idx]),
4435 OPT_GLOBAL);
4436 else if (((long *)varp == &p_wc
4437 || (long *)varp == &p_wcm)
4438 && (*arg == '<'
4439 || *arg == '^'
4440 || ((!arg[1] || vim_iswhite(arg[1]))
4441 && !VIM_ISDIGIT(*arg))))
4442 {
4443 value = string_to_key(arg);
4444 if (value == 0 && (long *)varp != &p_wcm)
4445 {
4446 errmsg = e_invarg;
4447 goto skip;
4448 }
4449 }
4450 /* allow negative numbers (for 'undolevels') */
4451 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4452 {
4453 i = 0;
4454 if (*arg == '-')
4455 i = 1;
4456#ifdef HAVE_STRTOL
4457 value = strtol((char *)arg, NULL, 0);
4458 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4459 i += 2;
4460#else
4461 value = atol((char *)arg);
4462#endif
4463 while (VIM_ISDIGIT(arg[i]))
4464 ++i;
4465 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4466 {
4467 errmsg = e_invarg;
4468 goto skip;
4469 }
4470 }
4471 else
4472 {
4473 errmsg = (char_u *)N_("E521: Number required after =");
4474 goto skip;
4475 }
4476
4477 if (adding)
4478 value = *(long *)varp + value;
4479 if (prepending)
4480 value = *(long *)varp * value;
4481 if (removing)
4482 value = *(long *)varp - value;
4483 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004484 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004485 }
4486 else if (opt_idx >= 0) /* string */
4487 {
4488 char_u *save_arg = NULL;
4489 char_u *s = NULL;
4490 char_u *oldval; /* previous value if *varp */
4491 char_u *newval;
4492 char_u *origval;
4493 unsigned newlen;
4494 int comma;
4495 int bs;
4496 int new_value_alloced; /* new string option
4497 was allocated */
4498
4499 /* When using ":set opt=val" for a global option
4500 * with a local value the local value will be
4501 * reset, use the global value here. */
4502 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004503 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004504 varp = options[opt_idx].var;
4505
4506 /* The old value is kept until we are sure that the
4507 * new value is valid. */
4508 oldval = *(char_u **)varp;
4509 if (nextchar == '&') /* set to default val */
4510 {
4511 newval = options[opt_idx].def_val[
4512 ((flags & P_VI_DEF) || cp_val)
4513 ? VI_DEFAULT : VIM_DEFAULT];
4514 if ((char_u **)varp == &p_bg)
4515 {
4516 /* guess the value of 'background' */
4517#ifdef FEAT_GUI
4518 if (gui.in_use)
4519 newval = gui_bg_default();
4520 else
4521#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004522 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004523 }
4524
4525 /* expand environment variables and ~ (since the
4526 * default value was already expanded, only
4527 * required when an environment variable was set
4528 * later */
4529 if (newval == NULL)
4530 newval = empty_option;
4531 else
4532 {
4533 s = option_expand(opt_idx, newval);
4534 if (s == NULL)
4535 s = newval;
4536 newval = vim_strsave(s);
4537 }
4538 new_value_alloced = TRUE;
4539 }
4540 else if (nextchar == '<') /* set to global val */
4541 {
4542 newval = vim_strsave(*(char_u **)get_varp_scope(
4543 &(options[opt_idx]), OPT_GLOBAL));
4544 new_value_alloced = TRUE;
4545 }
4546 else
4547 {
4548 ++arg; /* jump to after the '=' or ':' */
4549
4550 /*
4551 * Set 'keywordprg' to ":help" if an empty
4552 * value was passed to :set by the user.
4553 * Misuse errbuf[] for the resulting string.
4554 */
4555 if (varp == (char_u *)&p_kp
4556 && (*arg == NUL || *arg == ' '))
4557 {
4558 STRCPY(errbuf, ":help");
4559 save_arg = arg;
4560 arg = errbuf;
4561 }
4562 /*
4563 * Convert 'whichwrap' number to string, for
4564 * backwards compatibility with Vim 3.0.
4565 * Misuse errbuf[] for the resulting string.
4566 */
4567 else if (varp == (char_u *)&p_ww
4568 && VIM_ISDIGIT(*arg))
4569 {
4570 *errbuf = NUL;
4571 i = getdigits(&arg);
4572 if (i & 1)
4573 STRCAT(errbuf, "b,");
4574 if (i & 2)
4575 STRCAT(errbuf, "s,");
4576 if (i & 4)
4577 STRCAT(errbuf, "h,l,");
4578 if (i & 8)
4579 STRCAT(errbuf, "<,>,");
4580 if (i & 16)
4581 STRCAT(errbuf, "[,],");
4582 if (*errbuf != NUL) /* remove trailing , */
4583 errbuf[STRLEN(errbuf) - 1] = NUL;
4584 save_arg = arg;
4585 arg = errbuf;
4586 }
4587 /*
4588 * Remove '>' before 'dir' and 'bdir', for
4589 * backwards compatibility with version 3.0
4590 */
4591 else if ( *arg == '>'
4592 && (varp == (char_u *)&p_dir
4593 || varp == (char_u *)&p_bdir))
4594 {
4595 ++arg;
4596 }
4597
4598 /* When setting the local value of a global
4599 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004600 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601 && (opt_flags & OPT_LOCAL))
4602 origval = *(char_u **)get_varp(
4603 &options[opt_idx]);
4604 else
4605 origval = oldval;
4606
4607 /*
4608 * Copy the new string into allocated memory.
4609 * Can't use set_string_option_direct(), because
4610 * we need to remove the backslashes.
4611 */
4612 /* get a bit too much */
4613 newlen = (unsigned)STRLEN(arg) + 1;
4614 if (adding || prepending || removing)
4615 newlen += (unsigned)STRLEN(origval) + 1;
4616 newval = alloc(newlen);
4617 if (newval == NULL) /* out of mem, don't change */
4618 break;
4619 s = newval;
4620
4621 /*
4622 * Copy the string, skip over escaped chars.
4623 * For MS-DOS and WIN32 backslashes before normal
4624 * file name characters are not removed, and keep
4625 * backslash at start, for "\\machine\path", but
4626 * do remove it for "\\\\machine\\path".
4627 * The reverse is found in ExpandOldSetting().
4628 */
4629 while (*arg && !vim_iswhite(*arg))
4630 {
4631 if (*arg == '\\' && arg[1] != NUL
4632#ifdef BACKSLASH_IN_FILENAME
4633 && !((flags & P_EXPAND)
4634 && vim_isfilec(arg[1])
4635 && (arg[1] != '\\'
4636 || (s == newval
4637 && arg[2] != '\\')))
4638#endif
4639 )
4640 ++arg; /* remove backslash */
4641#ifdef FEAT_MBYTE
4642 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004643 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 {
4645 /* copy multibyte char */
4646 mch_memmove(s, arg, (size_t)i);
4647 arg += i;
4648 s += i;
4649 }
4650 else
4651#endif
4652 *s++ = *arg++;
4653 }
4654 *s = NUL;
4655
4656 /*
4657 * Expand environment variables and ~.
4658 * Don't do it when adding without inserting a
4659 * comma.
4660 */
4661 if (!(adding || prepending || removing)
4662 || (flags & P_COMMA))
4663 {
4664 s = option_expand(opt_idx, newval);
4665 if (s != NULL)
4666 {
4667 vim_free(newval);
4668 newlen = (unsigned)STRLEN(s) + 1;
4669 if (adding || prepending || removing)
4670 newlen += (unsigned)STRLEN(origval) + 1;
4671 newval = alloc(newlen);
4672 if (newval == NULL)
4673 break;
4674 STRCPY(newval, s);
4675 }
4676 }
4677
4678 /* locate newval[] in origval[] when removing it
4679 * and when adding to avoid duplicates */
4680 i = 0; /* init for GCC */
4681 if (removing || (flags & P_NODUP))
4682 {
4683 i = (int)STRLEN(newval);
4684 bs = 0;
4685 for (s = origval; *s; ++s)
4686 {
4687 if ((!(flags & P_COMMA)
4688 || s == origval
4689 || (s[-1] == ',' && !(bs & 1)))
4690 && STRNCMP(s, newval, i) == 0
4691 && (!(flags & P_COMMA)
4692 || s[i] == ','
4693 || s[i] == NUL))
4694 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004695 /* Count backslashes. Only a comma with an
4696 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 * recognized as a separator */
4698 if (s > origval && s[-1] == '\\')
4699 ++bs;
4700 else
4701 bs = 0;
4702 }
4703
4704 /* do not add if already there */
4705 if ((adding || prepending) && *s)
4706 {
4707 prepending = FALSE;
4708 adding = FALSE;
4709 STRCPY(newval, origval);
4710 }
4711 }
4712
4713 /* concatenate the two strings; add a ',' if
4714 * needed */
4715 if (adding || prepending)
4716 {
4717 comma = ((flags & P_COMMA) && *origval != NUL
4718 && *newval != NUL);
4719 if (adding)
4720 {
4721 i = (int)STRLEN(origval);
4722 mch_memmove(newval + i + comma, newval,
4723 STRLEN(newval) + 1);
4724 mch_memmove(newval, origval, (size_t)i);
4725 }
4726 else
4727 {
4728 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004729 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 }
4731 if (comma)
4732 newval[i] = ',';
4733 }
4734
4735 /* Remove newval[] from origval[]. (Note: "i" has
4736 * been set above and is used here). */
4737 if (removing)
4738 {
4739 STRCPY(newval, origval);
4740 if (*s)
4741 {
4742 /* may need to remove a comma */
4743 if (flags & P_COMMA)
4744 {
4745 if (s == origval)
4746 {
4747 /* include comma after string */
4748 if (s[i] == ',')
4749 ++i;
4750 }
4751 else
4752 {
4753 /* include comma before string */
4754 --s;
4755 ++i;
4756 }
4757 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004758 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 }
4760 }
4761
4762 if (flags & P_FLAGLIST)
4763 {
4764 /* Remove flags that appear twice. */
4765 for (s = newval; *s; ++s)
4766 if ((!(flags & P_COMMA) || *s != ',')
4767 && vim_strchr(s + 1, *s) != NULL)
4768 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004769 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 --s;
4771 }
4772 }
4773
4774 if (save_arg != NULL) /* number for 'whichwrap' */
4775 arg = save_arg;
4776 new_value_alloced = TRUE;
4777 }
4778
4779 /* Set the new value. */
4780 *(char_u **)(varp) = newval;
4781
4782 /* Handle side effects, and set the global value for
4783 * ":set" on local options. */
4784 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4785 new_value_alloced, oldval, errbuf, opt_flags);
4786
4787 /* If error detected, print the error message. */
4788 if (errmsg != NULL)
4789 goto skip;
4790 }
4791 else /* key code option */
4792 {
4793 char_u *p;
4794
4795 if (nextchar == '&')
4796 {
4797 if (add_termcap_entry(key_name, TRUE) == FAIL)
4798 errmsg = (char_u *)N_("E522: Not found in termcap");
4799 }
4800 else
4801 {
4802 ++arg; /* jump to after the '=' or ':' */
4803 for (p = arg; *p && !vim_iswhite(*p); ++p)
4804 if (*p == '\\' && p[1] != NUL)
4805 ++p;
4806 nextchar = *p;
4807 *p = NUL;
4808 add_termcode(key_name, arg, FALSE);
4809 *p = nextchar;
4810 }
4811 if (full_screen)
4812 ttest(FALSE);
4813 redraw_all_later(CLEAR);
4814 }
4815 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004816
Bram Moolenaar071d4272004-06-13 20:20:40 +00004817 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004818 did_set_option(opt_idx, opt_flags,
4819 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004820 }
4821
4822skip:
4823 /*
4824 * Advance to next argument.
4825 * - skip until a blank found, taking care of backslashes
4826 * - skip blanks
4827 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4828 */
4829 for (i = 0; i < 2 ; ++i)
4830 {
4831 while (*arg != NUL && !vim_iswhite(*arg))
4832 if (*arg++ == '\\' && *arg != NUL)
4833 ++arg;
4834 arg = skipwhite(arg);
4835 if (*arg != '=')
4836 break;
4837 }
4838 }
4839
4840 if (errmsg != NULL)
4841 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004842 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004843 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 if (i + (arg - startarg) < IOSIZE)
4845 {
4846 /* append the argument with the error */
4847 STRCAT(IObuff, ": ");
4848 mch_memmove(IObuff + i, startarg, (arg - startarg));
4849 IObuff[i + (arg - startarg)] = NUL;
4850 }
4851 /* make sure all characters are printable */
4852 trans_characters(IObuff, IOSIZE);
4853
4854 ++no_wait_return; /* wait_return done later */
4855 emsg(IObuff); /* show error highlighted */
4856 --no_wait_return;
4857
4858 return FAIL;
4859 }
4860
4861 arg = skipwhite(arg);
4862 }
4863
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004864theend:
4865 if (silent_mode && did_show)
4866 {
4867 /* After displaying option values in silent mode. */
4868 silent_mode = FALSE;
4869 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4870 msg_putchar('\n');
4871 cursor_on(); /* msg_start() switches it off */
4872 out_flush();
4873 silent_mode = TRUE;
4874 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4875 }
4876
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 return OK;
4878}
4879
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004880/*
4881 * Call this when an option has been given a new value through a user command.
4882 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4883 */
4884 static void
4885did_set_option(opt_idx, opt_flags, new_value)
4886 int opt_idx;
4887 int opt_flags; /* possibly with OPT_MODELINE */
4888 int new_value; /* value was replaced completely */
4889{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004890 long_u *p;
4891
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004892 options[opt_idx].flags |= P_WAS_SET;
4893
4894 /* When an option is set in the sandbox, from a modeline or in secure mode
4895 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004896 * flag. */
4897 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004898 if (secure
4899#ifdef HAVE_SANDBOX
4900 || sandbox != 0
4901#endif
4902 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004903 *p = *p | P_INSECURE;
4904 else if (new_value)
4905 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004906}
4907
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 static char_u *
4909illegal_char(errbuf, c)
4910 char_u *errbuf;
4911 int c;
4912{
4913 if (errbuf == NULL)
4914 return (char_u *)"";
4915 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004916 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004917 return errbuf;
4918}
4919
4920/*
4921 * Convert a key name or string into a key value.
4922 * Used for 'wildchar' and 'cedit' options.
4923 */
4924 static int
4925string_to_key(arg)
4926 char_u *arg;
4927{
4928 if (*arg == '<')
4929 return find_key_option(arg + 1);
4930 if (*arg == '^')
4931 return Ctrl_chr(arg[1]);
4932 return *arg;
4933}
4934
4935#ifdef FEAT_CMDWIN
4936/*
4937 * Check value of 'cedit' and set cedit_key.
4938 * Returns NULL if value is OK, error message otherwise.
4939 */
4940 static char_u *
4941check_cedit()
4942{
4943 int n;
4944
4945 if (*p_cedit == NUL)
4946 cedit_key = -1;
4947 else
4948 {
4949 n = string_to_key(p_cedit);
4950 if (vim_isprintc(n))
4951 return e_invarg;
4952 cedit_key = n;
4953 }
4954 return NULL;
4955}
4956#endif
4957
4958#ifdef FEAT_TITLE
4959/*
4960 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4961 * maketitle() to create and display it.
4962 * When switching the title or icon off, call mch_restore_title() to get
4963 * the old value back.
4964 */
4965 static void
4966did_set_title(icon)
4967 int icon; /* Did set icon instead of title */
4968{
4969 if (starting != NO_SCREEN
4970#ifdef FEAT_GUI
4971 && !gui.starting
4972#endif
4973 )
4974 {
4975 maketitle();
4976 if (icon)
4977 {
4978 if (!p_icon)
4979 mch_restore_title(2);
4980 }
4981 else
4982 {
4983 if (!p_title)
4984 mch_restore_title(1);
4985 }
4986 }
4987}
4988#endif
4989
4990/*
4991 * set_options_bin - called when 'bin' changes value.
4992 */
4993 void
4994set_options_bin(oldval, newval, opt_flags)
4995 int oldval;
4996 int newval;
4997 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4998{
4999 /*
5000 * The option values that are changed when 'bin' changes are
5001 * copied when 'bin is set and restored when 'bin' is reset.
5002 */
5003 if (newval)
5004 {
5005 if (!oldval) /* switched on */
5006 {
5007 if (!(opt_flags & OPT_GLOBAL))
5008 {
5009 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5010 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5011 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5012 curbuf->b_p_et_nobin = curbuf->b_p_et;
5013 }
5014 if (!(opt_flags & OPT_LOCAL))
5015 {
5016 p_tw_nobin = p_tw;
5017 p_wm_nobin = p_wm;
5018 p_ml_nobin = p_ml;
5019 p_et_nobin = p_et;
5020 }
5021 }
5022
5023 if (!(opt_flags & OPT_GLOBAL))
5024 {
5025 curbuf->b_p_tw = 0; /* no automatic line wrap */
5026 curbuf->b_p_wm = 0; /* no automatic line wrap */
5027 curbuf->b_p_ml = 0; /* no modelines */
5028 curbuf->b_p_et = 0; /* no expandtab */
5029 }
5030 if (!(opt_flags & OPT_LOCAL))
5031 {
5032 p_tw = 0;
5033 p_wm = 0;
5034 p_ml = FALSE;
5035 p_et = FALSE;
5036 p_bin = TRUE; /* needed when called for the "-b" argument */
5037 }
5038 }
5039 else if (oldval) /* switched off */
5040 {
5041 if (!(opt_flags & OPT_GLOBAL))
5042 {
5043 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5044 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5045 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5046 curbuf->b_p_et = curbuf->b_p_et_nobin;
5047 }
5048 if (!(opt_flags & OPT_LOCAL))
5049 {
5050 p_tw = p_tw_nobin;
5051 p_wm = p_wm_nobin;
5052 p_ml = p_ml_nobin;
5053 p_et = p_et_nobin;
5054 }
5055 }
5056}
5057
5058#ifdef FEAT_VIMINFO
5059/*
5060 * Find the parameter represented by the given character (eg ', :, ", or /),
5061 * and return its associated value in the 'viminfo' string.
5062 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005063 * If the parameter is not specified in the string or there is no following
5064 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 */
5066 int
5067get_viminfo_parameter(type)
5068 int type;
5069{
5070 char_u *p;
5071
5072 p = find_viminfo_parameter(type);
5073 if (p != NULL && VIM_ISDIGIT(*p))
5074 return atoi((char *)p);
5075 return -1;
5076}
5077
5078/*
5079 * Find the parameter represented by the given character (eg ''', ':', '"', or
5080 * '/') in the 'viminfo' option and return a pointer to the string after it.
5081 * Return NULL if the parameter is not specified in the string.
5082 */
5083 char_u *
5084find_viminfo_parameter(type)
5085 int type;
5086{
5087 char_u *p;
5088
5089 for (p = p_viminfo; *p; ++p)
5090 {
5091 if (*p == type)
5092 return p + 1;
5093 if (*p == 'n') /* 'n' is always the last one */
5094 break;
5095 p = vim_strchr(p, ','); /* skip until next ',' */
5096 if (p == NULL) /* hit the end without finding parameter */
5097 break;
5098 }
5099 return NULL;
5100}
5101#endif
5102
5103/*
5104 * Expand environment variables for some string options.
5105 * These string options cannot be indirect!
5106 * If "val" is NULL expand the current value of the option.
5107 * Return pointer to NameBuff, or NULL when not expanded.
5108 */
5109 static char_u *
5110option_expand(opt_idx, val)
5111 int opt_idx;
5112 char_u *val;
5113{
5114 /* if option doesn't need expansion nothing to do */
5115 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5116 return NULL;
5117
5118 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5119 * expand_env() would truncate the string. */
5120 if (val != NULL && STRLEN(val) > MAXPATHL)
5121 return NULL;
5122
5123 if (val == NULL)
5124 val = *(char_u **)options[opt_idx].var;
5125
5126 /*
5127 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5128 * Escape spaces when expanding 'tags', they are used to separate file
5129 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005130 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 */
5132 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005133 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005134#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005135 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5136#endif
5137 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5139 return NULL;
5140
5141 return NameBuff;
5142}
5143
5144/*
5145 * After setting various option values: recompute variables that depend on
5146 * option values.
5147 */
5148 static void
5149didset_options()
5150{
5151 /* initialize the table for 'iskeyword' et.al. */
5152 (void)init_chartab();
5153
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005154#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5158#ifdef FEAT_SESSION
5159 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5160 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5161#endif
5162#ifdef FEAT_FOLDING
5163 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5164#endif
5165 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5166#ifdef FEAT_VIRTUALEDIT
5167 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5168#endif
5169#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5170 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5171#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005172#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005173 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005174 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005175 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005177#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5178 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5179#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005180#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005181 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5182#endif
5183#ifdef FEAT_CMDWIN
5184 /* set cedit_key */
5185 (void)check_cedit();
5186#endif
5187}
5188
5189/*
5190 * Check for string options that are NULL (normally only termcap options).
5191 */
5192 void
5193check_options()
5194{
5195 int opt_idx;
5196
5197 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5198 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5199 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5200}
5201
5202/*
5203 * Check string options in a buffer for NULL value.
5204 */
5205 void
5206check_buf_options(buf)
5207 buf_T *buf;
5208{
5209#if defined(FEAT_QUICKFIX)
5210 check_string_option(&buf->b_p_bh);
5211 check_string_option(&buf->b_p_bt);
5212#endif
5213#ifdef FEAT_MBYTE
5214 check_string_option(&buf->b_p_fenc);
5215#endif
5216 check_string_option(&buf->b_p_ff);
5217#ifdef FEAT_FIND_ID
5218 check_string_option(&buf->b_p_def);
5219 check_string_option(&buf->b_p_inc);
5220# ifdef FEAT_EVAL
5221 check_string_option(&buf->b_p_inex);
5222# endif
5223#endif
5224#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5225 check_string_option(&buf->b_p_inde);
5226 check_string_option(&buf->b_p_indk);
5227#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005228#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5229 check_string_option(&buf->b_p_bexpr);
5230#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005231#if defined(FEAT_CRYPT)
5232 check_string_option(&buf->b_p_cm);
5233#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005234#if defined(FEAT_EVAL)
5235 check_string_option(&buf->b_p_fex);
5236#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237#ifdef FEAT_CRYPT
5238 check_string_option(&buf->b_p_key);
5239#endif
5240 check_string_option(&buf->b_p_kp);
5241 check_string_option(&buf->b_p_mps);
5242 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005243 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 check_string_option(&buf->b_p_isk);
5245#ifdef FEAT_COMMENTS
5246 check_string_option(&buf->b_p_com);
5247#endif
5248#ifdef FEAT_FOLDING
5249 check_string_option(&buf->b_p_cms);
5250#endif
5251 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005252#ifdef FEAT_TEXTOBJ
5253 check_string_option(&buf->b_p_qe);
5254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255#ifdef FEAT_SYN_HL
5256 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005257#endif
5258#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005259 check_string_option(&buf->b_s.b_p_spc);
5260 check_string_option(&buf->b_s.b_p_spf);
5261 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005262#endif
5263#ifdef FEAT_SEARCHPATH
5264 check_string_option(&buf->b_p_sua);
5265#endif
5266#ifdef FEAT_CINDENT
5267 check_string_option(&buf->b_p_cink);
5268 check_string_option(&buf->b_p_cino);
5269#endif
5270#ifdef FEAT_AUTOCMD
5271 check_string_option(&buf->b_p_ft);
5272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5274 check_string_option(&buf->b_p_cinw);
5275#endif
5276#ifdef FEAT_INS_EXPAND
5277 check_string_option(&buf->b_p_cpt);
5278#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005279#ifdef FEAT_COMPL_FUNC
5280 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005281 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283#ifdef FEAT_KEYMAP
5284 check_string_option(&buf->b_p_keymap);
5285#endif
5286#ifdef FEAT_QUICKFIX
5287 check_string_option(&buf->b_p_gp);
5288 check_string_option(&buf->b_p_mp);
5289 check_string_option(&buf->b_p_efm);
5290#endif
5291 check_string_option(&buf->b_p_ep);
5292 check_string_option(&buf->b_p_path);
5293 check_string_option(&buf->b_p_tags);
5294#ifdef FEAT_INS_EXPAND
5295 check_string_option(&buf->b_p_dict);
5296 check_string_option(&buf->b_p_tsr);
5297#endif
5298}
5299
5300/*
5301 * Free the string allocated for an option.
5302 * Checks for the string being empty_option. This may happen if we're out of
5303 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5304 * check_options().
5305 * Does NOT check for P_ALLOCED flag!
5306 */
5307 void
5308free_string_option(p)
5309 char_u *p;
5310{
5311 if (p != empty_option)
5312 vim_free(p);
5313}
5314
5315 void
5316clear_string_option(pp)
5317 char_u **pp;
5318{
5319 if (*pp != empty_option)
5320 vim_free(*pp);
5321 *pp = empty_option;
5322}
5323
5324 static void
5325check_string_option(pp)
5326 char_u **pp;
5327{
5328 if (*pp == NULL)
5329 *pp = empty_option;
5330}
5331
5332/*
5333 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5334 */
5335 void
5336set_term_option_alloced(p)
5337 char_u **p;
5338{
5339 int opt_idx;
5340
5341 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5342 if (options[opt_idx].var == (char_u *)p)
5343 {
5344 options[opt_idx].flags |= P_ALLOCED;
5345 return;
5346 }
5347 return; /* cannot happen: didn't find it! */
5348}
5349
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005350#if defined(FEAT_EVAL) || defined(PROTO)
5351/*
5352 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5353 * Return FALSE when it wasn't.
5354 * Return -1 for an unknown option.
5355 */
5356 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005357was_set_insecurely(opt, opt_flags)
5358 char_u *opt;
5359 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005360{
5361 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005362 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005363
5364 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005365 {
5366 flagp = insecure_flag(idx, opt_flags);
5367 return (*flagp & P_INSECURE) != 0;
5368 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005369 EMSG2(_(e_intern2), "was_set_insecurely()");
5370 return -1;
5371}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005372
5373/*
5374 * Get a pointer to the flags used for the P_INSECURE flag of option
5375 * "opt_idx". For some local options a local flags field is used.
5376 */
5377 static long_u *
5378insecure_flag(opt_idx, opt_flags)
5379 int opt_idx;
5380 int opt_flags;
5381{
5382 if (opt_flags & OPT_LOCAL)
5383 switch ((int)options[opt_idx].indir)
5384 {
5385#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005386 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005387#endif
5388#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005389# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005390 case PV_FDE: return &curwin->w_p_fde_flags;
5391 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005392# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005393# ifdef FEAT_BEVAL
5394 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5395# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005396# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005397 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005398# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005399 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005400# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005401 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005402# endif
5403#endif
5404 }
5405
5406 /* Nothing special, return global flags field. */
5407 return &options[opt_idx].flags;
5408}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005409#endif
5410
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005411#ifdef FEAT_TITLE
5412static void redraw_titles __ARGS((void));
5413
5414/*
5415 * Redraw the window title and/or tab page text later.
5416 */
5417static void redraw_titles()
5418{
5419 need_maketitle = TRUE;
5420# ifdef FEAT_WINDOWS
5421 redraw_tabline = TRUE;
5422# endif
5423}
5424#endif
5425
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426/*
5427 * Set a string option to a new value (without checking the effect).
5428 * The string is copied into allocated memory.
5429 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005430 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005431 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432 */
5433 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005434set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435 char_u *name;
5436 int opt_idx;
5437 char_u *val;
5438 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005439 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440{
5441 char_u *s;
5442 char_u **varp;
5443 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005444 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005445
Bram Moolenaar89d40322006-08-29 15:30:07 +00005446 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005447 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005448 idx = findoption(name);
5449 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005450 {
5451 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005454 }
5455
Bram Moolenaar89d40322006-08-29 15:30:07 +00005456 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457 return;
5458
5459 s = vim_strsave(val);
5460 if (s != NULL)
5461 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005462 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005464 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465 free_string_option(*varp);
5466 *varp = s;
5467
5468 /* For buffer/window local option may also set the global value. */
5469 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005470 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005471
Bram Moolenaar89d40322006-08-29 15:30:07 +00005472 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473
5474 /* When setting both values of a global option with a local value,
5475 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005476 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477 {
5478 free_string_option(*varp);
5479 *varp = empty_option;
5480 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005481# ifdef FEAT_EVAL
5482 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005483 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005484 set_sid == 0 ? current_SID : set_sid);
5485# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486 }
5487}
5488
5489/*
5490 * Set global value for string option when it's a local option.
5491 */
5492 static void
5493set_string_option_global(opt_idx, varp)
5494 int opt_idx; /* option index */
5495 char_u **varp; /* pointer to option variable */
5496{
5497 char_u **p, *s;
5498
5499 /* the global value is always allocated */
5500 if (options[opt_idx].var == VAR_WIN)
5501 p = (char_u **)GLOBAL_WO(varp);
5502 else
5503 p = (char_u **)options[opt_idx].var;
5504 if (options[opt_idx].indir != PV_NONE
5505 && p != varp
5506 && (s = vim_strsave(*varp)) != NULL)
5507 {
5508 free_string_option(*p);
5509 *p = s;
5510 }
5511}
5512
5513/*
5514 * Set a string option to a new value, and handle the effects.
5515 */
5516 static void
5517set_string_option(opt_idx, value, opt_flags)
5518 int opt_idx;
5519 char_u *value;
5520 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5521{
5522 char_u *s;
5523 char_u **varp;
5524 char_u *oldval;
5525
5526 if (options[opt_idx].var == NULL) /* don't set hidden option */
5527 return;
5528
5529 s = vim_strsave(value);
5530 if (s != NULL)
5531 {
5532 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5533 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005534 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535 ? OPT_GLOBAL : OPT_LOCAL)
5536 : opt_flags);
5537 oldval = *varp;
5538 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005539 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5540 opt_flags) == NULL)
5541 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542 }
5543}
5544
5545/*
5546 * Handle string options that need some action to perform when changed.
5547 * Returns NULL for success, or an error message for an error.
5548 */
5549 static char_u *
5550did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5551 opt_flags)
5552 int opt_idx; /* index in options[] table */
5553 char_u **varp; /* pointer to the option variable */
5554 int new_value_alloced; /* new value was allocated */
5555 char_u *oldval; /* previous value of the option */
5556 char_u *errbuf; /* buffer for errors, or NULL */
5557 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5558{
5559 char_u *errmsg = NULL;
5560 char_u *s, *p;
5561 int did_chartab = FALSE;
5562 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005563 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005564#ifdef FEAT_GUI
5565 /* set when changing an option that only requires a redraw in the GUI */
5566 int redraw_gui_only = FALSE;
5567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568
5569 /* Get the global option to compare with, otherwise we would have to check
5570 * two values for all local options. */
5571 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5572
5573 /* Disallow changing some options from secure mode */
5574 if ((secure
5575#ifdef HAVE_SANDBOX
5576 || sandbox != 0
5577#endif
5578 ) && (options[opt_idx].flags & P_SECURE))
5579 {
5580 errmsg = e_secure;
5581 }
5582
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005583 /* Check for a "normal" file name in some options. Disallow a path
5584 * separator (slash and/or backslash), wildcards and characters that are
5585 * often illegal in a file name. */
5586 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005587 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005588 {
5589 errmsg = e_invarg;
5590 }
5591
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592 /* 'term' */
5593 else if (varp == &T_NAME)
5594 {
5595 if (T_NAME[0] == NUL)
5596 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5597#ifdef FEAT_GUI
5598 if (gui.in_use)
5599 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5600 else if (term_is_gui(T_NAME))
5601 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5602#endif
5603 else if (set_termname(T_NAME) == FAIL)
5604 errmsg = (char_u *)N_("E522: Not found in termcap");
5605 else
5606 /* Screen colors may have changed. */
5607 redraw_later_clear();
5608 }
5609
5610 /* 'backupcopy' */
5611 else if (varp == &p_bkc)
5612 {
5613 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5614 errmsg = e_invarg;
5615 if (((bkc_flags & BKC_AUTO) != 0)
5616 + ((bkc_flags & BKC_YES) != 0)
5617 + ((bkc_flags & BKC_NO) != 0) != 1)
5618 {
5619 /* Must have exactly one of "auto", "yes" and "no". */
5620 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5621 errmsg = e_invarg;
5622 }
5623 }
5624
5625 /* 'backupext' and 'patchmode' */
5626 else if (varp == &p_bex || varp == &p_pm)
5627 {
5628 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5629 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5630 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5631 }
5632
5633 /*
5634 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5635 * If the new option is invalid, use old value. 'lisp' option: refill
5636 * chartab[] for '-' char
5637 */
5638 else if ( varp == &p_isi
5639 || varp == &(curbuf->b_p_isk)
5640 || varp == &p_isp
5641 || varp == &p_isf)
5642 {
5643 if (init_chartab() == FAIL)
5644 {
5645 did_chartab = TRUE; /* need to restore it below */
5646 errmsg = e_invarg; /* error in value */
5647 }
5648 }
5649
5650 /* 'helpfile' */
5651 else if (varp == &p_hf)
5652 {
5653 /* May compute new values for $VIM and $VIMRUNTIME */
5654 if (didset_vim)
5655 {
5656 vim_setenv((char_u *)"VIM", (char_u *)"");
5657 didset_vim = FALSE;
5658 }
5659 if (didset_vimruntime)
5660 {
5661 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5662 didset_vimruntime = FALSE;
5663 }
5664 }
5665
Bram Moolenaar1a384422010-07-14 19:53:30 +02005666#ifdef FEAT_SYN_HL
5667 /* 'colorcolumn' */
5668 else if (varp == &curwin->w_p_cc)
5669 errmsg = check_colorcolumn(curwin);
5670#endif
5671
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672#ifdef FEAT_MULTI_LANG
5673 /* 'helplang' */
5674 else if (varp == &p_hlg)
5675 {
5676 /* Check for "", "ab", "ab,cd", etc. */
5677 for (s = p_hlg; *s != NUL; s += 3)
5678 {
5679 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5680 {
5681 errmsg = e_invarg;
5682 break;
5683 }
5684 if (s[2] == NUL)
5685 break;
5686 }
5687 }
5688#endif
5689
5690 /* 'highlight' */
5691 else if (varp == &p_hl)
5692 {
5693 if (highlight_changed() == FAIL)
5694 errmsg = e_invarg; /* invalid flags */
5695 }
5696
5697 /* 'nrformats' */
5698 else if (gvarp == &p_nf)
5699 {
5700 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5701 errmsg = e_invarg;
5702 }
5703
5704#ifdef FEAT_SESSION
5705 /* 'sessionoptions' */
5706 else if (varp == &p_ssop)
5707 {
5708 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5709 errmsg = e_invarg;
5710 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5711 {
5712 /* Don't allow both "sesdir" and "curdir". */
5713 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5714 errmsg = e_invarg;
5715 }
5716 }
5717 /* 'viewoptions' */
5718 else if (varp == &p_vop)
5719 {
5720 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5721 errmsg = e_invarg;
5722 }
5723#endif
5724
5725 /* 'scrollopt' */
5726#ifdef FEAT_SCROLLBIND
5727 else if (varp == &p_sbo)
5728 {
5729 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5730 errmsg = e_invarg;
5731 }
5732#endif
5733
5734 /* 'ambiwidth' */
5735#ifdef FEAT_MBYTE
5736 else if (varp == &p_ambw)
5737 {
5738 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5739 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005740 else if (set_chars_option(&p_lcs) != NULL)
5741 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5742# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5743 else if (set_chars_option(&p_fcs) != NULL)
5744 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5745# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746 }
5747#endif
5748
5749 /* 'background' */
5750 else if (varp == &p_bg)
5751 {
5752 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5753 {
5754#ifdef FEAT_EVAL
5755 int dark = (*p_bg == 'd');
5756#endif
5757
5758 init_highlight(FALSE, FALSE);
5759
5760#ifdef FEAT_EVAL
5761 if (dark != (*p_bg == 'd')
5762 && get_var_value((char_u *)"g:colors_name") != NULL)
5763 {
5764 /* The color scheme must have set 'background' back to another
5765 * value, that's not what we want here. Disable the color
5766 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005767 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005768 free_string_option(p_bg);
5769 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5770 check_string_option(&p_bg);
5771 init_highlight(FALSE, FALSE);
5772 }
5773#endif
5774 }
5775 else
5776 errmsg = e_invarg;
5777 }
5778
5779 /* 'wildmode' */
5780 else if (varp == &p_wim)
5781 {
5782 if (check_opt_wim() == FAIL)
5783 errmsg = e_invarg;
5784 }
5785
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005786#ifdef FEAT_CMDL_COMPL
5787 /* 'wildoptions' */
5788 else if (varp == &p_wop)
5789 {
5790 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5791 errmsg = e_invarg;
5792 }
5793#endif
5794
Bram Moolenaar071d4272004-06-13 20:20:40 +00005795#ifdef FEAT_WAK
5796 /* 'winaltkeys' */
5797 else if (varp == &p_wak)
5798 {
5799 if (*p_wak == NUL
5800 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5801 errmsg = e_invarg;
5802# ifdef FEAT_MENU
5803# ifdef FEAT_GUI_MOTIF
5804 else if (gui.in_use)
5805 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5806# else
5807# ifdef FEAT_GUI_GTK
5808 else if (gui.in_use)
5809 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5810# endif
5811# endif
5812# endif
5813 }
5814#endif
5815
5816#ifdef FEAT_AUTOCMD
5817 /* 'eventignore' */
5818 else if (varp == &p_ei)
5819 {
5820 if (check_ei() == FAIL)
5821 errmsg = e_invarg;
5822 }
5823#endif
5824
5825#ifdef FEAT_MBYTE
5826 /* 'encoding' and 'fileencoding' */
5827 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5828 {
5829 if (gvarp == &p_fenc)
5830 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005831 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832 errmsg = e_modifiable;
5833 else if (vim_strchr(*varp, ',') != NULL)
5834 /* No comma allowed in 'fileencoding'; catches confusing it
5835 * with 'fileencodings'. */
5836 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005838 {
5839# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005841 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005843 /* Add 'fileencoding' to the swap file. */
5844 ml_setflags(curbuf);
5845 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 }
5847 if (errmsg == NULL)
5848 {
5849 /* canonize the value, so that STRCMP() can be used on it */
5850 p = enc_canonize(*varp);
5851 if (p != NULL)
5852 {
5853 vim_free(*varp);
5854 *varp = p;
5855 }
5856 if (varp == &p_enc)
5857 {
5858 errmsg = mb_init();
5859# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005860 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861# endif
5862 }
5863 }
5864
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005865# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5867 {
5868 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5869 if (STRCMP(p_tenc, "utf-8") != 0)
5870 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5871 }
5872# endif
5873
5874 if (errmsg == NULL)
5875 {
5876# ifdef FEAT_KEYMAP
5877 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5878 * (with another encoding). */
5879 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5880 (void)keymap_init();
5881# endif
5882
5883 /* When 'termencoding' is not empty and 'encoding' changes or when
5884 * 'termencoding' changes, need to setup for keyboard input and
5885 * display output conversion. */
5886 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5887 {
5888 convert_setup(&input_conv, p_tenc, p_enc);
5889 convert_setup(&output_conv, p_enc, p_tenc);
5890 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005891
5892# if defined(WIN3264) && defined(FEAT_MBYTE)
5893 /* $HOME may have characters in active code page. */
5894 if (varp == &p_enc)
5895 init_homedir();
5896# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 }
5898 }
5899#endif
5900
5901#if defined(FEAT_POSTSCRIPT)
5902 else if (varp == &p_penc)
5903 {
5904 /* Canonize printencoding if VIM standard one */
5905 p = enc_canonize(p_penc);
5906 if (p != NULL)
5907 {
5908 vim_free(p_penc);
5909 p_penc = p;
5910 }
5911 else
5912 {
5913 /* Ensure lower case and '-' for '_' */
5914 for (s = p_penc; *s != NUL; s++)
5915 {
5916 if (*s == '_')
5917 *s = '-';
5918 else
5919 *s = TOLOWER_ASC(*s);
5920 }
5921 }
5922 }
5923#endif
5924
Bram Moolenaar9372a112005-12-06 19:59:18 +00005925#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926 else if (varp == &p_imak)
5927 {
5928 if (gui.in_use && !im_xim_isvalid_imactivate())
5929 errmsg = e_invarg;
5930 }
5931#endif
5932
5933#ifdef FEAT_KEYMAP
5934 else if (varp == &curbuf->b_p_keymap)
5935 {
5936 /* load or unload key mapping tables */
5937 errmsg = keymap_init();
5938
Bram Moolenaarfab06232009-03-04 03:13:35 +00005939 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005941 if (*curbuf->b_p_keymap != NUL)
5942 {
5943 /* Installed a new keymap, switch on using it. */
5944 curbuf->b_p_iminsert = B_IMODE_LMAP;
5945 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5946 curbuf->b_p_imsearch = B_IMODE_LMAP;
5947 }
5948 else
5949 {
5950 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5951 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5952 curbuf->b_p_iminsert = B_IMODE_NONE;
5953 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5954 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5955 }
5956 if ((opt_flags & OPT_LOCAL) == 0)
5957 {
5958 set_iminsert_global();
5959 set_imsearch_global();
5960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961# ifdef FEAT_WINDOWS
5962 status_redraw_curbuf();
5963# endif
5964 }
5965 }
5966#endif
5967
5968 /* 'fileformat' */
5969 else if (gvarp == &p_ff)
5970 {
5971 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5972 errmsg = e_modifiable;
5973 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5974 errmsg = e_invarg;
5975 else
5976 {
5977 /* may also change 'textmode' */
5978 if (get_fileformat(curbuf) == EOL_DOS)
5979 curbuf->b_p_tx = TRUE;
5980 else
5981 curbuf->b_p_tx = FALSE;
5982#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005983 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005985 /* update flag in swap file */
5986 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005987 /* Redraw needed when switching to/from "mac": a CR in the text
5988 * will be displayed differently. */
5989 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5990 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
5992 }
5993
5994 /* 'fileformats' */
5995 else if (varp == &p_ffs)
5996 {
5997 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5998 errmsg = e_invarg;
5999 else
6000 {
6001 /* also change 'textauto' */
6002 if (*p_ffs == NUL)
6003 p_ta = FALSE;
6004 else
6005 p_ta = TRUE;
6006 }
6007 }
6008
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006009#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006010 /* 'cryptkey' */
6011 else if (gvarp == &p_key)
6012 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006013# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 /* Make sure the ":set" command doesn't show the new value in the
6015 * history. */
6016 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006017# endif
6018 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6019 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006020 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6021 }
6022
6023 else if (gvarp == &p_cm)
6024 {
6025 if (opt_flags & OPT_LOCAL)
6026 p = curbuf->b_p_cm;
6027 else
6028 p = p_cm;
6029 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6030 errmsg = e_invarg;
6031 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6032 errmsg = e_invarg;
6033 else
6034 {
6035 /* When setting the global value to empty, make it "zip". */
6036 if (*p_cm == NUL)
6037 {
6038 if (new_value_alloced)
6039 free_string_option(p_cm);
6040 p_cm = vim_strsave((char_u *)"zip");
6041 new_value_alloced = TRUE;
6042 }
6043
6044 /* Need to update the swapfile when the effective method changed.
6045 * Set "s" to the effective old value, "p" to the effective new
6046 * method and compare. */
6047 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6048 s = p_cm; /* was previously using the global value */
6049 else
6050 s = oldval;
6051 if (*curbuf->b_p_cm == NUL)
6052 p = p_cm; /* is now using the global value */
6053 else
6054 p = curbuf->b_p_cm;
6055 if (STRCMP(s, p) != 0)
6056 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6057 crypt_method_from_string(s));
6058
6059 /* If the global value changes need to update the swapfile for all
6060 * buffers using that value. */
6061 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6062 {
6063 buf_T *buf;
6064
6065 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6066 if (buf != curbuf && *buf->b_p_cm == NUL)
6067 ml_set_crypt_key(buf, buf->b_p_key,
6068 crypt_method_from_string(oldval));
6069 }
6070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006071 }
6072#endif
6073
6074 /* 'matchpairs' */
6075 else if (gvarp == &p_mps)
6076 {
6077 /* Check for "x:y,x:y" */
6078 for (p = *varp; *p != NUL; p += 4)
6079 {
6080 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6081 {
6082 errmsg = e_invarg;
6083 break;
6084 }
6085 if (p[3] == NUL)
6086 break;
6087 }
6088 }
6089
6090#ifdef FEAT_COMMENTS
6091 /* 'comments' */
6092 else if (gvarp == &p_com)
6093 {
6094 for (s = *varp; *s; )
6095 {
6096 while (*s && *s != ':')
6097 {
6098 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6099 && !VIM_ISDIGIT(*s) && *s != '-')
6100 {
6101 errmsg = illegal_char(errbuf, *s);
6102 break;
6103 }
6104 ++s;
6105 }
6106 if (*s++ == NUL)
6107 errmsg = (char_u *)N_("E524: Missing colon");
6108 else if (*s == ',' || *s == NUL)
6109 errmsg = (char_u *)N_("E525: Zero length string");
6110 if (errmsg != NULL)
6111 break;
6112 while (*s && *s != ',')
6113 {
6114 if (*s == '\\' && s[1] != NUL)
6115 ++s;
6116 ++s;
6117 }
6118 s = skip_to_option_part(s);
6119 }
6120 }
6121#endif
6122
6123 /* 'listchars' */
6124 else if (varp == &p_lcs)
6125 {
6126 errmsg = set_chars_option(varp);
6127 }
6128
6129#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6130 /* 'fillchars' */
6131 else if (varp == &p_fcs)
6132 {
6133 errmsg = set_chars_option(varp);
6134 }
6135#endif
6136
6137#ifdef FEAT_CMDWIN
6138 /* 'cedit' */
6139 else if (varp == &p_cedit)
6140 {
6141 errmsg = check_cedit();
6142 }
6143#endif
6144
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006145 /* 'verbosefile' */
6146 else if (varp == &p_vfile)
6147 {
6148 verbose_stop();
6149 if (*p_vfile != NUL && verbose_open() == FAIL)
6150 errmsg = e_invarg;
6151 }
6152
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153#ifdef FEAT_VIMINFO
6154 /* 'viminfo' */
6155 else if (varp == &p_viminfo)
6156 {
6157 for (s = p_viminfo; *s;)
6158 {
6159 /* Check it's a valid character */
6160 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6161 {
6162 errmsg = illegal_char(errbuf, *s);
6163 break;
6164 }
6165 if (*s == 'n') /* name is always last one */
6166 {
6167 break;
6168 }
6169 else if (*s == 'r') /* skip until next ',' */
6170 {
6171 while (*++s && *s != ',')
6172 ;
6173 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006174 else if (*s == '%')
6175 {
6176 /* optional number */
6177 while (vim_isdigit(*++s))
6178 ;
6179 }
6180 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 ++s; /* no extra chars */
6182 else /* must have a number */
6183 {
6184 while (vim_isdigit(*++s))
6185 ;
6186
6187 if (!VIM_ISDIGIT(*(s - 1)))
6188 {
6189 if (errbuf != NULL)
6190 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006191 sprintf((char *)errbuf,
6192 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 transchar_byte(*(s - 1)));
6194 errmsg = errbuf;
6195 }
6196 else
6197 errmsg = (char_u *)"";
6198 break;
6199 }
6200 }
6201 if (*s == ',')
6202 ++s;
6203 else if (*s)
6204 {
6205 if (errbuf != NULL)
6206 errmsg = (char_u *)N_("E527: Missing comma");
6207 else
6208 errmsg = (char_u *)"";
6209 break;
6210 }
6211 }
6212 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6213 errmsg = (char_u *)N_("E528: Must specify a ' value");
6214 }
6215#endif /* FEAT_VIMINFO */
6216
6217 /* terminal options */
6218 else if (istermoption(&options[opt_idx]) && full_screen)
6219 {
6220 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6221 if (varp == &T_CCO)
6222 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006223 int colors = atoi((char *)T_CCO);
6224
6225 /* Only reinitialize colors if t_Co value has really changed to
6226 * avoid expensive reload of colorscheme if t_Co is set to the
6227 * same value multiple times. */
6228 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006230 t_colors = colors;
6231 if (t_colors <= 1)
6232 {
6233 if (new_value_alloced)
6234 vim_free(T_CCO);
6235 T_CCO = empty_option;
6236 }
6237 /* We now have a different color setup, initialize it again. */
6238 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 }
6241 ttest(FALSE);
6242 if (varp == &T_ME)
6243 {
6244 out_str(T_ME);
6245 redraw_later(CLEAR);
6246#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6247 /* Since t_me has been set, this probably means that the user
6248 * wants to use this as default colors. Need to reset default
6249 * background/foreground colors. */
6250 mch_set_normal_colors();
6251#endif
6252 }
6253 }
6254
6255#ifdef FEAT_LINEBREAK
6256 /* 'showbreak' */
6257 else if (varp == &p_sbr)
6258 {
6259 for (s = p_sbr; *s; )
6260 {
6261 if (ptr2cells(s) != 1)
6262 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006263 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 }
6265 }
6266#endif
6267
6268#ifdef FEAT_GUI
6269 /* 'guifont' */
6270 else if (varp == &p_guifont)
6271 {
6272 if (gui.in_use)
6273 {
6274 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006275# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 /*
6277 * Put up a font dialog and let the user select a new value.
6278 * If this is cancelled go back to the old value but don't
6279 * give an error message.
6280 */
6281 if (STRCMP(p, "*") == 0)
6282 {
6283 p = gui_mch_font_dialog(oldval);
6284
6285 if (new_value_alloced)
6286 free_string_option(p_guifont);
6287
6288 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6289 new_value_alloced = TRUE;
6290 }
6291# endif
6292 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6293 {
6294# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6295 if (STRCMP(p_guifont, "*") == 0)
6296 {
6297 /* Dialog was cancelled: Keep the old value without giving
6298 * an error message. */
6299 if (new_value_alloced)
6300 free_string_option(p_guifont);
6301 p_guifont = vim_strsave(oldval);
6302 new_value_alloced = TRUE;
6303 }
6304 else
6305# endif
6306 errmsg = (char_u *)N_("E596: Invalid font(s)");
6307 }
6308 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006309 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 }
6311# ifdef FEAT_XFONTSET
6312 else if (varp == &p_guifontset)
6313 {
6314 if (STRCMP(p_guifontset, "*") == 0)
6315 errmsg = (char_u *)N_("E597: can't select fontset");
6316 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6317 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006318 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 }
6320# endif
6321# ifdef FEAT_MBYTE
6322 else if (varp == &p_guifontwide)
6323 {
6324 if (STRCMP(p_guifontwide, "*") == 0)
6325 errmsg = (char_u *)N_("E533: can't select wide font");
6326 else if (gui_get_wide_font() == FAIL)
6327 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006328 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 }
6330# endif
6331#endif
6332
6333#ifdef CURSOR_SHAPE
6334 /* 'guicursor' */
6335 else if (varp == &p_guicursor)
6336 errmsg = parse_shape_opt(SHAPE_CURSOR);
6337#endif
6338
6339#ifdef FEAT_MOUSESHAPE
6340 /* 'mouseshape' */
6341 else if (varp == &p_mouseshape)
6342 {
6343 errmsg = parse_shape_opt(SHAPE_MOUSE);
6344 update_mouseshape(-1);
6345 }
6346#endif
6347
6348#ifdef FEAT_PRINTER
6349 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006350 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006351# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006352 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006353 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006354# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355#endif
6356
6357#ifdef FEAT_LANGMAP
6358 /* 'langmap' */
6359 else if (varp == &p_langmap)
6360 langmap_set();
6361#endif
6362
6363#ifdef FEAT_LINEBREAK
6364 /* 'breakat' */
6365 else if (varp == &p_breakat)
6366 fill_breakat_flags();
6367#endif
6368
6369#ifdef FEAT_TITLE
6370 /* 'titlestring' and 'iconstring' */
6371 else if (varp == &p_titlestring || varp == &p_iconstring)
6372 {
6373# ifdef FEAT_STL_OPT
6374 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6375
6376 /* NULL => statusline syntax */
6377 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6378 stl_syntax |= flagval;
6379 else
6380 stl_syntax &= ~flagval;
6381# endif
6382 did_set_title(varp == &p_iconstring);
6383
6384 }
6385#endif
6386
6387#ifdef FEAT_GUI
6388 /* 'guioptions' */
6389 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006390 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006392 redraw_gui_only = TRUE;
6393 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394#endif
6395
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006396#if defined(FEAT_GUI_TABLINE)
6397 /* 'guitablabel' */
6398 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006399 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006400 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006401 redraw_gui_only = TRUE;
6402 }
6403 /* 'guitabtooltip' */
6404 else if (varp == &p_gtt)
6405 {
6406 redraw_gui_only = TRUE;
6407 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006408#endif
6409
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6411 /* 'ttymouse' */
6412 else if (varp == &p_ttym)
6413 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006414 /* Switch the mouse off before changing the escape sequences used for
6415 * that. */
6416 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6418 errmsg = e_invarg;
6419 else
6420 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006421 if (termcap_active)
6422 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423 }
6424#endif
6425
6426#ifdef FEAT_VISUAL
6427 /* 'selection' */
6428 else if (varp == &p_sel)
6429 {
6430 if (*p_sel == NUL
6431 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6432 errmsg = e_invarg;
6433 }
6434
6435 /* 'selectmode' */
6436 else if (varp == &p_slm)
6437 {
6438 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6439 errmsg = e_invarg;
6440 }
6441#endif
6442
6443#ifdef FEAT_BROWSE
6444 /* 'browsedir' */
6445 else if (varp == &p_bsdir)
6446 {
6447 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6448 && !mch_isdir(p_bsdir))
6449 errmsg = e_invarg;
6450 }
6451#endif
6452
6453#ifdef FEAT_VISUAL
6454 /* 'keymodel' */
6455 else if (varp == &p_km)
6456 {
6457 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6458 errmsg = e_invarg;
6459 else
6460 {
6461 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6462 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6463 }
6464 }
6465#endif
6466
6467 /* 'mousemodel' */
6468 else if (varp == &p_mousem)
6469 {
6470 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6471 errmsg = e_invarg;
6472#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6473 else if (*p_mousem != *oldval)
6474 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6475 * to create or delete the popup menus. */
6476 gui_motif_update_mousemodel(root_menu);
6477#endif
6478 }
6479
6480 /* 'switchbuf' */
6481 else if (varp == &p_swb)
6482 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006483 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 errmsg = e_invarg;
6485 }
6486
6487 /* 'debug' */
6488 else if (varp == &p_debug)
6489 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006490 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491 errmsg = e_invarg;
6492 }
6493
6494 /* 'display' */
6495 else if (varp == &p_dy)
6496 {
6497 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6498 errmsg = e_invarg;
6499 else
6500 (void)init_chartab();
6501
6502 }
6503
6504#ifdef FEAT_VERTSPLIT
6505 /* 'eadirection' */
6506 else if (varp == &p_ead)
6507 {
6508 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6509 errmsg = e_invarg;
6510 }
6511#endif
6512
6513#ifdef FEAT_CLIPBOARD
6514 /* 'clipboard' */
6515 else if (varp == &p_cb)
6516 errmsg = check_clipboard_option();
6517#endif
6518
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006519#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006520 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6521 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006522 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006523 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006524 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006525 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006526
Bram Moolenaar860cae12010-06-05 23:22:07 +02006527 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006528 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006529 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6530 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006531 ".add") != 0))
6532 errmsg = e_invarg;
6533 }
6534
6535 if (errmsg == NULL)
6536 {
6537 FOR_ALL_WINDOWS(wp)
6538 if (wp->w_buffer == curbuf && wp->w_p_spell)
6539 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006540 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006541# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006542 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006543# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006544 }
6545 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006546 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006547 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006548 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006549 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006550 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006551 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006552 /* 'spellsuggest' */
6553 else if (varp == &p_sps)
6554 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006555 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006556 errmsg = e_invarg;
6557 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006558 /* 'mkspellmem' */
6559 else if (varp == &p_msm)
6560 {
6561 if (spell_check_msm() != OK)
6562 errmsg = e_invarg;
6563 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006564#endif
6565
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566#ifdef FEAT_QUICKFIX
6567 /* When 'bufhidden' is set, check for valid value. */
6568 else if (gvarp == &p_bh)
6569 {
6570 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6571 errmsg = e_invarg;
6572 }
6573
6574 /* When 'buftype' is set, check for valid value. */
6575 else if (gvarp == &p_bt)
6576 {
6577 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6578 errmsg = e_invarg;
6579 else
6580 {
6581# ifdef FEAT_WINDOWS
6582 if (curwin->w_status_height)
6583 {
6584 curwin->w_redr_status = TRUE;
6585 redraw_later(VALID);
6586 }
6587# endif
6588 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006589# ifdef FEAT_TITLE
6590 redraw_titles();
6591# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 }
6593 }
6594#endif
6595
6596#ifdef FEAT_STL_OPT
6597 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006598 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006599 {
6600 int wid;
6601
6602 if (varp == &p_ruf) /* reset ru_wid first */
6603 ru_wid = 0;
6604 s = *varp;
6605 if (varp == &p_ruf && *s == '%')
6606 {
6607 /* set ru_wid if 'ruf' starts with "%99(" */
6608 if (*++s == '-') /* ignore a '-' */
6609 s++;
6610 wid = getdigits(&s);
6611 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6612 ru_wid = wid;
6613 else
6614 errmsg = check_stl_option(p_ruf);
6615 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006616 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006617 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006619 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620 comp_col();
6621 }
6622#endif
6623
6624#ifdef FEAT_INS_EXPAND
6625 /* check if it is a valid value for 'complete' -- Acevedo */
6626 else if (gvarp == &p_cpt)
6627 {
6628 for (s = *varp; *s;)
6629 {
6630 while(*s == ',' || *s == ' ')
6631 s++;
6632 if (!*s)
6633 break;
6634 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6635 {
6636 errmsg = illegal_char(errbuf, *s);
6637 break;
6638 }
6639 if (*++s != NUL && *s != ',' && *s != ' ')
6640 {
6641 if (s[-1] == 'k' || s[-1] == 's')
6642 {
6643 /* skip optional filename after 'k' and 's' */
6644 while (*s && *s != ',' && *s != ' ')
6645 {
6646 if (*s == '\\')
6647 ++s;
6648 ++s;
6649 }
6650 }
6651 else
6652 {
6653 if (errbuf != NULL)
6654 {
6655 sprintf((char *)errbuf,
6656 _("E535: Illegal character after <%c>"),
6657 *--s);
6658 errmsg = errbuf;
6659 }
6660 else
6661 errmsg = (char_u *)"";
6662 break;
6663 }
6664 }
6665 }
6666 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006667
6668 /* 'completeopt' */
6669 else if (varp == &p_cot)
6670 {
6671 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6672 errmsg = e_invarg;
6673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674#endif /* FEAT_INS_EXPAND */
6675
6676
6677#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6678 else if (varp == &p_toolbar)
6679 {
6680 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6681 &toolbar_flags, TRUE) != OK)
6682 errmsg = e_invarg;
6683 else
6684 {
6685 out_flush();
6686 gui_mch_show_toolbar((toolbar_flags &
6687 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6688 }
6689 }
6690#endif
6691
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006692#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693 /* 'toolbariconsize': GTK+ 2 only */
6694 else if (varp == &p_tbis)
6695 {
6696 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6697 errmsg = e_invarg;
6698 else
6699 {
6700 out_flush();
6701 gui_mch_show_toolbar((toolbar_flags &
6702 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6703 }
6704 }
6705#endif
6706
6707 /* 'pastetoggle': translate key codes like in a mapping */
6708 else if (varp == &p_pt)
6709 {
6710 if (*p_pt)
6711 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006712 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713 if (p != NULL)
6714 {
6715 if (new_value_alloced)
6716 free_string_option(p_pt);
6717 p_pt = p;
6718 new_value_alloced = TRUE;
6719 }
6720 }
6721 }
6722
6723 /* 'backspace' */
6724 else if (varp == &p_bs)
6725 {
6726 if (VIM_ISDIGIT(*p_bs))
6727 {
6728 if (*p_bs >'2' || p_bs[1] != NUL)
6729 errmsg = e_invarg;
6730 }
6731 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6732 errmsg = e_invarg;
6733 }
6734
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006735#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 /* 'casemap' */
6737 else if (varp == &p_cmp)
6738 {
6739 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6740 errmsg = e_invarg;
6741 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006743
6744#ifdef FEAT_DIFF
6745 /* 'diffopt' */
6746 else if (varp == &p_dip)
6747 {
6748 if (diffopt_changed() == FAIL)
6749 errmsg = e_invarg;
6750 }
6751#endif
6752
6753#ifdef FEAT_FOLDING
6754 /* 'foldmethod' */
6755 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6756 {
6757 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6758 || *curwin->w_p_fdm == NUL)
6759 errmsg = e_invarg;
6760 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006761 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006763 if (foldmethodIsDiff(curwin))
6764 newFoldLevel();
6765 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 }
6767# ifdef FEAT_EVAL
6768 /* 'foldexpr' */
6769 else if (varp == &curwin->w_p_fde)
6770 {
6771 if (foldmethodIsExpr(curwin))
6772 foldUpdateAll(curwin);
6773 }
6774# endif
6775 /* 'foldmarker' */
6776 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6777 {
6778 p = vim_strchr(*varp, ',');
6779 if (p == NULL)
6780 errmsg = (char_u *)N_("E536: comma required");
6781 else if (p == *varp || p[1] == NUL)
6782 errmsg = e_invarg;
6783 else if (foldmethodIsMarker(curwin))
6784 foldUpdateAll(curwin);
6785 }
6786 /* 'commentstring' */
6787 else if (gvarp == &p_cms)
6788 {
6789 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6790 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6791 }
6792 /* 'foldopen' */
6793 else if (varp == &p_fdo)
6794 {
6795 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6796 errmsg = e_invarg;
6797 }
6798 /* 'foldclose' */
6799 else if (varp == &p_fcl)
6800 {
6801 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6802 errmsg = e_invarg;
6803 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006804 /* 'foldignore' */
6805 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6806 {
6807 if (foldmethodIsIndent(curwin))
6808 foldUpdateAll(curwin);
6809 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810#endif
6811
6812#ifdef FEAT_VIRTUALEDIT
6813 /* 'virtualedit' */
6814 else if (varp == &p_ve)
6815 {
6816 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6817 errmsg = e_invarg;
6818 else if (STRCMP(p_ve, oldval) != 0)
6819 {
6820 /* Recompute cursor position in case the new 've' setting
6821 * changes something. */
6822 validate_virtcol();
6823 coladvance(curwin->w_virtcol);
6824 }
6825 }
6826#endif
6827
6828#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6829 else if (varp == &p_csqf)
6830 {
6831 if (p_csqf != NULL)
6832 {
6833 p = p_csqf;
6834 while (*p != NUL)
6835 {
6836 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6837 || p[1] == NUL
6838 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6839 || (p[2] != NUL && p[2] != ','))
6840 {
6841 errmsg = e_invarg;
6842 break;
6843 }
6844 else if (p[2] == NUL)
6845 break;
6846 else
6847 p += 3;
6848 }
6849 }
6850 }
6851#endif
6852
6853 /* Options that are a list of flags. */
6854 else
6855 {
6856 p = NULL;
6857 if (varp == &p_ww)
6858 p = (char_u *)WW_ALL;
6859 if (varp == &p_shm)
6860 p = (char_u *)SHM_ALL;
6861 else if (varp == &(p_cpo))
6862 p = (char_u *)CPO_ALL;
6863 else if (varp == &(curbuf->b_p_fo))
6864 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006865#ifdef FEAT_CONCEAL
6866 else if (varp == &curwin->w_p_cocu)
6867 p = (char_u *)COCU_ALL;
6868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869 else if (varp == &p_mouse)
6870 {
6871#ifdef FEAT_MOUSE
6872 p = (char_u *)MOUSE_ALL;
6873#else
6874 if (*p_mouse != NUL)
6875 errmsg = (char_u *)N_("E538: No mouse support");
6876#endif
6877 }
6878#if defined(FEAT_GUI)
6879 else if (varp == &p_go)
6880 p = (char_u *)GO_ALL;
6881#endif
6882 if (p != NULL)
6883 {
6884 for (s = *varp; *s; ++s)
6885 if (vim_strchr(p, *s) == NULL)
6886 {
6887 errmsg = illegal_char(errbuf, *s);
6888 break;
6889 }
6890 }
6891 }
6892
6893 /*
6894 * If error detected, restore the previous value.
6895 */
6896 if (errmsg != NULL)
6897 {
6898 if (new_value_alloced)
6899 free_string_option(*varp);
6900 *varp = oldval;
6901 /*
6902 * When resetting some values, need to act on it.
6903 */
6904 if (did_chartab)
6905 (void)init_chartab();
6906 if (varp == &p_hl)
6907 (void)highlight_changed();
6908 }
6909 else
6910 {
6911#ifdef FEAT_EVAL
6912 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006913 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914#endif
6915 /*
6916 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006917 * Use "free_oldval", because recursiveness may change the flags under
6918 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006920 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 free_string_option(oldval);
6922 if (new_value_alloced)
6923 options[opt_idx].flags |= P_ALLOCED;
6924 else
6925 options[opt_idx].flags &= ~P_ALLOCED;
6926
6927 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006928 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 {
6930 /* global option with local value set to use global value; free
6931 * the local value and make it empty */
6932 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6933 free_string_option(*(char_u **)p);
6934 *(char_u **)p = empty_option;
6935 }
6936
6937 /* May set global value for local option. */
6938 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6939 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006940
6941#ifdef FEAT_AUTOCMD
6942 /*
6943 * Trigger the autocommand only after setting the flags.
6944 */
6945# ifdef FEAT_SYN_HL
6946 /* When 'syntax' is set, load the syntax of that name */
6947 if (varp == &(curbuf->b_p_syn))
6948 {
6949 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6950 curbuf->b_fname, TRUE, curbuf);
6951 }
6952# endif
6953 else if (varp == &(curbuf->b_p_ft))
6954 {
6955 /* 'filetype' is set, trigger the FileType autocommand */
6956 did_filetype = TRUE;
6957 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6958 curbuf->b_fname, TRUE, curbuf);
6959 }
6960#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006961#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006962 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006963 {
6964 char_u fname[200];
6965
6966 /*
6967 * Source the spell/LANG.vim in 'runtimepath'.
6968 * They could set 'spellcapcheck' depending on the language.
6969 * Use the first name in 'spelllang' up to '_region' or
6970 * '.encoding'.
6971 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006972 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006973 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6974 break;
6975 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006976 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006977 source_runtime(fname, TRUE);
6978 }
6979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 }
6981
6982#ifdef FEAT_MOUSE
6983 if (varp == &p_mouse)
6984 {
6985# ifdef FEAT_MOUSE_TTY
6986 if (*p_mouse == NUL)
6987 mch_setmouse(FALSE); /* switch mouse off */
6988 else
6989# endif
6990 setmouse(); /* in case 'mouse' changed */
6991 }
6992#endif
6993
6994 if (curwin->w_curswant != MAXCOL)
6995 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006996#ifdef FEAT_GUI
6997 /* check redraw when it's not a GUI option or the GUI is active. */
6998 if (!redraw_gui_only || gui.in_use)
6999#endif
7000 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001
7002 return errmsg;
7003}
7004
Bram Moolenaar1a384422010-07-14 19:53:30 +02007005#ifdef FEAT_SYN_HL
7006/*
7007 * Simple int comparison function for use with qsort()
7008 */
7009 static int
7010int_cmp(a, b)
7011 const void *a;
7012 const void *b;
7013{
7014 return *(const int *)a - *(const int *)b;
7015}
7016
7017/*
7018 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7019 * Returns error message, NULL if it's OK.
7020 */
7021 char_u *
7022check_colorcolumn(wp)
7023 win_T *wp;
7024{
7025 char_u *s;
7026 int col;
7027 int count = 0;
7028 int color_cols[256];
7029 int i;
7030 int j = 0;
7031
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007032 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007033 {
7034 if (*s == '-' || *s == '+')
7035 {
7036 /* -N and +N: add to 'textwidth' */
7037 col = (*s == '-') ? -1 : 1;
7038 ++s;
7039 if (!VIM_ISDIGIT(*s))
7040 return e_invarg;
7041 col = col * getdigits(&s);
7042 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007043 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007044 col += wp->w_buffer->b_p_tw;
7045 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007046 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007047 }
7048 else if (VIM_ISDIGIT(*s))
7049 col = getdigits(&s);
7050 else
7051 return e_invarg;
7052 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007053skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007054 if (*s == NUL)
7055 break;
7056 if (*s != ',')
7057 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007058 if (*++s == NUL)
7059 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007060 }
7061
7062 vim_free(wp->w_p_cc_cols);
7063 if (count == 0)
7064 wp->w_p_cc_cols = NULL;
7065 else
7066 {
7067 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7068 if (wp->w_p_cc_cols != NULL)
7069 {
7070 /* sort the columns for faster usage on screen redraw inside
7071 * win_line() */
7072 qsort(color_cols, count, sizeof(int), int_cmp);
7073
7074 for (i = 0; i < count; ++i)
7075 /* skip duplicates */
7076 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7077 wp->w_p_cc_cols[j++] = color_cols[i];
7078 wp->w_p_cc_cols[j] = -1; /* end marker */
7079 }
7080 }
7081
7082 return NULL; /* no error */
7083}
7084#endif
7085
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086/*
7087 * Handle setting 'listchars' or 'fillchars'.
7088 * Returns error message, NULL if it's OK.
7089 */
7090 static char_u *
7091set_chars_option(varp)
7092 char_u **varp;
7093{
7094 int round, i, len, entries;
7095 char_u *p, *s;
7096 int c1, c2 = 0;
7097 struct charstab
7098 {
7099 int *cp;
7100 char *name;
7101 };
7102#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7103 static struct charstab filltab[] =
7104 {
7105 {&fill_stl, "stl"},
7106 {&fill_stlnc, "stlnc"},
7107 {&fill_vert, "vert"},
7108 {&fill_fold, "fold"},
7109 {&fill_diff, "diff"},
7110 };
7111#endif
7112 static struct charstab lcstab[] =
7113 {
7114 {&lcs_eol, "eol"},
7115 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007116 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 {&lcs_prec, "precedes"},
7118 {&lcs_tab2, "tab"},
7119 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007120#ifdef FEAT_CONCEAL
7121 {&lcs_conceal, "conceal"},
7122#else
7123 {NULL, "conceal"},
7124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 };
7126 struct charstab *tab;
7127
7128#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7129 if (varp == &p_lcs)
7130#endif
7131 {
7132 tab = lcstab;
7133 entries = sizeof(lcstab) / sizeof(struct charstab);
7134 }
7135#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7136 else
7137 {
7138 tab = filltab;
7139 entries = sizeof(filltab) / sizeof(struct charstab);
7140 }
7141#endif
7142
7143 /* first round: check for valid value, second round: assign values */
7144 for (round = 0; round <= 1; ++round)
7145 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007146 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007147 {
7148 /* After checking that the value is valid: set defaults: space for
7149 * 'fillchars', NUL for 'listchars' */
7150 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007151 if (tab[i].cp != NULL)
7152 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 if (varp == &p_lcs)
7154 lcs_tab1 = NUL;
7155#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7156 else
7157 fill_diff = '-';
7158#endif
7159 }
7160 p = *varp;
7161 while (*p)
7162 {
7163 for (i = 0; i < entries; ++i)
7164 {
7165 len = (int)STRLEN(tab[i].name);
7166 if (STRNCMP(p, tab[i].name, len) == 0
7167 && p[len] == ':'
7168 && p[len + 1] != NUL)
7169 {
7170 s = p + len + 1;
7171#ifdef FEAT_MBYTE
7172 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007173 if (mb_char2cells(c1) > 1)
7174 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175#else
7176 c1 = *s++;
7177#endif
7178 if (tab[i].cp == &lcs_tab2)
7179 {
7180 if (*s == NUL)
7181 continue;
7182#ifdef FEAT_MBYTE
7183 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007184 if (mb_char2cells(c2) > 1)
7185 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186#else
7187 c2 = *s++;
7188#endif
7189 }
7190 if (*s == ',' || *s == NUL)
7191 {
7192 if (round)
7193 {
7194 if (tab[i].cp == &lcs_tab2)
7195 {
7196 lcs_tab1 = c1;
7197 lcs_tab2 = c2;
7198 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007199 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200 *(tab[i].cp) = c1;
7201
7202 }
7203 p = s;
7204 break;
7205 }
7206 }
7207 }
7208
7209 if (i == entries)
7210 return e_invarg;
7211 if (*p == ',')
7212 ++p;
7213 }
7214 }
7215
7216 return NULL; /* no error */
7217}
7218
7219#ifdef FEAT_STL_OPT
7220/*
7221 * Check validity of options with the 'statusline' format.
7222 * Return error message or NULL.
7223 */
7224 char_u *
7225check_stl_option(s)
7226 char_u *s;
7227{
7228 int itemcnt = 0;
7229 int groupdepth = 0;
7230 static char_u errbuf[80];
7231
7232 while (*s && itemcnt < STL_MAX_ITEM)
7233 {
7234 /* Check for valid keys after % sequences */
7235 while (*s && *s != '%')
7236 s++;
7237 if (!*s)
7238 break;
7239 s++;
7240 if (*s != '%' && *s != ')')
7241 ++itemcnt;
7242 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7243 {
7244 s++;
7245 continue;
7246 }
7247 if (*s == ')')
7248 {
7249 s++;
7250 if (--groupdepth < 0)
7251 break;
7252 continue;
7253 }
7254 if (*s == '-')
7255 s++;
7256 while (VIM_ISDIGIT(*s))
7257 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007258 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259 continue;
7260 if (*s == '.')
7261 {
7262 s++;
7263 while (*s && VIM_ISDIGIT(*s))
7264 s++;
7265 }
7266 if (*s == '(')
7267 {
7268 groupdepth++;
7269 continue;
7270 }
7271 if (vim_strchr(STL_ALL, *s) == NULL)
7272 {
7273 return illegal_char(errbuf, *s);
7274 }
7275 if (*s == '{')
7276 {
7277 s++;
7278 while (*s != '}' && *s)
7279 s++;
7280 if (*s != '}')
7281 return (char_u *)N_("E540: Unclosed expression sequence");
7282 }
7283 }
7284 if (itemcnt >= STL_MAX_ITEM)
7285 return (char_u *)N_("E541: too many items");
7286 if (groupdepth != 0)
7287 return (char_u *)N_("E542: unbalanced groups");
7288 return NULL;
7289}
7290#endif
7291
7292#ifdef FEAT_CLIPBOARD
7293/*
7294 * Extract the items in the 'clipboard' option and set global values.
7295 */
7296 static char_u *
7297check_clipboard_option()
7298{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007299 int new_unnamed = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 int new_autoselect = FALSE;
7301 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007302 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 regprog_T *new_exclude_prog = NULL;
7304 char_u *errmsg = NULL;
7305 char_u *p;
7306
7307 for (p = p_cb; *p != NUL; )
7308 {
7309 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7310 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007311 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 p += 7;
7313 }
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007314 else if (STRNCMP(p, "unnamedplus", 11) == 0
7315 && (p[11] == ',' || p[11] == NUL))
7316 {
7317 new_unnamed |= CLIP_UNNAMED_PLUS;
7318 p += 11;
7319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 else if (STRNCMP(p, "autoselect", 10) == 0
7321 && (p[10] == ',' || p[10] == NUL))
7322 {
7323 new_autoselect = TRUE;
7324 p += 10;
7325 }
7326 else if (STRNCMP(p, "autoselectml", 12) == 0
7327 && (p[12] == ',' || p[12] == NUL))
7328 {
7329 new_autoselectml = TRUE;
7330 p += 12;
7331 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007332 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7333 {
7334 new_html = TRUE;
7335 p += 4;
7336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7338 {
7339 p += 8;
7340 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7341 if (new_exclude_prog == NULL)
7342 errmsg = e_invarg;
7343 break;
7344 }
7345 else
7346 {
7347 errmsg = e_invarg;
7348 break;
7349 }
7350 if (*p == ',')
7351 ++p;
7352 }
7353 if (errmsg == NULL)
7354 {
7355 clip_unnamed = new_unnamed;
7356 clip_autoselect = new_autoselect;
7357 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007358 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 vim_free(clip_exclude_prog);
7360 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007361#ifdef FEAT_GUI_GTK
7362 if (gui.in_use)
7363 {
7364 gui_gtk_set_selection_targets();
7365 gui_gtk_set_dnd_targets();
7366 }
7367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 }
7369 else
7370 vim_free(new_exclude_prog);
7371
7372 return errmsg;
7373}
7374#endif
7375
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007376#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007377/*
7378 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7379 * Return error message when failed, NULL when OK.
7380 */
7381 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007382compile_cap_prog(synblock)
7383 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007384{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007385 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007386 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007387
Bram Moolenaar860cae12010-06-05 23:22:07 +02007388 if (*synblock->b_p_spc == NUL)
7389 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007390 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007391 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007392 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007393 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007394 if (re != NULL)
7395 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007396 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7397 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007398 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007399 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007400 return e_invarg;
7401 }
7402 vim_free(re);
7403 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007404 }
7405
7406 vim_free(rp);
7407 return NULL;
7408}
7409#endif
7410
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007411#if defined(FEAT_EVAL) || defined(PROTO)
7412/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007413 * Set the scriptID for an option, taking care of setting the buffer- or
7414 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007415 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007416 static void
7417set_option_scriptID_idx(opt_idx, opt_flags, id)
7418 int opt_idx;
7419 int opt_flags;
7420 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007421{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007422 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7423 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007424
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007425 /* Remember where the option was set. For local options need to do that
7426 * in the buffer or window structure. */
7427 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007428 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007429 if (both || (opt_flags & OPT_LOCAL))
7430 {
7431 if (indir & PV_BUF)
7432 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7433 else if (indir & PV_WIN)
7434 curwin->w_p_scriptID[indir & PV_MASK] = id;
7435 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007436}
7437#endif
7438
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439/*
7440 * Set the value of a boolean option, and take care of side effects.
7441 * Returns NULL for success, or an error message for an error.
7442 */
7443 static char_u *
7444set_bool_option(opt_idx, varp, value, opt_flags)
7445 int opt_idx; /* index in options[] table */
7446 char_u *varp; /* pointer to the option variable */
7447 int value; /* new value */
7448 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7449{
7450 int old_value = *(int *)varp;
7451
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 /* Disallow changing some options from secure mode */
7453 if ((secure
7454#ifdef HAVE_SANDBOX
7455 || sandbox != 0
7456#endif
7457 ) && (options[opt_idx].flags & P_SECURE))
7458 return e_secure;
7459
7460 *(int *)varp = value; /* set the new value */
7461#ifdef FEAT_EVAL
7462 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007463 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464#endif
7465
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007466#ifdef FEAT_GUI
7467 need_mouse_correct = TRUE;
7468#endif
7469
Bram Moolenaar071d4272004-06-13 20:20:40 +00007470 /* May set global value for local option. */
7471 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7472 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7473
7474 /*
7475 * Handle side effects of changing a bool option.
7476 */
7477
7478 /* 'compatible' */
7479 if ((int *)varp == &p_cp)
7480 {
7481 compatible_set();
7482 }
7483
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007484 /* 'list', 'number' */
7485 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007486 || (int *)varp == &curwin->w_p_nu
7487 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007488 {
7489 if (curwin->w_curswant != MAXCOL)
7490 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007491
7492 /* If 'number' is set, reset 'relativenumber'. */
7493 /* If 'relativenumber' is set, reset 'number'. */
7494 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7495 curwin->w_p_rnu = FALSE;
7496 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7497 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007498 }
7499
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 else if ((int *)varp == &curbuf->b_p_ro)
7501 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007502 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7504 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007505
7506 /* when 'readonly' is set may give W10 again */
7507 if (curbuf->b_p_ro)
7508 curbuf->b_did_warn = FALSE;
7509
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007511 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007512#endif
7513 }
7514
Bram Moolenaar9c449722010-07-20 18:44:27 +02007515#ifdef FEAT_GUI
7516 else if ((int *)varp == &p_mh)
7517 {
7518 if (!p_mh)
7519 gui_mch_mousehide(FALSE);
7520 }
7521#endif
7522
Bram Moolenaara539df02010-08-01 14:35:05 +02007523#ifdef FEAT_TITLE
7524 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007526 {
7527 redraw_titles();
7528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 /* when 'endofline' is changed, redraw the window title */
7530 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007531 {
7532 redraw_titles();
7533 }
7534# ifdef FEAT_MBYTE
7535 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007536 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007537 {
7538 redraw_titles();
7539 }
7540# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541#endif
7542
7543 /* when 'bin' is set also set some other options */
7544 else if ((int *)varp == &curbuf->b_p_bin)
7545 {
7546 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7547#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007548 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549#endif
7550 }
7551
7552#ifdef FEAT_AUTOCMD
7553 /* when 'buflisted' changes, trigger autocommands */
7554 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7555 {
7556 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7557 NULL, NULL, TRUE, curbuf);
7558 }
7559#endif
7560
7561 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7562 else if ((int *)varp == &curbuf->b_p_swf)
7563 {
7564 if (curbuf->b_p_swf && p_uc)
7565 ml_open_file(curbuf); /* create the swap file */
7566 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007567 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7568 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 mf_close_file(curbuf, TRUE); /* remove the swap file */
7570 }
7571
7572 /* when 'terse' is set change 'shortmess' */
7573 else if ((int *)varp == &p_terse)
7574 {
7575 char_u *p;
7576
7577 p = vim_strchr(p_shm, SHM_SEARCH);
7578
7579 /* insert 's' in p_shm */
7580 if (p_terse && p == NULL)
7581 {
7582 STRCPY(IObuff, p_shm);
7583 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007584 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 }
7586 /* remove 's' from p_shm */
7587 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007588 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007589 }
7590
7591 /* when 'paste' is set or reset also change other options */
7592 else if ((int *)varp == &p_paste)
7593 {
7594 paste_option_changed();
7595 }
7596
7597 /* when 'insertmode' is set from an autocommand need to do work here */
7598 else if ((int *)varp == &p_im)
7599 {
7600 if (p_im)
7601 {
7602 if ((State & INSERT) == 0)
7603 need_start_insertmode = TRUE;
7604 stop_insert_mode = FALSE;
7605 }
7606 else
7607 {
7608 need_start_insertmode = FALSE;
7609 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007610 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007611 clear_cmdline = TRUE; /* remove "(insert)" */
7612 restart_edit = 0;
7613 }
7614 }
7615
7616 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7617 else if ((int *)varp == &p_ic && p_hls)
7618 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007619 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007620 }
7621
7622#ifdef FEAT_SEARCH_EXTRA
7623 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7624 else if ((int *)varp == &p_hls)
7625 {
7626 no_hlsearch = FALSE;
7627 }
7628#endif
7629
7630#ifdef FEAT_SCROLLBIND
7631 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7632 * at the end of normal_cmd() */
7633 else if ((int *)varp == &curwin->w_p_scb)
7634 {
7635 if (curwin->w_p_scb)
7636 do_check_scrollbind(FALSE);
7637 }
7638#endif
7639
7640#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7641 /* There can be only one window with 'previewwindow' set. */
7642 else if ((int *)varp == &curwin->w_p_pvw)
7643 {
7644 if (curwin->w_p_pvw)
7645 {
7646 win_T *win;
7647
7648 for (win = firstwin; win != NULL; win = win->w_next)
7649 if (win->w_p_pvw && win != curwin)
7650 {
7651 curwin->w_p_pvw = FALSE;
7652 return (char_u *)N_("E590: A preview window already exists");
7653 }
7654 }
7655 }
7656#endif
7657
7658 /* when 'textmode' is set or reset also change 'fileformat' */
7659 else if ((int *)varp == &curbuf->b_p_tx)
7660 {
7661 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7662 }
7663
7664 /* when 'textauto' is set or reset also change 'fileformats' */
7665 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 set_string_option_direct((char_u *)"ffs", -1,
7667 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007668 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669
7670 /*
7671 * When 'lisp' option changes include/exclude '-' in
7672 * keyword characters.
7673 */
7674#ifdef FEAT_LISP
7675 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7676 {
7677 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7678 }
7679#endif
7680
7681#ifdef FEAT_TITLE
7682 /* when 'title' changed, may need to change the title; same for 'icon' */
7683 else if ((int *)varp == &p_title)
7684 {
7685 did_set_title(FALSE);
7686 }
7687
7688 else if ((int *)varp == &p_icon)
7689 {
7690 did_set_title(TRUE);
7691 }
7692#endif
7693
7694 else if ((int *)varp == &curbuf->b_changed)
7695 {
7696 if (!value)
7697 save_file_ff(curbuf); /* Buffer is unchanged */
7698#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007699 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700#endif
7701#ifdef FEAT_AUTOCMD
7702 modified_was_set = value;
7703#endif
7704 }
7705
7706#ifdef BACKSLASH_IN_FILENAME
7707 else if ((int *)varp == &p_ssl)
7708 {
7709 if (p_ssl)
7710 {
7711 psepc = '/';
7712 psepcN = '\\';
7713 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007714 }
7715 else
7716 {
7717 psepc = '\\';
7718 psepcN = '/';
7719 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 }
7721
7722 /* need to adjust the file name arguments and buffer names. */
7723 buflist_slash_adjust();
7724 alist_slash_adjust();
7725# ifdef FEAT_EVAL
7726 scriptnames_slash_adjust();
7727# endif
7728 }
7729#endif
7730
7731 /* If 'wrap' is set, set w_leftcol to zero. */
7732 else if ((int *)varp == &curwin->w_p_wrap)
7733 {
7734 if (curwin->w_p_wrap)
7735 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007736 if (curwin->w_curswant != MAXCOL)
7737 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 }
7739
7740#ifdef FEAT_WINDOWS
7741 else if ((int *)varp == &p_ea)
7742 {
7743 if (p_ea && !old_value)
7744 win_equal(curwin, FALSE, 0);
7745 }
7746#endif
7747
7748 else if ((int *)varp == &p_wiv)
7749 {
7750 /*
7751 * When 'weirdinvert' changed, set/reset 't_xs'.
7752 * Then set 'weirdinvert' according to value of 't_xs'.
7753 */
7754 if (p_wiv && !old_value)
7755 T_XS = (char_u *)"y";
7756 else if (!p_wiv && old_value)
7757 T_XS = empty_option;
7758 p_wiv = (*T_XS != NUL);
7759 }
7760
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007761#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762 else if ((int *)varp == &p_beval)
7763 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 if (p_beval == TRUE)
7765 gui_mch_enable_beval_area(balloonEval);
7766 else
7767 gui_mch_disable_beval_area(balloonEval);
7768 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007771#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772 else if ((int *)varp == &p_acd)
7773 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007774 /* Change directories when the 'acd' option is set now. */
7775 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776 }
7777#endif
7778
7779#ifdef FEAT_DIFF
7780 /* 'diff' */
7781 else if ((int *)varp == &curwin->w_p_diff)
7782 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007783 /* May add or remove the buffer from the list of diff buffers. */
7784 diff_buf_adjust(curwin);
7785# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786 if (foldmethodIsDiff(curwin))
7787 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007788# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 }
7790#endif
7791
7792#ifdef USE_IM_CONTROL
7793 /* 'imdisable' */
7794 else if ((int *)varp == &p_imdisable)
7795 {
7796 /* Only de-activate it here, it will be enabled when changing mode. */
7797 if (p_imdisable)
7798 im_set_active(FALSE);
7799 }
7800#endif
7801
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007802#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007803 /* 'spell' */
7804 else if ((int *)varp == &curwin->w_p_spell)
7805 {
7806 if (curwin->w_p_spell)
7807 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007808 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007809 if (errmsg != NULL)
7810 EMSG(_(errmsg));
7811 }
7812 }
7813#endif
7814
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815#ifdef FEAT_FKMAP
7816 else if ((int *)varp == &p_altkeymap)
7817 {
7818 if (old_value != p_altkeymap)
7819 {
7820 if (!p_altkeymap)
7821 {
7822 p_hkmap = p_fkmap;
7823 p_fkmap = 0;
7824 }
7825 else
7826 {
7827 p_fkmap = p_hkmap;
7828 p_hkmap = 0;
7829 }
7830 (void)init_chartab();
7831 }
7832 }
7833
7834 /*
7835 * In case some second language keymapping options have changed, check
7836 * and correct the setting in a consistent way.
7837 */
7838
7839 /*
7840 * If hkmap or fkmap are set, reset Arabic keymapping.
7841 */
7842 if ((p_hkmap || p_fkmap) && p_altkeymap)
7843 {
7844 p_altkeymap = p_fkmap;
7845# ifdef FEAT_ARABIC
7846 curwin->w_p_arab = FALSE;
7847# endif
7848 (void)init_chartab();
7849 }
7850
7851 /*
7852 * If hkmap set, reset Farsi keymapping.
7853 */
7854 if (p_hkmap && p_altkeymap)
7855 {
7856 p_altkeymap = 0;
7857 p_fkmap = 0;
7858# ifdef FEAT_ARABIC
7859 curwin->w_p_arab = FALSE;
7860# endif
7861 (void)init_chartab();
7862 }
7863
7864 /*
7865 * If fkmap set, reset Hebrew keymapping.
7866 */
7867 if (p_fkmap && !p_altkeymap)
7868 {
7869 p_altkeymap = 1;
7870 p_hkmap = 0;
7871# ifdef FEAT_ARABIC
7872 curwin->w_p_arab = FALSE;
7873# endif
7874 (void)init_chartab();
7875 }
7876#endif
7877
7878#ifdef FEAT_ARABIC
7879 if ((int *)varp == &curwin->w_p_arab)
7880 {
7881 if (curwin->w_p_arab)
7882 {
7883 /*
7884 * 'arabic' is set, handle various sub-settings.
7885 */
7886 if (!p_tbidi)
7887 {
7888 /* set rightleft mode */
7889 if (!curwin->w_p_rl)
7890 {
7891 curwin->w_p_rl = TRUE;
7892 changed_window_setting();
7893 }
7894
7895 /* Enable Arabic shaping (major part of what Arabic requires) */
7896 if (!p_arshape)
7897 {
7898 p_arshape = TRUE;
7899 redraw_later_clear();
7900 }
7901 }
7902
7903 /* Arabic requires a utf-8 encoding, inform the user if its not
7904 * set. */
7905 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007906 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007907 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7908
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007909 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007910 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7911#ifdef FEAT_EVAL
7912 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7913#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915
7916# ifdef FEAT_MBYTE
7917 /* set 'delcombine' */
7918 p_deco = TRUE;
7919# endif
7920
7921# ifdef FEAT_KEYMAP
7922 /* Force-set the necessary keymap for arabic */
7923 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7924 OPT_LOCAL);
7925# endif
7926# ifdef FEAT_FKMAP
7927 p_altkeymap = 0;
7928 p_hkmap = 0;
7929 p_fkmap = 0;
7930 (void)init_chartab();
7931# endif
7932 }
7933 else
7934 {
7935 /*
7936 * 'arabic' is reset, handle various sub-settings.
7937 */
7938 if (!p_tbidi)
7939 {
7940 /* reset rightleft mode */
7941 if (curwin->w_p_rl)
7942 {
7943 curwin->w_p_rl = FALSE;
7944 changed_window_setting();
7945 }
7946
7947 /* 'arabicshape' isn't reset, it is a global option and
7948 * another window may still need it "on". */
7949 }
7950
7951 /* 'delcombine' isn't reset, it is a global option and another
7952 * window may still want it "on". */
7953
7954# ifdef FEAT_KEYMAP
7955 /* Revert to the default keymap */
7956 curbuf->b_p_iminsert = B_IMODE_NONE;
7957 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7958# endif
7959 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007960 if (curwin->w_curswant != MAXCOL)
7961 curwin->w_set_curswant = TRUE;
7962 }
7963
7964 else if ((int *)varp == &p_arshape)
7965 {
7966 if (curwin->w_curswant != MAXCOL)
7967 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 }
7969#endif
7970
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007971#ifdef FEAT_LINEBREAK
7972 if ((int *)varp == &curwin->w_p_lbr)
7973 {
7974 if (curwin->w_curswant != MAXCOL)
7975 curwin->w_set_curswant = TRUE;
7976 }
7977#endif
7978
7979#ifdef FEAT_RIGHTLEFT
7980 if ((int *)varp == &curwin->w_p_rl)
7981 {
7982 if (curwin->w_curswant != MAXCOL)
7983 curwin->w_set_curswant = TRUE;
7984 }
7985#endif
7986
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 /*
7988 * End of handling side effects for bool options.
7989 */
7990
7991 options[opt_idx].flags |= P_WAS_SET;
7992
7993 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007994
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 check_redraw(options[opt_idx].flags);
7996
7997 return NULL;
7998}
7999
8000/*
8001 * Set the value of a number option, and take care of side effects.
8002 * Returns NULL for success, or an error message for an error.
8003 */
8004 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008005set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 int opt_idx; /* index in options[] table */
8007 char_u *varp; /* pointer to the option variable */
8008 long value; /* new value */
8009 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008010 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8012 OPT_MODELINE */
8013{
8014 char_u *errmsg = NULL;
8015 long old_value = *(long *)varp;
8016 long old_Rows = Rows; /* remember old Rows */
8017 long old_Columns = Columns; /* remember old Columns */
8018 long *pp = (long *)varp;
8019
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008020 /* Disallow changing some options from secure mode. */
8021 if ((secure
8022#ifdef HAVE_SANDBOX
8023 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008025 ) && (options[opt_idx].flags & P_SECURE))
8026 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027
8028 *pp = value;
8029#ifdef FEAT_EVAL
8030 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008031 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008033#ifdef FEAT_GUI
8034 need_mouse_correct = TRUE;
8035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036
8037 if (curbuf->b_p_sw <= 0)
8038 {
8039 errmsg = e_positive;
8040 curbuf->b_p_sw = curbuf->b_p_ts;
8041 }
8042
8043 /*
8044 * Number options that need some action when changed
8045 */
8046#ifdef FEAT_WINDOWS
8047 if (pp == &p_wh || pp == &p_hh)
8048 {
8049 if (p_wh < 1)
8050 {
8051 errmsg = e_positive;
8052 p_wh = 1;
8053 }
8054 if (p_wmh > p_wh)
8055 {
8056 errmsg = e_winheight;
8057 p_wh = p_wmh;
8058 }
8059 if (p_hh < 0)
8060 {
8061 errmsg = e_positive;
8062 p_hh = 0;
8063 }
8064
8065 /* Change window height NOW */
8066 if (lastwin != firstwin)
8067 {
8068 if (pp == &p_wh && curwin->w_height < p_wh)
8069 win_setheight((int)p_wh);
8070 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8071 win_setheight((int)p_hh);
8072 }
8073 }
8074
8075 /* 'winminheight' */
8076 else if (pp == &p_wmh)
8077 {
8078 if (p_wmh < 0)
8079 {
8080 errmsg = e_positive;
8081 p_wmh = 0;
8082 }
8083 if (p_wmh > p_wh)
8084 {
8085 errmsg = e_winheight;
8086 p_wmh = p_wh;
8087 }
8088 win_setminheight();
8089 }
8090
8091# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008092 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 {
8094 if (p_wiw < 1)
8095 {
8096 errmsg = e_positive;
8097 p_wiw = 1;
8098 }
8099 if (p_wmw > p_wiw)
8100 {
8101 errmsg = e_winwidth;
8102 p_wiw = p_wmw;
8103 }
8104
8105 /* Change window width NOW */
8106 if (lastwin != firstwin && curwin->w_width < p_wiw)
8107 win_setwidth((int)p_wiw);
8108 }
8109
8110 /* 'winminwidth' */
8111 else if (pp == &p_wmw)
8112 {
8113 if (p_wmw < 0)
8114 {
8115 errmsg = e_positive;
8116 p_wmw = 0;
8117 }
8118 if (p_wmw > p_wiw)
8119 {
8120 errmsg = e_winwidth;
8121 p_wmw = p_wiw;
8122 }
8123 win_setminheight();
8124 }
8125# endif
8126
8127#endif
8128
8129#ifdef FEAT_WINDOWS
8130 /* (re)set last window status line */
8131 else if (pp == &p_ls)
8132 {
8133 last_status(FALSE);
8134 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008135
8136 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008137 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008138 {
8139 shell_new_rows(); /* recompute window positions and heights */
8140 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141#endif
8142
8143#ifdef FEAT_GUI
8144 else if (pp == &p_linespace)
8145 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008146 /* Recompute gui.char_height and resize the Vim window to keep the
8147 * same number of lines. */
8148 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008149 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 }
8151#endif
8152
8153#ifdef FEAT_FOLDING
8154 /* 'foldlevel' */
8155 else if (pp == &curwin->w_p_fdl)
8156 {
8157 if (curwin->w_p_fdl < 0)
8158 curwin->w_p_fdl = 0;
8159 newFoldLevel();
8160 }
8161
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008162 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 else if (pp == &curwin->w_p_fml)
8164 {
8165 foldUpdateAll(curwin);
8166 }
8167
8168 /* 'foldnestmax' */
8169 else if (pp == &curwin->w_p_fdn)
8170 {
8171 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8172 foldUpdateAll(curwin);
8173 }
8174
8175 /* 'foldcolumn' */
8176 else if (pp == &curwin->w_p_fdc)
8177 {
8178 if (curwin->w_p_fdc < 0)
8179 {
8180 errmsg = e_positive;
8181 curwin->w_p_fdc = 0;
8182 }
8183 else if (curwin->w_p_fdc > 12)
8184 {
8185 errmsg = e_invarg;
8186 curwin->w_p_fdc = 12;
8187 }
8188 }
8189
8190 /* 'shiftwidth' or 'tabstop' */
8191 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8192 {
8193 if (foldmethodIsIndent(curwin))
8194 foldUpdateAll(curwin);
8195 }
8196#endif /* FEAT_FOLDING */
8197
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008198#ifdef FEAT_MBYTE
8199 /* 'maxcombine' */
8200 else if (pp == &p_mco)
8201 {
8202 if (p_mco > MAX_MCO)
8203 p_mco = MAX_MCO;
8204 else if (p_mco < 0)
8205 p_mco = 0;
8206 screenclear(); /* will re-allocate the screen */
8207 }
8208#endif
8209
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210 else if (pp == &curbuf->b_p_iminsert)
8211 {
8212 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8213 {
8214 errmsg = e_invarg;
8215 curbuf->b_p_iminsert = B_IMODE_NONE;
8216 }
8217 p_iminsert = curbuf->b_p_iminsert;
8218 if (termcap_active) /* don't do this in the alternate screen */
8219 showmode();
8220#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8221 /* Show/unshow value of 'keymap' in status lines. */
8222 status_redraw_curbuf();
8223#endif
8224 }
8225
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008226 else if (pp == &p_window)
8227 {
8228 if (p_window < 1)
8229 p_window = 1;
8230 else if (p_window >= Rows)
8231 p_window = Rows - 1;
8232 }
8233
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 else if (pp == &curbuf->b_p_imsearch)
8235 {
8236 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8237 {
8238 errmsg = e_invarg;
8239 curbuf->b_p_imsearch = B_IMODE_NONE;
8240 }
8241 p_imsearch = curbuf->b_p_imsearch;
8242 }
8243
8244#ifdef FEAT_TITLE
8245 /* if 'titlelen' has changed, redraw the title */
8246 else if (pp == &p_titlelen)
8247 {
8248 if (p_titlelen < 0)
8249 {
8250 errmsg = e_positive;
8251 p_titlelen = 85;
8252 }
8253 if (starting != NO_SCREEN && old_value != p_titlelen)
8254 need_maketitle = TRUE;
8255 }
8256#endif
8257
8258 /* if p_ch changed value, change the command line height */
8259 else if (pp == &p_ch)
8260 {
8261 if (p_ch < 1)
8262 {
8263 errmsg = e_positive;
8264 p_ch = 1;
8265 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008266 if (p_ch > Rows - min_rows() + 1)
8267 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268
8269 /* Only compute the new window layout when startup has been
8270 * completed. Otherwise the frame sizes may be wrong. */
8271 if (p_ch != old_value && full_screen
8272#ifdef FEAT_GUI
8273 && !gui.starting
8274#endif
8275 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008276 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 }
8278
8279 /* when 'updatecount' changes from zero to non-zero, open swap files */
8280 else if (pp == &p_uc)
8281 {
8282 if (p_uc < 0)
8283 {
8284 errmsg = e_positive;
8285 p_uc = 100;
8286 }
8287 if (p_uc && !old_value)
8288 ml_open_files();
8289 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008290#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008291 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008292 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008293 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008294 {
8295 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008296 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008297 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008298 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008299 {
8300 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008301 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008302 }
8303 }
8304#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008305#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008306 else if (pp == &p_mzq)
8307 mzvim_reset_timer();
8308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309
8310 /* sync undo before 'undolevels' changes */
8311 else if (pp == &p_ul)
8312 {
8313 /* use the old value, otherwise u_sync() may not work properly */
8314 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008315 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 p_ul = value;
8317 }
8318
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008319#ifdef FEAT_LINEBREAK
8320 /* 'numberwidth' must be positive */
8321 else if (pp == &curwin->w_p_nuw)
8322 {
8323 if (curwin->w_p_nuw < 1)
8324 {
8325 errmsg = e_positive;
8326 curwin->w_p_nuw = 1;
8327 }
8328 if (curwin->w_p_nuw > 10)
8329 {
8330 errmsg = e_invarg;
8331 curwin->w_p_nuw = 10;
8332 }
8333 curwin->w_nrwidth_line_count = 0;
8334 }
8335#endif
8336
Bram Moolenaar1a384422010-07-14 19:53:30 +02008337 else if (pp == &curbuf->b_p_tw)
8338 {
8339 if (curbuf->b_p_tw < 0)
8340 {
8341 errmsg = e_positive;
8342 curbuf->b_p_tw = 0;
8343 }
8344#ifdef FEAT_SYN_HL
8345# ifdef FEAT_WINDOWS
8346 {
8347 win_T *wp;
8348 tabpage_T *tp;
8349
8350 FOR_ALL_TAB_WINDOWS(tp, wp)
8351 check_colorcolumn(wp);
8352 }
8353# else
8354 check_colorcolumn(curwin);
8355# endif
8356#endif
8357 }
8358
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 /*
8360 * Check the bounds for numeric options here
8361 */
8362 if (Rows < min_rows() && full_screen)
8363 {
8364 if (errbuf != NULL)
8365 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008366 vim_snprintf((char *)errbuf, errbuflen,
8367 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008368 errmsg = errbuf;
8369 }
8370 Rows = min_rows();
8371 }
8372 if (Columns < MIN_COLUMNS && full_screen)
8373 {
8374 if (errbuf != NULL)
8375 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008376 vim_snprintf((char *)errbuf, errbuflen,
8377 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 errmsg = errbuf;
8379 }
8380 Columns = MIN_COLUMNS;
8381 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008382 /* Limit the values to avoid an overflow in Rows * Columns. */
8383 if (Columns > 10000)
8384 Columns = 10000;
8385 if (Rows > 1000)
8386 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387
8388#ifdef DJGPP
8389 /* avoid a crash by checking for a too large value of 'columns' */
8390 if (old_Columns != Columns && full_screen && term_console)
8391 mch_check_columns();
8392#endif
8393
8394 /*
8395 * If the screen (shell) height has been changed, assume it is the
8396 * physical screenheight.
8397 */
8398 if (old_Rows != Rows || old_Columns != Columns)
8399 {
8400 /* Changing the screen size is not allowed while updating the screen. */
8401 if (updating_screen)
8402 *pp = old_value;
8403 else if (full_screen
8404#ifdef FEAT_GUI
8405 && !gui.starting
8406#endif
8407 )
8408 set_shellsize((int)Columns, (int)Rows, TRUE);
8409 else
8410 {
8411 /* Postpone the resizing; check the size and cmdline position for
8412 * messages. */
8413 check_shellsize();
8414 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8415 cmdline_row = Rows - p_ch;
8416 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008417 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008418 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 }
8420
8421 if (curbuf->b_p_sts < 0)
8422 {
8423 errmsg = e_positive;
8424 curbuf->b_p_sts = 0;
8425 }
8426 if (curbuf->b_p_ts <= 0)
8427 {
8428 errmsg = e_positive;
8429 curbuf->b_p_ts = 8;
8430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431 if (p_tm < 0)
8432 {
8433 errmsg = e_positive;
8434 p_tm = 0;
8435 }
8436 if ((curwin->w_p_scr <= 0
8437 || (curwin->w_p_scr > curwin->w_height
8438 && curwin->w_height > 0))
8439 && full_screen)
8440 {
8441 if (pp == &(curwin->w_p_scr))
8442 {
8443 if (curwin->w_p_scr != 0)
8444 errmsg = e_scroll;
8445 win_comp_scroll(curwin);
8446 }
8447 /* If 'scroll' became invalid because of a side effect silently adjust
8448 * it. */
8449 else if (curwin->w_p_scr <= 0)
8450 curwin->w_p_scr = 1;
8451 else /* curwin->w_p_scr > curwin->w_height */
8452 curwin->w_p_scr = curwin->w_height;
8453 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008454 if (p_hi < 0)
8455 {
8456 errmsg = e_positive;
8457 p_hi = 0;
8458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459 if (p_report < 0)
8460 {
8461 errmsg = e_positive;
8462 p_report = 1;
8463 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008464 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465 {
8466 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8467 p_sj = Rows / 2;
8468 else
8469 {
8470 errmsg = e_scroll;
8471 p_sj = 1;
8472 }
8473 }
8474 if (p_so < 0 && full_screen)
8475 {
8476 errmsg = e_scroll;
8477 p_so = 0;
8478 }
8479 if (p_siso < 0 && full_screen)
8480 {
8481 errmsg = e_positive;
8482 p_siso = 0;
8483 }
8484#ifdef FEAT_CMDWIN
8485 if (p_cwh < 1)
8486 {
8487 errmsg = e_positive;
8488 p_cwh = 1;
8489 }
8490#endif
8491 if (p_ut < 0)
8492 {
8493 errmsg = e_positive;
8494 p_ut = 2000;
8495 }
8496 if (p_ss < 0)
8497 {
8498 errmsg = e_positive;
8499 p_ss = 0;
8500 }
8501
8502 /* May set global value for local option. */
8503 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8504 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8505
8506 options[opt_idx].flags |= P_WAS_SET;
8507
8508 comp_col(); /* in case 'columns' or 'ls' changed */
8509 if (curwin->w_curswant != MAXCOL)
8510 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8511 check_redraw(options[opt_idx].flags);
8512
8513 return errmsg;
8514}
8515
8516/*
8517 * Called after an option changed: check if something needs to be redrawn.
8518 */
8519 static void
8520check_redraw(flags)
8521 long_u flags;
8522{
8523 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8524 int clear = (flags & P_RCLR) == P_RCLR;
8525 int all = ((flags & P_RALL) == P_RALL || clear);
8526
8527#ifdef FEAT_WINDOWS
8528 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8529 status_redraw_all();
8530#endif
8531
8532 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8533 changed_window_setting();
8534 if (flags & P_RBUF)
8535 redraw_curbuf_later(NOT_VALID);
8536 if (clear)
8537 redraw_all_later(CLEAR);
8538 else if (all)
8539 redraw_all_later(NOT_VALID);
8540}
8541
8542/*
8543 * Find index for option 'arg'.
8544 * Return -1 if not found.
8545 */
8546 static int
8547findoption(arg)
8548 char_u *arg;
8549{
8550 int opt_idx;
8551 char *s, *p;
8552 static short quick_tab[27] = {0, 0}; /* quick access table */
8553 int is_term_opt;
8554
8555 /*
8556 * For first call: Initialize the quick-access table.
8557 * It contains the index for the first option that starts with a certain
8558 * letter. There are 26 letters, plus the first "t_" option.
8559 */
8560 if (quick_tab[1] == 0)
8561 {
8562 p = options[0].fullname;
8563 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8564 {
8565 if (s[0] != p[0])
8566 {
8567 if (s[0] == 't' && s[1] == '_')
8568 quick_tab[26] = opt_idx;
8569 else
8570 quick_tab[CharOrdLow(s[0])] = opt_idx;
8571 }
8572 p = s;
8573 }
8574 }
8575
8576 /*
8577 * Check for name starting with an illegal character.
8578 */
8579#ifdef EBCDIC
8580 if (!islower(arg[0]))
8581#else
8582 if (arg[0] < 'a' || arg[0] > 'z')
8583#endif
8584 return -1;
8585
8586 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8587 if (is_term_opt)
8588 opt_idx = quick_tab[26];
8589 else
8590 opt_idx = quick_tab[CharOrdLow(arg[0])];
8591 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8592 {
8593 if (STRCMP(arg, s) == 0) /* match full name */
8594 break;
8595 }
8596 if (s == NULL && !is_term_opt)
8597 {
8598 opt_idx = quick_tab[CharOrdLow(arg[0])];
8599 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8600 {
8601 s = options[opt_idx].shortname;
8602 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8603 break;
8604 s = NULL;
8605 }
8606 }
8607 if (s == NULL)
8608 opt_idx = -1;
8609 return opt_idx;
8610}
8611
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008612#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613/*
8614 * Get the value for an option.
8615 *
8616 * Returns:
8617 * Number or Toggle option: 1, *numval gets value.
8618 * String option: 0, *stringval gets allocated string.
8619 * Hidden Number or Toggle option: -1.
8620 * hidden String option: -2.
8621 * unknown option: -3.
8622 */
8623 int
8624get_option_value(name, numval, stringval, opt_flags)
8625 char_u *name;
8626 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008627 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 int opt_flags;
8629{
8630 int opt_idx;
8631 char_u *varp;
8632
8633 opt_idx = findoption(name);
8634 if (opt_idx < 0) /* unknown option */
8635 return -3;
8636
8637 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8638
8639 if (options[opt_idx].flags & P_STRING)
8640 {
8641 if (varp == NULL) /* hidden option */
8642 return -2;
8643 if (stringval != NULL)
8644 {
8645#ifdef FEAT_CRYPT
8646 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008647 if ((char_u **)varp == &curbuf->b_p_key
8648 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008649 *stringval = vim_strsave((char_u *)"*****");
8650 else
8651#endif
8652 *stringval = vim_strsave(*(char_u **)(varp));
8653 }
8654 return 0;
8655 }
8656
8657 if (varp == NULL) /* hidden option */
8658 return -1;
8659 if (options[opt_idx].flags & P_NUM)
8660 *numval = *(long *)varp;
8661 else
8662 {
8663 /* Special case: 'modified' is b_changed, but we also want to consider
8664 * it set when 'ff' or 'fenc' changed. */
8665 if ((int *)varp == &curbuf->b_changed)
8666 *numval = curbufIsChanged();
8667 else
8668 *numval = *(int *)varp;
8669 }
8670 return 1;
8671}
8672#endif
8673
8674/*
8675 * Set the value of option "name".
8676 * Use "string" for string options, use "number" for other options.
8677 */
8678 void
8679set_option_value(name, number, string, opt_flags)
8680 char_u *name;
8681 long number;
8682 char_u *string;
8683 int opt_flags; /* OPT_LOCAL or 0 (both) */
8684{
8685 int opt_idx;
8686 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008687 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688
8689 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008690 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 EMSG2(_("E355: Unknown option: %s"), name);
8692 else
8693 {
8694 flags = options[opt_idx].flags;
8695#ifdef HAVE_SANDBOX
8696 /* Disallow changing some options in the sandbox */
8697 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008698 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008700 return;
8701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008703 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 set_string_option(opt_idx, string, opt_flags);
8705 else
8706 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008707 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 if (varp != NULL) /* hidden option is not changed */
8709 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008710 if (number == 0 && string != NULL)
8711 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008712 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008713
8714 /* Either we are given a string or we are setting option
8715 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008716 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008717 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008718 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008719 {
8720 /* There's another character after zeros or the string
8721 * is empty. In both cases, we are trying to set a
8722 * num option using a string. */
8723 EMSG3(_("E521: Number required: &%s = '%s'"),
8724 name, string);
8725 return; /* do nothing as we hit an error */
8726
8727 }
8728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008730 (void)set_num_option(opt_idx, varp, number,
8731 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008733 (void)set_bool_option(opt_idx, varp, (int)number,
8734 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735 }
8736 }
8737 }
8738}
8739
8740/*
8741 * Get the terminal code for a terminal option.
8742 * Returns NULL when not found.
8743 */
8744 char_u *
8745get_term_code(tname)
8746 char_u *tname;
8747{
8748 int opt_idx;
8749 char_u *varp;
8750
8751 if (tname[0] != 't' || tname[1] != '_' ||
8752 tname[2] == NUL || tname[3] == NUL)
8753 return NULL;
8754 if ((opt_idx = findoption(tname)) >= 0)
8755 {
8756 varp = get_varp(&(options[opt_idx]));
8757 if (varp != NULL)
8758 varp = *(char_u **)(varp);
8759 return varp;
8760 }
8761 return find_termcode(tname + 2);
8762}
8763
8764 char_u *
8765get_highlight_default()
8766{
8767 int i;
8768
8769 i = findoption((char_u *)"hl");
8770 if (i >= 0)
8771 return options[i].def_val[VI_DEFAULT];
8772 return (char_u *)NULL;
8773}
8774
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008775#if defined(FEAT_MBYTE) || defined(PROTO)
8776 char_u *
8777get_encoding_default()
8778{
8779 int i;
8780
8781 i = findoption((char_u *)"enc");
8782 if (i >= 0)
8783 return options[i].def_val[VI_DEFAULT];
8784 return (char_u *)NULL;
8785}
8786#endif
8787
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788/*
8789 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8790 */
8791 static int
8792find_key_option(arg)
8793 char_u *arg;
8794{
8795 int key;
8796 int modifiers;
8797
8798 /*
8799 * Don't use get_special_key_code() for t_xx, we don't want it to call
8800 * add_termcap_entry().
8801 */
8802 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8803 key = TERMCAP2KEY(arg[2], arg[3]);
8804 else
8805 {
8806 --arg; /* put arg at the '<' */
8807 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008808 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 if (modifiers) /* can't handle modifiers here */
8810 key = 0;
8811 }
8812 return key;
8813}
8814
8815/*
8816 * if 'all' == 0: show changed options
8817 * if 'all' == 1: show all normal options
8818 * if 'all' == 2: show all terminal options
8819 */
8820 static void
8821showoptions(all, opt_flags)
8822 int all;
8823 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8824{
8825 struct vimoption *p;
8826 int col;
8827 int isterm;
8828 char_u *varp;
8829 struct vimoption **items;
8830 int item_count;
8831 int run;
8832 int row, rows;
8833 int cols;
8834 int i;
8835 int len;
8836
8837#define INC 20
8838#define GAP 3
8839
8840 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8841 PARAM_COUNT));
8842 if (items == NULL)
8843 return;
8844
8845 /* Highlight title */
8846 if (all == 2)
8847 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8848 else if (opt_flags & OPT_GLOBAL)
8849 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8850 else if (opt_flags & OPT_LOCAL)
8851 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8852 else
8853 MSG_PUTS_TITLE(_("\n--- Options ---"));
8854
8855 /*
8856 * do the loop two times:
8857 * 1. display the short items
8858 * 2. display the long items (only strings and numbers)
8859 */
8860 for (run = 1; run <= 2 && !got_int; ++run)
8861 {
8862 /*
8863 * collect the items in items[]
8864 */
8865 item_count = 0;
8866 for (p = &options[0]; p->fullname != NULL; p++)
8867 {
8868 varp = NULL;
8869 isterm = istermoption(p);
8870 if (opt_flags != 0)
8871 {
8872 if (p->indir != PV_NONE && !isterm)
8873 varp = get_varp_scope(p, opt_flags);
8874 }
8875 else
8876 varp = get_varp(p);
8877 if (varp != NULL
8878 && ((all == 2 && isterm)
8879 || (all == 1 && !isterm)
8880 || (all == 0 && !optval_default(p, varp))))
8881 {
8882 if (p->flags & P_BOOL)
8883 len = 1; /* a toggle option fits always */
8884 else
8885 {
8886 option_value2string(p, opt_flags);
8887 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8888 }
8889 if ((len <= INC - GAP && run == 1) ||
8890 (len > INC - GAP && run == 2))
8891 items[item_count++] = p;
8892 }
8893 }
8894
8895 /*
8896 * display the items
8897 */
8898 if (run == 1)
8899 {
8900 cols = (Columns + GAP - 3) / INC;
8901 if (cols == 0)
8902 cols = 1;
8903 rows = (item_count + cols - 1) / cols;
8904 }
8905 else /* run == 2 */
8906 rows = item_count;
8907 for (row = 0; row < rows && !got_int; ++row)
8908 {
8909 msg_putchar('\n'); /* go to next line */
8910 if (got_int) /* 'q' typed in more */
8911 break;
8912 col = 0;
8913 for (i = row; i < item_count; i += rows)
8914 {
8915 msg_col = col; /* make columns */
8916 showoneopt(items[i], opt_flags);
8917 col += INC;
8918 }
8919 out_flush();
8920 ui_breakcheck();
8921 }
8922 }
8923 vim_free(items);
8924}
8925
8926/*
8927 * Return TRUE if option "p" has its default value.
8928 */
8929 static int
8930optval_default(p, varp)
8931 struct vimoption *p;
8932 char_u *varp;
8933{
8934 int dvi;
8935
8936 if (varp == NULL)
8937 return TRUE; /* hidden option is always at default */
8938 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8939 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008940 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008942 /* the cast to long is required for Manx C, long_i is
8943 * needed for MSVC */
8944 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 /* P_STRING */
8946 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8947}
8948
8949/*
8950 * showoneopt: show the value of one option
8951 * must not be called with a hidden option!
8952 */
8953 static void
8954showoneopt(p, opt_flags)
8955 struct vimoption *p;
8956 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8957{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008958 char_u *varp;
8959 int save_silent = silent_mode;
8960
8961 silent_mode = FALSE;
8962 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963
8964 varp = get_varp_scope(p, opt_flags);
8965
8966 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8967 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8968 ? !curbufIsChanged() : !*(int *)varp))
8969 MSG_PUTS("no");
8970 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8971 MSG_PUTS("--");
8972 else
8973 MSG_PUTS(" ");
8974 MSG_PUTS(p->fullname);
8975 if (!(p->flags & P_BOOL))
8976 {
8977 msg_putchar('=');
8978 /* put value string in NameBuff */
8979 option_value2string(p, opt_flags);
8980 msg_outtrans(NameBuff);
8981 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008982
8983 silent_mode = save_silent;
8984 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985}
8986
8987/*
8988 * Write modified options as ":set" commands to a file.
8989 *
8990 * There are three values for "opt_flags":
8991 * OPT_GLOBAL: Write global option values and fresh values of
8992 * buffer-local options (used for start of a session
8993 * file).
8994 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8995 * curwin (used for a vimrc file).
8996 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8997 * and local values for window-local options of
8998 * curwin. Local values are also written when at the
8999 * default value, because a modeline or autocommand
9000 * may have set them when doing ":edit file" and the
9001 * user has set them back at the default or fresh
9002 * value.
9003 * When "local_only" is TRUE, don't write fresh
9004 * values, only local values (for ":mkview").
9005 * (fresh value = value used for a new buffer or window for a local option).
9006 *
9007 * Return FAIL on error, OK otherwise.
9008 */
9009 int
9010makeset(fd, opt_flags, local_only)
9011 FILE *fd;
9012 int opt_flags;
9013 int local_only;
9014{
9015 struct vimoption *p;
9016 char_u *varp; /* currently used value */
9017 char_u *varp_fresh; /* local value */
9018 char_u *varp_local = NULL; /* fresh value */
9019 char *cmd;
9020 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009021 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022
9023 /*
9024 * The options that don't have a default (terminal name, columns, lines)
9025 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009026 * Do the loop over "options[]" twice: once for options with the
9027 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009029 for (pri = 1; pri >= 0; --pri)
9030 {
9031 for (p = &options[0]; !istermoption(p); p++)
9032 if (!(p->flags & P_NO_MKRC)
9033 && !istermoption(p)
9034 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 {
9036 /* skip global option when only doing locals */
9037 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9038 continue;
9039
9040 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9041 * file, they are always buffer-specific. */
9042 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9043 continue;
9044
9045 /* Global values are only written when not at the default value. */
9046 varp = get_varp_scope(p, opt_flags);
9047 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9048 continue;
9049
9050 round = 2;
9051 if (p->indir != PV_NONE)
9052 {
9053 if (p->var == VAR_WIN)
9054 {
9055 /* skip window-local option when only doing globals */
9056 if (!(opt_flags & OPT_LOCAL))
9057 continue;
9058 /* When fresh value of window-local option is not at the
9059 * default, need to write it too. */
9060 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9061 {
9062 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9063 if (!optval_default(p, varp_fresh))
9064 {
9065 round = 1;
9066 varp_local = varp;
9067 varp = varp_fresh;
9068 }
9069 }
9070 }
9071 }
9072
9073 /* Round 1: fresh value for window-local options.
9074 * Round 2: other values */
9075 for ( ; round <= 2; varp = varp_local, ++round)
9076 {
9077 if (round == 1 || (opt_flags & OPT_GLOBAL))
9078 cmd = "set";
9079 else
9080 cmd = "setlocal";
9081
9082 if (p->flags & P_BOOL)
9083 {
9084 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9085 return FAIL;
9086 }
9087 else if (p->flags & P_NUM)
9088 {
9089 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9090 return FAIL;
9091 }
9092 else /* P_STRING */
9093 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009094#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9095 int do_endif = FALSE;
9096
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097 /* Don't set 'syntax' and 'filetype' again if the value is
9098 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009099 if (
9100# if defined(FEAT_SYN_HL)
9101 p->indir == PV_SYN
9102# if defined(FEAT_AUTOCMD)
9103 ||
9104# endif
9105# endif
9106# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009107 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009108# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009109 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110 {
9111 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9112 *(char_u **)(varp)) < 0
9113 || put_eol(fd) < 0)
9114 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009115 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9119 (p->flags & P_EXPAND) != 0) == FAIL)
9120 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009121#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9122 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 {
9124 if (put_line(fd, "endif") == FAIL)
9125 return FAIL;
9126 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 }
9129 }
9130 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 return OK;
9133}
9134
9135#if defined(FEAT_FOLDING) || defined(PROTO)
9136/*
9137 * Generate set commands for the local fold options only. Used when
9138 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9139 */
9140 int
9141makefoldset(fd)
9142 FILE *fd;
9143{
9144 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9145# ifdef FEAT_EVAL
9146 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9147 == FAIL
9148# endif
9149 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9150 == FAIL
9151 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9152 == FAIL
9153 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9154 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9155 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9156 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9157 )
9158 return FAIL;
9159
9160 return OK;
9161}
9162#endif
9163
9164 static int
9165put_setstring(fd, cmd, name, valuep, expand)
9166 FILE *fd;
9167 char *cmd;
9168 char *name;
9169 char_u **valuep;
9170 int expand;
9171{
9172 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009173 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174
9175 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9176 return FAIL;
9177 if (*valuep != NULL)
9178 {
9179 /* Output 'pastetoggle' as key names. For other
9180 * options some characters have to be escaped with
9181 * CTRL-V or backslash */
9182 if (valuep == &p_pt)
9183 {
9184 s = *valuep;
9185 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009186 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 return FAIL;
9188 }
9189 else if (expand)
9190 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009191 buf = alloc(MAXPATHL);
9192 if (buf == NULL)
9193 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9195 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009196 {
9197 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009199 }
9200 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201 }
9202 else if (put_escstr(fd, *valuep, 2) == FAIL)
9203 return FAIL;
9204 }
9205 if (put_eol(fd) < 0)
9206 return FAIL;
9207 return OK;
9208}
9209
9210 static int
9211put_setnum(fd, cmd, name, valuep)
9212 FILE *fd;
9213 char *cmd;
9214 char *name;
9215 long *valuep;
9216{
9217 long wc;
9218
9219 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9220 return FAIL;
9221 if (wc_use_keyname((char_u *)valuep, &wc))
9222 {
9223 /* print 'wildchar' and 'wildcharm' as a key name */
9224 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9225 return FAIL;
9226 }
9227 else if (fprintf(fd, "%ld", *valuep) < 0)
9228 return FAIL;
9229 if (put_eol(fd) < 0)
9230 return FAIL;
9231 return OK;
9232}
9233
9234 static int
9235put_setbool(fd, cmd, name, value)
9236 FILE *fd;
9237 char *cmd;
9238 char *name;
9239 int value;
9240{
Bram Moolenaar893de922007-10-02 18:40:57 +00009241 if (value < 0) /* global/local option using global value */
9242 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9244 || put_eol(fd) < 0)
9245 return FAIL;
9246 return OK;
9247}
9248
9249/*
9250 * Clear all the terminal options.
9251 * If the option has been allocated, free the memory.
9252 * Terminal options are never hidden or indirect.
9253 */
9254 void
9255clear_termoptions()
9256{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009257 /*
9258 * Reset a few things before clearing the old options. This may cause
9259 * outputting a few things that the terminal doesn't understand, but the
9260 * screen will be cleared later, so this is OK.
9261 */
9262#ifdef FEAT_MOUSE_TTY
9263 mch_setmouse(FALSE); /* switch mouse off */
9264#endif
9265#ifdef FEAT_TITLE
9266 mch_restore_title(3); /* restore window titles */
9267#endif
9268#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9269 /* When starting the GUI close the display opened for the clipboard.
9270 * After restoring the title, because that will need the display. */
9271 if (gui.starting)
9272 clear_xterm_clip();
9273#endif
9274#ifdef WIN3264
9275 /*
9276 * Check if this is allowed now.
9277 */
9278 if (can_end_termcap_mode(FALSE) == TRUE)
9279#endif
9280 stoptermcap(); /* stop termcap mode */
9281
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009282 free_termoptions();
9283}
9284
9285 void
9286free_termoptions()
9287{
9288 struct vimoption *p;
9289
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 for (p = &options[0]; p->fullname != NULL; p++)
9291 if (istermoption(p))
9292 {
9293 if (p->flags & P_ALLOCED)
9294 free_string_option(*(char_u **)(p->var));
9295 if (p->flags & P_DEF_ALLOCED)
9296 free_string_option(p->def_val[VI_DEFAULT]);
9297 *(char_u **)(p->var) = empty_option;
9298 p->def_val[VI_DEFAULT] = empty_option;
9299 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9300 }
9301 clear_termcodes();
9302}
9303
9304/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009305 * Free the string for one term option, if it was allocated.
9306 * Set the string to empty_option and clear allocated flag.
9307 * "var" points to the option value.
9308 */
9309 void
9310free_one_termoption(var)
9311 char_u *var;
9312{
9313 struct vimoption *p;
9314
9315 for (p = &options[0]; p->fullname != NULL; p++)
9316 if (p->var == var)
9317 {
9318 if (p->flags & P_ALLOCED)
9319 free_string_option(*(char_u **)(p->var));
9320 *(char_u **)(p->var) = empty_option;
9321 p->flags &= ~P_ALLOCED;
9322 break;
9323 }
9324}
9325
9326/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 * Set the terminal option defaults to the current value.
9328 * Used after setting the terminal name.
9329 */
9330 void
9331set_term_defaults()
9332{
9333 struct vimoption *p;
9334
9335 for (p = &options[0]; p->fullname != NULL; p++)
9336 {
9337 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9338 {
9339 if (p->flags & P_DEF_ALLOCED)
9340 {
9341 free_string_option(p->def_val[VI_DEFAULT]);
9342 p->flags &= ~P_DEF_ALLOCED;
9343 }
9344 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9345 if (p->flags & P_ALLOCED)
9346 {
9347 p->flags |= P_DEF_ALLOCED;
9348 p->flags &= ~P_ALLOCED; /* don't free the value now */
9349 }
9350 }
9351 }
9352}
9353
9354/*
9355 * return TRUE if 'p' starts with 't_'
9356 */
9357 static int
9358istermoption(p)
9359 struct vimoption *p;
9360{
9361 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9362}
9363
9364/*
9365 * Compute columns for ruler and shown command. 'sc_col' is also used to
9366 * decide what the maximum length of a message on the status line can be.
9367 * If there is a status line for the last window, 'sc_col' is independent
9368 * of 'ru_col'.
9369 */
9370
9371#define COL_RULER 17 /* columns needed by standard ruler */
9372
9373 void
9374comp_col()
9375{
9376#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9377 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9378
9379 sc_col = 0;
9380 ru_col = 0;
9381 if (p_ru)
9382 {
9383#ifdef FEAT_STL_OPT
9384 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9385#else
9386 ru_col = COL_RULER + 1;
9387#endif
9388 /* no last status line, adjust sc_col */
9389 if (!last_has_status)
9390 sc_col = ru_col;
9391 }
9392 if (p_sc)
9393 {
9394 sc_col += SHOWCMD_COLS;
9395 if (!p_ru || last_has_status) /* no need for separating space */
9396 ++sc_col;
9397 }
9398 sc_col = Columns - sc_col;
9399 ru_col = Columns - ru_col;
9400 if (sc_col <= 0) /* screen too narrow, will become a mess */
9401 sc_col = 1;
9402 if (ru_col <= 0)
9403 ru_col = 1;
9404#else
9405 sc_col = Columns;
9406 ru_col = Columns;
9407#endif
9408}
9409
9410/*
9411 * Get pointer to option variable, depending on local or global scope.
9412 */
9413 static char_u *
9414get_varp_scope(p, opt_flags)
9415 struct vimoption *p;
9416 int opt_flags;
9417{
9418 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9419 {
9420 if (p->var == VAR_WIN)
9421 return (char_u *)GLOBAL_WO(get_varp(p));
9422 return p->var;
9423 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009424 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 {
9426 switch ((int)p->indir)
9427 {
9428#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009429 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9430 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9431 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009433 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9434 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9435 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009436 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009437 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009439 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9440 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441#endif
9442#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009443 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9444 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009445#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009446#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9447 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9448#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009449#if defined(FEAT_CRYPT)
9450 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9451#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009452#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009453 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009455 }
9456 return NULL; /* "cannot happen" */
9457 }
9458 return get_varp(p);
9459}
9460
9461/*
9462 * Get pointer to option variable.
9463 */
9464 static char_u *
9465get_varp(p)
9466 struct vimoption *p;
9467{
9468 /* hidden option, always return NULL */
9469 if (p->var == NULL)
9470 return NULL;
9471
9472 switch ((int)p->indir)
9473 {
9474 case PV_NONE: return p->var;
9475
9476 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009477 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009479 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009481 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009483 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009485 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9487#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009488 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009490 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009491 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9492#endif
9493#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009494 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009496 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9498#endif
9499#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009500 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009502 case PV_GP: return *curbuf->b_p_gp != NUL
9503 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9504 case PV_MP: return *curbuf->b_p_mp != NUL
9505 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009506#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009507#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9508 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9509 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9510#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009511#if defined(FEAT_CRYPT)
9512 case PV_CM: return *curbuf->b_p_cm != NUL
9513 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9514#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009515#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009516 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009517 ? (char_u *)&(curwin->w_p_stl) : p->var;
9518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009519
9520#ifdef FEAT_ARABIC
9521 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9522#endif
9523 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009524#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009525 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9526#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009527#ifdef FEAT_SYN_HL
9528 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9529 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009530 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009532#ifdef FEAT_DIFF
9533 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9534#endif
9535#ifdef FEAT_FOLDING
9536 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9537 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9538 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9539 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9540 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9541 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9542 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9543# ifdef FEAT_EVAL
9544 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9545 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9546# endif
9547 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9548#endif
9549 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009550 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009551#ifdef FEAT_LINEBREAK
9552 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9553#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009554#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9556#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009557#ifdef FEAT_VERTSPLIT
9558 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9561 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9562#endif
9563#ifdef FEAT_RIGHTLEFT
9564 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9565 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9566#endif
9567 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9568 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9569#ifdef FEAT_LINEBREAK
9570 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9571#endif
9572#ifdef FEAT_SCROLLBIND
9573 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9574#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009575#ifdef FEAT_CURSORBIND
9576 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9577#endif
9578#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009579 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
9580 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582
9583 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9584 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9585#ifdef FEAT_MBYTE
9586 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9587#endif
9588#if defined(FEAT_QUICKFIX)
9589 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9590 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9591#endif
9592 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9593 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9594#ifdef FEAT_CINDENT
9595 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9596 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9597 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9598#endif
9599#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9600 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9601#endif
9602#ifdef FEAT_COMMENTS
9603 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9604#endif
9605#ifdef FEAT_FOLDING
9606 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9607#endif
9608#ifdef FEAT_INS_EXPAND
9609 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9610#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009611#ifdef FEAT_COMPL_FUNC
9612 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009613 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9616 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9617#ifdef FEAT_MBYTE
9618 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9619#endif
9620 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9621#ifdef FEAT_AUTOCMD
9622 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9623#endif
9624 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009625 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009626 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9627 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9628 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9629 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9630#ifdef FEAT_FIND_ID
9631# ifdef FEAT_EVAL
9632 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9633# endif
9634#endif
9635#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9636 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9637 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9638#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009639#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009640 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642#ifdef FEAT_CRYPT
9643 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9644#endif
9645#ifdef FEAT_LISP
9646 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9647#endif
9648 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9649 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9650 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9651 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9652 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009654#ifdef FEAT_TEXTOBJ
9655 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9658#ifdef FEAT_SMARTINDENT
9659 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9660#endif
9661#ifndef SHORT_FNAME
9662 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9663#endif
9664 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9665#ifdef FEAT_SEARCHPATH
9666 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9667#endif
9668 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9669#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009670 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009671 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9672#endif
9673#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009674 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9675 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9676 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009677#endif
9678 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9679 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9680 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9681 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009682#ifdef FEAT_PERSISTENT_UNDO
9683 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009685 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9686#ifdef FEAT_KEYMAP
9687 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9688#endif
9689 default: EMSG(_("E356: get_varp ERROR"));
9690 }
9691 /* always return a valid pointer to avoid a crash! */
9692 return (char_u *)&(curbuf->b_p_wm);
9693}
9694
9695/*
9696 * Get the value of 'equalprg', either the buffer-local one or the global one.
9697 */
9698 char_u *
9699get_equalprg()
9700{
9701 if (*curbuf->b_p_ep == NUL)
9702 return p_ep;
9703 return curbuf->b_p_ep;
9704}
9705
9706#if defined(FEAT_WINDOWS) || defined(PROTO)
9707/*
9708 * Copy options from one window to another.
9709 * Used when splitting a window.
9710 */
9711 void
9712win_copy_options(wp_from, wp_to)
9713 win_T *wp_from;
9714 win_T *wp_to;
9715{
9716 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9717 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9718# ifdef FEAT_RIGHTLEFT
9719# ifdef FEAT_FKMAP
9720 /* Is this right? */
9721 wp_to->w_farsi = wp_from->w_farsi;
9722# endif
9723# endif
9724}
9725#endif
9726
9727/*
9728 * Copy the options from one winopt_T to another.
9729 * Doesn't free the old option values in "to", use clear_winopt() for that.
9730 * The 'scroll' option is not copied, because it depends on the window height.
9731 * The 'previewwindow' option is reset, there can be only one preview window.
9732 */
9733 void
9734copy_winopt(from, to)
9735 winopt_T *from;
9736 winopt_T *to;
9737{
9738#ifdef FEAT_ARABIC
9739 to->wo_arab = from->wo_arab;
9740#endif
9741 to->wo_list = from->wo_list;
9742 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009743 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009744#ifdef FEAT_LINEBREAK
9745 to->wo_nuw = from->wo_nuw;
9746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747#ifdef FEAT_RIGHTLEFT
9748 to->wo_rl = from->wo_rl;
9749 to->wo_rlc = vim_strsave(from->wo_rlc);
9750#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009751#ifdef FEAT_STL_OPT
9752 to->wo_stl = vim_strsave(from->wo_stl);
9753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754 to->wo_wrap = from->wo_wrap;
9755#ifdef FEAT_LINEBREAK
9756 to->wo_lbr = from->wo_lbr;
9757#endif
9758#ifdef FEAT_SCROLLBIND
9759 to->wo_scb = from->wo_scb;
9760#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +01009761#ifdef FEAT_CURSORBIND
9762 to->wo_crb = from->wo_crb;
9763#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009764#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009765 to->wo_spell = from->wo_spell;
9766#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009767#ifdef FEAT_SYN_HL
9768 to->wo_cuc = from->wo_cuc;
9769 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009770 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772#ifdef FEAT_DIFF
9773 to->wo_diff = from->wo_diff;
9774#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009775#ifdef FEAT_CONCEAL
9776 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +02009777 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009779#ifdef FEAT_FOLDING
9780 to->wo_fdc = from->wo_fdc;
9781 to->wo_fen = from->wo_fen;
9782 to->wo_fdi = vim_strsave(from->wo_fdi);
9783 to->wo_fml = from->wo_fml;
9784 to->wo_fdl = from->wo_fdl;
9785 to->wo_fdm = vim_strsave(from->wo_fdm);
9786 to->wo_fdn = from->wo_fdn;
9787# ifdef FEAT_EVAL
9788 to->wo_fde = vim_strsave(from->wo_fde);
9789 to->wo_fdt = vim_strsave(from->wo_fdt);
9790# endif
9791 to->wo_fmr = vim_strsave(from->wo_fmr);
9792#endif
9793 check_winopt(to); /* don't want NULL pointers */
9794}
9795
9796/*
9797 * Check string options in a window for a NULL value.
9798 */
9799 void
9800check_win_options(win)
9801 win_T *win;
9802{
9803 check_winopt(&win->w_onebuf_opt);
9804 check_winopt(&win->w_allbuf_opt);
9805}
9806
9807/*
9808 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9809 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 void
9811check_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 check_string_option(&wop->wo_fdi);
9816 check_string_option(&wop->wo_fdm);
9817# ifdef FEAT_EVAL
9818 check_string_option(&wop->wo_fde);
9819 check_string_option(&wop->wo_fdt);
9820# endif
9821 check_string_option(&wop->wo_fmr);
9822#endif
9823#ifdef FEAT_RIGHTLEFT
9824 check_string_option(&wop->wo_rlc);
9825#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009826#ifdef FEAT_STL_OPT
9827 check_string_option(&wop->wo_stl);
9828#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009829#ifdef FEAT_SYN_HL
9830 check_string_option(&wop->wo_cc);
9831#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009832#ifdef FEAT_CONCEAL
9833 check_string_option(&wop->wo_cocu);
9834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009835}
9836
9837/*
9838 * Free the allocated memory inside a winopt_T.
9839 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840 void
9841clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009842 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843{
9844#ifdef FEAT_FOLDING
9845 clear_string_option(&wop->wo_fdi);
9846 clear_string_option(&wop->wo_fdm);
9847# ifdef FEAT_EVAL
9848 clear_string_option(&wop->wo_fde);
9849 clear_string_option(&wop->wo_fdt);
9850# endif
9851 clear_string_option(&wop->wo_fmr);
9852#endif
9853#ifdef FEAT_RIGHTLEFT
9854 clear_string_option(&wop->wo_rlc);
9855#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009856#ifdef FEAT_STL_OPT
9857 clear_string_option(&wop->wo_stl);
9858#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009859#ifdef FEAT_SYN_HL
9860 clear_string_option(&wop->wo_cc);
9861#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009862#ifdef FEAT_CONCEAL
9863 clear_string_option(&wop->wo_cocu);
9864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865}
9866
9867/*
9868 * Copy global option values to local options for one buffer.
9869 * Used when creating a new buffer and sometimes when entering a buffer.
9870 * flags:
9871 * BCO_ENTER We will enter the buf buffer.
9872 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9873 * appropriate.
9874 * BCO_NOHELP Don't copy the values to a help buffer.
9875 */
9876 void
9877buf_copy_options(buf, flags)
9878 buf_T *buf;
9879 int flags;
9880{
9881 int should_copy = TRUE;
9882 char_u *save_p_isk = NULL; /* init for GCC */
9883 int dont_do_help;
9884 int did_isk = FALSE;
9885
9886 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009887 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 */
9889 if (buf == NULL || !buf_valid(buf))
9890 return;
9891
9892 /*
9893 * Skip this when the option defaults have not been set yet. Happens when
9894 * main() allocates the first buffer.
9895 */
9896 if (p_cpo != NULL)
9897 {
9898 /*
9899 * Always copy when entering and 'cpo' contains 'S'.
9900 * Don't copy when already initialized.
9901 * Don't copy when 'cpo' contains 's' and not entering.
9902 * 'S' BCO_ENTER initialized 's' should_copy
9903 * yes yes X X TRUE
9904 * yes no yes X FALSE
9905 * no X yes X FALSE
9906 * X no no yes FALSE
9907 * X no no no TRUE
9908 * no yes no X TRUE
9909 */
9910 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9911 && (buf->b_p_initialized
9912 || (!(flags & BCO_ENTER)
9913 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9914 should_copy = FALSE;
9915
9916 if (should_copy || (flags & BCO_ALWAYS))
9917 {
9918 /* Don't copy the options specific to a help buffer when
9919 * BCO_NOHELP is given or the options were initialized already
9920 * (jumping back to a help file with CTRL-T or CTRL-O) */
9921 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9922 || buf->b_p_initialized;
9923 if (dont_do_help) /* don't free b_p_isk */
9924 {
9925 save_p_isk = buf->b_p_isk;
9926 buf->b_p_isk = NULL;
9927 }
9928 /*
9929 * Always free the allocated strings.
9930 * If not already initialized, set 'readonly' and copy 'fileformat'.
9931 */
9932 if (!buf->b_p_initialized)
9933 {
9934 free_buf_options(buf, TRUE);
9935 buf->b_p_ro = FALSE; /* don't copy readonly */
9936 buf->b_p_tx = p_tx;
9937#ifdef FEAT_MBYTE
9938 buf->b_p_fenc = vim_strsave(p_fenc);
9939#endif
9940 buf->b_p_ff = vim_strsave(p_ff);
9941#if defined(FEAT_QUICKFIX)
9942 buf->b_p_bh = empty_option;
9943 buf->b_p_bt = empty_option;
9944#endif
9945 }
9946 else
9947 free_buf_options(buf, FALSE);
9948
9949 buf->b_p_ai = p_ai;
9950 buf->b_p_ai_nopaste = p_ai_nopaste;
9951 buf->b_p_sw = p_sw;
9952 buf->b_p_tw = p_tw;
9953 buf->b_p_tw_nopaste = p_tw_nopaste;
9954 buf->b_p_tw_nobin = p_tw_nobin;
9955 buf->b_p_wm = p_wm;
9956 buf->b_p_wm_nopaste = p_wm_nopaste;
9957 buf->b_p_wm_nobin = p_wm_nobin;
9958 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009959#ifdef FEAT_MBYTE
9960 buf->b_p_bomb = p_bomb;
9961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962 buf->b_p_et = p_et;
9963 buf->b_p_et_nobin = p_et_nobin;
9964 buf->b_p_ml = p_ml;
9965 buf->b_p_ml_nobin = p_ml_nobin;
9966 buf->b_p_inf = p_inf;
9967 buf->b_p_swf = p_swf;
9968#ifdef FEAT_INS_EXPAND
9969 buf->b_p_cpt = vim_strsave(p_cpt);
9970#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009971#ifdef FEAT_COMPL_FUNC
9972 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009973 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 buf->b_p_sts = p_sts;
9976 buf->b_p_sts_nopaste = p_sts_nopaste;
9977#ifndef SHORT_FNAME
9978 buf->b_p_sn = p_sn;
9979#endif
9980#ifdef FEAT_COMMENTS
9981 buf->b_p_com = vim_strsave(p_com);
9982#endif
9983#ifdef FEAT_FOLDING
9984 buf->b_p_cms = vim_strsave(p_cms);
9985#endif
9986 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009987 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988 buf->b_p_nf = vim_strsave(p_nf);
9989 buf->b_p_mps = vim_strsave(p_mps);
9990#ifdef FEAT_SMARTINDENT
9991 buf->b_p_si = p_si;
9992#endif
9993 buf->b_p_ci = p_ci;
9994#ifdef FEAT_CINDENT
9995 buf->b_p_cin = p_cin;
9996 buf->b_p_cink = vim_strsave(p_cink);
9997 buf->b_p_cino = vim_strsave(p_cino);
9998#endif
9999#ifdef FEAT_AUTOCMD
10000 /* Don't copy 'filetype', it must be detected */
10001 buf->b_p_ft = empty_option;
10002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 buf->b_p_pi = p_pi;
10004#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10005 buf->b_p_cinw = vim_strsave(p_cinw);
10006#endif
10007#ifdef FEAT_LISP
10008 buf->b_p_lisp = p_lisp;
10009#endif
10010#ifdef FEAT_SYN_HL
10011 /* Don't copy 'syntax', it must be set */
10012 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010013 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010014#endif
10015#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010016 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010017 (void)compile_cap_prog(&buf->b_s);
10018 buf->b_s.b_p_spf = vim_strsave(p_spf);
10019 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010020#endif
10021#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10022 buf->b_p_inde = vim_strsave(p_inde);
10023 buf->b_p_indk = vim_strsave(p_indk);
10024#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010025#if defined(FEAT_EVAL)
10026 buf->b_p_fex = vim_strsave(p_fex);
10027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028#ifdef FEAT_CRYPT
10029 buf->b_p_key = vim_strsave(p_key);
10030#endif
10031#ifdef FEAT_SEARCHPATH
10032 buf->b_p_sua = vim_strsave(p_sua);
10033#endif
10034#ifdef FEAT_KEYMAP
10035 buf->b_p_keymap = vim_strsave(p_keymap);
10036 buf->b_kmap_state |= KEYMAP_INIT;
10037#endif
10038 /* This isn't really an option, but copying the langmap and IME
10039 * state from the current buffer is better than resetting it. */
10040 buf->b_p_iminsert = p_iminsert;
10041 buf->b_p_imsearch = p_imsearch;
10042
10043 /* options that are normally global but also have a local value
10044 * are not copied, start using the global value */
10045 buf->b_p_ar = -1;
10046#ifdef FEAT_QUICKFIX
10047 buf->b_p_gp = empty_option;
10048 buf->b_p_mp = empty_option;
10049 buf->b_p_efm = empty_option;
10050#endif
10051 buf->b_p_ep = empty_option;
10052 buf->b_p_kp = empty_option;
10053 buf->b_p_path = empty_option;
10054 buf->b_p_tags = empty_option;
10055#ifdef FEAT_FIND_ID
10056 buf->b_p_def = empty_option;
10057 buf->b_p_inc = empty_option;
10058# ifdef FEAT_EVAL
10059 buf->b_p_inex = vim_strsave(p_inex);
10060# endif
10061#endif
10062#ifdef FEAT_INS_EXPAND
10063 buf->b_p_dict = empty_option;
10064 buf->b_p_tsr = empty_option;
10065#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010066#ifdef FEAT_TEXTOBJ
10067 buf->b_p_qe = vim_strsave(p_qe);
10068#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010069#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10070 buf->b_p_bexpr = empty_option;
10071#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010072#if defined(FEAT_CRYPT)
10073 buf->b_p_cm = empty_option;
10074#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010075#ifdef FEAT_PERSISTENT_UNDO
10076 buf->b_p_udf = p_udf;
10077#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078
10079 /*
10080 * Don't copy the options set by ex_help(), use the saved values,
10081 * when going from a help buffer to a non-help buffer.
10082 * Don't touch these at all when BCO_NOHELP is used and going from
10083 * or to a help buffer.
10084 */
10085 if (dont_do_help)
10086 buf->b_p_isk = save_p_isk;
10087 else
10088 {
10089 buf->b_p_isk = vim_strsave(p_isk);
10090 did_isk = TRUE;
10091 buf->b_p_ts = p_ts;
10092 buf->b_help = FALSE;
10093#ifdef FEAT_QUICKFIX
10094 if (buf->b_p_bt[0] == 'h')
10095 clear_string_option(&buf->b_p_bt);
10096#endif
10097 buf->b_p_ma = p_ma;
10098 }
10099 }
10100
10101 /*
10102 * When the options should be copied (ignoring BCO_ALWAYS), set the
10103 * flag that indicates that the options have been initialized.
10104 */
10105 if (should_copy)
10106 buf->b_p_initialized = TRUE;
10107 }
10108
10109 check_buf_options(buf); /* make sure we don't have NULLs */
10110 if (did_isk)
10111 (void)buf_init_chartab(buf, FALSE);
10112}
10113
10114/*
10115 * Reset the 'modifiable' option and its default value.
10116 */
10117 void
10118reset_modifiable()
10119{
10120 int opt_idx;
10121
10122 curbuf->b_p_ma = FALSE;
10123 p_ma = FALSE;
10124 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010125 if (opt_idx >= 0)
10126 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127}
10128
10129/*
10130 * Set the global value for 'iminsert' to the local value.
10131 */
10132 void
10133set_iminsert_global()
10134{
10135 p_iminsert = curbuf->b_p_iminsert;
10136}
10137
10138/*
10139 * Set the global value for 'imsearch' to the local value.
10140 */
10141 void
10142set_imsearch_global()
10143{
10144 p_imsearch = curbuf->b_p_imsearch;
10145}
10146
10147#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10148static int expand_option_idx = -1;
10149static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10150static int expand_option_flags = 0;
10151
10152 void
10153set_context_in_set_cmd(xp, arg, opt_flags)
10154 expand_T *xp;
10155 char_u *arg;
10156 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10157{
10158 int nextchar;
10159 long_u flags = 0; /* init for GCC */
10160 int opt_idx = 0; /* init for GCC */
10161 char_u *p;
10162 char_u *s;
10163 int is_term_option = FALSE;
10164 int key;
10165
10166 expand_option_flags = opt_flags;
10167
10168 xp->xp_context = EXPAND_SETTINGS;
10169 if (*arg == NUL)
10170 {
10171 xp->xp_pattern = arg;
10172 return;
10173 }
10174 p = arg + STRLEN(arg) - 1;
10175 if (*p == ' ' && *(p - 1) != '\\')
10176 {
10177 xp->xp_pattern = p + 1;
10178 return;
10179 }
10180 while (p > arg)
10181 {
10182 s = p;
10183 /* count number of backslashes before ' ' or ',' */
10184 if (*p == ' ' || *p == ',')
10185 {
10186 while (s > arg && *(s - 1) == '\\')
10187 --s;
10188 }
10189 /* break at a space with an even number of backslashes */
10190 if (*p == ' ' && ((p - s) & 1) == 0)
10191 {
10192 ++p;
10193 break;
10194 }
10195 --p;
10196 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010197 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 {
10199 xp->xp_context = EXPAND_BOOL_SETTINGS;
10200 p += 2;
10201 }
10202 if (STRNCMP(p, "inv", 3) == 0)
10203 {
10204 xp->xp_context = EXPAND_BOOL_SETTINGS;
10205 p += 3;
10206 }
10207 xp->xp_pattern = arg = p;
10208 if (*arg == '<')
10209 {
10210 while (*p != '>')
10211 if (*p++ == NUL) /* expand terminal option name */
10212 return;
10213 key = get_special_key_code(arg + 1);
10214 if (key == 0) /* unknown name */
10215 {
10216 xp->xp_context = EXPAND_NOTHING;
10217 return;
10218 }
10219 nextchar = *++p;
10220 is_term_option = TRUE;
10221 expand_option_name[2] = KEY2TERMCAP0(key);
10222 expand_option_name[3] = KEY2TERMCAP1(key);
10223 }
10224 else
10225 {
10226 if (p[0] == 't' && p[1] == '_')
10227 {
10228 p += 2;
10229 if (*p != NUL)
10230 ++p;
10231 if (*p == NUL)
10232 return; /* expand option name */
10233 nextchar = *++p;
10234 is_term_option = TRUE;
10235 expand_option_name[2] = p[-2];
10236 expand_option_name[3] = p[-1];
10237 }
10238 else
10239 {
10240 /* Allow * wildcard */
10241 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10242 p++;
10243 if (*p == NUL)
10244 return;
10245 nextchar = *p;
10246 *p = NUL;
10247 opt_idx = findoption(arg);
10248 *p = nextchar;
10249 if (opt_idx == -1 || options[opt_idx].var == NULL)
10250 {
10251 xp->xp_context = EXPAND_NOTHING;
10252 return;
10253 }
10254 flags = options[opt_idx].flags;
10255 if (flags & P_BOOL)
10256 {
10257 xp->xp_context = EXPAND_NOTHING;
10258 return;
10259 }
10260 }
10261 }
10262 /* handle "-=" and "+=" */
10263 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10264 {
10265 ++p;
10266 nextchar = '=';
10267 }
10268 if ((nextchar != '=' && nextchar != ':')
10269 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10270 {
10271 xp->xp_context = EXPAND_UNSUCCESSFUL;
10272 return;
10273 }
10274 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10275 {
10276 xp->xp_context = EXPAND_OLD_SETTING;
10277 if (is_term_option)
10278 expand_option_idx = -1;
10279 else
10280 expand_option_idx = opt_idx;
10281 xp->xp_pattern = p + 1;
10282 return;
10283 }
10284 xp->xp_context = EXPAND_NOTHING;
10285 if (is_term_option || (flags & P_NUM))
10286 return;
10287
10288 xp->xp_pattern = p + 1;
10289
10290 if (flags & P_EXPAND)
10291 {
10292 p = options[opt_idx].var;
10293 if (p == (char_u *)&p_bdir
10294 || p == (char_u *)&p_dir
10295 || p == (char_u *)&p_path
10296 || p == (char_u *)&p_rtp
10297#ifdef FEAT_SEARCHPATH
10298 || p == (char_u *)&p_cdpath
10299#endif
10300#ifdef FEAT_SESSION
10301 || p == (char_u *)&p_vdir
10302#endif
10303 )
10304 {
10305 xp->xp_context = EXPAND_DIRECTORIES;
10306 if (p == (char_u *)&p_path
10307#ifdef FEAT_SEARCHPATH
10308 || p == (char_u *)&p_cdpath
10309#endif
10310 )
10311 xp->xp_backslash = XP_BS_THREE;
10312 else
10313 xp->xp_backslash = XP_BS_ONE;
10314 }
10315 else
10316 {
10317 xp->xp_context = EXPAND_FILES;
10318 /* for 'tags' need three backslashes for a space */
10319 if (p == (char_u *)&p_tags)
10320 xp->xp_backslash = XP_BS_THREE;
10321 else
10322 xp->xp_backslash = XP_BS_ONE;
10323 }
10324 }
10325
10326 /* For an option that is a list of file names, find the start of the
10327 * last file name. */
10328 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10329 {
10330 /* count number of backslashes before ' ' or ',' */
10331 if (*p == ' ' || *p == ',')
10332 {
10333 s = p;
10334 while (s > xp->xp_pattern && *(s - 1) == '\\')
10335 --s;
10336 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10337 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10338 {
10339 xp->xp_pattern = p + 1;
10340 break;
10341 }
10342 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010343
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010344#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010345 /* for 'spellsuggest' start at "file:" */
10346 if (options[opt_idx].var == (char_u *)&p_sps
10347 && STRNCMP(p, "file:", 5) == 0)
10348 {
10349 xp->xp_pattern = p + 5;
10350 break;
10351 }
10352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353 }
10354
10355 return;
10356}
10357
10358 int
10359ExpandSettings(xp, regmatch, num_file, file)
10360 expand_T *xp;
10361 regmatch_T *regmatch;
10362 int *num_file;
10363 char_u ***file;
10364{
10365 int num_normal = 0; /* Nr of matching non-term-code settings */
10366 int num_term = 0; /* Nr of matching terminal code settings */
10367 int opt_idx;
10368 int match;
10369 int count = 0;
10370 char_u *str;
10371 int loop;
10372 int is_term_opt;
10373 char_u name_buf[MAX_KEY_NAME_LEN];
10374 static char *(names[]) = {"all", "termcap"};
10375 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10376
10377 /* do this loop twice:
10378 * loop == 0: count the number of matching options
10379 * loop == 1: copy the matching options into allocated memory
10380 */
10381 for (loop = 0; loop <= 1; ++loop)
10382 {
10383 regmatch->rm_ic = ic;
10384 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10385 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010386 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10387 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10389 {
10390 if (loop == 0)
10391 num_normal++;
10392 else
10393 (*file)[count++] = vim_strsave((char_u *)names[match]);
10394 }
10395 }
10396 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10397 opt_idx++)
10398 {
10399 if (options[opt_idx].var == NULL)
10400 continue;
10401 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10402 && !(options[opt_idx].flags & P_BOOL))
10403 continue;
10404 is_term_opt = istermoption(&options[opt_idx]);
10405 if (is_term_opt && num_normal > 0)
10406 continue;
10407 match = FALSE;
10408 if (vim_regexec(regmatch, str, (colnr_T)0)
10409 || (options[opt_idx].shortname != NULL
10410 && vim_regexec(regmatch,
10411 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10412 match = TRUE;
10413 else if (is_term_opt)
10414 {
10415 name_buf[0] = '<';
10416 name_buf[1] = 't';
10417 name_buf[2] = '_';
10418 name_buf[3] = str[2];
10419 name_buf[4] = str[3];
10420 name_buf[5] = '>';
10421 name_buf[6] = NUL;
10422 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10423 {
10424 match = TRUE;
10425 str = name_buf;
10426 }
10427 }
10428 if (match)
10429 {
10430 if (loop == 0)
10431 {
10432 if (is_term_opt)
10433 num_term++;
10434 else
10435 num_normal++;
10436 }
10437 else
10438 (*file)[count++] = vim_strsave(str);
10439 }
10440 }
10441 /*
10442 * Check terminal key codes, these are not in the option table
10443 */
10444 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10445 {
10446 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10447 {
10448 if (!isprint(str[0]) || !isprint(str[1]))
10449 continue;
10450
10451 name_buf[0] = 't';
10452 name_buf[1] = '_';
10453 name_buf[2] = str[0];
10454 name_buf[3] = str[1];
10455 name_buf[4] = NUL;
10456
10457 match = FALSE;
10458 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10459 match = TRUE;
10460 else
10461 {
10462 name_buf[0] = '<';
10463 name_buf[1] = 't';
10464 name_buf[2] = '_';
10465 name_buf[3] = str[0];
10466 name_buf[4] = str[1];
10467 name_buf[5] = '>';
10468 name_buf[6] = NUL;
10469
10470 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10471 match = TRUE;
10472 }
10473 if (match)
10474 {
10475 if (loop == 0)
10476 num_term++;
10477 else
10478 (*file)[count++] = vim_strsave(name_buf);
10479 }
10480 }
10481
10482 /*
10483 * Check special key names.
10484 */
10485 regmatch->rm_ic = TRUE; /* ignore case here */
10486 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10487 {
10488 name_buf[0] = '<';
10489 STRCPY(name_buf + 1, str);
10490 STRCAT(name_buf, ">");
10491
10492 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10493 {
10494 if (loop == 0)
10495 num_term++;
10496 else
10497 (*file)[count++] = vim_strsave(name_buf);
10498 }
10499 }
10500 }
10501 if (loop == 0)
10502 {
10503 if (num_normal > 0)
10504 *num_file = num_normal;
10505 else if (num_term > 0)
10506 *num_file = num_term;
10507 else
10508 return OK;
10509 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10510 if (*file == NULL)
10511 {
10512 *file = (char_u **)"";
10513 return FAIL;
10514 }
10515 }
10516 }
10517 return OK;
10518}
10519
10520 int
10521ExpandOldSetting(num_file, file)
10522 int *num_file;
10523 char_u ***file;
10524{
10525 char_u *var = NULL; /* init for GCC */
10526 char_u *buf;
10527
10528 *num_file = 0;
10529 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10530 if (*file == NULL)
10531 return FAIL;
10532
10533 /*
10534 * For a terminal key code expand_option_idx is < 0.
10535 */
10536 if (expand_option_idx < 0)
10537 {
10538 var = find_termcode(expand_option_name + 2);
10539 if (var == NULL)
10540 expand_option_idx = findoption(expand_option_name);
10541 }
10542
10543 if (expand_option_idx >= 0)
10544 {
10545 /* put string of option value in NameBuff */
10546 option_value2string(&options[expand_option_idx], expand_option_flags);
10547 var = NameBuff;
10548 }
10549 else if (var == NULL)
10550 var = (char_u *)"";
10551
10552 /* A backslash is required before some characters. This is the reverse of
10553 * what happens in do_set(). */
10554 buf = vim_strsave_escaped(var, escape_chars);
10555
10556 if (buf == NULL)
10557 {
10558 vim_free(*file);
10559 *file = NULL;
10560 return FAIL;
10561 }
10562
10563#ifdef BACKSLASH_IN_FILENAME
10564 /* For MS-Windows et al. we don't double backslashes at the start and
10565 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010566 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 if (var[0] == '\\' && var[1] == '\\'
10568 && expand_option_idx >= 0
10569 && (options[expand_option_idx].flags & P_EXPAND)
10570 && vim_isfilec(var[2])
10571 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010572 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573#endif
10574
10575 *file[0] = buf;
10576 *num_file = 1;
10577 return OK;
10578}
10579#endif
10580
10581/*
10582 * Get the value for the numeric or string option *opp in a nice format into
10583 * NameBuff[]. Must not be called with a hidden option!
10584 */
10585 static void
10586option_value2string(opp, opt_flags)
10587 struct vimoption *opp;
10588 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10589{
10590 char_u *varp;
10591
10592 varp = get_varp_scope(opp, opt_flags);
10593
10594 if (opp->flags & P_NUM)
10595 {
10596 long wc = 0;
10597
10598 if (wc_use_keyname(varp, &wc))
10599 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10600 else if (wc != 0)
10601 STRCPY(NameBuff, transchar((int)wc));
10602 else
10603 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10604 }
10605 else /* P_STRING */
10606 {
10607 varp = *(char_u **)(varp);
10608 if (varp == NULL) /* just in case */
10609 NameBuff[0] = NUL;
10610#ifdef FEAT_CRYPT
10611 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010612 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613 STRCPY(NameBuff, "*****");
10614#endif
10615 else if (opp->flags & P_EXPAND)
10616 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10617 /* Translate 'pastetoggle' into special key names */
10618 else if ((char_u **)opp->var == &p_pt)
10619 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10620 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010621 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622 }
10623}
10624
10625/*
10626 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10627 * printed as a keyname.
10628 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10629 */
10630 static int
10631wc_use_keyname(varp, wcp)
10632 char_u *varp;
10633 long *wcp;
10634{
10635 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10636 {
10637 *wcp = *(long *)varp;
10638 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10639 return TRUE;
10640 }
10641 return FALSE;
10642}
10643
10644#ifdef FEAT_LANGMAP
10645/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010646 * Any character has an equivalent 'langmap' character. This is used for
10647 * keyboards that have a special language mode that sends characters above
10648 * 128 (although other characters can be translated too). The "to" field is a
10649 * Vim command character. This avoids having to switch the keyboard back to
10650 * ASCII mode when leaving Insert mode.
10651 *
10652 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10653 * commands.
10654 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10655 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10656 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010658# ifdef FEAT_MBYTE
10659/*
10660 * With multi-byte support use growarray for 'langmap' chars >= 256
10661 */
10662typedef struct
10663{
10664 int from;
10665 int to;
10666} langmap_entry_T;
10667
10668static garray_T langmap_mapga;
10669static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670
10671/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010672 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10673 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010675 static void
10676langmap_set_entry(from, to)
10677 int from;
10678 int to;
10679{
10680 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010681 int a = 0;
10682 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010683
10684 /* Do a binary search for an existing entry. */
10685 while (a != b)
10686 {
10687 int i = (a + b) / 2;
10688 int d = entries[i].from - from;
10689
10690 if (d == 0)
10691 {
10692 entries[i].to = to;
10693 return;
10694 }
10695 if (d < 0)
10696 a = i + 1;
10697 else
10698 b = i;
10699 }
10700
10701 if (ga_grow(&langmap_mapga, 1) != OK)
10702 return; /* out of memory */
10703
10704 /* insert new entry at position "a" */
10705 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10706 mch_memmove(entries + 1, entries,
10707 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10708 ++langmap_mapga.ga_len;
10709 entries[0].from = from;
10710 entries[0].to = to;
10711}
10712
10713/*
10714 * Apply 'langmap' to multi-byte character "c" and return the result.
10715 */
10716 int
10717langmap_adjust_mb(c)
10718 int c;
10719{
10720 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10721 int a = 0;
10722 int b = langmap_mapga.ga_len;
10723
10724 while (a != b)
10725 {
10726 int i = (a + b) / 2;
10727 int d = entries[i].from - c;
10728
10729 if (d == 0)
10730 return entries[i].to; /* found matching entry */
10731 if (d < 0)
10732 a = i + 1;
10733 else
10734 b = i;
10735 }
10736 return c; /* no entry found, return "c" unmodified */
10737}
10738# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739
10740 static void
10741langmap_init()
10742{
10743 int i;
10744
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010745 for (i = 0; i < 256; i++)
10746 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10747# ifdef FEAT_MBYTE
10748 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10749# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750}
10751
10752/*
10753 * Called when langmap option is set; the language map can be
10754 * changed at any time!
10755 */
10756 static void
10757langmap_set()
10758{
10759 char_u *p;
10760 char_u *p2;
10761 int from, to;
10762
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010763#ifdef FEAT_MBYTE
10764 ga_clear(&langmap_mapga); /* clear the previous map first */
10765#endif
10766 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767
10768 for (p = p_langmap; p[0] != NUL; )
10769 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010770 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10771 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 {
10773 if (p2[0] == '\\' && p2[1] != NUL)
10774 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775 }
10776 if (p2[0] == ';')
10777 ++p2; /* abcd;ABCD form, p2 points to A */
10778 else
10779 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10780 while (p[0])
10781 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010782 if (p[0] == ',')
10783 {
10784 ++p;
10785 break;
10786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 if (p[0] == '\\' && p[1] != NUL)
10788 ++p;
10789#ifdef FEAT_MBYTE
10790 from = (*mb_ptr2char)(p);
10791#else
10792 from = p[0];
10793#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010794 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795 if (p2 == NULL)
10796 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010797 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010798 if (p[0] != ',')
10799 {
10800 if (p[0] == '\\')
10801 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010803 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010805 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808 }
10809 else
10810 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010811 if (p2[0] != ',')
10812 {
10813 if (p2[0] == '\\')
10814 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010816 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010818 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010820 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821 }
10822 if (to == NUL)
10823 {
10824 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10825 transchar(from));
10826 return;
10827 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010828
10829#ifdef FEAT_MBYTE
10830 if (from >= 256)
10831 langmap_set_entry(from, to);
10832 else
10833#endif
10834 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835
10836 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010837 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010838 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010840 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841 if (*p == ';')
10842 {
10843 p = p2;
10844 if (p[0] != NUL)
10845 {
10846 if (p[0] != ',')
10847 {
10848 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10849 return;
10850 }
10851 ++p;
10852 }
10853 break;
10854 }
10855 }
10856 }
10857 }
10858}
10859#endif
10860
10861/*
10862 * Return TRUE if format option 'x' is in effect.
10863 * Take care of no formatting when 'paste' is set.
10864 */
10865 int
10866has_format_option(x)
10867 int x;
10868{
10869 if (p_paste)
10870 return FALSE;
10871 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10872}
10873
10874/*
10875 * Return TRUE if "x" is present in 'shortmess' option, or
10876 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10877 */
10878 int
10879shortmess(x)
10880 int x;
10881{
10882 return ( vim_strchr(p_shm, x) != NULL
10883 || (vim_strchr(p_shm, 'a') != NULL
10884 && vim_strchr((char_u *)SHM_A, x) != NULL));
10885}
10886
10887/*
10888 * paste_option_changed() - Called after p_paste was set or reset.
10889 */
10890 static void
10891paste_option_changed()
10892{
10893 static int old_p_paste = FALSE;
10894 static int save_sm = 0;
10895#ifdef FEAT_CMDL_INFO
10896 static int save_ru = 0;
10897#endif
10898#ifdef FEAT_RIGHTLEFT
10899 static int save_ri = 0;
10900 static int save_hkmap = 0;
10901#endif
10902 buf_T *buf;
10903
10904 if (p_paste)
10905 {
10906 /*
10907 * Paste switched from off to on.
10908 * Save the current values, so they can be restored later.
10909 */
10910 if (!old_p_paste)
10911 {
10912 /* save options for each buffer */
10913 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10914 {
10915 buf->b_p_tw_nopaste = buf->b_p_tw;
10916 buf->b_p_wm_nopaste = buf->b_p_wm;
10917 buf->b_p_sts_nopaste = buf->b_p_sts;
10918 buf->b_p_ai_nopaste = buf->b_p_ai;
10919 }
10920
10921 /* save global options */
10922 save_sm = p_sm;
10923#ifdef FEAT_CMDL_INFO
10924 save_ru = p_ru;
10925#endif
10926#ifdef FEAT_RIGHTLEFT
10927 save_ri = p_ri;
10928 save_hkmap = p_hkmap;
10929#endif
10930 /* save global values for local buffer options */
10931 p_tw_nopaste = p_tw;
10932 p_wm_nopaste = p_wm;
10933 p_sts_nopaste = p_sts;
10934 p_ai_nopaste = p_ai;
10935 }
10936
10937 /*
10938 * Always set the option values, also when 'paste' is set when it is
10939 * already on.
10940 */
10941 /* set options for each buffer */
10942 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10943 {
10944 buf->b_p_tw = 0; /* textwidth is 0 */
10945 buf->b_p_wm = 0; /* wrapmargin is 0 */
10946 buf->b_p_sts = 0; /* softtabstop is 0 */
10947 buf->b_p_ai = 0; /* no auto-indent */
10948 }
10949
10950 /* set global options */
10951 p_sm = 0; /* no showmatch */
10952#ifdef FEAT_CMDL_INFO
10953# ifdef FEAT_WINDOWS
10954 if (p_ru)
10955 status_redraw_all(); /* redraw to remove the ruler */
10956# endif
10957 p_ru = 0; /* no ruler */
10958#endif
10959#ifdef FEAT_RIGHTLEFT
10960 p_ri = 0; /* no reverse insert */
10961 p_hkmap = 0; /* no Hebrew keyboard */
10962#endif
10963 /* set global values for local buffer options */
10964 p_tw = 0;
10965 p_wm = 0;
10966 p_sts = 0;
10967 p_ai = 0;
10968 }
10969
10970 /*
10971 * Paste switched from on to off: Restore saved values.
10972 */
10973 else if (old_p_paste)
10974 {
10975 /* restore options for each buffer */
10976 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10977 {
10978 buf->b_p_tw = buf->b_p_tw_nopaste;
10979 buf->b_p_wm = buf->b_p_wm_nopaste;
10980 buf->b_p_sts = buf->b_p_sts_nopaste;
10981 buf->b_p_ai = buf->b_p_ai_nopaste;
10982 }
10983
10984 /* restore global options */
10985 p_sm = save_sm;
10986#ifdef FEAT_CMDL_INFO
10987# ifdef FEAT_WINDOWS
10988 if (p_ru != save_ru)
10989 status_redraw_all(); /* redraw to draw the ruler */
10990# endif
10991 p_ru = save_ru;
10992#endif
10993#ifdef FEAT_RIGHTLEFT
10994 p_ri = save_ri;
10995 p_hkmap = save_hkmap;
10996#endif
10997 /* set global values for local buffer options */
10998 p_tw = p_tw_nopaste;
10999 p_wm = p_wm_nopaste;
11000 p_sts = p_sts_nopaste;
11001 p_ai = p_ai_nopaste;
11002 }
11003
11004 old_p_paste = p_paste;
11005}
11006
11007/*
11008 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11009 *
11010 * Reset 'compatible' and set the values for options that didn't get set yet
11011 * to the Vim defaults.
11012 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011013 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014 */
11015 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011016vimrc_found(fname, envname)
11017 char_u *fname;
11018 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011020 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011021 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011022 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011023
11024 if (!option_was_set((char_u *)"cp"))
11025 {
11026 p_cp = FALSE;
11027 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11028 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11029 set_option_default(opt_idx, OPT_FREE, FALSE);
11030 didset_options();
11031 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011032
11033 if (fname != NULL)
11034 {
11035 p = vim_getenv(envname, &dofree);
11036 if (p == NULL)
11037 {
11038 /* Set $MYVIMRC to the first vimrc file found. */
11039 p = FullName_save(fname, FALSE);
11040 if (p != NULL)
11041 {
11042 vim_setenv(envname, p);
11043 vim_free(p);
11044 }
11045 }
11046 else if (dofree)
11047 vim_free(p);
11048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049}
11050
11051/*
11052 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11053 */
11054 void
11055change_compatible(on)
11056 int on;
11057{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011058 int opt_idx;
11059
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060 if (p_cp != on)
11061 {
11062 p_cp = on;
11063 compatible_set();
11064 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011065 opt_idx = findoption((char_u *)"cp");
11066 if (opt_idx >= 0)
11067 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011068}
11069
11070/*
11071 * Return TRUE when option "name" has been set.
11072 */
11073 int
11074option_was_set(name)
11075 char_u *name;
11076{
11077 int idx;
11078
11079 idx = findoption(name);
11080 if (idx < 0) /* unknown option */
11081 return FALSE;
11082 if (options[idx].flags & P_WAS_SET)
11083 return TRUE;
11084 return FALSE;
11085}
11086
11087/*
11088 * compatible_set() - Called when 'compatible' has been set or unset.
11089 *
11090 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11091 * flag) to a Vi compatible value.
11092 * When 'compatible' is unset: Set all options that have a different default
11093 * for Vim (without the P_VI_DEF flag) to that default.
11094 */
11095 static void
11096compatible_set()
11097{
11098 int opt_idx;
11099
11100 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11101 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11102 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11103 set_option_default(opt_idx, OPT_FREE, p_cp);
11104 didset_options();
11105}
11106
11107#ifdef FEAT_LINEBREAK
11108
11109# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11110 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011111 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112# endif
11113
11114/*
11115 * fill_breakat_flags() -- called when 'breakat' changes value.
11116 */
11117 static void
11118fill_breakat_flags()
11119{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011120 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121 int i;
11122
11123 for (i = 0; i < 256; i++)
11124 breakat_flags[i] = FALSE;
11125
11126 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011127 for (p = p_breakat; *p; p++)
11128 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129}
11130
11131# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011132 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133# endif
11134
11135#endif
11136
11137/*
11138 * Check an option that can be a range of string values.
11139 *
11140 * Return OK for correct value, FAIL otherwise.
11141 * Empty is always OK.
11142 */
11143 static int
11144check_opt_strings(val, values, list)
11145 char_u *val;
11146 char **values;
11147 int list; /* when TRUE: accept a list of values */
11148{
11149 return opt_strings_flags(val, values, NULL, list);
11150}
11151
11152/*
11153 * Handle an option that can be a range of string values.
11154 * Set a flag in "*flagp" for each string present.
11155 *
11156 * Return OK for correct value, FAIL otherwise.
11157 * Empty is always OK.
11158 */
11159 static int
11160opt_strings_flags(val, values, flagp, list)
11161 char_u *val; /* new value */
11162 char **values; /* array of valid string values */
11163 unsigned *flagp;
11164 int list; /* when TRUE: accept a list of values */
11165{
11166 int i;
11167 int len;
11168 unsigned new_flags = 0;
11169
11170 while (*val)
11171 {
11172 for (i = 0; ; ++i)
11173 {
11174 if (values[i] == NULL) /* val not found in values[] */
11175 return FAIL;
11176
11177 len = (int)STRLEN(values[i]);
11178 if (STRNCMP(values[i], val, len) == 0
11179 && ((list && val[len] == ',') || val[len] == NUL))
11180 {
11181 val += len + (val[len] == ',');
11182 new_flags |= (1 << i);
11183 break; /* check next item in val list */
11184 }
11185 }
11186 }
11187 if (flagp != NULL)
11188 *flagp = new_flags;
11189
11190 return OK;
11191}
11192
11193/*
11194 * Read the 'wildmode' option, fill wim_flags[].
11195 */
11196 static int
11197check_opt_wim()
11198{
11199 char_u new_wim_flags[4];
11200 char_u *p;
11201 int i;
11202 int idx = 0;
11203
11204 for (i = 0; i < 4; ++i)
11205 new_wim_flags[i] = 0;
11206
11207 for (p = p_wim; *p; ++p)
11208 {
11209 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11210 ;
11211 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11212 return FAIL;
11213 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11214 new_wim_flags[idx] |= WIM_LONGEST;
11215 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11216 new_wim_flags[idx] |= WIM_FULL;
11217 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11218 new_wim_flags[idx] |= WIM_LIST;
11219 else
11220 return FAIL;
11221 p += i;
11222 if (*p == NUL)
11223 break;
11224 if (*p == ',')
11225 {
11226 if (idx == 3)
11227 return FAIL;
11228 ++idx;
11229 }
11230 }
11231
11232 /* fill remaining entries with last flag */
11233 while (idx < 3)
11234 {
11235 new_wim_flags[idx + 1] = new_wim_flags[idx];
11236 ++idx;
11237 }
11238
11239 /* only when there are no errors, wim_flags[] is changed */
11240 for (i = 0; i < 4; ++i)
11241 wim_flags[i] = new_wim_flags[i];
11242 return OK;
11243}
11244
11245/*
11246 * Check if backspacing over something is allowed.
11247 */
11248 int
11249can_bs(what)
11250 int what; /* BS_INDENT, BS_EOL or BS_START */
11251{
11252 switch (*p_bs)
11253 {
11254 case '2': return TRUE;
11255 case '1': return (what != BS_START);
11256 case '0': return FALSE;
11257 }
11258 return vim_strchr(p_bs, what) != NULL;
11259}
11260
11261/*
11262 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11263 * the file must be considered changed when the value is different.
11264 */
11265 void
11266save_file_ff(buf)
11267 buf_T *buf;
11268{
11269 buf->b_start_ffc = *buf->b_p_ff;
11270 buf->b_start_eol = buf->b_p_eol;
11271#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011272 buf->b_start_bomb = buf->b_p_bomb;
11273
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274 /* Only use free/alloc when necessary, they take time. */
11275 if (buf->b_start_fenc == NULL
11276 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11277 {
11278 vim_free(buf->b_start_fenc);
11279 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11280 }
11281#endif
11282}
11283
11284/*
11285 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11286 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011287 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11288 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011289 * When "ignore_empty" is true don't consider a new, empty buffer to be
11290 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011291 */
11292 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011293file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011295 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011296{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011297 /* In a buffer that was never loaded the options are not valid. */
11298 if (buf->b_flags & BF_NEVERLOADED)
11299 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011300 if (ignore_empty
11301 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302 && buf->b_ml.ml_line_count == 1
11303 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11304 return FALSE;
11305 if (buf->b_start_ffc != *buf->b_p_ff)
11306 return TRUE;
11307 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11308 return TRUE;
11309#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011310 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11311 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312 if (buf->b_start_fenc == NULL)
11313 return (*buf->b_p_fenc != NUL);
11314 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11315#else
11316 return FALSE;
11317#endif
11318}
11319
11320/*
11321 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11322 */
11323 int
11324check_ff_value(p)
11325 char_u *p;
11326{
11327 return check_opt_strings(p, p_ff_values, FALSE);
11328}