blob: e7ec0c8b985a5388005f4ca6167d721397b178dc [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +020080#define PV_CM OPT_BUF(BV_CM)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
143#ifdef FEAT_OSFILETYPE
144# define PV_OFT OPT_BUF(BV_OFT)
145#endif
146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
180#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)
232#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233#ifdef FEAT_STL_OPT
234# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
235#endif
236#ifdef FEAT_WINDOWS
237# define PV_WFH OPT_WIN(WV_WFH)
238#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000239#ifdef FEAT_VERTSPLIT
240# define PV_WFW OPT_WIN(WV_WFW)
241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000243
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244
245/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246typedef enum
247{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000248 PV_NONE = 0,
249 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250} idopt_T;
251
252/*
253 * Options local to a window have a value local to a buffer and global to all
254 * buffers. Indicate this by setting "var" to VAR_WIN.
255 */
256#define VAR_WIN ((char_u *)-1)
257
258/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000259 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260 * Only to be used in option.c!
261 */
262static int p_ai;
263static int p_bin;
264#ifdef FEAT_MBYTE
265static int p_bomb;
266#endif
267#if defined(FEAT_QUICKFIX)
268static char_u *p_bh;
269static char_u *p_bt;
270#endif
271static int p_bl;
272static int p_ci;
273#ifdef FEAT_CINDENT
274static int p_cin;
275static char_u *p_cink;
276static char_u *p_cino;
277#endif
278#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
279static char_u *p_cinw;
280#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200281static long p_cm;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282#ifdef FEAT_COMMENTS
283static char_u *p_com;
284#endif
285#ifdef FEAT_FOLDING
286static char_u *p_cms;
287#endif
288#ifdef FEAT_INS_EXPAND
289static char_u *p_cpt;
290#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000291#ifdef FEAT_COMPL_FUNC
292static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000293static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295static int p_eol;
296static int p_et;
297#ifdef FEAT_MBYTE
298static char_u *p_fenc;
299#endif
300static char_u *p_ff;
301static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000302static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303#ifdef FEAT_AUTOCMD
304static char_u *p_ft;
305#endif
306static long p_iminsert;
307static long p_imsearch;
308#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
309static char_u *p_inex;
310#endif
311#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
312static char_u *p_inde;
313static char_u *p_indk;
314#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000315#if defined(FEAT_EVAL)
316static char_u *p_fex;
317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static int p_inf;
319static char_u *p_isk;
320#ifdef FEAT_CRYPT
321static char_u *p_key;
322#endif
323#ifdef FEAT_LISP
324static int p_lisp;
325#endif
326static int p_ml;
327static int p_ma;
328static int p_mod;
329static char_u *p_mps;
330static char_u *p_nf;
331#ifdef FEAT_OSFILETYPE
332static char_u *p_oft;
333#endif
334static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000335#ifdef FEAT_TEXTOBJ
336static char_u *p_qe;
337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000338static int p_ro;
339#ifdef FEAT_SMARTINDENT
340static int p_si;
341#endif
342#ifndef SHORT_FNAME
343static int p_sn;
344#endif
345static long p_sts;
346#if defined(FEAT_SEARCHPATH)
347static char_u *p_sua;
348#endif
349static long p_sw;
350static int p_swf;
351#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000352static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000354#endif
355#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000356static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000357static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000358static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359#endif
360static long p_ts;
361static long p_tw;
362static int p_tx;
363static long p_wm;
364#ifdef FEAT_KEYMAP
365static char_u *p_keymap;
366#endif
367
368/* Saved values for when 'bin' is set. */
369static int p_et_nobin;
370static int p_ml_nobin;
371static long p_tw_nobin;
372static long p_wm_nobin;
373
374/* Saved values for when 'paste' is set */
375static long p_tw_nopaste;
376static long p_wm_nopaste;
377static long p_sts_nopaste;
378static int p_ai_nopaste;
379
380struct vimoption
381{
382 char *fullname; /* full option name */
383 char *shortname; /* permissible abbreviation */
384 long_u flags; /* see below */
385 char_u *var; /* global option: pointer to variable;
386 * window-local option: VAR_WIN;
387 * buffer-local option: global value */
388 idopt_T indir; /* global option: PV_NONE;
389 * local option: indirect option index */
390 char_u *def_val[2]; /* default values for variable (vi and vim) */
391#ifdef FEAT_EVAL
392 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000393# define SCRIPTID_INIT , 0
394#else
395# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396#endif
397};
398
399#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
400#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
401
402/*
403 * Flags
404 */
405#define P_BOOL 0x01 /* the option is boolean */
406#define P_NUM 0x02 /* the option is numeric */
407#define P_STRING 0x04 /* the option is a string */
408#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000409 must use free_string_option() when
410 assigning new value. Not set if default is
411 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000412#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
413 never be used for local or hidden options! */
414#define P_NODEFAULT 0x40 /* don't set to default value */
415#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
416 use vim_free() when assigning new value */
417#define P_WAS_SET 0x100 /* option has been set/reset */
418#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
419#define P_VI_DEF 0x400 /* Use Vi default for Vim */
420#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
421
422 /* when option changed, what to display: */
423#define P_RSTAT 0x1000 /* redraw status lines */
424#define P_RWIN 0x2000 /* redraw current window */
425#define P_RBUF 0x4000 /* redraw current buffer */
426#define P_RALL 0x6000 /* redraw all windows */
427#define P_RCLR 0x7000 /* clear and redraw all */
428
429#define P_COMMA 0x8000 /* comma separated list */
430#define P_NODUP 0x10000L/* don't allow duplicate strings */
431#define P_FLAGLIST 0x20000L/* list of single-char flags */
432
433#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
434#define P_GETTEXT 0x80000L/* expand default value with _() */
435#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000436#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000437#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000438#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
439 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000441#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
442
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000443/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
444 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000445#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000446# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000447#else
448# define ISP_LATIN1 (char_u *)"@,161-255"
449#endif
450
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000451/* The 16 bit MS-DOS version is low on space, make the string as short as
452 * possible when compiling with few features. */
453#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
454 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
455 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
456# 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,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine"
457#else
458# 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"
459#endif
460
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461/*
462 * options[] is initialized here.
463 * The order of the options MUST be alphabetic for ":set all" and findoption().
464 * All option names MUST start with a lowercase letter (for findoption()).
465 * Exception: "t_" options are at the end.
466 * The options with a NULL variable are 'hidden': a set command for them is
467 * ignored and they are not printed.
468 */
469static struct vimoption
470#ifdef FEAT_GUI_W16
471 _far
472#endif
473 options[] =
474{
475 {"aleph", "al", P_NUM|P_VI_DEF,
476#ifdef FEAT_RIGHTLEFT
477 (char_u *)&p_aleph, PV_NONE,
478#else
479 (char_u *)NULL, PV_NONE,
480#endif
481 {
482#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
483 (char_u *)128L,
484#else
485 (char_u *)224L,
486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000487 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
489#if defined(FEAT_GUI) && defined(MACOS_X)
490 (char_u *)&p_antialias, PV_NONE,
491 {(char_u *)FALSE, (char_u *)FALSE}
492#else
493 (char_u *)NULL, PV_NONE,
494 {(char_u *)FALSE, (char_u *)FALSE}
495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
498#ifdef FEAT_ARABIC
499 (char_u *)VAR_WIN, PV_ARAB,
500#else
501 (char_u *)NULL, PV_NONE,
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
505#ifdef FEAT_ARABIC
506 (char_u *)&p_arshape, PV_NONE,
507#else
508 (char_u *)NULL, PV_NONE,
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
512#ifdef FEAT_RIGHTLEFT
513 (char_u *)&p_ari, PV_NONE,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
519#ifdef FEAT_FKMAP
520 (char_u *)&p_altkeymap, 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 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
526#if defined(FEAT_MBYTE)
527 (char_u *)&p_ambw, PV_NONE,
528 {(char_u *)"single", (char_u *)0L}
529#else
530 (char_u *)NULL, PV_NONE,
531 {(char_u *)0L, (char_u *)0L}
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000534#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"autochdir", "acd", P_BOOL|P_VI_DEF,
536 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538#endif
539 {"autoindent", "ai", P_BOOL|P_VI_DEF,
540 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"autoprint", "ap", P_BOOL|P_VI_DEF,
543 (char_u *)NULL, 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 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000546 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000548 {"autowrite", "aw", P_BOOL|P_VI_DEF,
549 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"autowriteall","awa", P_BOOL|P_VI_DEF,
552 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
555 (char_u *)&p_bg, PV_NONE,
556 {
557#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
558 (char_u *)"dark",
559#else
560 (char_u *)"light",
561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
564 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
567 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
570 (char_u *)&p_bkc, PV_NONE,
571#ifdef UNIX
572 {(char_u *)"yes", (char_u *)"auto"}
573#else
574 {(char_u *)"auto", (char_u *)"auto"}
575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
578 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000580 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 (char_u *)&p_bex, PV_NONE,
582 {
583#ifdef VMS
584 (char_u *)"_",
585#else
586 (char_u *)"~",
587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
590#ifdef FEAT_WILDIGN
591 (char_u *)&p_bsk, PV_NONE,
592 {(char_u *)"", (char_u *)0L}
593#else
594 (char_u *)NULL, PV_NONE,
595 {(char_u *)0L, (char_u *)0L}
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598#ifdef FEAT_BEVAL
599 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
600 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
603 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000605# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000606 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000607 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000609# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#endif
611 {"beautify", "bf", P_BOOL|P_VI_DEF,
612 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
615 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
618#ifdef MSDOS
619 (char_u *)&p_biosk, PV_NONE,
620#else
621 (char_u *)NULL, PV_NONE,
622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
625#ifdef FEAT_MBYTE
626 (char_u *)&p_bomb, PV_BOMB,
627#else
628 (char_u *)NULL, PV_NONE,
629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
632#ifdef FEAT_LINEBREAK
633 (char_u *)&p_breakat, PV_NONE,
634 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
635#else
636 (char_u *)NULL, PV_NONE,
637 {(char_u *)0L, (char_u *)0L}
638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000639 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
641#ifdef FEAT_BROWSE
642 (char_u *)&p_bsdir, PV_NONE,
643 {(char_u *)"last", (char_u *)0L}
644#else
645 (char_u *)NULL, PV_NONE,
646 {(char_u *)0L, (char_u *)0L}
647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000648 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
650#if defined(FEAT_QUICKFIX)
651 (char_u *)&p_bh, PV_BH,
652 {(char_u *)"", (char_u *)0L}
653#else
654 (char_u *)NULL, PV_NONE,
655 {(char_u *)0L, (char_u *)0L}
656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000657 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
659 (char_u *)&p_bl, PV_BL,
660 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
663#if defined(FEAT_QUICKFIX)
664 (char_u *)&p_bt, PV_BT,
665 {(char_u *)"", (char_u *)0L}
666#else
667 (char_u *)NULL, PV_NONE,
668 {(char_u *)0L, (char_u *)0L}
669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000672#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)&p_cmp, PV_NONE,
674 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000675#else
676 (char_u *)NULL, PV_NONE,
677 {(char_u *)0L, (char_u *)0L}
678#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000679 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
681#ifdef FEAT_SEARCHPATH
682 (char_u *)&p_cdpath, PV_NONE,
683 {(char_u *)",,", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000688 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 {"cedit", NULL, P_STRING,
690#ifdef FEAT_CMDWIN
691 (char_u *)&p_cedit, PV_NONE,
692 {(char_u *)"", (char_u *)CTRL_F_STR}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
699#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
700 (char_u *)&p_ccv, PV_NONE,
701 {(char_u *)"", (char_u *)0L}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)0L, (char_u *)0L}
705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
708#ifdef FEAT_CINDENT
709 (char_u *)&p_cin, PV_CIN,
710#else
711 (char_u *)NULL, PV_NONE,
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
715#ifdef FEAT_CINDENT
716 (char_u *)&p_cink, PV_CINK,
717 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
718#else
719 (char_u *)NULL, PV_NONE,
720 {(char_u *)0L, (char_u *)0L}
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
724#ifdef FEAT_CINDENT
725 (char_u *)&p_cino, PV_CINO,
726#else
727 (char_u *)NULL, PV_NONE,
728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
731#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
732 (char_u *)&p_cinw, PV_CINW,
733 {(char_u *)"if,else,while,do,for,switch",
734 (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
741#ifdef FEAT_CLIPBOARD
742 (char_u *)&p_cb, PV_NONE,
743# ifdef FEAT_XCLIPBOARD
744 {(char_u *)"autoselect,exclude:cons\\|linux",
745 (char_u *)0L}
746# else
747 {(char_u *)"", (char_u *)0L}
748# endif
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)"", (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
755 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
758#ifdef FEAT_CMDWIN
759 (char_u *)&p_cwh, PV_NONE,
760#else
761 (char_u *)NULL, PV_NONE,
762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
765 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
768#ifdef FEAT_COMMENTS
769 (char_u *)&p_com, PV_COM,
770 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
771 (char_u *)0L}
772#else
773 (char_u *)NULL, PV_NONE,
774 {(char_u *)0L, (char_u *)0L}
775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000776 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
778#ifdef FEAT_FOLDING
779 (char_u *)&p_cms, PV_CMS,
780 {(char_u *)"/*%s*/", (char_u *)0L}
781#else
782 (char_u *)NULL, PV_NONE,
783 {(char_u *)0L, (char_u *)0L}
784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000785 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000786 /* P_PRI_MKRC isn't needed here, optval_default()
787 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788 {"compatible", "cp", P_BOOL|P_RALL,
789 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
792#ifdef FEAT_INS_EXPAND
793 (char_u *)&p_cpt, PV_CPT,
794 {(char_u *)".,w,b,u,t,i", (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 Moolenaarcfbc5ee2004-07-02 15:38:35 +0000800 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
801#ifdef FEAT_COMPL_FUNC
802 (char_u *)&p_cfu, PV_CFU,
803 {(char_u *)"", (char_u *)0L}
804#else
805 (char_u *)NULL, PV_NONE,
806 {(char_u *)0L, (char_u *)0L}
807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000809 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
810#ifdef FEAT_INS_EXPAND
811 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000812 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 {"confirm", "cf", P_BOOL|P_VI_DEF,
819#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
820 (char_u *)&p_confirm, PV_NONE,
821#else
822 (char_u *)NULL, PV_NONE,
823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825 {"conskey", "consk",P_BOOL|P_VI_DEF,
826#ifdef MSDOS
827 (char_u *)&p_consk, PV_NONE,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
833 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000835 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
836 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
838 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200839 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
840 (char_u *)&p_cm, PV_CM,
841 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
843#ifdef FEAT_CSCOPE
844 (char_u *)&p_cspc, PV_NONE,
845#else
846 (char_u *)NULL, PV_NONE,
847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000848 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
850#ifdef FEAT_CSCOPE
851 (char_u *)&p_csprg, PV_NONE,
852 {(char_u *)"cscope", (char_u *)0L}
853#else
854 (char_u *)NULL, PV_NONE,
855 {(char_u *)0L, (char_u *)0L}
856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000857 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
859#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
860 (char_u *)&p_csqf, PV_NONE,
861 {(char_u *)"", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
868#ifdef FEAT_CSCOPE
869 (char_u *)&p_cst, PV_NONE,
870#else
871 (char_u *)NULL, PV_NONE,
872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000873 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000874 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
875#ifdef FEAT_CSCOPE
876 (char_u *)&p_csto, PV_NONE,
877#else
878 (char_u *)NULL, PV_NONE,
879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000880 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
882#ifdef FEAT_CSCOPE
883 (char_u *)&p_csverbose, PV_NONE,
884#else
885 (char_u *)NULL, PV_NONE,
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000888 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
889#ifdef FEAT_SYN_HL
890 (char_u *)VAR_WIN, PV_CUC,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000895 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
896#ifdef FEAT_SYN_HL
897 (char_u *)VAR_WIN, PV_CUL,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"debug", NULL, P_STRING|P_VI_DEF,
903 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
906#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000907 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000908 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909#else
910 (char_u *)NULL, PV_NONE,
911 {(char_u *)NULL, (char_u *)0L}
912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
915#ifdef FEAT_MBYTE
916 (char_u *)&p_deco, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
922#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000923 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924#else
925 (char_u *)NULL, PV_NONE,
926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000927 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
929#ifdef FEAT_DIFF
930 (char_u *)VAR_WIN, PV_DIFF,
931#else
932 (char_u *)NULL, PV_NONE,
933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000934 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
936#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
937 (char_u *)&p_dex, PV_NONE,
938 {(char_u *)"", (char_u *)0L}
939#else
940 (char_u *)NULL, PV_NONE,
941 {(char_u *)0L, (char_u *)0L}
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
945#ifdef FEAT_DIFF
946 (char_u *)&p_dip, PV_NONE,
947 {(char_u *)"filler", (char_u *)NULL}
948#else
949 (char_u *)NULL, PV_NONE,
950 {(char_u *)"", (char_u *)NULL}
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
954#ifdef FEAT_DIGRAPHS
955 (char_u *)&p_dg, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
961 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000962 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
964 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"eadirection", "ead", P_STRING|P_VI_DEF,
967#ifdef FEAT_VERTSPLIT
968 (char_u *)&p_ead, PV_NONE,
969 {(char_u *)"both", (char_u *)0L}
970#else
971 (char_u *)NULL, PV_NONE,
972 {(char_u *)NULL, (char_u *)0L}
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"edcompatible","ed", P_BOOL|P_VI_DEF,
976 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
979#ifdef FEAT_MBYTE
980 (char_u *)&p_enc, PV_NONE,
981 {(char_u *)ENC_DFLT, (char_u *)0L}
982#else
983 (char_u *)NULL, PV_NONE,
984 {(char_u *)0L, (char_u *)0L}
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
988 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
991 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000994 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996 {"errorbells", "eb", P_BOOL|P_VI_DEF,
997 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1000#ifdef FEAT_QUICKFIX
1001 (char_u *)&p_ef, PV_NONE,
1002 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1003#else
1004 (char_u *)NULL, PV_NONE,
1005 {(char_u *)NULL, (char_u *)0L}
1006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1009#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001010 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014 {(char_u *)NULL, (char_u *)0L}
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"esckeys", "ek", P_BOOL|P_VIM,
1018 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1021#ifdef FEAT_AUTOCMD
1022 (char_u *)&p_ei, PV_NONE,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1028 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1031 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1034#ifdef FEAT_MBYTE
1035 (char_u *)&p_fenc, PV_FENC,
1036 {(char_u *)"", (char_u *)0L}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)0L, (char_u *)0L}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1043#ifdef FEAT_MBYTE
1044 (char_u *)&p_fencs, PV_NONE,
1045 {(char_u *)"ucs-bom", (char_u *)0L}
1046#else
1047 (char_u *)NULL, PV_NONE,
1048 {(char_u *)0L, (char_u *)0L}
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1052 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1055 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1057 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001058 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059#ifdef FEAT_AUTOCMD
1060 (char_u *)&p_ft, PV_FT,
1061 {(char_u *)"", (char_u *)0L}
1062#else
1063 (char_u *)NULL, PV_NONE,
1064 {(char_u *)0L, (char_u *)0L}
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1068#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1069 (char_u *)&p_fcs, PV_NONE,
1070 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1071#else
1072 (char_u *)NULL, PV_NONE,
1073 {(char_u *)"", (char_u *)0L}
1074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1077#ifdef FEAT_FKMAP
1078 (char_u *)&p_fkmap, PV_NONE,
1079#else
1080 (char_u *)NULL, PV_NONE,
1081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"flash", "fl", P_BOOL|P_VI_DEF,
1084 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_FOLDING
1087 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1088 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1091 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1094 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1097# ifdef FEAT_EVAL
1098 (char_u *)VAR_WIN, PV_FDE,
1099 {(char_u *)"0", (char_u *)NULL}
1100# else
1101 (char_u *)NULL, PV_NONE,
1102 {(char_u *)NULL, (char_u *)0L}
1103# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1106 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1109 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1112 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001113 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1115 P_RWIN|P_COMMA|P_NODUP,
1116 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)"{{{,}}}", (char_u *)NULL}
1118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1120 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1123 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1126 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1129 (char_u *)&p_fdo, PV_NONE,
1130 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1133# ifdef FEAT_EVAL
1134 (char_u *)VAR_WIN, PV_FDT,
1135 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001136# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001139# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001142 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001143#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001144 (char_u *)&p_fex, PV_FEX,
1145 {(char_u *)"", (char_u *)0L}
1146#else
1147 (char_u *)NULL, PV_NONE,
1148 {(char_u *)0L, (char_u *)0L}
1149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1152 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1154 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001155 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1156 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1158 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1160 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001162 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1163#ifdef HAVE_FSYNC
1164 (char_u *)&p_fs, PV_NONE,
1165 {(char_u *)TRUE, (char_u *)0L}
1166#else
1167 (char_u *)NULL, PV_NONE,
1168 {(char_u *)FALSE, (char_u *)0L}
1169#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001170 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1172 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001173 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 {"graphic", "gr", P_BOOL|P_VI_DEF,
1175 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1178#ifdef FEAT_QUICKFIX
1179 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181#else
1182 (char_u *)NULL, PV_NONE,
1183 {(char_u *)NULL, (char_u *)0L}
1184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1187#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001188 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {
1190# ifdef WIN3264
1191 /* may be changed to "grep -n" in os_win32.c */
1192 (char_u *)"findstr /n",
1193# else
1194# ifdef UNIX
1195 /* Add an extra file name so that grep will always
1196 * insert a file name in the match line. */
1197 (char_u *)"grep -n $* /dev/null",
1198# else
1199# ifdef VMS
1200 (char_u *)"SEARCH/NUMBERS ",
1201# else
1202 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203# endif
1204# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207#else
1208 (char_u *)NULL, PV_NONE,
1209 {(char_u *)NULL, (char_u *)0L}
1210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1213#ifdef CURSOR_SHAPE
1214 (char_u *)&p_guicursor, PV_NONE,
1215 {
1216# ifdef FEAT_GUI
1217 (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",
1218# else /* MSDOS or Win32 console */
1219 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1220# endif
1221 (char_u *)0L}
1222#else
1223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
1225#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1228#ifdef FEAT_GUI
1229 (char_u *)&p_guifont, PV_NONE,
1230 {(char_u *)"", (char_u *)0L}
1231#else
1232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
1234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1237#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1238 (char_u *)&p_guifontset, PV_NONE,
1239 {(char_u *)"", (char_u *)0L}
1240#else
1241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
1243#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1246#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1247 (char_u *)&p_guifontwide, PV_NONE,
1248 {(char_u *)"", (char_u *)0L}
1249#else
1250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
1252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001255#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 (char_u *)&p_ghr, PV_NONE,
1257#else
1258 (char_u *)NULL, PV_NONE,
1259#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001262#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 (char_u *)&p_go, PV_NONE,
1264# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001265 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001267 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268# endif
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001273 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274 {"guipty", NULL, P_BOOL|P_VI_DEF,
1275#if defined(FEAT_GUI)
1276 (char_u *)&p_guipty, PV_NONE,
1277#else
1278 (char_u *)NULL, PV_NONE,
1279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001280 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001281 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001282#if defined(FEAT_GUI_TABLINE)
1283 (char_u *)&p_gtl, PV_NONE,
1284 {(char_u *)"", (char_u *)0L}
1285#else
1286 (char_u *)NULL, PV_NONE,
1287 {(char_u *)NULL, (char_u *)0L}
1288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001290 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001291#if defined(FEAT_GUI_TABLINE)
1292 (char_u *)&p_gtt, PV_NONE,
1293 {(char_u *)"", (char_u *)0L}
1294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1300 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001301 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1303 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001304 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1305 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306 {"helpheight", "hh", P_NUM|P_VI_DEF,
1307#ifdef FEAT_WINDOWS
1308 (char_u *)&p_hh, PV_NONE,
1309#else
1310 (char_u *)NULL, PV_NONE,
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1314#ifdef FEAT_MULTI_LANG
1315 (char_u *)&p_hlg, PV_NONE,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)0L, (char_u *)0L}
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 {"hidden", "hid", P_BOOL|P_VI_DEF,
1323 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1326 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1328 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"history", "hi", P_NUM|P_VIM,
1330 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1333#ifdef FEAT_RIGHTLEFT
1334 (char_u *)&p_hkmap, PV_NONE,
1335#else
1336 (char_u *)NULL, PV_NONE,
1337#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1340#ifdef FEAT_RIGHTLEFT
1341 (char_u *)&p_hkmapp, PV_NONE,
1342#else
1343 (char_u *)NULL, PV_NONE,
1344#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001345 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1347 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 {"icon", NULL, P_BOOL|P_VI_DEF,
1350#ifdef FEAT_TITLE
1351 (char_u *)&p_icon, PV_NONE,
1352#else
1353 (char_u *)NULL, PV_NONE,
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"iconstring", NULL, P_STRING|P_VI_DEF,
1357#ifdef FEAT_TITLE
1358 (char_u *)&p_iconstring, PV_NONE,
1359#else
1360 (char_u *)NULL, PV_NONE,
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1364 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001367#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 (char_u *)&p_imak, PV_NONE,
1369#else
1370 (char_u *)NULL, PV_NONE,
1371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1374#ifdef USE_IM_CONTROL
1375 (char_u *)&p_imcmdline, PV_NONE,
1376#else
1377 (char_u *)NULL, PV_NONE,
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1381#ifdef USE_IM_CONTROL
1382 (char_u *)&p_imdisable, PV_NONE,
1383#else
1384 (char_u *)NULL, PV_NONE,
1385#endif
1386#ifdef __sgi
1387 {(char_u *)TRUE, (char_u *)0L}
1388#else
1389 {(char_u *)FALSE, (char_u *)0L}
1390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"iminsert", "imi", P_NUM|P_VI_DEF,
1393 (char_u *)&p_iminsert, PV_IMI,
1394#ifdef B_IMODE_IM
1395 {(char_u *)B_IMODE_IM, (char_u *)0L}
1396#else
1397 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"imsearch", "ims", P_NUM|P_VI_DEF,
1401 (char_u *)&p_imsearch, PV_IMS,
1402#ifdef B_IMODE_IM
1403 {(char_u *)B_IMODE_IM, (char_u *)0L}
1404#else
1405 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1409#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001410 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1412#else
1413 (char_u *)NULL, PV_NONE,
1414 {(char_u *)0L, (char_u *)0L}
1415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1418#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1419 (char_u *)&p_inex, PV_INEX,
1420 {(char_u *)"", (char_u *)0L}
1421#else
1422 (char_u *)NULL, PV_NONE,
1423 {(char_u *)0L, (char_u *)0L}
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1427 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1430#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1431 (char_u *)&p_inde, PV_INDE,
1432 {(char_u *)"", (char_u *)0L}
1433#else
1434 (char_u *)NULL, PV_NONE,
1435 {(char_u *)0L, (char_u *)0L}
1436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1439#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1440 (char_u *)&p_indk, PV_INDK,
1441 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1442#else
1443 (char_u *)NULL, PV_NONE,
1444 {(char_u *)0L, (char_u *)0L}
1445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001446 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 {"infercase", "inf", P_BOOL|P_VI_DEF,
1448 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1451 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1454 (char_u *)&p_isf, PV_NONE,
1455 {
1456#ifdef BACKSLASH_IN_FILENAME
1457 /* Excluded are: & and ^ are special in cmd.exe
1458 * ( and ) are used in text separating fnames */
1459 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1460#else
1461# ifdef AMIGA
1462 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1463# else
1464# ifdef VMS
1465 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1466# else /* UNIX et al. */
1467# ifdef EBCDIC
1468 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1469# else
1470 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1471# endif
1472# endif
1473# endif
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1477 (char_u *)&p_isi, PV_NONE,
1478 {
1479#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1480 (char_u *)"@,48-57,_,128-167,224-235",
1481#else
1482# ifdef EBCDIC
1483 /* TODO: EBCDIC Check this! @ == isalpha()*/
1484 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1485 "112-120,128,140-142,156,158,172,"
1486 "174,186,191,203-207,219-225,235-239,"
1487 "251-254",
1488# else
1489 (char_u *)"@,48-57,_,192-255",
1490# endif
1491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1494 (char_u *)&p_isk, PV_ISK,
1495 {
1496#ifdef EBCDIC
1497 (char_u *)"@,240-249,_",
1498 /* TODO: EBCDIC Check this! @ == isalpha()*/
1499 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1500 "112-120,128,140-142,156,158,172,"
1501 "174,186,191,203-207,219-225,235-239,"
1502 "251-254",
1503#else
1504 (char_u *)"@,48-57,_",
1505# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1506 (char_u *)"@,48-57,_,128-167,224-235"
1507# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001508 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509# endif
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1513 (char_u *)&p_isp, PV_NONE,
1514 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001515#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1516 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 || defined(VMS)
1518 (char_u *)"@,~-255",
1519#else
1520# ifdef EBCDIC
1521 /* all chars above 63 are printable */
1522 (char_u *)"63-255",
1523# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001524 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525# endif
1526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001527 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1529 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1532#ifdef FEAT_CRYPT
1533 (char_u *)&p_key, PV_KEY,
1534 {(char_u *)"", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001540 {"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 +00001541#ifdef FEAT_KEYMAP
1542 (char_u *)&p_keymap, PV_KMAP,
1543 {(char_u *)"", (char_u *)0L}
1544#else
1545 (char_u *)NULL, PV_NONE,
1546 {(char_u *)"", (char_u *)0L}
1547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001548 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1550#ifdef FEAT_VISUAL
1551 (char_u *)&p_km, PV_NONE,
1552#else
1553 (char_u *)NULL, PV_NONE,
1554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001555 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001557 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {
1559#if defined(MSDOS) || defined(MSWIN)
1560 (char_u *)":help",
1561#else
1562#ifdef VMS
1563 (char_u *)"help",
1564#else
1565# if defined(OS2)
1566 (char_u *)"view /",
1567# else
1568# ifdef USEMAN_S
1569 (char_u *)"man -s",
1570# else
1571 (char_u *)"man",
1572# endif
1573# endif
1574#endif
1575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001576 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1578#ifdef FEAT_LANGMAP
1579 (char_u *)&p_langmap, PV_NONE,
1580 {(char_u *)"", /* unmatched } */
1581#else
1582 (char_u *)NULL, PV_NONE,
1583 {(char_u *)NULL,
1584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001585 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001586 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1588 (char_u *)&p_lm, PV_NONE,
1589#else
1590 (char_u *)NULL, PV_NONE,
1591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001592 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1594#ifdef FEAT_WINDOWS
1595 (char_u *)&p_ls, PV_NONE,
1596#else
1597 (char_u *)NULL, PV_NONE,
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1601 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001602 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1604#ifdef FEAT_LINEBREAK
1605 (char_u *)VAR_WIN, PV_LBR,
1606#else
1607 (char_u *)NULL, PV_NONE,
1608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1611 (char_u *)&Rows, PV_NONE,
1612 {
1613#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1614 (char_u *)25L,
1615#else
1616 (char_u *)24L,
1617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001618 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001619 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1620#ifdef FEAT_GUI
1621 (char_u *)&p_linespace, PV_NONE,
1622#else
1623 (char_u *)NULL, PV_NONE,
1624#endif
1625#ifdef FEAT_GUI_W32
1626 {(char_u *)1L, (char_u *)0L}
1627#else
1628 {(char_u *)0L, (char_u *)0L}
1629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"lisp", NULL, P_BOOL|P_VI_DEF,
1632#ifdef FEAT_LISP
1633 (char_u *)&p_lisp, PV_LISP,
1634#else
1635 (char_u *)NULL, PV_NONE,
1636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639#ifdef FEAT_LISP
1640 (char_u *)&p_lispwords, PV_NONE,
1641 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1642#else
1643 (char_u *)NULL, PV_NONE,
1644 {(char_u *)"", (char_u *)0L}
1645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1648 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1651 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1654 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001656#ifdef FEAT_GUI_MAC
1657 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1658 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"magic", NULL, P_BOOL|P_VI_DEF,
1662 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001664 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665#ifdef FEAT_QUICKFIX
1666 (char_u *)&p_mef, PV_NONE,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)NULL, (char_u *)0L}
1671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1674#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001675 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676# ifdef VMS
1677 {(char_u *)"MMS", (char_u *)0L}
1678# else
1679 {(char_u *)"make", (char_u *)0L}
1680# endif
1681#else
1682 (char_u *)NULL, PV_NONE,
1683 {(char_u *)NULL, (char_u *)0L}
1684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001685 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1687 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1689 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 {"matchtime", "mat", P_NUM|P_VI_DEF,
1691 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001693 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1694#ifdef FEAT_MBYTE
1695 (char_u *)&p_mco, PV_NONE,
1696#else
1697 (char_u *)NULL, PV_NONE,
1698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1701#ifdef FEAT_EVAL
1702 (char_u *)&p_mfd, PV_NONE,
1703#else
1704 (char_u *)NULL, PV_NONE,
1705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001706 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001707 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1708 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"maxmem", "mm", P_NUM|P_VI_DEF,
1711 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1713 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001714 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1715 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001716 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1718 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 {"menuitems", "mis", P_NUM|P_VI_DEF,
1722#ifdef FEAT_MENU
1723 (char_u *)&p_mis, PV_NONE,
1724#else
1725 (char_u *)NULL, PV_NONE,
1726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"mesg", NULL, P_BOOL|P_VI_DEF,
1729 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001731 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001732#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001733 (char_u *)&p_msm, PV_NONE,
1734 {(char_u *)"460000,2000,500", (char_u *)0L}
1735#else
1736 (char_u *)NULL, PV_NONE,
1737 {(char_u *)0L, (char_u *)0L}
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"modeline", "ml", P_BOOL|P_VIM,
1741 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"modelines", "mls", P_NUM|P_VI_DEF,
1744 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1747 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1750 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 {"more", NULL, P_BOOL|P_VIM,
1753 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1756 (char_u *)&p_mouse, PV_NONE,
1757 {
1758#if defined(MSDOS) || defined(WIN3264)
1759 (char_u *)"a",
1760#else
1761 (char_u *)"",
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1765#ifdef FEAT_GUI
1766 (char_u *)&p_mousef, PV_NONE,
1767#else
1768 (char_u *)NULL, PV_NONE,
1769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1772#ifdef FEAT_GUI
1773 (char_u *)&p_mh, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1779 (char_u *)&p_mousem, PV_NONE,
1780 {
1781#if defined(MSDOS) || defined(MSWIN)
1782 (char_u *)"popup",
1783#else
1784# if defined(MACOS)
1785 (char_u *)"popup_setpos",
1786# else
1787 (char_u *)"extend",
1788# endif
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1792#ifdef FEAT_MOUSESHAPE
1793 (char_u *)&p_mouseshape, PV_NONE,
1794 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1795#else
1796 (char_u *)NULL, PV_NONE,
1797 {(char_u *)NULL, (char_u *)0L}
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1801 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001803 {"mzquantum", "mzq", P_NUM,
1804#ifdef FEAT_MZSCHEME
1805 (char_u *)&p_mzq, PV_NONE,
1806#else
1807 (char_u *)NULL, PV_NONE,
1808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"novice", NULL, P_BOOL|P_VI_DEF,
1811 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1814 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 {(char_u *)"octal,hex", (char_u *)0L}
1816 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1818 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001820 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1821#ifdef FEAT_LINEBREAK
1822 (char_u *)VAR_WIN, PV_NUW,
1823#else
1824 (char_u *)NULL, PV_NONE,
1825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001827 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001828#ifdef FEAT_COMPL_FUNC
1829 (char_u *)&p_ofu, PV_OFU,
1830 {(char_u *)"", (char_u *)0L}
1831#else
1832 (char_u *)NULL, PV_NONE,
1833 {(char_u *)0L, (char_u *)0L}
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"open", NULL, P_BOOL|P_VI_DEF,
1837 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001839 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1840#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1841 (char_u *)&p_odev, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
1845 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001847 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1848 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"optimize", "opt", P_BOOL|P_VI_DEF,
1851 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1854#ifdef FEAT_OSFILETYPE
1855 (char_u *)&p_oft, PV_OFT,
1856 {(char_u *)DFLT_OFT, (char_u *)0L}
1857#else
1858 (char_u *)NULL, PV_NONE,
1859 {(char_u *)0L, (char_u *)0L}
1860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"paragraphs", "para", P_STRING|P_VI_DEF,
1863 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001864 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001866 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1870 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1873#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1874 (char_u *)&p_pex, PV_NONE,
1875 {(char_u *)"", (char_u *)0L}
1876#else
1877 (char_u *)NULL, PV_NONE,
1878 {(char_u *)0L, (char_u *)0L}
1879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001881 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001885 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {
1887#if defined AMIGA || defined MSDOS || defined MSWIN
1888 (char_u *)".,,",
1889#else
1890# if defined(__EMX__)
1891 (char_u *)".,/emx/include,,",
1892# else /* Unix, probably */
1893 (char_u *)".,/usr/include,,",
1894# endif
1895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1898 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001900 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1902 (char_u *)&p_pvh, PV_NONE,
1903#else
1904 (char_u *)NULL, PV_NONE,
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1908#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1909 (char_u *)VAR_WIN, PV_PVW,
1910#else
1911 (char_u *)NULL, PV_NONE,
1912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001914 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915#ifdef FEAT_PRINTER
1916 (char_u *)&p_pdev, PV_NONE,
1917 {(char_u *)"", (char_u *)0L}
1918#else
1919 (char_u *)NULL, PV_NONE,
1920 {(char_u *)NULL, (char_u *)0L}
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"printencoding", "penc", P_STRING|P_VI_DEF,
1924#ifdef FEAT_POSTSCRIPT
1925 (char_u *)&p_penc, PV_NONE,
1926 {(char_u *)"", (char_u *)0L}
1927#else
1928 (char_u *)NULL, PV_NONE,
1929 {(char_u *)NULL, (char_u *)0L}
1930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1933#ifdef FEAT_POSTSCRIPT
1934 (char_u *)&p_pexpr, PV_NONE,
1935 {(char_u *)"", (char_u *)0L}
1936#else
1937 (char_u *)NULL, PV_NONE,
1938 {(char_u *)NULL, (char_u *)0L}
1939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"printfont", "pfn", P_STRING|P_VI_DEF,
1942#ifdef FEAT_PRINTER
1943 (char_u *)&p_pfn, PV_NONE,
1944 {
1945# ifdef MSWIN
1946 (char_u *)"Courier_New:h10",
1947# else
1948 (char_u *)"courier",
1949# endif
1950 (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)NULL, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1957#ifdef FEAT_PRINTER
1958 (char_u *)&p_header, PV_NONE,
1959 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1960#else
1961 (char_u *)NULL, PV_NONE,
1962 {(char_u *)NULL, (char_u *)0L}
1963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001965 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1966#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1967 (char_u *)&p_pmcs, PV_NONE,
1968 {(char_u *)"", (char_u *)0L}
1969#else
1970 (char_u *)NULL, PV_NONE,
1971 {(char_u *)NULL, (char_u *)0L}
1972#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001974 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1975#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1976 (char_u *)&p_pmfn, PV_NONE,
1977 {(char_u *)"", (char_u *)0L}
1978#else
1979 (char_u *)NULL, PV_NONE,
1980 {(char_u *)NULL, (char_u *)0L}
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1984#ifdef FEAT_PRINTER
1985 (char_u *)&p_popt, PV_NONE,
1986 {(char_u *)"", (char_u *)0L}
1987#else
1988 (char_u *)NULL, PV_NONE,
1989 {(char_u *)NULL, (char_u *)0L}
1990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001993 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00001995 {"pumheight", "ph", P_NUM|P_VI_DEF,
1996#ifdef FEAT_INS_EXPAND
1997 (char_u *)&p_ph, PV_NONE,
1998#else
1999 (char_u *)NULL, PV_NONE,
2000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002002 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2003#ifdef FEAT_TEXTOBJ
2004 (char_u *)&p_qe, PV_QE,
2005 {(char_u *)"\\", (char_u *)0L}
2006#else
2007 (char_u *)NULL, PV_NONE,
2008 {(char_u *)NULL, (char_u *)0L}
2009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2012 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 {"redraw", NULL, P_BOOL|P_VI_DEF,
2015 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002017 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2018#ifdef FEAT_RELTIME
2019 (char_u *)&p_rdt, PV_NONE,
2020#else
2021 (char_u *)NULL, PV_NONE,
2022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002023 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002024 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2025 (char_u *)VAR_WIN, PV_RNU,
2026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"remap", NULL, P_BOOL|P_VI_DEF,
2028 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"report", NULL, P_NUM|P_VI_DEF,
2031 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2034#ifdef WIN3264
2035 (char_u *)&p_rs, PV_NONE,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2041#ifdef FEAT_RIGHTLEFT
2042 (char_u *)&p_ri, PV_NONE,
2043#else
2044 (char_u *)NULL, PV_NONE,
2045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2048#ifdef FEAT_RIGHTLEFT
2049 (char_u *)VAR_WIN, PV_RL,
2050#else
2051 (char_u *)NULL, PV_NONE,
2052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2055#ifdef FEAT_RIGHTLEFT
2056 (char_u *)VAR_WIN, PV_RLC,
2057 {(char_u *)"search", (char_u *)NULL}
2058#else
2059 (char_u *)NULL, PV_NONE,
2060 {(char_u *)NULL, (char_u *)0L}
2061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2064#ifdef FEAT_CMDL_INFO
2065 (char_u *)&p_ru, PV_NONE,
2066#else
2067 (char_u *)NULL, PV_NONE,
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2071#ifdef FEAT_STL_OPT
2072 (char_u *)&p_ruf, PV_NONE,
2073#else
2074 (char_u *)NULL, PV_NONE,
2075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002076 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2078 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2080 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2082 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2085#ifdef FEAT_SCROLLBIND
2086 (char_u *)VAR_WIN, PV_SCBIND,
2087#else
2088 (char_u *)NULL, PV_NONE,
2089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2092 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2095 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2098#ifdef FEAT_SCROLLBIND
2099 (char_u *)&p_sbo, PV_NONE,
2100 {(char_u *)"ver,jump", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)0L, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"sections", "sect", P_STRING|P_VI_DEF,
2107 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2109 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2111 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"selection", "sel", P_STRING|P_VI_DEF,
2114#ifdef FEAT_VISUAL
2115 (char_u *)&p_sel, PV_NONE,
2116#else
2117 (char_u *)NULL, PV_NONE,
2118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)"inclusive", (char_u *)0L}
2120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2122#ifdef FEAT_VISUAL
2123 (char_u *)&p_slm, PV_NONE,
2124#else
2125 (char_u *)NULL, PV_NONE,
2126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2129#ifdef FEAT_SESSION
2130 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002131 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 (char_u *)0L}
2133#else
2134 (char_u *)NULL, PV_NONE,
2135 {(char_u *)0L, (char_u *)0L}
2136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2139 (char_u *)&p_sh, PV_NONE,
2140 {
2141#ifdef VMS
2142 (char_u *)"-",
2143#else
2144# if defined(MSDOS)
2145 (char_u *)"command",
2146# else
2147# if defined(WIN16)
2148 (char_u *)"command.com",
2149# else
2150# if defined(WIN3264)
2151 (char_u *)"", /* set in set_init_1() */
2152# else
2153# if defined(OS2)
2154 (char_u *)"cmd.exe",
2155# else
2156# if defined(ARCHIE)
2157 (char_u *)"gos",
2158# else
2159 (char_u *)"sh",
2160# endif
2161# endif
2162# endif
2163# endif
2164# endif
2165#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002166 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2168 (char_u *)&p_shcf, PV_NONE,
2169 {
2170#if defined(MSDOS) || defined(MSWIN)
2171 (char_u *)"/c",
2172#else
2173# if defined(OS2)
2174 (char_u *)"/c",
2175# else
2176 (char_u *)"-c",
2177# endif
2178#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2181#ifdef FEAT_QUICKFIX
2182 (char_u *)&p_sp, PV_NONE,
2183 {
2184#if defined(UNIX) || defined(OS2)
2185# ifdef ARCHIE
2186 (char_u *)"2>",
2187# else
2188 (char_u *)"| tee",
2189# endif
2190#else
2191 (char_u *)">",
2192#endif
2193 (char_u *)0L}
2194#else
2195 (char_u *)NULL, PV_NONE,
2196 {(char_u *)0L, (char_u *)0L}
2197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002198 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2200 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2203 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2206#ifdef BACKSLASH_IN_FILENAME
2207 (char_u *)&p_ssl, PV_NONE,
2208#else
2209 (char_u *)NULL, PV_NONE,
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002212 {"shelltemp", "stmp", P_BOOL,
2213 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"shelltype", "st", P_NUM|P_VI_DEF,
2216#ifdef AMIGA
2217 (char_u *)&p_st, PV_NONE,
2218#else
2219 (char_u *)NULL, PV_NONE,
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2223 (char_u *)&p_sxq, PV_NONE,
2224 {
2225#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2226 (char_u *)"\"",
2227#else
2228 (char_u *)"",
2229#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002230 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2232 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2235 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2238 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)"", (char_u *)"filnxtToO"}
2240 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"shortname", "sn", P_BOOL|P_VI_DEF,
2242#ifdef SHORT_FNAME
2243 (char_u *)NULL, PV_NONE,
2244#else
2245 (char_u *)&p_sn, PV_SN,
2246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2249#ifdef FEAT_LINEBREAK
2250 (char_u *)&p_sbr, PV_NONE,
2251#else
2252 (char_u *)NULL, PV_NONE,
2253#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"showcmd", "sc", P_BOOL|P_VIM,
2256#ifdef FEAT_CMDL_INFO
2257 (char_u *)&p_sc, PV_NONE,
2258#else
2259 (char_u *)NULL, PV_NONE,
2260#endif
2261 {(char_u *)FALSE,
2262#ifdef UNIX
2263 (char_u *)FALSE
2264#else
2265 (char_u *)TRUE
2266#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2269 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2272 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"showmode", "smd", P_BOOL|P_VIM,
2275 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002277 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2278#ifdef FEAT_WINDOWS
2279 (char_u *)&p_stal, PV_NONE,
2280#else
2281 (char_u *)NULL, PV_NONE,
2282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2285 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2288 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2291 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2294 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2297#ifdef FEAT_SMARTINDENT
2298 (char_u *)&p_si, PV_SI,
2299#else
2300 (char_u *)NULL, PV_NONE,
2301#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2304 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2307 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2310 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002312 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002313#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002314 (char_u *)VAR_WIN, PV_SPELL,
2315#else
2316 (char_u *)NULL, PV_NONE,
2317#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002319 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002320#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002321 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002322 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002323#else
2324 (char_u *)NULL, PV_NONE,
2325 {(char_u *)0L, (char_u *)0L}
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002328 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002329#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002330 (char_u *)&p_spf, PV_SPF,
2331 {(char_u *)"", (char_u *)0L}
2332#else
2333 (char_u *)NULL, PV_NONE,
2334 {(char_u *)0L, (char_u *)0L}
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002337 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002338#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002339 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002340 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002341#else
2342 (char_u *)NULL, PV_NONE,
2343 {(char_u *)0L, (char_u *)0L}
2344#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002346 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002347#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002348 (char_u *)&p_sps, PV_NONE,
2349 {(char_u *)"best", (char_u *)0L}
2350#else
2351 (char_u *)NULL, PV_NONE,
2352 {(char_u *)0L, (char_u *)0L}
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2356#ifdef FEAT_WINDOWS
2357 (char_u *)&p_sb, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"splitright", "spr", P_BOOL|P_VI_DEF,
2363#ifdef FEAT_VERTSPLIT
2364 (char_u *)&p_spr, PV_NONE,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2370 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2373#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002374 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2380 (char_u *)&p_su, PV_NONE,
2381 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002384#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 (char_u *)&p_sua, PV_SUA,
2386 {(char_u *)"", (char_u *)0L}
2387#else
2388 (char_u *)NULL, PV_NONE,
2389 {(char_u *)0L, (char_u *)0L}
2390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2393 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"swapsync", "sws", P_STRING|P_VI_DEF,
2396 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2399 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002401 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2402#ifdef FEAT_SYN_HL
2403 (char_u *)&p_smc, PV_SMC,
2404 {(char_u *)3000L, (char_u *)0L}
2405#else
2406 (char_u *)NULL, PV_NONE,
2407 {(char_u *)0L, (char_u *)0L}
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002410 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411#ifdef FEAT_SYN_HL
2412 (char_u *)&p_syn, PV_SYN,
2413 {(char_u *)"", (char_u *)0L}
2414#else
2415 (char_u *)NULL, PV_NONE,
2416 {(char_u *)0L, (char_u *)0L}
2417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002419 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2420#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002421 (char_u *)&p_tal, PV_NONE,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002426 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2427#ifdef FEAT_WINDOWS
2428 (char_u *)&p_tpm, PV_NONE,
2429#else
2430 (char_u *)NULL, PV_NONE,
2431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2434 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2437 (char_u *)&p_tbs, PV_NONE,
2438#ifdef VMS /* binary searching doesn't appear to work on VMS */
2439 {(char_u *)0L, (char_u *)0L}
2440#else
2441 {(char_u *)TRUE, (char_u *)0L}
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"taglength", "tl", P_NUM|P_VI_DEF,
2445 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"tagrelative", "tr", P_BOOL|P_VIM,
2448 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002451 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {
2453#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2454 (char_u *)"./tags,./TAGS,tags,TAGS",
2455#else
2456 (char_u *)"./tags,tags",
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2460 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2463 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2466#ifdef FEAT_ARABIC
2467 (char_u *)&p_tbidi, PV_NONE,
2468#else
2469 (char_u *)NULL, PV_NONE,
2470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2473#ifdef FEAT_MBYTE
2474 (char_u *)&p_tenc, PV_NONE,
2475 {(char_u *)"", (char_u *)0L}
2476#else
2477 (char_u *)NULL, PV_NONE,
2478 {(char_u *)0L, (char_u *)0L}
2479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"terse", NULL, P_BOOL|P_VI_DEF,
2482 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"textauto", "ta", P_BOOL|P_VIM,
2485 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2489 (char_u *)&p_tx, PV_TX,
2490 {
2491#ifdef USE_CRNL
2492 (char_u *)TRUE,
2493#else
2494 (char_u *)FALSE,
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2498 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2501#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002502 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503#else
2504 (char_u *)NULL, PV_NONE,
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2508 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"timeout", "to", P_BOOL|P_VI_DEF,
2511 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2514 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"title", NULL, P_BOOL|P_VI_DEF,
2517#ifdef FEAT_TITLE
2518 (char_u *)&p_title, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"titlelen", NULL, P_NUM|P_VI_DEF,
2524#ifdef FEAT_TITLE
2525 (char_u *)&p_titlelen, PV_NONE,
2526#else
2527 (char_u *)NULL, PV_NONE,
2528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002530 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531#ifdef FEAT_TITLE
2532 (char_u *)&p_titleold, PV_NONE,
2533 {(char_u *)N_("Thanks for flying Vim"),
2534 (char_u *)0L}
2535#else
2536 (char_u *)NULL, PV_NONE,
2537 {(char_u *)0L, (char_u *)0L}
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"titlestring", NULL, P_STRING|P_VI_DEF,
2541#ifdef FEAT_TITLE
2542 (char_u *)&p_titlestring, PV_NONE,
2543#else
2544 (char_u *)NULL, PV_NONE,
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2548 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2549 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)"icons,tooltips", (char_u *)0L}
2551 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552#endif
2553#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2554 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2555 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557#endif
2558 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2559 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2562 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2565 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2568 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2571#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2572 (char_u *)&p_ttym, PV_NONE,
2573#else
2574 (char_u *)NULL, PV_NONE,
2575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2578 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2581 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"undolevels", "ul", P_NUM|P_VI_DEF,
2584 (char_u *)&p_ul, PV_NONE,
2585 {
2586#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2587 (char_u *)1000L,
2588#else
2589 (char_u *)100L,
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"updatecount", "uc", P_NUM|P_VI_DEF,
2593 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"updatetime", "ut", P_NUM|P_VI_DEF,
2596 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"verbose", "vbs", P_NUM|P_VI_DEF,
2599 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002601 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2602 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2605#ifdef FEAT_SESSION
2606 (char_u *)&p_vdir, PV_NONE,
2607 {(char_u *)DFLT_VDIR, (char_u *)0L}
2608#else
2609 (char_u *)NULL, PV_NONE,
2610 {(char_u *)0L, (char_u *)0L}
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2614#ifdef FEAT_SESSION
2615 (char_u *)&p_vop, PV_NONE,
2616 {(char_u *)"folds,options,cursor", (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2623#ifdef FEAT_VIMINFO
2624 (char_u *)&p_viminfo, PV_NONE,
2625#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002626 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627#else
2628# ifdef AMIGA
2629 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002630 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002632 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633# endif
2634#endif
2635#else
2636 (char_u *)NULL, PV_NONE,
2637 {(char_u *)0L, (char_u *)0L}
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2641#ifdef FEAT_VIRTUALEDIT
2642 (char_u *)&p_ve, PV_NONE,
2643 {(char_u *)"", (char_u *)""}
2644#else
2645 (char_u *)NULL, PV_NONE,
2646 {(char_u *)0L, (char_u *)0L}
2647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2650 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"w300", NULL, P_NUM|P_VI_DEF,
2653 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"w1200", NULL, P_NUM|P_VI_DEF,
2656 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"w9600", NULL, P_NUM|P_VI_DEF,
2659 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"warn", NULL, P_BOOL|P_VI_DEF,
2662 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2665 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2668 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"wildchar", "wc", P_NUM|P_VIM,
2671 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2673 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2675 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2678#ifdef FEAT_WILDIGN
2679 (char_u *)&p_wig, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2685#ifdef FEAT_WILDMENU
2686 (char_u *)&p_wmnu, PV_NONE,
2687#else
2688 (char_u *)NULL, PV_NONE,
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2692 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002694 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2695#ifdef FEAT_CMDL_COMPL
2696 (char_u *)&p_wop, PV_NONE,
2697 {(char_u *)"", (char_u *)0L}
2698#else
2699 (char_u *)NULL, PV_NONE,
2700 {(char_u *)NULL, (char_u *)0L}
2701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2704#ifdef FEAT_WAK
2705 (char_u *)&p_wak, PV_NONE,
2706 {(char_u *)"menu", (char_u *)0L}
2707#else
2708 (char_u *)NULL, PV_NONE,
2709 {(char_u *)NULL, (char_u *)0L}
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002713 (char_u *)&p_window, 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 {"winheight", "wh", P_NUM|P_VI_DEF,
2716#ifdef FEAT_WINDOWS
2717 (char_u *)&p_wh, PV_NONE,
2718#else
2719 (char_u *)NULL, PV_NONE,
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002723#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 (char_u *)VAR_WIN, PV_WFH,
2725#else
2726 (char_u *)NULL, PV_NONE,
2727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002729 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2730#ifdef FEAT_VERTSPLIT
2731 (char_u *)VAR_WIN, PV_WFW,
2732#else
2733 (char_u *)NULL, PV_NONE,
2734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2737#ifdef FEAT_WINDOWS
2738 (char_u *)&p_wmh, PV_NONE,
2739#else
2740 (char_u *)NULL, PV_NONE,
2741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2744#ifdef FEAT_VERTSPLIT
2745 (char_u *)&p_wmw, PV_NONE,
2746#else
2747 (char_u *)NULL, PV_NONE,
2748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2751#ifdef FEAT_VERTSPLIT
2752 (char_u *)&p_wiw, PV_NONE,
2753#else
2754 (char_u *)NULL, PV_NONE,
2755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2758 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2761 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2764 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"write", NULL, P_BOOL|P_VI_DEF,
2767 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"writeany", "wa", P_BOOL|P_VI_DEF,
2770 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2773 (char_u *)&p_wb, PV_NONE,
2774 {
2775#ifdef FEAT_WRITEBACKUP
2776 (char_u *)TRUE,
2777#else
2778 (char_u *)FALSE,
2779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"writedelay", "wd", P_NUM|P_VI_DEF,
2782 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784
2785/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002786#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789
2790 p_term("t_AB", T_CAB)
2791 p_term("t_AF", T_CAF)
2792 p_term("t_AL", T_CAL)
2793 p_term("t_al", T_AL)
2794 p_term("t_bc", T_BC)
2795 p_term("t_cd", T_CD)
2796 p_term("t_ce", T_CE)
2797 p_term("t_cl", T_CL)
2798 p_term("t_cm", T_CM)
2799 p_term("t_Co", T_CCO)
2800 p_term("t_CS", T_CCS)
2801 p_term("t_cs", T_CS)
2802#ifdef FEAT_VERTSPLIT
2803 p_term("t_CV", T_CSV)
2804#endif
2805 p_term("t_ut", T_UT)
2806 p_term("t_da", T_DA)
2807 p_term("t_db", T_DB)
2808 p_term("t_DL", T_CDL)
2809 p_term("t_dl", T_DL)
2810 p_term("t_fs", T_FS)
2811 p_term("t_IE", T_CIE)
2812 p_term("t_IS", T_CIS)
2813 p_term("t_ke", T_KE)
2814 p_term("t_ks", T_KS)
2815 p_term("t_le", T_LE)
2816 p_term("t_mb", T_MB)
2817 p_term("t_md", T_MD)
2818 p_term("t_me", T_ME)
2819 p_term("t_mr", T_MR)
2820 p_term("t_ms", T_MS)
2821 p_term("t_nd", T_ND)
2822 p_term("t_op", T_OP)
2823 p_term("t_RI", T_CRI)
2824 p_term("t_RV", T_CRV)
2825 p_term("t_Sb", T_CSB)
2826 p_term("t_Sf", T_CSF)
2827 p_term("t_se", T_SE)
2828 p_term("t_so", T_SO)
2829 p_term("t_sr", T_SR)
2830 p_term("t_ts", T_TS)
2831 p_term("t_te", T_TE)
2832 p_term("t_ti", T_TI)
2833 p_term("t_ue", T_UE)
2834 p_term("t_us", T_US)
2835 p_term("t_vb", T_VB)
2836 p_term("t_ve", T_VE)
2837 p_term("t_vi", T_VI)
2838 p_term("t_vs", T_VS)
2839 p_term("t_WP", T_CWP)
2840 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002841 p_term("t_SI", T_CSI)
2842 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 p_term("t_xs", T_XS)
2844 p_term("t_ZH", T_CZH)
2845 p_term("t_ZR", T_CZR)
2846
2847/* terminal key codes are not in here */
2848
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 /* end marker */
2850 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851};
2852
2853#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2854
2855#ifdef FEAT_MBYTE
2856static char *(p_ambw_values[]) = {"single", "double", NULL};
2857#endif
2858static char *(p_bg_values[]) = {"light", "dark", NULL};
2859static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2860static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002861#ifdef FEAT_CMDL_COMPL
2862static char *(p_wop_values[]) = {"tagfile", NULL};
2863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864#ifdef FEAT_WAK
2865static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2866#endif
2867static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2868#ifdef FEAT_VISUAL
2869static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2870static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2871#endif
2872#ifdef FEAT_VISUAL
2873static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2874#endif
2875#ifdef FEAT_BROWSE
2876static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2877#endif
2878#ifdef FEAT_SCROLLBIND
2879static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2880#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002881static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882#ifdef FEAT_VERTSPLIT
2883static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2884#endif
2885#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002886# ifdef FEAT_AUTOCMD
2887static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2888# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002890# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2892#endif
2893static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2894#ifdef FEAT_FOLDING
2895static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002896# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002898# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 NULL};
2900static char *(p_fcl_values[]) = {"all", NULL};
2901#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002902#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002903static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905
2906static void set_option_default __ARGS((int, int opt_flags, int compatible));
2907static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002908static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002909static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910static char_u *illegal_char __ARGS((char_u *, int));
2911static int string_to_key __ARGS((char_u *arg));
2912#ifdef FEAT_CMDWIN
2913static char_u *check_cedit __ARGS((void));
2914#endif
2915#ifdef FEAT_TITLE
2916static void did_set_title __ARGS((int icon));
2917#endif
2918static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2919static void didset_options __ARGS((void));
2920static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002921#if defined(FEAT_EVAL) || defined(PROTO)
2922static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2923#else
2924# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2927static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2928static 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));
2929static char_u *set_chars_option __ARGS((char_u **varp));
2930#ifdef FEAT_CLIPBOARD
2931static char_u *check_clipboard_option __ARGS((void));
2932#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002933#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002934static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002935#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002936#ifdef FEAT_EVAL
2937static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2938#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002940static 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 +00002941static void check_redraw __ARGS((long_u flags));
2942static int findoption __ARGS((char_u *));
2943static int find_key_option __ARGS((char_u *));
2944static void showoptions __ARGS((int all, int opt_flags));
2945static int optval_default __ARGS((struct vimoption *, char_u *varp));
2946static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2947static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2948static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2949static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2950static int istermoption __ARGS((struct vimoption *));
2951static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2952static char_u *get_varp __ARGS((struct vimoption *));
2953static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2954static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2955#ifdef FEAT_LANGMAP
2956static void langmap_init __ARGS((void));
2957static void langmap_set __ARGS((void));
2958#endif
2959static void paste_option_changed __ARGS((void));
2960static void compatible_set __ARGS((void));
2961#ifdef FEAT_LINEBREAK
2962static void fill_breakat_flags __ARGS((void));
2963#endif
2964static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2965static int check_opt_strings __ARGS((char_u *val, char **values, int));
2966static int check_opt_wim __ARGS((void));
2967
2968/*
2969 * Initialize the options, first part.
2970 *
2971 * Called only once from main(), just after creating the first buffer.
2972 */
2973 void
2974set_init_1()
2975{
2976 char_u *p;
2977 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00002978 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979
2980#ifdef FEAT_LANGMAP
2981 langmap_init();
2982#endif
2983
2984 /* Be Vi compatible by default */
2985 p_cp = TRUE;
2986
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002987 /* Use POSIX compatibility when $VIM_POSIX is set. */
2988 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002989 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002990 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002991 set_string_default("shm", (char_u *)"A");
2992 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002993
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 /*
2995 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002996 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002998 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3000# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003001 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003003 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003005 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006# endif
3007#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003008 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 set_string_default("sh", p);
3010
3011#ifdef FEAT_WILDIGN
3012 /*
3013 * Set the default for 'backupskip' to include environment variables for
3014 * temp files.
3015 */
3016 {
3017# ifdef UNIX
3018 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3019# else
3020 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3021# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003022 int len;
3023 garray_T ga;
3024 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025
3026 ga_init2(&ga, 1, 100);
3027 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3028 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003029 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030# ifdef UNIX
3031 if (*names[n] == NUL)
3032 p = (char_u *)"/tmp";
3033 else
3034# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003035 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 if (p != NULL && *p != NUL)
3037 {
3038 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003039 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 if (ga_grow(&ga, len) == OK)
3041 {
3042 if (ga.ga_len > 0)
3043 STRCAT(ga.ga_data, ",");
3044 STRCAT(ga.ga_data, p);
3045 add_pathsep(ga.ga_data);
3046 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 ga.ga_len += len;
3048 }
3049 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003050 if (mustfree)
3051 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 }
3053 if (ga.ga_data != NULL)
3054 {
3055 set_string_default("bsk", ga.ga_data);
3056 vim_free(ga.ga_data);
3057 }
3058 }
3059#endif
3060
3061 /*
3062 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3063 */
3064 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003065 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003067#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3068 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3069#endif
3070 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003072 /* Use amount of memory available at this moment. */
3073 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074#else
3075# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003076 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003077 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003079 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080# endif
3081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003083 opt_idx = findoption((char_u *)"maxmem");
3084 if (opt_idx >= 0)
3085 {
3086#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3087 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3088 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3089#endif
3090 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3091 }
3092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 }
3094
3095#ifdef FEAT_GUI_W32
3096 /* force 'shortname' for Win32s */
3097 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003098 {
3099 opt_idx = findoption((char_u *)"shortname");
3100 if (opt_idx >= 0)
3101 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103#endif
3104
3105#ifdef FEAT_SEARCHPATH
3106 {
3107 char_u *cdpath;
3108 char_u *buf;
3109 int i;
3110 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003111 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112
3113 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003114 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115 if (cdpath != NULL)
3116 {
3117 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3118 if (buf != NULL)
3119 {
3120 buf[0] = ','; /* start with ",", current dir first */
3121 j = 1;
3122 for (i = 0; cdpath[i] != NUL; ++i)
3123 {
3124 if (vim_ispathlistsep(cdpath[i]))
3125 buf[j++] = ',';
3126 else
3127 {
3128 if (cdpath[i] == ' ' || cdpath[i] == ',')
3129 buf[j++] = '\\';
3130 buf[j++] = cdpath[i];
3131 }
3132 }
3133 buf[j] = NUL;
3134 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003135 if (opt_idx >= 0)
3136 {
3137 options[opt_idx].def_val[VI_DEFAULT] = buf;
3138 options[opt_idx].flags |= P_DEF_ALLOCED;
3139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003141 if (mustfree)
3142 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 }
3144 }
3145#endif
3146
3147#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3148 /* Set print encoding on platforms that don't default to latin1 */
3149 set_string_default("penc",
3150# if defined(MSWIN) || defined(OS2)
3151 (char_u *)"cp1252"
3152# else
3153# ifdef VMS
3154 (char_u *)"dec-mcs"
3155# else
3156# ifdef EBCDIC
3157 (char_u *)"ebcdic-uk"
3158# else
3159# ifdef MAC
3160 (char_u *)"mac-roman"
3161# else /* HPUX */
3162 (char_u *)"hp-roman8"
3163# endif
3164# endif
3165# endif
3166# endif
3167 );
3168#endif
3169
3170#ifdef FEAT_POSTSCRIPT
3171 /* 'printexpr' must be allocated to be able to evaluate it. */
3172 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003173# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3174 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175# else
3176# ifdef VMS
3177 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3178
3179# else
3180 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3181# endif
3182# endif
3183 );
3184#endif
3185
3186 /*
3187 * Set all the options (except the terminal options) to their default
3188 * value. Also set the global value for local options.
3189 */
3190 set_options_default(0);
3191
3192#ifdef FEAT_GUI
3193 if (found_reverse_arg)
3194 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3195#endif
3196
3197 curbuf->b_p_initialized = TRUE;
3198 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3199 check_buf_options(curbuf);
3200 check_win_options(curwin);
3201 check_options();
3202
3203 /* Must be before option_expand(), because that one needs vim_isIDc() */
3204 didset_options();
3205
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003206#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003207 /* Use the current chartab for the generic chartab. */
3208 init_spell_chartab();
3209#endif
3210
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211#ifdef FEAT_LINEBREAK
3212 /*
3213 * initialize the table for 'breakat'.
3214 */
3215 fill_breakat_flags();
3216#endif
3217
3218 /*
3219 * Expand environment variables and things like "~" for the defaults.
3220 * If option_expand() returns non-NULL the variable is expanded. This can
3221 * only happen for non-indirect options.
3222 * Also set the default to the expanded value, so ":set" does not list
3223 * them.
3224 * Don't set the P_ALLOCED flag, because we don't want to free the
3225 * default.
3226 */
3227 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3228 {
3229 if ((options[opt_idx].flags & P_GETTEXT)
3230 && options[opt_idx].var != NULL)
3231 p = (char_u *)_(*(char **)options[opt_idx].var);
3232 else
3233 p = option_expand(opt_idx, NULL);
3234 if (p != NULL && (p = vim_strsave(p)) != NULL)
3235 {
3236 *(char_u **)options[opt_idx].var = p;
3237 /* VIMEXP
3238 * Defaults for all expanded options are currently the same for Vi
3239 * and Vim. When this changes, add some code here! Also need to
3240 * split P_DEF_ALLOCED in two.
3241 */
3242 if (options[opt_idx].flags & P_DEF_ALLOCED)
3243 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3244 options[opt_idx].def_val[VI_DEFAULT] = p;
3245 options[opt_idx].flags |= P_DEF_ALLOCED;
3246 }
3247 }
3248
3249 /* Initialize the highlight_attr[] table. */
3250 highlight_changed();
3251
3252 save_file_ff(curbuf); /* Buffer is unchanged */
3253
3254 /* Parse default for 'wildmode' */
3255 check_opt_wim();
3256
3257#if defined(FEAT_ARABIC)
3258 /* Detect use of mlterm.
3259 * Mlterm is a terminal emulator akin to xterm that has some special
3260 * abilities (bidi namely).
3261 * NOTE: mlterm's author is being asked to 'set' a variable
3262 * instead of an environment variable due to inheritance.
3263 */
3264 if (mch_getenv((char_u *)"MLTERM") != NULL)
3265 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3266#endif
3267
3268#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3269 /* Parse default for 'fillchars'. */
3270 (void)set_chars_option(&p_fcs);
3271#endif
3272
3273#ifdef FEAT_CLIPBOARD
3274 /* Parse default for 'clipboard' */
3275 (void)check_clipboard_option();
3276#endif
3277
3278#ifdef FEAT_MBYTE
3279# if defined(WIN3264) && defined(FEAT_GETTEXT)
3280 /*
3281 * If $LANG isn't set, try to get a good value for it. This makes the
3282 * right language be used automatically. Don't do this for English.
3283 */
3284 if (mch_getenv((char_u *)"LANG") == NULL)
3285 {
3286 char buf[20];
3287
3288 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3289 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3290 * only the first two. */
3291 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3292 (LPTSTR)buf, 20);
3293 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3294 {
3295 /* There are a few exceptions (probably more) */
3296 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3297 STRCPY(buf, "zh_TW");
3298 else if (STRNICMP(buf, "chs", 3) == 0
3299 || STRNICMP(buf, "zhc", 3) == 0)
3300 STRCPY(buf, "zh_CN");
3301 else if (STRNICMP(buf, "jp", 2) == 0)
3302 STRCPY(buf, "ja");
3303 else
3304 buf[2] = NUL; /* truncate to two-letter code */
3305 vim_setenv("LANG", buf);
3306 }
3307 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003308# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003309# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003310 /* Moved to os_mac_conv.c to avoid dependency problems. */
3311 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003312# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313# endif
3314
3315 /* enc_locale() will try to find the encoding of the current locale. */
3316 p = enc_locale();
3317 if (p != NULL)
3318 {
3319 char_u *save_enc;
3320
3321 /* Try setting 'encoding' and check if the value is valid.
3322 * If not, go back to the default "latin1". */
3323 save_enc = p_enc;
3324 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003325 if (STRCMP(p_enc, "gb18030") == 0)
3326 {
3327 /* We don't support "gb18030", but "cp936" is a good substitute
3328 * for practical purposes, thus use that. It's not an alias to
3329 * still support conversion between gb18030 and utf-8. */
3330 p_enc = vim_strsave((char_u *)"cp936");
3331 vim_free(p);
3332 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 if (mb_init() == NULL)
3334 {
3335 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003336 if (opt_idx >= 0)
3337 {
3338 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3339 options[opt_idx].flags |= P_DEF_ALLOCED;
3340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003342#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3343 || defined(VMS)
3344 if (STRCMP(p_enc, "latin1") == 0
3345# ifdef FEAT_MBYTE
3346 || enc_utf8
3347# endif
3348 )
3349 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003350 /* Adjust the default for 'isprint' and 'iskeyword' to match
3351 * latin1. Also set the defaults for when 'nocompatible' is
3352 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003353 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003354 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003355 set_string_option_direct((char_u *)"isk", -1,
3356 ISK_LATIN1, OPT_FREE, SID_NONE);
3357 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003358 if (opt_idx >= 0)
3359 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003360 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003361 if (opt_idx >= 0)
3362 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003363 (void)init_chartab();
3364 }
3365#endif
3366
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367# if defined(WIN3264) && !defined(FEAT_GUI)
3368 /* Win32 console: When GetACP() returns a different value from
3369 * GetConsoleCP() set 'termencoding'. */
3370 if (GetACP() != GetConsoleCP())
3371 {
3372 char buf[50];
3373
3374 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3375 p_tenc = vim_strsave((char_u *)buf);
3376 if (p_tenc != NULL)
3377 {
3378 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003379 if (opt_idx >= 0)
3380 {
3381 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3382 options[opt_idx].flags |= P_DEF_ALLOCED;
3383 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 convert_setup(&input_conv, p_tenc, p_enc);
3385 convert_setup(&output_conv, p_enc, p_tenc);
3386 }
3387 else
3388 p_tenc = empty_option;
3389 }
3390# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003391# if defined(WIN3264) && defined(FEAT_MBYTE)
3392 /* $HOME may have characters in active code page. */
3393 init_homedir();
3394# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 }
3396 else
3397 {
3398 vim_free(p_enc);
3399 p_enc = save_enc;
3400 }
3401 }
3402#endif
3403
3404#ifdef FEAT_MULTI_LANG
3405 /* Set the default for 'helplang'. */
3406 set_helplang_default(get_mess_lang());
3407#endif
3408}
3409
3410/*
3411 * Set an option to its default value.
3412 * This does not take care of side effects!
3413 */
3414 static void
3415set_option_default(opt_idx, opt_flags, compatible)
3416 int opt_idx;
3417 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3418 int compatible; /* use Vi default value */
3419{
3420 char_u *varp; /* pointer to variable for current option */
3421 int dvi; /* index in def_val[] */
3422 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003423 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3425
3426 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3427 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003428 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 {
3430 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3431 if (flags & P_STRING)
3432 {
3433 /* Use set_string_option_direct() for local options to handle
3434 * freeing and allocating the value. */
3435 if (options[opt_idx].indir != PV_NONE)
3436 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003437 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438 else
3439 {
3440 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3441 free_string_option(*(char_u **)(varp));
3442 *(char_u **)varp = options[opt_idx].def_val[dvi];
3443 options[opt_idx].flags &= ~P_ALLOCED;
3444 }
3445 }
3446 else if (flags & P_NUM)
3447 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003448 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 win_comp_scroll(curwin);
3450 else
3451 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003452 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 /* May also set global value for local option. */
3454 if (both)
3455 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3456 *(long *)varp;
3457 }
3458 }
3459 else /* P_BOOL */
3460 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003461 /* the cast to long is required for Manx C, long_i is needed for
3462 * MSVC */
3463 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003464#ifdef UNIX
3465 /* 'modeline' defaults to off for root */
3466 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3467 *(int *)varp = FALSE;
3468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 /* May also set global value for local option. */
3470 if (both)
3471 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3472 *(int *)varp;
3473 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003474
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003475 /* The default value is not insecure. */
3476 flagsp = insecure_flag(opt_idx, opt_flags);
3477 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 }
3479
3480#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003481 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482#endif
3483}
3484
3485/*
3486 * Set all options (except terminal options) to their default value.
3487 */
3488 static void
3489set_options_default(opt_flags)
3490 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3491{
3492 int i;
3493#ifdef FEAT_WINDOWS
3494 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003495 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496#endif
3497
3498 for (i = 0; !istermoption(&options[i]); i++)
3499 if (!(options[i].flags & P_NODEFAULT))
3500 set_option_default(i, opt_flags, p_cp);
3501
3502#ifdef FEAT_WINDOWS
3503 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003504 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 win_comp_scroll(wp);
3506#else
3507 win_comp_scroll(curwin);
3508#endif
3509}
3510
3511/*
3512 * Set the Vi-default value of a string option.
3513 * Used for 'sh', 'backupskip' and 'term'.
3514 */
3515 void
3516set_string_default(name, val)
3517 char *name;
3518 char_u *val;
3519{
3520 char_u *p;
3521 int opt_idx;
3522
3523 p = vim_strsave(val);
3524 if (p != NULL) /* we don't want a NULL */
3525 {
3526 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 {
3529 if (options[opt_idx].flags & P_DEF_ALLOCED)
3530 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3531 options[opt_idx].def_val[VI_DEFAULT] = p;
3532 options[opt_idx].flags |= P_DEF_ALLOCED;
3533 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534 }
3535}
3536
3537/*
3538 * Set the Vi-default value of a number option.
3539 * Used for 'lines' and 'columns'.
3540 */
3541 void
3542set_number_default(name, val)
3543 char *name;
3544 long val;
3545{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003546 int opt_idx;
3547
3548 opt_idx = findoption((char_u *)name);
3549 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003550 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003551}
3552
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003553#if defined(EXITFREE) || defined(PROTO)
3554/*
3555 * Free all options.
3556 */
3557 void
3558free_all_options()
3559{
3560 int i;
3561
3562 for (i = 0; !istermoption(&options[i]); i++)
3563 {
3564 if (options[i].indir == PV_NONE)
3565 {
3566 /* global option: free value and default value. */
3567 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3568 free_string_option(*(char_u **)options[i].var);
3569 if (options[i].flags & P_DEF_ALLOCED)
3570 free_string_option(options[i].def_val[VI_DEFAULT]);
3571 }
3572 else if (options[i].var != VAR_WIN
3573 && (options[i].flags & P_STRING))
3574 /* buffer-local option: free global value */
3575 free_string_option(*(char_u **)options[i].var);
3576 }
3577}
3578#endif
3579
3580
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581/*
3582 * Initialize the options, part two: After getting Rows and Columns and
3583 * setting 'term'.
3584 */
3585 void
3586set_init_2()
3587{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003588 int idx;
3589
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 /*
3591 * 'scroll' defaults to half the window height. Note that this default is
3592 * wrong when the window height changes.
3593 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003594 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003595 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003596 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003597 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 comp_col();
3599
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003600 /*
3601 * 'window' is only for backwards compatibility with Vi.
3602 * Default is Rows - 1.
3603 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003604 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003605 p_window = Rows - 1;
3606 set_number_default("window", Rows - 1);
3607
Bram Moolenaarf740b292006-02-16 22:11:02 +00003608 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003610 /*
3611 * If 'background' wasn't set by the user, try guessing the value,
3612 * depending on the terminal name. Only need to check for terminals
3613 * with a dark background, that can handle color.
3614 */
3615 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003616 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3617 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003619 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003620 /* don't mark it as set, when starting the GUI it may be
3621 * changed again */
3622 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 }
3624#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003625
3626#ifdef CURSOR_SHAPE
3627 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3628#endif
3629#ifdef FEAT_MOUSESHAPE
3630 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3631#endif
3632#ifdef FEAT_PRINTER
3633 (void)parse_printoptions(); /* parse 'printoptions' default value */
3634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635}
3636
3637/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003638 * Return "dark" or "light" depending on the kind of terminal.
3639 * This is just guessing! Recognized are:
3640 * "linux" Linux console
3641 * "screen.linux" Linux console with screen
3642 * "cygwin" Cygwin shell
3643 * "putty" Putty program
3644 * We also check the COLORFGBG environment variable, which is set by
3645 * rxvt and derivatives. This variable contains either two or three
3646 * values separated by semicolons; we want the last value in either
3647 * case. If this value is 0-6 or 8, our background is dark.
3648 */
3649 static char_u *
3650term_bg_default()
3651{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003652#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3653 /* DOS console nearly always black */
3654 return (char_u *)"dark";
3655#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003656 char_u *p;
3657
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658 if (STRCMP(T_NAME, "linux") == 0
3659 || STRCMP(T_NAME, "screen.linux") == 0
3660 || STRCMP(T_NAME, "cygwin") == 0
3661 || STRCMP(T_NAME, "putty") == 0
3662 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3663 && (p = vim_strrchr(p, ';')) != NULL
3664 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3665 && p[2] == NUL))
3666 return (char_u *)"dark";
3667 return (char_u *)"light";
3668#endif
3669}
3670
3671/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 * Initialize the options, part three: After reading the .vimrc
3673 */
3674 void
3675set_init_3()
3676{
3677#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3678/*
3679 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3680 * This is done after other initializations, where 'shell' might have been
3681 * set, but only if they have not been set before.
3682 */
3683 char_u *p;
3684 int idx_srr;
3685 int do_srr;
3686#ifdef FEAT_QUICKFIX
3687 int idx_sp;
3688 int do_sp;
3689#endif
3690
3691 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003692 if (idx_srr < 0)
3693 do_srr = FALSE;
3694 else
3695 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696#ifdef FEAT_QUICKFIX
3697 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (idx_sp < 0)
3699 do_sp = FALSE;
3700 else
3701 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702#endif
3703
3704 /*
3705 * Isolate the name of the shell:
3706 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3707 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003708 * But don't allow a space in the path, so that this works:
3709 * "/usr/bin/csh --rcfile ~/.cshrc"
3710 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003712#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 p = gettail(p_sh);
3714 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003715#else
3716 p = skiptowhite(p_sh);
3717 if (*p == NUL)
3718 {
3719 /* No white space, use the tail. */
3720 p = vim_strsave(gettail(p_sh));
3721 }
3722 else
3723 {
3724 char_u *p1, *p2;
3725
3726 /* Find the last path separator before the space. */
3727 p1 = p_sh;
3728 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3729 if (vim_ispathsep(*p2))
3730 p1 = p2 + 1;
3731 p = vim_strnsave(p1, (int)(p - p1));
3732 }
3733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 if (p != NULL)
3735 {
3736 /*
3737 * Default for p_sp is "| tee", for p_srr is ">".
3738 * For known shells it is changed here to include stderr.
3739 */
3740 if ( fnamecmp(p, "csh") == 0
3741 || fnamecmp(p, "tcsh") == 0
3742# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3743 || fnamecmp(p, "csh.exe") == 0
3744 || fnamecmp(p, "tcsh.exe") == 0
3745# endif
3746 )
3747 {
3748#if defined(FEAT_QUICKFIX)
3749 if (do_sp)
3750 {
3751# ifdef WIN3264
3752 p_sp = (char_u *)">&";
3753# else
3754 p_sp = (char_u *)"|& tee";
3755# endif
3756 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3757 }
3758#endif
3759 if (do_srr)
3760 {
3761 p_srr = (char_u *)">&";
3762 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3763 }
3764 }
3765 else
3766# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3767 if ( fnamecmp(p, "sh") == 0
3768 || fnamecmp(p, "ksh") == 0
3769 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003770 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 || fnamecmp(p, "bash") == 0
3772# ifdef WIN3264
3773 || fnamecmp(p, "cmd") == 0
3774 || fnamecmp(p, "sh.exe") == 0
3775 || fnamecmp(p, "ksh.exe") == 0
3776 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003777 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778 || fnamecmp(p, "bash.exe") == 0
3779 || fnamecmp(p, "cmd.exe") == 0
3780# endif
3781 )
3782# endif
3783 {
3784#if defined(FEAT_QUICKFIX)
3785 if (do_sp)
3786 {
3787# ifdef WIN3264
3788 p_sp = (char_u *)">%s 2>&1";
3789# else
3790 p_sp = (char_u *)"2>&1| tee";
3791# endif
3792 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3793 }
3794#endif
3795 if (do_srr)
3796 {
3797 p_srr = (char_u *)">%s 2>&1";
3798 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3799 }
3800 }
3801 vim_free(p);
3802 }
3803#endif
3804
3805#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3806 /*
3807 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3808 * This is done after other initializations, where 'shell' might have been
3809 * set, but only if they have not been set before. Default for p_shcf is
3810 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3811 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3812 * command.com. And for Win32 we need to set p_sxq instead.
3813 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003814 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 {
3816 int idx3;
3817
3818 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003819 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 {
3821 p_shcf = (char_u *)"-c";
3822 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3823 }
3824
3825# ifndef DJGPP
3826# ifdef WIN3264
3827 /* Somehow Win32 requires the quotes around the redirection too */
3828 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003829 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 {
3831 p_sxq = (char_u *)"\"";
3832 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3833 }
3834# else
3835 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003836 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 {
3838 p_shq = (char_u *)"\"";
3839 options[idx3].def_val[VI_DEFAULT] = p_shq;
3840 }
3841# endif
3842# endif
3843 }
3844#endif
3845
3846#ifdef FEAT_TITLE
3847 set_title_defaults();
3848#endif
3849}
3850
3851#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3852/*
3853 * When 'helplang' is still at its default value, set it to "lang".
3854 * Only the first two characters of "lang" are used.
3855 */
3856 void
3857set_helplang_default(lang)
3858 char_u *lang;
3859{
3860 int idx;
3861
3862 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3863 return;
3864 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003865 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 {
3867 if (options[idx].flags & P_ALLOCED)
3868 free_string_option(p_hlg);
3869 p_hlg = vim_strsave(lang);
3870 if (p_hlg == NULL)
3871 p_hlg = empty_option;
3872 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003873 {
3874 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3875 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3876 {
3877 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3878 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882 options[idx].flags |= P_ALLOCED;
3883 }
3884}
3885#endif
3886
3887#ifdef FEAT_GUI
3888static char_u *gui_bg_default __ARGS((void));
3889
3890 static char_u *
3891gui_bg_default()
3892{
3893 if (gui_get_lightness(gui.back_pixel) < 127)
3894 return (char_u *)"dark";
3895 return (char_u *)"light";
3896}
3897
3898/*
3899 * Option initializations that can only be done after opening the GUI window.
3900 */
3901 void
3902init_gui_options()
3903{
3904 /* Set the 'background' option according to the lightness of the
3905 * background color, unless the user has set it already. */
3906 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3907 {
3908 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3909 highlight_changed();
3910 }
3911}
3912#endif
3913
3914#ifdef FEAT_TITLE
3915/*
3916 * 'title' and 'icon' only default to true if they have not been set or reset
3917 * in .vimrc and we can read the old value.
3918 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3919 * they can be reset. This reduces startup time when using X on a remote
3920 * machine.
3921 */
3922 void
3923set_title_defaults()
3924{
3925 int idx1;
3926 long val;
3927
3928 /*
3929 * If GUI is (going to be) used, we can always set the window title and
3930 * icon name. Saves a bit of time, because the X11 display server does
3931 * not need to be contacted.
3932 */
3933 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003934 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 {
3936#ifdef FEAT_GUI
3937 if (gui.starting || gui.in_use)
3938 val = TRUE;
3939 else
3940#endif
3941 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003942 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 p_title = val;
3944 }
3945 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003946 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 {
3948#ifdef FEAT_GUI
3949 if (gui.starting || gui.in_use)
3950 val = TRUE;
3951 else
3952#endif
3953 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003954 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 p_icon = val;
3956 }
3957}
3958#endif
3959
3960/*
3961 * Parse 'arg' for option settings.
3962 *
3963 * 'arg' may be IObuff, but only when no errors can be present and option
3964 * does not need to be expanded with option_expand().
3965 * "opt_flags":
3966 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003967 * OPT_GLOBAL for ":setglobal"
3968 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003970 * OPT_WINONLY to only set window-local options
3971 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 *
3973 * returns FAIL if an error is detected, OK otherwise
3974 */
3975 int
3976do_set(arg, opt_flags)
3977 char_u *arg; /* option string (may be written to!) */
3978 int opt_flags;
3979{
3980 int opt_idx;
3981 char_u *errmsg;
3982 char_u errbuf[80];
3983 char_u *startarg;
3984 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3985 int nextchar; /* next non-white char after option name */
3986 int afterchar; /* character just after option name */
3987 int len;
3988 int i;
3989 long value;
3990 int key;
3991 long_u flags; /* flags for current option */
3992 char_u *varp = NULL; /* pointer to variable for current option */
3993 int did_show = FALSE; /* already showed one value */
3994 int adding; /* "opt+=arg" */
3995 int prepending; /* "opt^=arg" */
3996 int removing; /* "opt-=arg" */
3997 int cp_val = 0;
3998 char_u key_name[2];
3999
4000 if (*arg == NUL)
4001 {
4002 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004003 did_show = TRUE;
4004 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 }
4006
4007 while (*arg != NUL) /* loop to process all options */
4008 {
4009 errmsg = NULL;
4010 startarg = arg; /* remember for error message */
4011
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004012 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4013 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 {
4015 /*
4016 * ":set all" show all options.
4017 * ":set all&" set all options to their default value.
4018 */
4019 arg += 3;
4020 if (*arg == '&')
4021 {
4022 ++arg;
4023 /* Only for :set command set global value of local options. */
4024 set_options_default(OPT_FREE | opt_flags);
4025 }
4026 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004027 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004029 did_show = TRUE;
4030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004032 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 {
4034 showoptions(2, opt_flags);
4035 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004036 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 arg += 7;
4038 }
4039 else
4040 {
4041 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004042 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 {
4044 prefix = 0;
4045 arg += 2;
4046 }
4047 else if (STRNCMP(arg, "inv", 3) == 0)
4048 {
4049 prefix = 2;
4050 arg += 3;
4051 }
4052
4053 /* find end of name */
4054 key = 0;
4055 if (*arg == '<')
4056 {
4057 nextchar = 0;
4058 opt_idx = -1;
4059 /* look out for <t_>;> */
4060 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4061 len = 5;
4062 else
4063 {
4064 len = 1;
4065 while (arg[len] != NUL && arg[len] != '>')
4066 ++len;
4067 }
4068 if (arg[len] != '>')
4069 {
4070 errmsg = e_invarg;
4071 goto skip;
4072 }
4073 arg[len] = NUL; /* put NUL after name */
4074 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4075 opt_idx = findoption(arg + 1);
4076 arg[len++] = '>'; /* restore '>' */
4077 if (opt_idx == -1)
4078 key = find_key_option(arg + 1);
4079 }
4080 else
4081 {
4082 len = 0;
4083 /*
4084 * The two characters after "t_" may not be alphanumeric.
4085 */
4086 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4087 len = 4;
4088 else
4089 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4090 ++len;
4091 nextchar = arg[len];
4092 arg[len] = NUL; /* put NUL after name */
4093 opt_idx = findoption(arg);
4094 arg[len] = nextchar; /* restore nextchar */
4095 if (opt_idx == -1)
4096 key = find_key_option(arg);
4097 }
4098
4099 /* remember character after option name */
4100 afterchar = arg[len];
4101
4102 /* skip white space, allow ":set ai ?" */
4103 while (vim_iswhite(arg[len]))
4104 ++len;
4105
4106 adding = FALSE;
4107 prepending = FALSE;
4108 removing = FALSE;
4109 if (arg[len] != NUL && arg[len + 1] == '=')
4110 {
4111 if (arg[len] == '+')
4112 {
4113 adding = TRUE; /* "+=" */
4114 ++len;
4115 }
4116 else if (arg[len] == '^')
4117 {
4118 prepending = TRUE; /* "^=" */
4119 ++len;
4120 }
4121 else if (arg[len] == '-')
4122 {
4123 removing = TRUE; /* "-=" */
4124 ++len;
4125 }
4126 }
4127 nextchar = arg[len];
4128
4129 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4130 {
4131 errmsg = (char_u *)N_("E518: Unknown option");
4132 goto skip;
4133 }
4134
4135 if (opt_idx >= 0)
4136 {
4137 if (options[opt_idx].var == NULL) /* hidden option: skip */
4138 {
4139 /* Only give an error message when requesting the value of
4140 * a hidden option, ignore setting it. */
4141 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4142 && (!(options[opt_idx].flags & P_BOOL)
4143 || nextchar == '?'))
4144 errmsg = (char_u *)N_("E519: Option not supported");
4145 goto skip;
4146 }
4147
4148 flags = options[opt_idx].flags;
4149 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4150 }
4151 else
4152 {
4153 flags = P_STRING;
4154 if (key < 0)
4155 {
4156 key_name[0] = KEY2TERMCAP0(key);
4157 key_name[1] = KEY2TERMCAP1(key);
4158 }
4159 else
4160 {
4161 key_name[0] = KS_KEY;
4162 key_name[1] = (key & 0xff);
4163 }
4164 }
4165
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004166 /* Skip all options that are not window-local (used when showing
4167 * an already loaded buffer in a window). */
4168 if ((opt_flags & OPT_WINONLY)
4169 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4170 goto skip;
4171
Bram Moolenaara3227e22006-03-08 21:32:40 +00004172 /* Skip all options that are window-local (used for :vimgrep). */
4173 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4174 && options[opt_idx].var == VAR_WIN)
4175 goto skip;
4176
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004177 /* Disallow changing some options from modelines. */
4178 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004180 if (flags & P_SECURE)
4181 {
4182 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4183 goto skip;
4184 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004185#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004186 /* In diff mode some options are overruled. This avoids that
4187 * 'foldmethod' becomes "marker" instead of "diff" and that
4188 * "wrap" gets set. */
4189 if (curwin->w_p_diff
4190 && (options[opt_idx].indir == PV_FDM
4191 || options[opt_idx].indir == PV_WRAP))
4192 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004193#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 }
4195
4196#ifdef HAVE_SANDBOX
4197 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004198 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 {
4200 errmsg = (char_u *)_(e_sandbox);
4201 goto skip;
4202 }
4203#endif
4204
4205 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4206 {
4207 arg += len;
4208 cp_val = p_cp;
4209 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4210 {
4211 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4212 {
4213 cp_val = FALSE;
4214 arg += 3;
4215 }
4216 else /* "opt&vi": set to Vi default */
4217 {
4218 cp_val = TRUE;
4219 arg += 2;
4220 }
4221 }
4222 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4223 && arg[1] != NUL && !vim_iswhite(arg[1]))
4224 {
4225 errmsg = e_trailing;
4226 goto skip;
4227 }
4228 }
4229
4230 /*
4231 * allow '=' and ':' as MSDOS command.com allows only one
4232 * '=' character per "set" command line. grrr. (jw)
4233 */
4234 if (nextchar == '?'
4235 || (prefix == 1
4236 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4237 && !(flags & P_BOOL)))
4238 {
4239 /*
4240 * print value
4241 */
4242 if (did_show)
4243 msg_putchar('\n'); /* cursor below last one */
4244 else
4245 {
4246 gotocmdline(TRUE); /* cursor at status line */
4247 did_show = TRUE; /* remember that we did a line */
4248 }
4249 if (opt_idx >= 0)
4250 {
4251 showoneopt(&options[opt_idx], opt_flags);
4252#ifdef FEAT_EVAL
4253 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004254 {
4255 /* Mention where the option was last set. */
4256 if (varp == options[opt_idx].var)
4257 last_set_msg(options[opt_idx].scriptID);
4258 else if ((int)options[opt_idx].indir & PV_WIN)
4259 last_set_msg(curwin->w_p_scriptID[
4260 (int)options[opt_idx].indir & PV_MASK]);
4261 else if ((int)options[opt_idx].indir & PV_BUF)
4262 last_set_msg(curbuf->b_p_scriptID[
4263 (int)options[opt_idx].indir & PV_MASK]);
4264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265#endif
4266 }
4267 else
4268 {
4269 char_u *p;
4270
4271 p = find_termcode(key_name);
4272 if (p == NULL)
4273 {
4274 errmsg = (char_u *)N_("E518: Unknown option");
4275 goto skip;
4276 }
4277 else
4278 (void)show_one_termcode(key_name, p, TRUE);
4279 }
4280 if (nextchar != '?'
4281 && nextchar != NUL && !vim_iswhite(afterchar))
4282 errmsg = e_trailing;
4283 }
4284 else
4285 {
4286 if (flags & P_BOOL) /* boolean */
4287 {
4288 if (nextchar == '=' || nextchar == ':')
4289 {
4290 errmsg = e_invarg;
4291 goto skip;
4292 }
4293
4294 /*
4295 * ":set opt!": invert
4296 * ":set opt&": reset to default value
4297 * ":set opt<": reset to global value
4298 */
4299 if (nextchar == '!')
4300 value = *(int *)(varp) ^ 1;
4301 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004302 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 ((flags & P_VI_DEF) || cp_val)
4304 ? VI_DEFAULT : VIM_DEFAULT];
4305 else if (nextchar == '<')
4306 {
4307 /* For 'autoread' -1 means to use global value. */
4308 if ((int *)varp == &curbuf->b_p_ar
4309 && opt_flags == OPT_LOCAL)
4310 value = -1;
4311 else
4312 value = *(int *)get_varp_scope(&(options[opt_idx]),
4313 OPT_GLOBAL);
4314 }
4315 else
4316 {
4317 /*
4318 * ":set invopt": invert
4319 * ":set opt" or ":set noopt": set or reset
4320 */
4321 if (nextchar != NUL && !vim_iswhite(afterchar))
4322 {
4323 errmsg = e_trailing;
4324 goto skip;
4325 }
4326 if (prefix == 2) /* inv */
4327 value = *(int *)(varp) ^ 1;
4328 else
4329 value = prefix;
4330 }
4331
4332 errmsg = set_bool_option(opt_idx, varp, (int)value,
4333 opt_flags);
4334 }
4335 else /* numeric or string */
4336 {
4337 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4338 || prefix != 1)
4339 {
4340 errmsg = e_invarg;
4341 goto skip;
4342 }
4343
4344 if (flags & P_NUM) /* numeric */
4345 {
4346 /*
4347 * Different ways to set a number option:
4348 * & set to default value
4349 * < set to global value
4350 * <xx> accept special key codes for 'wildchar'
4351 * c accept any non-digit for 'wildchar'
4352 * [-]0-9 set number
4353 * other error
4354 */
4355 ++arg;
4356 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004357 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 ((flags & P_VI_DEF) || cp_val)
4359 ? VI_DEFAULT : VIM_DEFAULT];
4360 else if (nextchar == '<')
4361 value = *(long *)get_varp_scope(&(options[opt_idx]),
4362 OPT_GLOBAL);
4363 else if (((long *)varp == &p_wc
4364 || (long *)varp == &p_wcm)
4365 && (*arg == '<'
4366 || *arg == '^'
4367 || ((!arg[1] || vim_iswhite(arg[1]))
4368 && !VIM_ISDIGIT(*arg))))
4369 {
4370 value = string_to_key(arg);
4371 if (value == 0 && (long *)varp != &p_wcm)
4372 {
4373 errmsg = e_invarg;
4374 goto skip;
4375 }
4376 }
4377 /* allow negative numbers (for 'undolevels') */
4378 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4379 {
4380 i = 0;
4381 if (*arg == '-')
4382 i = 1;
4383#ifdef HAVE_STRTOL
4384 value = strtol((char *)arg, NULL, 0);
4385 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4386 i += 2;
4387#else
4388 value = atol((char *)arg);
4389#endif
4390 while (VIM_ISDIGIT(arg[i]))
4391 ++i;
4392 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4393 {
4394 errmsg = e_invarg;
4395 goto skip;
4396 }
4397 }
4398 else
4399 {
4400 errmsg = (char_u *)N_("E521: Number required after =");
4401 goto skip;
4402 }
4403
4404 if (adding)
4405 value = *(long *)varp + value;
4406 if (prepending)
4407 value = *(long *)varp * value;
4408 if (removing)
4409 value = *(long *)varp - value;
4410 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004411 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004412 }
4413 else if (opt_idx >= 0) /* string */
4414 {
4415 char_u *save_arg = NULL;
4416 char_u *s = NULL;
4417 char_u *oldval; /* previous value if *varp */
4418 char_u *newval;
4419 char_u *origval;
4420 unsigned newlen;
4421 int comma;
4422 int bs;
4423 int new_value_alloced; /* new string option
4424 was allocated */
4425
4426 /* When using ":set opt=val" for a global option
4427 * with a local value the local value will be
4428 * reset, use the global value here. */
4429 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004430 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 varp = options[opt_idx].var;
4432
4433 /* The old value is kept until we are sure that the
4434 * new value is valid. */
4435 oldval = *(char_u **)varp;
4436 if (nextchar == '&') /* set to default val */
4437 {
4438 newval = options[opt_idx].def_val[
4439 ((flags & P_VI_DEF) || cp_val)
4440 ? VI_DEFAULT : VIM_DEFAULT];
4441 if ((char_u **)varp == &p_bg)
4442 {
4443 /* guess the value of 'background' */
4444#ifdef FEAT_GUI
4445 if (gui.in_use)
4446 newval = gui_bg_default();
4447 else
4448#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004449 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 }
4451
4452 /* expand environment variables and ~ (since the
4453 * default value was already expanded, only
4454 * required when an environment variable was set
4455 * later */
4456 if (newval == NULL)
4457 newval = empty_option;
4458 else
4459 {
4460 s = option_expand(opt_idx, newval);
4461 if (s == NULL)
4462 s = newval;
4463 newval = vim_strsave(s);
4464 }
4465 new_value_alloced = TRUE;
4466 }
4467 else if (nextchar == '<') /* set to global val */
4468 {
4469 newval = vim_strsave(*(char_u **)get_varp_scope(
4470 &(options[opt_idx]), OPT_GLOBAL));
4471 new_value_alloced = TRUE;
4472 }
4473 else
4474 {
4475 ++arg; /* jump to after the '=' or ':' */
4476
4477 /*
4478 * Set 'keywordprg' to ":help" if an empty
4479 * value was passed to :set by the user.
4480 * Misuse errbuf[] for the resulting string.
4481 */
4482 if (varp == (char_u *)&p_kp
4483 && (*arg == NUL || *arg == ' '))
4484 {
4485 STRCPY(errbuf, ":help");
4486 save_arg = arg;
4487 arg = errbuf;
4488 }
4489 /*
4490 * Convert 'whichwrap' number to string, for
4491 * backwards compatibility with Vim 3.0.
4492 * Misuse errbuf[] for the resulting string.
4493 */
4494 else if (varp == (char_u *)&p_ww
4495 && VIM_ISDIGIT(*arg))
4496 {
4497 *errbuf = NUL;
4498 i = getdigits(&arg);
4499 if (i & 1)
4500 STRCAT(errbuf, "b,");
4501 if (i & 2)
4502 STRCAT(errbuf, "s,");
4503 if (i & 4)
4504 STRCAT(errbuf, "h,l,");
4505 if (i & 8)
4506 STRCAT(errbuf, "<,>,");
4507 if (i & 16)
4508 STRCAT(errbuf, "[,],");
4509 if (*errbuf != NUL) /* remove trailing , */
4510 errbuf[STRLEN(errbuf) - 1] = NUL;
4511 save_arg = arg;
4512 arg = errbuf;
4513 }
4514 /*
4515 * Remove '>' before 'dir' and 'bdir', for
4516 * backwards compatibility with version 3.0
4517 */
4518 else if ( *arg == '>'
4519 && (varp == (char_u *)&p_dir
4520 || varp == (char_u *)&p_bdir))
4521 {
4522 ++arg;
4523 }
4524
4525 /* When setting the local value of a global
4526 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004527 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004528 && (opt_flags & OPT_LOCAL))
4529 origval = *(char_u **)get_varp(
4530 &options[opt_idx]);
4531 else
4532 origval = oldval;
4533
4534 /*
4535 * Copy the new string into allocated memory.
4536 * Can't use set_string_option_direct(), because
4537 * we need to remove the backslashes.
4538 */
4539 /* get a bit too much */
4540 newlen = (unsigned)STRLEN(arg) + 1;
4541 if (adding || prepending || removing)
4542 newlen += (unsigned)STRLEN(origval) + 1;
4543 newval = alloc(newlen);
4544 if (newval == NULL) /* out of mem, don't change */
4545 break;
4546 s = newval;
4547
4548 /*
4549 * Copy the string, skip over escaped chars.
4550 * For MS-DOS and WIN32 backslashes before normal
4551 * file name characters are not removed, and keep
4552 * backslash at start, for "\\machine\path", but
4553 * do remove it for "\\\\machine\\path".
4554 * The reverse is found in ExpandOldSetting().
4555 */
4556 while (*arg && !vim_iswhite(*arg))
4557 {
4558 if (*arg == '\\' && arg[1] != NUL
4559#ifdef BACKSLASH_IN_FILENAME
4560 && !((flags & P_EXPAND)
4561 && vim_isfilec(arg[1])
4562 && (arg[1] != '\\'
4563 || (s == newval
4564 && arg[2] != '\\')))
4565#endif
4566 )
4567 ++arg; /* remove backslash */
4568#ifdef FEAT_MBYTE
4569 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004570 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 {
4572 /* copy multibyte char */
4573 mch_memmove(s, arg, (size_t)i);
4574 arg += i;
4575 s += i;
4576 }
4577 else
4578#endif
4579 *s++ = *arg++;
4580 }
4581 *s = NUL;
4582
4583 /*
4584 * Expand environment variables and ~.
4585 * Don't do it when adding without inserting a
4586 * comma.
4587 */
4588 if (!(adding || prepending || removing)
4589 || (flags & P_COMMA))
4590 {
4591 s = option_expand(opt_idx, newval);
4592 if (s != NULL)
4593 {
4594 vim_free(newval);
4595 newlen = (unsigned)STRLEN(s) + 1;
4596 if (adding || prepending || removing)
4597 newlen += (unsigned)STRLEN(origval) + 1;
4598 newval = alloc(newlen);
4599 if (newval == NULL)
4600 break;
4601 STRCPY(newval, s);
4602 }
4603 }
4604
4605 /* locate newval[] in origval[] when removing it
4606 * and when adding to avoid duplicates */
4607 i = 0; /* init for GCC */
4608 if (removing || (flags & P_NODUP))
4609 {
4610 i = (int)STRLEN(newval);
4611 bs = 0;
4612 for (s = origval; *s; ++s)
4613 {
4614 if ((!(flags & P_COMMA)
4615 || s == origval
4616 || (s[-1] == ',' && !(bs & 1)))
4617 && STRNCMP(s, newval, i) == 0
4618 && (!(flags & P_COMMA)
4619 || s[i] == ','
4620 || s[i] == NUL))
4621 break;
4622 /* Count backspaces. Only a comma with an
4623 * even number of backspaces before it is
4624 * recognized as a separator */
4625 if (s > origval && s[-1] == '\\')
4626 ++bs;
4627 else
4628 bs = 0;
4629 }
4630
4631 /* do not add if already there */
4632 if ((adding || prepending) && *s)
4633 {
4634 prepending = FALSE;
4635 adding = FALSE;
4636 STRCPY(newval, origval);
4637 }
4638 }
4639
4640 /* concatenate the two strings; add a ',' if
4641 * needed */
4642 if (adding || prepending)
4643 {
4644 comma = ((flags & P_COMMA) && *origval != NUL
4645 && *newval != NUL);
4646 if (adding)
4647 {
4648 i = (int)STRLEN(origval);
4649 mch_memmove(newval + i + comma, newval,
4650 STRLEN(newval) + 1);
4651 mch_memmove(newval, origval, (size_t)i);
4652 }
4653 else
4654 {
4655 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004656 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 }
4658 if (comma)
4659 newval[i] = ',';
4660 }
4661
4662 /* Remove newval[] from origval[]. (Note: "i" has
4663 * been set above and is used here). */
4664 if (removing)
4665 {
4666 STRCPY(newval, origval);
4667 if (*s)
4668 {
4669 /* may need to remove a comma */
4670 if (flags & P_COMMA)
4671 {
4672 if (s == origval)
4673 {
4674 /* include comma after string */
4675 if (s[i] == ',')
4676 ++i;
4677 }
4678 else
4679 {
4680 /* include comma before string */
4681 --s;
4682 ++i;
4683 }
4684 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004685 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004686 }
4687 }
4688
4689 if (flags & P_FLAGLIST)
4690 {
4691 /* Remove flags that appear twice. */
4692 for (s = newval; *s; ++s)
4693 if ((!(flags & P_COMMA) || *s != ',')
4694 && vim_strchr(s + 1, *s) != NULL)
4695 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004696 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 --s;
4698 }
4699 }
4700
4701 if (save_arg != NULL) /* number for 'whichwrap' */
4702 arg = save_arg;
4703 new_value_alloced = TRUE;
4704 }
4705
4706 /* Set the new value. */
4707 *(char_u **)(varp) = newval;
4708
4709 /* Handle side effects, and set the global value for
4710 * ":set" on local options. */
4711 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4712 new_value_alloced, oldval, errbuf, opt_flags);
4713
4714 /* If error detected, print the error message. */
4715 if (errmsg != NULL)
4716 goto skip;
4717 }
4718 else /* key code option */
4719 {
4720 char_u *p;
4721
4722 if (nextchar == '&')
4723 {
4724 if (add_termcap_entry(key_name, TRUE) == FAIL)
4725 errmsg = (char_u *)N_("E522: Not found in termcap");
4726 }
4727 else
4728 {
4729 ++arg; /* jump to after the '=' or ':' */
4730 for (p = arg; *p && !vim_iswhite(*p); ++p)
4731 if (*p == '\\' && p[1] != NUL)
4732 ++p;
4733 nextchar = *p;
4734 *p = NUL;
4735 add_termcode(key_name, arg, FALSE);
4736 *p = nextchar;
4737 }
4738 if (full_screen)
4739 ttest(FALSE);
4740 redraw_all_later(CLEAR);
4741 }
4742 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004743
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004745 did_set_option(opt_idx, opt_flags,
4746 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004747 }
4748
4749skip:
4750 /*
4751 * Advance to next argument.
4752 * - skip until a blank found, taking care of backslashes
4753 * - skip blanks
4754 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4755 */
4756 for (i = 0; i < 2 ; ++i)
4757 {
4758 while (*arg != NUL && !vim_iswhite(*arg))
4759 if (*arg++ == '\\' && *arg != NUL)
4760 ++arg;
4761 arg = skipwhite(arg);
4762 if (*arg != '=')
4763 break;
4764 }
4765 }
4766
4767 if (errmsg != NULL)
4768 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004769 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004770 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 if (i + (arg - startarg) < IOSIZE)
4772 {
4773 /* append the argument with the error */
4774 STRCAT(IObuff, ": ");
4775 mch_memmove(IObuff + i, startarg, (arg - startarg));
4776 IObuff[i + (arg - startarg)] = NUL;
4777 }
4778 /* make sure all characters are printable */
4779 trans_characters(IObuff, IOSIZE);
4780
4781 ++no_wait_return; /* wait_return done later */
4782 emsg(IObuff); /* show error highlighted */
4783 --no_wait_return;
4784
4785 return FAIL;
4786 }
4787
4788 arg = skipwhite(arg);
4789 }
4790
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004791theend:
4792 if (silent_mode && did_show)
4793 {
4794 /* After displaying option values in silent mode. */
4795 silent_mode = FALSE;
4796 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4797 msg_putchar('\n');
4798 cursor_on(); /* msg_start() switches it off */
4799 out_flush();
4800 silent_mode = TRUE;
4801 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4802 }
4803
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 return OK;
4805}
4806
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004807/*
4808 * Call this when an option has been given a new value through a user command.
4809 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4810 */
4811 static void
4812did_set_option(opt_idx, opt_flags, new_value)
4813 int opt_idx;
4814 int opt_flags; /* possibly with OPT_MODELINE */
4815 int new_value; /* value was replaced completely */
4816{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004817 long_u *p;
4818
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004819 options[opt_idx].flags |= P_WAS_SET;
4820
4821 /* When an option is set in the sandbox, from a modeline or in secure mode
4822 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004823 * flag. */
4824 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004825 if (secure
4826#ifdef HAVE_SANDBOX
4827 || sandbox != 0
4828#endif
4829 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004830 *p = *p | P_INSECURE;
4831 else if (new_value)
4832 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004833}
4834
Bram Moolenaar071d4272004-06-13 20:20:40 +00004835 static char_u *
4836illegal_char(errbuf, c)
4837 char_u *errbuf;
4838 int c;
4839{
4840 if (errbuf == NULL)
4841 return (char_u *)"";
4842 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004843 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 return errbuf;
4845}
4846
4847/*
4848 * Convert a key name or string into a key value.
4849 * Used for 'wildchar' and 'cedit' options.
4850 */
4851 static int
4852string_to_key(arg)
4853 char_u *arg;
4854{
4855 if (*arg == '<')
4856 return find_key_option(arg + 1);
4857 if (*arg == '^')
4858 return Ctrl_chr(arg[1]);
4859 return *arg;
4860}
4861
4862#ifdef FEAT_CMDWIN
4863/*
4864 * Check value of 'cedit' and set cedit_key.
4865 * Returns NULL if value is OK, error message otherwise.
4866 */
4867 static char_u *
4868check_cedit()
4869{
4870 int n;
4871
4872 if (*p_cedit == NUL)
4873 cedit_key = -1;
4874 else
4875 {
4876 n = string_to_key(p_cedit);
4877 if (vim_isprintc(n))
4878 return e_invarg;
4879 cedit_key = n;
4880 }
4881 return NULL;
4882}
4883#endif
4884
4885#ifdef FEAT_TITLE
4886/*
4887 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4888 * maketitle() to create and display it.
4889 * When switching the title or icon off, call mch_restore_title() to get
4890 * the old value back.
4891 */
4892 static void
4893did_set_title(icon)
4894 int icon; /* Did set icon instead of title */
4895{
4896 if (starting != NO_SCREEN
4897#ifdef FEAT_GUI
4898 && !gui.starting
4899#endif
4900 )
4901 {
4902 maketitle();
4903 if (icon)
4904 {
4905 if (!p_icon)
4906 mch_restore_title(2);
4907 }
4908 else
4909 {
4910 if (!p_title)
4911 mch_restore_title(1);
4912 }
4913 }
4914}
4915#endif
4916
4917/*
4918 * set_options_bin - called when 'bin' changes value.
4919 */
4920 void
4921set_options_bin(oldval, newval, opt_flags)
4922 int oldval;
4923 int newval;
4924 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4925{
4926 /*
4927 * The option values that are changed when 'bin' changes are
4928 * copied when 'bin is set and restored when 'bin' is reset.
4929 */
4930 if (newval)
4931 {
4932 if (!oldval) /* switched on */
4933 {
4934 if (!(opt_flags & OPT_GLOBAL))
4935 {
4936 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4937 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4938 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4939 curbuf->b_p_et_nobin = curbuf->b_p_et;
4940 }
4941 if (!(opt_flags & OPT_LOCAL))
4942 {
4943 p_tw_nobin = p_tw;
4944 p_wm_nobin = p_wm;
4945 p_ml_nobin = p_ml;
4946 p_et_nobin = p_et;
4947 }
4948 }
4949
4950 if (!(opt_flags & OPT_GLOBAL))
4951 {
4952 curbuf->b_p_tw = 0; /* no automatic line wrap */
4953 curbuf->b_p_wm = 0; /* no automatic line wrap */
4954 curbuf->b_p_ml = 0; /* no modelines */
4955 curbuf->b_p_et = 0; /* no expandtab */
4956 }
4957 if (!(opt_flags & OPT_LOCAL))
4958 {
4959 p_tw = 0;
4960 p_wm = 0;
4961 p_ml = FALSE;
4962 p_et = FALSE;
4963 p_bin = TRUE; /* needed when called for the "-b" argument */
4964 }
4965 }
4966 else if (oldval) /* switched off */
4967 {
4968 if (!(opt_flags & OPT_GLOBAL))
4969 {
4970 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4971 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4972 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4973 curbuf->b_p_et = curbuf->b_p_et_nobin;
4974 }
4975 if (!(opt_flags & OPT_LOCAL))
4976 {
4977 p_tw = p_tw_nobin;
4978 p_wm = p_wm_nobin;
4979 p_ml = p_ml_nobin;
4980 p_et = p_et_nobin;
4981 }
4982 }
4983}
4984
4985#ifdef FEAT_VIMINFO
4986/*
4987 * Find the parameter represented by the given character (eg ', :, ", or /),
4988 * and return its associated value in the 'viminfo' string.
4989 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004990 * If the parameter is not specified in the string or there is no following
4991 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004992 */
4993 int
4994get_viminfo_parameter(type)
4995 int type;
4996{
4997 char_u *p;
4998
4999 p = find_viminfo_parameter(type);
5000 if (p != NULL && VIM_ISDIGIT(*p))
5001 return atoi((char *)p);
5002 return -1;
5003}
5004
5005/*
5006 * Find the parameter represented by the given character (eg ''', ':', '"', or
5007 * '/') in the 'viminfo' option and return a pointer to the string after it.
5008 * Return NULL if the parameter is not specified in the string.
5009 */
5010 char_u *
5011find_viminfo_parameter(type)
5012 int type;
5013{
5014 char_u *p;
5015
5016 for (p = p_viminfo; *p; ++p)
5017 {
5018 if (*p == type)
5019 return p + 1;
5020 if (*p == 'n') /* 'n' is always the last one */
5021 break;
5022 p = vim_strchr(p, ','); /* skip until next ',' */
5023 if (p == NULL) /* hit the end without finding parameter */
5024 break;
5025 }
5026 return NULL;
5027}
5028#endif
5029
5030/*
5031 * Expand environment variables for some string options.
5032 * These string options cannot be indirect!
5033 * If "val" is NULL expand the current value of the option.
5034 * Return pointer to NameBuff, or NULL when not expanded.
5035 */
5036 static char_u *
5037option_expand(opt_idx, val)
5038 int opt_idx;
5039 char_u *val;
5040{
5041 /* if option doesn't need expansion nothing to do */
5042 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5043 return NULL;
5044
5045 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5046 * expand_env() would truncate the string. */
5047 if (val != NULL && STRLEN(val) > MAXPATHL)
5048 return NULL;
5049
5050 if (val == NULL)
5051 val = *(char_u **)options[opt_idx].var;
5052
5053 /*
5054 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5055 * Escape spaces when expanding 'tags', they are used to separate file
5056 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005057 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 */
5059 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005060 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005061#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005062 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5063#endif
5064 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5066 return NULL;
5067
5068 return NameBuff;
5069}
5070
5071/*
5072 * After setting various option values: recompute variables that depend on
5073 * option values.
5074 */
5075 static void
5076didset_options()
5077{
5078 /* initialize the table for 'iskeyword' et.al. */
5079 (void)init_chartab();
5080
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005081#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005083#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5085#ifdef FEAT_SESSION
5086 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5087 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5088#endif
5089#ifdef FEAT_FOLDING
5090 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5091#endif
5092 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5093#ifdef FEAT_VIRTUALEDIT
5094 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5095#endif
5096#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5097 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5098#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005099#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005100 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005101 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005102 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5105 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5106#endif
5107#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5108 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5109#endif
5110#ifdef FEAT_CMDWIN
5111 /* set cedit_key */
5112 (void)check_cedit();
5113#endif
5114}
5115
5116/*
5117 * Check for string options that are NULL (normally only termcap options).
5118 */
5119 void
5120check_options()
5121{
5122 int opt_idx;
5123
5124 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5125 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5126 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5127}
5128
5129/*
5130 * Check string options in a buffer for NULL value.
5131 */
5132 void
5133check_buf_options(buf)
5134 buf_T *buf;
5135{
5136#if defined(FEAT_QUICKFIX)
5137 check_string_option(&buf->b_p_bh);
5138 check_string_option(&buf->b_p_bt);
5139#endif
5140#ifdef FEAT_MBYTE
5141 check_string_option(&buf->b_p_fenc);
5142#endif
5143 check_string_option(&buf->b_p_ff);
5144#ifdef FEAT_FIND_ID
5145 check_string_option(&buf->b_p_def);
5146 check_string_option(&buf->b_p_inc);
5147# ifdef FEAT_EVAL
5148 check_string_option(&buf->b_p_inex);
5149# endif
5150#endif
5151#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5152 check_string_option(&buf->b_p_inde);
5153 check_string_option(&buf->b_p_indk);
5154#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005155#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5156 check_string_option(&buf->b_p_bexpr);
5157#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005158#if defined(FEAT_EVAL)
5159 check_string_option(&buf->b_p_fex);
5160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161#ifdef FEAT_CRYPT
5162 check_string_option(&buf->b_p_key);
5163#endif
5164 check_string_option(&buf->b_p_kp);
5165 check_string_option(&buf->b_p_mps);
5166 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005167 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 check_string_option(&buf->b_p_isk);
5169#ifdef FEAT_COMMENTS
5170 check_string_option(&buf->b_p_com);
5171#endif
5172#ifdef FEAT_FOLDING
5173 check_string_option(&buf->b_p_cms);
5174#endif
5175 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005176#ifdef FEAT_TEXTOBJ
5177 check_string_option(&buf->b_p_qe);
5178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005179#ifdef FEAT_SYN_HL
5180 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005181#endif
5182#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005183 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005184 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005185 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186#endif
5187#ifdef FEAT_SEARCHPATH
5188 check_string_option(&buf->b_p_sua);
5189#endif
5190#ifdef FEAT_CINDENT
5191 check_string_option(&buf->b_p_cink);
5192 check_string_option(&buf->b_p_cino);
5193#endif
5194#ifdef FEAT_AUTOCMD
5195 check_string_option(&buf->b_p_ft);
5196#endif
5197#ifdef FEAT_OSFILETYPE
5198 check_string_option(&buf->b_p_oft);
5199#endif
5200#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5201 check_string_option(&buf->b_p_cinw);
5202#endif
5203#ifdef FEAT_INS_EXPAND
5204 check_string_option(&buf->b_p_cpt);
5205#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005206#ifdef FEAT_COMPL_FUNC
5207 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005208 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210#ifdef FEAT_KEYMAP
5211 check_string_option(&buf->b_p_keymap);
5212#endif
5213#ifdef FEAT_QUICKFIX
5214 check_string_option(&buf->b_p_gp);
5215 check_string_option(&buf->b_p_mp);
5216 check_string_option(&buf->b_p_efm);
5217#endif
5218 check_string_option(&buf->b_p_ep);
5219 check_string_option(&buf->b_p_path);
5220 check_string_option(&buf->b_p_tags);
5221#ifdef FEAT_INS_EXPAND
5222 check_string_option(&buf->b_p_dict);
5223 check_string_option(&buf->b_p_tsr);
5224#endif
5225}
5226
5227/*
5228 * Free the string allocated for an option.
5229 * Checks for the string being empty_option. This may happen if we're out of
5230 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5231 * check_options().
5232 * Does NOT check for P_ALLOCED flag!
5233 */
5234 void
5235free_string_option(p)
5236 char_u *p;
5237{
5238 if (p != empty_option)
5239 vim_free(p);
5240}
5241
5242 void
5243clear_string_option(pp)
5244 char_u **pp;
5245{
5246 if (*pp != empty_option)
5247 vim_free(*pp);
5248 *pp = empty_option;
5249}
5250
5251 static void
5252check_string_option(pp)
5253 char_u **pp;
5254{
5255 if (*pp == NULL)
5256 *pp = empty_option;
5257}
5258
5259/*
5260 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5261 */
5262 void
5263set_term_option_alloced(p)
5264 char_u **p;
5265{
5266 int opt_idx;
5267
5268 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5269 if (options[opt_idx].var == (char_u *)p)
5270 {
5271 options[opt_idx].flags |= P_ALLOCED;
5272 return;
5273 }
5274 return; /* cannot happen: didn't find it! */
5275}
5276
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005277#if defined(FEAT_EVAL) || defined(PROTO)
5278/*
5279 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5280 * Return FALSE when it wasn't.
5281 * Return -1 for an unknown option.
5282 */
5283 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005284was_set_insecurely(opt, opt_flags)
5285 char_u *opt;
5286 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005287{
5288 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005289 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005290
5291 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005292 {
5293 flagp = insecure_flag(idx, opt_flags);
5294 return (*flagp & P_INSECURE) != 0;
5295 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296 EMSG2(_(e_intern2), "was_set_insecurely()");
5297 return -1;
5298}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005299
5300/*
5301 * Get a pointer to the flags used for the P_INSECURE flag of option
5302 * "opt_idx". For some local options a local flags field is used.
5303 */
5304 static long_u *
5305insecure_flag(opt_idx, opt_flags)
5306 int opt_idx;
5307 int opt_flags;
5308{
5309 if (opt_flags & OPT_LOCAL)
5310 switch ((int)options[opt_idx].indir)
5311 {
5312#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005313 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005314#endif
5315#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005316# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005317 case PV_FDE: return &curwin->w_p_fde_flags;
5318 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005319# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005320# ifdef FEAT_BEVAL
5321 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5322# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005323# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005324 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005325# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005326 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005327# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005328 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005329# endif
5330#endif
5331 }
5332
5333 /* Nothing special, return global flags field. */
5334 return &options[opt_idx].flags;
5335}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336#endif
5337
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005338#ifdef FEAT_TITLE
5339static void redraw_titles __ARGS((void));
5340
5341/*
5342 * Redraw the window title and/or tab page text later.
5343 */
5344static void redraw_titles()
5345{
5346 need_maketitle = TRUE;
5347# ifdef FEAT_WINDOWS
5348 redraw_tabline = TRUE;
5349# endif
5350}
5351#endif
5352
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353/*
5354 * Set a string option to a new value (without checking the effect).
5355 * The string is copied into allocated memory.
5356 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005357 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005358 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 */
5360 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005361set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 char_u *name;
5363 int opt_idx;
5364 char_u *val;
5365 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005366 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367{
5368 char_u *s;
5369 char_u **varp;
5370 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005371 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372
Bram Moolenaar89d40322006-08-29 15:30:07 +00005373 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005375 idx = findoption(name);
5376 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005377 {
5378 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381 }
5382
Bram Moolenaar89d40322006-08-29 15:30:07 +00005383 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384 return;
5385
5386 s = vim_strsave(val);
5387 if (s != NULL)
5388 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005389 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005390 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005391 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392 free_string_option(*varp);
5393 *varp = s;
5394
5395 /* For buffer/window local option may also set the global value. */
5396 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005397 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398
Bram Moolenaar89d40322006-08-29 15:30:07 +00005399 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400
5401 /* When setting both values of a global option with a local value,
5402 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005403 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404 {
5405 free_string_option(*varp);
5406 *varp = empty_option;
5407 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005408# ifdef FEAT_EVAL
5409 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005410 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005411 set_sid == 0 ? current_SID : set_sid);
5412# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413 }
5414}
5415
5416/*
5417 * Set global value for string option when it's a local option.
5418 */
5419 static void
5420set_string_option_global(opt_idx, varp)
5421 int opt_idx; /* option index */
5422 char_u **varp; /* pointer to option variable */
5423{
5424 char_u **p, *s;
5425
5426 /* the global value is always allocated */
5427 if (options[opt_idx].var == VAR_WIN)
5428 p = (char_u **)GLOBAL_WO(varp);
5429 else
5430 p = (char_u **)options[opt_idx].var;
5431 if (options[opt_idx].indir != PV_NONE
5432 && p != varp
5433 && (s = vim_strsave(*varp)) != NULL)
5434 {
5435 free_string_option(*p);
5436 *p = s;
5437 }
5438}
5439
5440/*
5441 * Set a string option to a new value, and handle the effects.
5442 */
5443 static void
5444set_string_option(opt_idx, value, opt_flags)
5445 int opt_idx;
5446 char_u *value;
5447 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5448{
5449 char_u *s;
5450 char_u **varp;
5451 char_u *oldval;
5452
5453 if (options[opt_idx].var == NULL) /* don't set hidden option */
5454 return;
5455
5456 s = vim_strsave(value);
5457 if (s != NULL)
5458 {
5459 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5460 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005461 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462 ? OPT_GLOBAL : OPT_LOCAL)
5463 : opt_flags);
5464 oldval = *varp;
5465 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005466 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5467 opt_flags) == NULL)
5468 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469 }
5470}
5471
5472/*
5473 * Handle string options that need some action to perform when changed.
5474 * Returns NULL for success, or an error message for an error.
5475 */
5476 static char_u *
5477did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5478 opt_flags)
5479 int opt_idx; /* index in options[] table */
5480 char_u **varp; /* pointer to the option variable */
5481 int new_value_alloced; /* new value was allocated */
5482 char_u *oldval; /* previous value of the option */
5483 char_u *errbuf; /* buffer for errors, or NULL */
5484 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5485{
5486 char_u *errmsg = NULL;
5487 char_u *s, *p;
5488 int did_chartab = FALSE;
5489 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005490 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005491#ifdef FEAT_GUI
5492 /* set when changing an option that only requires a redraw in the GUI */
5493 int redraw_gui_only = FALSE;
5494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495
5496 /* Get the global option to compare with, otherwise we would have to check
5497 * two values for all local options. */
5498 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5499
5500 /* Disallow changing some options from secure mode */
5501 if ((secure
5502#ifdef HAVE_SANDBOX
5503 || sandbox != 0
5504#endif
5505 ) && (options[opt_idx].flags & P_SECURE))
5506 {
5507 errmsg = e_secure;
5508 }
5509
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005510 /* Check for a "normal" file name in some options. Disallow a path
5511 * separator (slash and/or backslash), wildcards and characters that are
5512 * often illegal in a file name. */
5513 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005514 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005515 {
5516 errmsg = e_invarg;
5517 }
5518
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 /* 'term' */
5520 else if (varp == &T_NAME)
5521 {
5522 if (T_NAME[0] == NUL)
5523 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5524#ifdef FEAT_GUI
5525 if (gui.in_use)
5526 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5527 else if (term_is_gui(T_NAME))
5528 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5529#endif
5530 else if (set_termname(T_NAME) == FAIL)
5531 errmsg = (char_u *)N_("E522: Not found in termcap");
5532 else
5533 /* Screen colors may have changed. */
5534 redraw_later_clear();
5535 }
5536
5537 /* 'backupcopy' */
5538 else if (varp == &p_bkc)
5539 {
5540 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5541 errmsg = e_invarg;
5542 if (((bkc_flags & BKC_AUTO) != 0)
5543 + ((bkc_flags & BKC_YES) != 0)
5544 + ((bkc_flags & BKC_NO) != 0) != 1)
5545 {
5546 /* Must have exactly one of "auto", "yes" and "no". */
5547 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5548 errmsg = e_invarg;
5549 }
5550 }
5551
5552 /* 'backupext' and 'patchmode' */
5553 else if (varp == &p_bex || varp == &p_pm)
5554 {
5555 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5556 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5557 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5558 }
5559
5560 /*
5561 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5562 * If the new option is invalid, use old value. 'lisp' option: refill
5563 * chartab[] for '-' char
5564 */
5565 else if ( varp == &p_isi
5566 || varp == &(curbuf->b_p_isk)
5567 || varp == &p_isp
5568 || varp == &p_isf)
5569 {
5570 if (init_chartab() == FAIL)
5571 {
5572 did_chartab = TRUE; /* need to restore it below */
5573 errmsg = e_invarg; /* error in value */
5574 }
5575 }
5576
5577 /* 'helpfile' */
5578 else if (varp == &p_hf)
5579 {
5580 /* May compute new values for $VIM and $VIMRUNTIME */
5581 if (didset_vim)
5582 {
5583 vim_setenv((char_u *)"VIM", (char_u *)"");
5584 didset_vim = FALSE;
5585 }
5586 if (didset_vimruntime)
5587 {
5588 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5589 didset_vimruntime = FALSE;
5590 }
5591 }
5592
5593#ifdef FEAT_MULTI_LANG
5594 /* 'helplang' */
5595 else if (varp == &p_hlg)
5596 {
5597 /* Check for "", "ab", "ab,cd", etc. */
5598 for (s = p_hlg; *s != NUL; s += 3)
5599 {
5600 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5601 {
5602 errmsg = e_invarg;
5603 break;
5604 }
5605 if (s[2] == NUL)
5606 break;
5607 }
5608 }
5609#endif
5610
5611 /* 'highlight' */
5612 else if (varp == &p_hl)
5613 {
5614 if (highlight_changed() == FAIL)
5615 errmsg = e_invarg; /* invalid flags */
5616 }
5617
5618 /* 'nrformats' */
5619 else if (gvarp == &p_nf)
5620 {
5621 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5622 errmsg = e_invarg;
5623 }
5624
5625#ifdef FEAT_SESSION
5626 /* 'sessionoptions' */
5627 else if (varp == &p_ssop)
5628 {
5629 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5630 errmsg = e_invarg;
5631 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5632 {
5633 /* Don't allow both "sesdir" and "curdir". */
5634 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5635 errmsg = e_invarg;
5636 }
5637 }
5638 /* 'viewoptions' */
5639 else if (varp == &p_vop)
5640 {
5641 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5642 errmsg = e_invarg;
5643 }
5644#endif
5645
5646 /* 'scrollopt' */
5647#ifdef FEAT_SCROLLBIND
5648 else if (varp == &p_sbo)
5649 {
5650 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5651 errmsg = e_invarg;
5652 }
5653#endif
5654
5655 /* 'ambiwidth' */
5656#ifdef FEAT_MBYTE
5657 else if (varp == &p_ambw)
5658 {
5659 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5660 errmsg = e_invarg;
5661 }
5662#endif
5663
5664 /* 'background' */
5665 else if (varp == &p_bg)
5666 {
5667 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5668 {
5669#ifdef FEAT_EVAL
5670 int dark = (*p_bg == 'd');
5671#endif
5672
5673 init_highlight(FALSE, FALSE);
5674
5675#ifdef FEAT_EVAL
5676 if (dark != (*p_bg == 'd')
5677 && get_var_value((char_u *)"g:colors_name") != NULL)
5678 {
5679 /* The color scheme must have set 'background' back to another
5680 * value, that's not what we want here. Disable the color
5681 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005682 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 free_string_option(p_bg);
5684 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5685 check_string_option(&p_bg);
5686 init_highlight(FALSE, FALSE);
5687 }
5688#endif
5689 }
5690 else
5691 errmsg = e_invarg;
5692 }
5693
5694 /* 'wildmode' */
5695 else if (varp == &p_wim)
5696 {
5697 if (check_opt_wim() == FAIL)
5698 errmsg = e_invarg;
5699 }
5700
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005701#ifdef FEAT_CMDL_COMPL
5702 /* 'wildoptions' */
5703 else if (varp == &p_wop)
5704 {
5705 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5706 errmsg = e_invarg;
5707 }
5708#endif
5709
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710#ifdef FEAT_WAK
5711 /* 'winaltkeys' */
5712 else if (varp == &p_wak)
5713 {
5714 if (*p_wak == NUL
5715 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5716 errmsg = e_invarg;
5717# ifdef FEAT_MENU
5718# ifdef FEAT_GUI_MOTIF
5719 else if (gui.in_use)
5720 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5721# else
5722# ifdef FEAT_GUI_GTK
5723 else if (gui.in_use)
5724 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5725# endif
5726# endif
5727# endif
5728 }
5729#endif
5730
5731#ifdef FEAT_AUTOCMD
5732 /* 'eventignore' */
5733 else if (varp == &p_ei)
5734 {
5735 if (check_ei() == FAIL)
5736 errmsg = e_invarg;
5737 }
5738#endif
5739
5740#ifdef FEAT_MBYTE
5741 /* 'encoding' and 'fileencoding' */
5742 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5743 {
5744 if (gvarp == &p_fenc)
5745 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005746 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747 errmsg = e_modifiable;
5748 else if (vim_strchr(*varp, ',') != NULL)
5749 /* No comma allowed in 'fileencoding'; catches confusing it
5750 * with 'fileencodings'. */
5751 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005753 {
5754# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005756 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005758 /* Add 'fileencoding' to the swap file. */
5759 ml_setflags(curbuf);
5760 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761 }
5762 if (errmsg == NULL)
5763 {
5764 /* canonize the value, so that STRCMP() can be used on it */
5765 p = enc_canonize(*varp);
5766 if (p != NULL)
5767 {
5768 vim_free(*varp);
5769 *varp = p;
5770 }
5771 if (varp == &p_enc)
5772 {
5773 errmsg = mb_init();
5774# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005775 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776# endif
5777 }
5778 }
5779
5780# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5781 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5782 {
5783 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5784 if (STRCMP(p_tenc, "utf-8") != 0)
5785 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5786 }
5787# endif
5788
5789 if (errmsg == NULL)
5790 {
5791# ifdef FEAT_KEYMAP
5792 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5793 * (with another encoding). */
5794 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5795 (void)keymap_init();
5796# endif
5797
5798 /* When 'termencoding' is not empty and 'encoding' changes or when
5799 * 'termencoding' changes, need to setup for keyboard input and
5800 * display output conversion. */
5801 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5802 {
5803 convert_setup(&input_conv, p_tenc, p_enc);
5804 convert_setup(&output_conv, p_enc, p_tenc);
5805 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005806
5807# if defined(WIN3264) && defined(FEAT_MBYTE)
5808 /* $HOME may have characters in active code page. */
5809 if (varp == &p_enc)
5810 init_homedir();
5811# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812 }
5813 }
5814#endif
5815
5816#if defined(FEAT_POSTSCRIPT)
5817 else if (varp == &p_penc)
5818 {
5819 /* Canonize printencoding if VIM standard one */
5820 p = enc_canonize(p_penc);
5821 if (p != NULL)
5822 {
5823 vim_free(p_penc);
5824 p_penc = p;
5825 }
5826 else
5827 {
5828 /* Ensure lower case and '-' for '_' */
5829 for (s = p_penc; *s != NUL; s++)
5830 {
5831 if (*s == '_')
5832 *s = '-';
5833 else
5834 *s = TOLOWER_ASC(*s);
5835 }
5836 }
5837 }
5838#endif
5839
Bram Moolenaar9372a112005-12-06 19:59:18 +00005840#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 else if (varp == &p_imak)
5842 {
5843 if (gui.in_use && !im_xim_isvalid_imactivate())
5844 errmsg = e_invarg;
5845 }
5846#endif
5847
5848#ifdef FEAT_KEYMAP
5849 else if (varp == &curbuf->b_p_keymap)
5850 {
5851 /* load or unload key mapping tables */
5852 errmsg = keymap_init();
5853
Bram Moolenaarfab06232009-03-04 03:13:35 +00005854 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005856 if (*curbuf->b_p_keymap != NUL)
5857 {
5858 /* Installed a new keymap, switch on using it. */
5859 curbuf->b_p_iminsert = B_IMODE_LMAP;
5860 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5861 curbuf->b_p_imsearch = B_IMODE_LMAP;
5862 }
5863 else
5864 {
5865 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5866 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5867 curbuf->b_p_iminsert = B_IMODE_NONE;
5868 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5869 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5870 }
5871 if ((opt_flags & OPT_LOCAL) == 0)
5872 {
5873 set_iminsert_global();
5874 set_imsearch_global();
5875 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876# ifdef FEAT_WINDOWS
5877 status_redraw_curbuf();
5878# endif
5879 }
5880 }
5881#endif
5882
5883 /* 'fileformat' */
5884 else if (gvarp == &p_ff)
5885 {
5886 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5887 errmsg = e_modifiable;
5888 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5889 errmsg = e_invarg;
5890 else
5891 {
5892 /* may also change 'textmode' */
5893 if (get_fileformat(curbuf) == EOL_DOS)
5894 curbuf->b_p_tx = TRUE;
5895 else
5896 curbuf->b_p_tx = FALSE;
5897#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005898 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005900 /* update flag in swap file */
5901 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005902 /* Redraw needed when switching to/from "mac": a CR in the text
5903 * will be displayed differently. */
5904 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5905 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 }
5907 }
5908
5909 /* 'fileformats' */
5910 else if (varp == &p_ffs)
5911 {
5912 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5913 errmsg = e_invarg;
5914 else
5915 {
5916 /* also change 'textauto' */
5917 if (*p_ffs == NUL)
5918 p_ta = FALSE;
5919 else
5920 p_ta = TRUE;
5921 }
5922 }
5923
5924#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5925 /* 'cryptkey' */
5926 else if (gvarp == &p_key)
5927 {
5928 /* Make sure the ":set" command doesn't show the new value in the
5929 * history. */
5930 remove_key_from_history();
5931 }
5932#endif
5933
5934 /* 'matchpairs' */
5935 else if (gvarp == &p_mps)
5936 {
5937 /* Check for "x:y,x:y" */
5938 for (p = *varp; *p != NUL; p += 4)
5939 {
5940 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5941 {
5942 errmsg = e_invarg;
5943 break;
5944 }
5945 if (p[3] == NUL)
5946 break;
5947 }
5948 }
5949
5950#ifdef FEAT_COMMENTS
5951 /* 'comments' */
5952 else if (gvarp == &p_com)
5953 {
5954 for (s = *varp; *s; )
5955 {
5956 while (*s && *s != ':')
5957 {
5958 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5959 && !VIM_ISDIGIT(*s) && *s != '-')
5960 {
5961 errmsg = illegal_char(errbuf, *s);
5962 break;
5963 }
5964 ++s;
5965 }
5966 if (*s++ == NUL)
5967 errmsg = (char_u *)N_("E524: Missing colon");
5968 else if (*s == ',' || *s == NUL)
5969 errmsg = (char_u *)N_("E525: Zero length string");
5970 if (errmsg != NULL)
5971 break;
5972 while (*s && *s != ',')
5973 {
5974 if (*s == '\\' && s[1] != NUL)
5975 ++s;
5976 ++s;
5977 }
5978 s = skip_to_option_part(s);
5979 }
5980 }
5981#endif
5982
5983 /* 'listchars' */
5984 else if (varp == &p_lcs)
5985 {
5986 errmsg = set_chars_option(varp);
5987 }
5988
5989#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5990 /* 'fillchars' */
5991 else if (varp == &p_fcs)
5992 {
5993 errmsg = set_chars_option(varp);
5994 }
5995#endif
5996
5997#ifdef FEAT_CMDWIN
5998 /* 'cedit' */
5999 else if (varp == &p_cedit)
6000 {
6001 errmsg = check_cedit();
6002 }
6003#endif
6004
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006005 /* 'verbosefile' */
6006 else if (varp == &p_vfile)
6007 {
6008 verbose_stop();
6009 if (*p_vfile != NUL && verbose_open() == FAIL)
6010 errmsg = e_invarg;
6011 }
6012
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013#ifdef FEAT_VIMINFO
6014 /* 'viminfo' */
6015 else if (varp == &p_viminfo)
6016 {
6017 for (s = p_viminfo; *s;)
6018 {
6019 /* Check it's a valid character */
6020 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6021 {
6022 errmsg = illegal_char(errbuf, *s);
6023 break;
6024 }
6025 if (*s == 'n') /* name is always last one */
6026 {
6027 break;
6028 }
6029 else if (*s == 'r') /* skip until next ',' */
6030 {
6031 while (*++s && *s != ',')
6032 ;
6033 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006034 else if (*s == '%')
6035 {
6036 /* optional number */
6037 while (vim_isdigit(*++s))
6038 ;
6039 }
6040 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041 ++s; /* no extra chars */
6042 else /* must have a number */
6043 {
6044 while (vim_isdigit(*++s))
6045 ;
6046
6047 if (!VIM_ISDIGIT(*(s - 1)))
6048 {
6049 if (errbuf != NULL)
6050 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006051 sprintf((char *)errbuf,
6052 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006053 transchar_byte(*(s - 1)));
6054 errmsg = errbuf;
6055 }
6056 else
6057 errmsg = (char_u *)"";
6058 break;
6059 }
6060 }
6061 if (*s == ',')
6062 ++s;
6063 else if (*s)
6064 {
6065 if (errbuf != NULL)
6066 errmsg = (char_u *)N_("E527: Missing comma");
6067 else
6068 errmsg = (char_u *)"";
6069 break;
6070 }
6071 }
6072 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6073 errmsg = (char_u *)N_("E528: Must specify a ' value");
6074 }
6075#endif /* FEAT_VIMINFO */
6076
6077 /* terminal options */
6078 else if (istermoption(&options[opt_idx]) && full_screen)
6079 {
6080 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6081 if (varp == &T_CCO)
6082 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006083 int colors = atoi((char *)T_CCO);
6084
6085 /* Only reinitialize colors if t_Co value has really changed to
6086 * avoid expensive reload of colorscheme if t_Co is set to the
6087 * same value multiple times. */
6088 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006090 t_colors = colors;
6091 if (t_colors <= 1)
6092 {
6093 if (new_value_alloced)
6094 vim_free(T_CCO);
6095 T_CCO = empty_option;
6096 }
6097 /* We now have a different color setup, initialize it again. */
6098 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 }
6101 ttest(FALSE);
6102 if (varp == &T_ME)
6103 {
6104 out_str(T_ME);
6105 redraw_later(CLEAR);
6106#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6107 /* Since t_me has been set, this probably means that the user
6108 * wants to use this as default colors. Need to reset default
6109 * background/foreground colors. */
6110 mch_set_normal_colors();
6111#endif
6112 }
6113 }
6114
6115#ifdef FEAT_LINEBREAK
6116 /* 'showbreak' */
6117 else if (varp == &p_sbr)
6118 {
6119 for (s = p_sbr; *s; )
6120 {
6121 if (ptr2cells(s) != 1)
6122 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006123 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 }
6125 }
6126#endif
6127
6128#ifdef FEAT_GUI
6129 /* 'guifont' */
6130 else if (varp == &p_guifont)
6131 {
6132 if (gui.in_use)
6133 {
6134 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006135# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 /*
6137 * Put up a font dialog and let the user select a new value.
6138 * If this is cancelled go back to the old value but don't
6139 * give an error message.
6140 */
6141 if (STRCMP(p, "*") == 0)
6142 {
6143 p = gui_mch_font_dialog(oldval);
6144
6145 if (new_value_alloced)
6146 free_string_option(p_guifont);
6147
6148 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6149 new_value_alloced = TRUE;
6150 }
6151# endif
6152 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6153 {
6154# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6155 if (STRCMP(p_guifont, "*") == 0)
6156 {
6157 /* Dialog was cancelled: Keep the old value without giving
6158 * an error message. */
6159 if (new_value_alloced)
6160 free_string_option(p_guifont);
6161 p_guifont = vim_strsave(oldval);
6162 new_value_alloced = TRUE;
6163 }
6164 else
6165# endif
6166 errmsg = (char_u *)N_("E596: Invalid font(s)");
6167 }
6168 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006169 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 }
6171# ifdef FEAT_XFONTSET
6172 else if (varp == &p_guifontset)
6173 {
6174 if (STRCMP(p_guifontset, "*") == 0)
6175 errmsg = (char_u *)N_("E597: can't select fontset");
6176 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6177 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006178 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 }
6180# endif
6181# ifdef FEAT_MBYTE
6182 else if (varp == &p_guifontwide)
6183 {
6184 if (STRCMP(p_guifontwide, "*") == 0)
6185 errmsg = (char_u *)N_("E533: can't select wide font");
6186 else if (gui_get_wide_font() == FAIL)
6187 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006188 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189 }
6190# endif
6191#endif
6192
6193#ifdef CURSOR_SHAPE
6194 /* 'guicursor' */
6195 else if (varp == &p_guicursor)
6196 errmsg = parse_shape_opt(SHAPE_CURSOR);
6197#endif
6198
6199#ifdef FEAT_MOUSESHAPE
6200 /* 'mouseshape' */
6201 else if (varp == &p_mouseshape)
6202 {
6203 errmsg = parse_shape_opt(SHAPE_MOUSE);
6204 update_mouseshape(-1);
6205 }
6206#endif
6207
6208#ifdef FEAT_PRINTER
6209 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006210 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006211# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006212 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006213 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006214# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215#endif
6216
6217#ifdef FEAT_LANGMAP
6218 /* 'langmap' */
6219 else if (varp == &p_langmap)
6220 langmap_set();
6221#endif
6222
6223#ifdef FEAT_LINEBREAK
6224 /* 'breakat' */
6225 else if (varp == &p_breakat)
6226 fill_breakat_flags();
6227#endif
6228
6229#ifdef FEAT_TITLE
6230 /* 'titlestring' and 'iconstring' */
6231 else if (varp == &p_titlestring || varp == &p_iconstring)
6232 {
6233# ifdef FEAT_STL_OPT
6234 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6235
6236 /* NULL => statusline syntax */
6237 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6238 stl_syntax |= flagval;
6239 else
6240 stl_syntax &= ~flagval;
6241# endif
6242 did_set_title(varp == &p_iconstring);
6243
6244 }
6245#endif
6246
6247#ifdef FEAT_GUI
6248 /* 'guioptions' */
6249 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006250 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006252 redraw_gui_only = TRUE;
6253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254#endif
6255
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006256#if defined(FEAT_GUI_TABLINE)
6257 /* 'guitablabel' */
6258 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006259 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006260 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006261 redraw_gui_only = TRUE;
6262 }
6263 /* 'guitabtooltip' */
6264 else if (varp == &p_gtt)
6265 {
6266 redraw_gui_only = TRUE;
6267 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006268#endif
6269
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6271 /* 'ttymouse' */
6272 else if (varp == &p_ttym)
6273 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006274 /* Switch the mouse off before changing the escape sequences used for
6275 * that. */
6276 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6278 errmsg = e_invarg;
6279 else
6280 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006281 if (termcap_active)
6282 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 }
6284#endif
6285
6286#ifdef FEAT_VISUAL
6287 /* 'selection' */
6288 else if (varp == &p_sel)
6289 {
6290 if (*p_sel == NUL
6291 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6292 errmsg = e_invarg;
6293 }
6294
6295 /* 'selectmode' */
6296 else if (varp == &p_slm)
6297 {
6298 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6299 errmsg = e_invarg;
6300 }
6301#endif
6302
6303#ifdef FEAT_BROWSE
6304 /* 'browsedir' */
6305 else if (varp == &p_bsdir)
6306 {
6307 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6308 && !mch_isdir(p_bsdir))
6309 errmsg = e_invarg;
6310 }
6311#endif
6312
6313#ifdef FEAT_VISUAL
6314 /* 'keymodel' */
6315 else if (varp == &p_km)
6316 {
6317 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6318 errmsg = e_invarg;
6319 else
6320 {
6321 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6322 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6323 }
6324 }
6325#endif
6326
6327 /* 'mousemodel' */
6328 else if (varp == &p_mousem)
6329 {
6330 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6331 errmsg = e_invarg;
6332#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6333 else if (*p_mousem != *oldval)
6334 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6335 * to create or delete the popup menus. */
6336 gui_motif_update_mousemodel(root_menu);
6337#endif
6338 }
6339
6340 /* 'switchbuf' */
6341 else if (varp == &p_swb)
6342 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006343 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 errmsg = e_invarg;
6345 }
6346
6347 /* 'debug' */
6348 else if (varp == &p_debug)
6349 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006350 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 errmsg = e_invarg;
6352 }
6353
6354 /* 'display' */
6355 else if (varp == &p_dy)
6356 {
6357 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6358 errmsg = e_invarg;
6359 else
6360 (void)init_chartab();
6361
6362 }
6363
6364#ifdef FEAT_VERTSPLIT
6365 /* 'eadirection' */
6366 else if (varp == &p_ead)
6367 {
6368 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6369 errmsg = e_invarg;
6370 }
6371#endif
6372
6373#ifdef FEAT_CLIPBOARD
6374 /* 'clipboard' */
6375 else if (varp == &p_cb)
6376 errmsg = check_clipboard_option();
6377#endif
6378
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006379#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006380 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6381 * buffer in which 'spell' is set load the wordlists. */
6382 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006383 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006384 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006385 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006386
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006387 if (varp == &(curbuf->b_p_spf))
6388 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006389 l = (int)STRLEN(curbuf->b_p_spf);
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006390 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6391 ".add") != 0))
6392 errmsg = e_invarg;
6393 }
6394
6395 if (errmsg == NULL)
6396 {
6397 FOR_ALL_WINDOWS(wp)
6398 if (wp->w_buffer == curbuf && wp->w_p_spell)
6399 {
6400 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006401# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006402 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006403# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006404 }
6405 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006406 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006407 /* When 'spellcapcheck' is set compile the regexp program. */
6408 else if (varp == &(curbuf->b_p_spc))
6409 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006410 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006411 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006412 /* 'spellsuggest' */
6413 else if (varp == &p_sps)
6414 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006415 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006416 errmsg = e_invarg;
6417 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006418 /* 'mkspellmem' */
6419 else if (varp == &p_msm)
6420 {
6421 if (spell_check_msm() != OK)
6422 errmsg = e_invarg;
6423 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006424#endif
6425
Bram Moolenaar071d4272004-06-13 20:20:40 +00006426#ifdef FEAT_QUICKFIX
6427 /* When 'bufhidden' is set, check for valid value. */
6428 else if (gvarp == &p_bh)
6429 {
6430 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6431 errmsg = e_invarg;
6432 }
6433
6434 /* When 'buftype' is set, check for valid value. */
6435 else if (gvarp == &p_bt)
6436 {
6437 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6438 errmsg = e_invarg;
6439 else
6440 {
6441# ifdef FEAT_WINDOWS
6442 if (curwin->w_status_height)
6443 {
6444 curwin->w_redr_status = TRUE;
6445 redraw_later(VALID);
6446 }
6447# endif
6448 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006449# ifdef FEAT_TITLE
6450 redraw_titles();
6451# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452 }
6453 }
6454#endif
6455
6456#ifdef FEAT_STL_OPT
6457 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006458 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 {
6460 int wid;
6461
6462 if (varp == &p_ruf) /* reset ru_wid first */
6463 ru_wid = 0;
6464 s = *varp;
6465 if (varp == &p_ruf && *s == '%')
6466 {
6467 /* set ru_wid if 'ruf' starts with "%99(" */
6468 if (*++s == '-') /* ignore a '-' */
6469 s++;
6470 wid = getdigits(&s);
6471 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6472 ru_wid = wid;
6473 else
6474 errmsg = check_stl_option(p_ruf);
6475 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006476 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006477 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006478 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006479 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 comp_col();
6481 }
6482#endif
6483
6484#ifdef FEAT_INS_EXPAND
6485 /* check if it is a valid value for 'complete' -- Acevedo */
6486 else if (gvarp == &p_cpt)
6487 {
6488 for (s = *varp; *s;)
6489 {
6490 while(*s == ',' || *s == ' ')
6491 s++;
6492 if (!*s)
6493 break;
6494 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6495 {
6496 errmsg = illegal_char(errbuf, *s);
6497 break;
6498 }
6499 if (*++s != NUL && *s != ',' && *s != ' ')
6500 {
6501 if (s[-1] == 'k' || s[-1] == 's')
6502 {
6503 /* skip optional filename after 'k' and 's' */
6504 while (*s && *s != ',' && *s != ' ')
6505 {
6506 if (*s == '\\')
6507 ++s;
6508 ++s;
6509 }
6510 }
6511 else
6512 {
6513 if (errbuf != NULL)
6514 {
6515 sprintf((char *)errbuf,
6516 _("E535: Illegal character after <%c>"),
6517 *--s);
6518 errmsg = errbuf;
6519 }
6520 else
6521 errmsg = (char_u *)"";
6522 break;
6523 }
6524 }
6525 }
6526 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006527
6528 /* 'completeopt' */
6529 else if (varp == &p_cot)
6530 {
6531 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6532 errmsg = e_invarg;
6533 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534#endif /* FEAT_INS_EXPAND */
6535
6536
6537#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6538 else if (varp == &p_toolbar)
6539 {
6540 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6541 &toolbar_flags, TRUE) != OK)
6542 errmsg = e_invarg;
6543 else
6544 {
6545 out_flush();
6546 gui_mch_show_toolbar((toolbar_flags &
6547 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6548 }
6549 }
6550#endif
6551
6552#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6553 /* 'toolbariconsize': GTK+ 2 only */
6554 else if (varp == &p_tbis)
6555 {
6556 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6557 errmsg = e_invarg;
6558 else
6559 {
6560 out_flush();
6561 gui_mch_show_toolbar((toolbar_flags &
6562 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6563 }
6564 }
6565#endif
6566
6567 /* 'pastetoggle': translate key codes like in a mapping */
6568 else if (varp == &p_pt)
6569 {
6570 if (*p_pt)
6571 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006572 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006573 if (p != NULL)
6574 {
6575 if (new_value_alloced)
6576 free_string_option(p_pt);
6577 p_pt = p;
6578 new_value_alloced = TRUE;
6579 }
6580 }
6581 }
6582
6583 /* 'backspace' */
6584 else if (varp == &p_bs)
6585 {
6586 if (VIM_ISDIGIT(*p_bs))
6587 {
6588 if (*p_bs >'2' || p_bs[1] != NUL)
6589 errmsg = e_invarg;
6590 }
6591 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6592 errmsg = e_invarg;
6593 }
6594
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006595#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 /* 'casemap' */
6597 else if (varp == &p_cmp)
6598 {
6599 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6600 errmsg = e_invarg;
6601 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603
6604#ifdef FEAT_DIFF
6605 /* 'diffopt' */
6606 else if (varp == &p_dip)
6607 {
6608 if (diffopt_changed() == FAIL)
6609 errmsg = e_invarg;
6610 }
6611#endif
6612
6613#ifdef FEAT_FOLDING
6614 /* 'foldmethod' */
6615 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6616 {
6617 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6618 || *curwin->w_p_fdm == NUL)
6619 errmsg = e_invarg;
6620 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006621 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006622 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006623 if (foldmethodIsDiff(curwin))
6624 newFoldLevel();
6625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 }
6627# ifdef FEAT_EVAL
6628 /* 'foldexpr' */
6629 else if (varp == &curwin->w_p_fde)
6630 {
6631 if (foldmethodIsExpr(curwin))
6632 foldUpdateAll(curwin);
6633 }
6634# endif
6635 /* 'foldmarker' */
6636 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6637 {
6638 p = vim_strchr(*varp, ',');
6639 if (p == NULL)
6640 errmsg = (char_u *)N_("E536: comma required");
6641 else if (p == *varp || p[1] == NUL)
6642 errmsg = e_invarg;
6643 else if (foldmethodIsMarker(curwin))
6644 foldUpdateAll(curwin);
6645 }
6646 /* 'commentstring' */
6647 else if (gvarp == &p_cms)
6648 {
6649 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6650 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6651 }
6652 /* 'foldopen' */
6653 else if (varp == &p_fdo)
6654 {
6655 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6656 errmsg = e_invarg;
6657 }
6658 /* 'foldclose' */
6659 else if (varp == &p_fcl)
6660 {
6661 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6662 errmsg = e_invarg;
6663 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006664 /* 'foldignore' */
6665 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6666 {
6667 if (foldmethodIsIndent(curwin))
6668 foldUpdateAll(curwin);
6669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670#endif
6671
6672#ifdef FEAT_VIRTUALEDIT
6673 /* 'virtualedit' */
6674 else if (varp == &p_ve)
6675 {
6676 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6677 errmsg = e_invarg;
6678 else if (STRCMP(p_ve, oldval) != 0)
6679 {
6680 /* Recompute cursor position in case the new 've' setting
6681 * changes something. */
6682 validate_virtcol();
6683 coladvance(curwin->w_virtcol);
6684 }
6685 }
6686#endif
6687
6688#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6689 else if (varp == &p_csqf)
6690 {
6691 if (p_csqf != NULL)
6692 {
6693 p = p_csqf;
6694 while (*p != NUL)
6695 {
6696 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6697 || p[1] == NUL
6698 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6699 || (p[2] != NUL && p[2] != ','))
6700 {
6701 errmsg = e_invarg;
6702 break;
6703 }
6704 else if (p[2] == NUL)
6705 break;
6706 else
6707 p += 3;
6708 }
6709 }
6710 }
6711#endif
6712
6713 /* Options that are a list of flags. */
6714 else
6715 {
6716 p = NULL;
6717 if (varp == &p_ww)
6718 p = (char_u *)WW_ALL;
6719 if (varp == &p_shm)
6720 p = (char_u *)SHM_ALL;
6721 else if (varp == &(p_cpo))
6722 p = (char_u *)CPO_ALL;
6723 else if (varp == &(curbuf->b_p_fo))
6724 p = (char_u *)FO_ALL;
6725 else if (varp == &p_mouse)
6726 {
6727#ifdef FEAT_MOUSE
6728 p = (char_u *)MOUSE_ALL;
6729#else
6730 if (*p_mouse != NUL)
6731 errmsg = (char_u *)N_("E538: No mouse support");
6732#endif
6733 }
6734#if defined(FEAT_GUI)
6735 else if (varp == &p_go)
6736 p = (char_u *)GO_ALL;
6737#endif
6738 if (p != NULL)
6739 {
6740 for (s = *varp; *s; ++s)
6741 if (vim_strchr(p, *s) == NULL)
6742 {
6743 errmsg = illegal_char(errbuf, *s);
6744 break;
6745 }
6746 }
6747 }
6748
6749 /*
6750 * If error detected, restore the previous value.
6751 */
6752 if (errmsg != NULL)
6753 {
6754 if (new_value_alloced)
6755 free_string_option(*varp);
6756 *varp = oldval;
6757 /*
6758 * When resetting some values, need to act on it.
6759 */
6760 if (did_chartab)
6761 (void)init_chartab();
6762 if (varp == &p_hl)
6763 (void)highlight_changed();
6764 }
6765 else
6766 {
6767#ifdef FEAT_EVAL
6768 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006769 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770#endif
6771 /*
6772 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006773 * Use "free_oldval", because recursiveness may change the flags under
6774 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006776 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 free_string_option(oldval);
6778 if (new_value_alloced)
6779 options[opt_idx].flags |= P_ALLOCED;
6780 else
6781 options[opt_idx].flags &= ~P_ALLOCED;
6782
6783 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006784 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 {
6786 /* global option with local value set to use global value; free
6787 * the local value and make it empty */
6788 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6789 free_string_option(*(char_u **)p);
6790 *(char_u **)p = empty_option;
6791 }
6792
6793 /* May set global value for local option. */
6794 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6795 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006796
6797#ifdef FEAT_AUTOCMD
6798 /*
6799 * Trigger the autocommand only after setting the flags.
6800 */
6801# ifdef FEAT_SYN_HL
6802 /* When 'syntax' is set, load the syntax of that name */
6803 if (varp == &(curbuf->b_p_syn))
6804 {
6805 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6806 curbuf->b_fname, TRUE, curbuf);
6807 }
6808# endif
6809 else if (varp == &(curbuf->b_p_ft))
6810 {
6811 /* 'filetype' is set, trigger the FileType autocommand */
6812 did_filetype = TRUE;
6813 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6814 curbuf->b_fname, TRUE, curbuf);
6815 }
6816#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006817#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006818 if (varp == &(curbuf->b_p_spl))
6819 {
6820 char_u fname[200];
6821
6822 /*
6823 * Source the spell/LANG.vim in 'runtimepath'.
6824 * They could set 'spellcapcheck' depending on the language.
6825 * Use the first name in 'spelllang' up to '_region' or
6826 * '.encoding'.
6827 */
6828 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6829 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6830 break;
6831 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6832 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6833 source_runtime(fname, TRUE);
6834 }
6835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 }
6837
6838#ifdef FEAT_MOUSE
6839 if (varp == &p_mouse)
6840 {
6841# ifdef FEAT_MOUSE_TTY
6842 if (*p_mouse == NUL)
6843 mch_setmouse(FALSE); /* switch mouse off */
6844 else
6845# endif
6846 setmouse(); /* in case 'mouse' changed */
6847 }
6848#endif
6849
6850 if (curwin->w_curswant != MAXCOL)
6851 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006852#ifdef FEAT_GUI
6853 /* check redraw when it's not a GUI option or the GUI is active. */
6854 if (!redraw_gui_only || gui.in_use)
6855#endif
6856 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857
6858 return errmsg;
6859}
6860
6861/*
6862 * Handle setting 'listchars' or 'fillchars'.
6863 * Returns error message, NULL if it's OK.
6864 */
6865 static char_u *
6866set_chars_option(varp)
6867 char_u **varp;
6868{
6869 int round, i, len, entries;
6870 char_u *p, *s;
6871 int c1, c2 = 0;
6872 struct charstab
6873 {
6874 int *cp;
6875 char *name;
6876 };
6877#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6878 static struct charstab filltab[] =
6879 {
6880 {&fill_stl, "stl"},
6881 {&fill_stlnc, "stlnc"},
6882 {&fill_vert, "vert"},
6883 {&fill_fold, "fold"},
6884 {&fill_diff, "diff"},
6885 };
6886#endif
6887 static struct charstab lcstab[] =
6888 {
6889 {&lcs_eol, "eol"},
6890 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006891 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 {&lcs_prec, "precedes"},
6893 {&lcs_tab2, "tab"},
6894 {&lcs_trail, "trail"},
6895 };
6896 struct charstab *tab;
6897
6898#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6899 if (varp == &p_lcs)
6900#endif
6901 {
6902 tab = lcstab;
6903 entries = sizeof(lcstab) / sizeof(struct charstab);
6904 }
6905#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6906 else
6907 {
6908 tab = filltab;
6909 entries = sizeof(filltab) / sizeof(struct charstab);
6910 }
6911#endif
6912
6913 /* first round: check for valid value, second round: assign values */
6914 for (round = 0; round <= 1; ++round)
6915 {
6916 if (round)
6917 {
6918 /* After checking that the value is valid: set defaults: space for
6919 * 'fillchars', NUL for 'listchars' */
6920 for (i = 0; i < entries; ++i)
6921 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6922 if (varp == &p_lcs)
6923 lcs_tab1 = NUL;
6924#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6925 else
6926 fill_diff = '-';
6927#endif
6928 }
6929 p = *varp;
6930 while (*p)
6931 {
6932 for (i = 0; i < entries; ++i)
6933 {
6934 len = (int)STRLEN(tab[i].name);
6935 if (STRNCMP(p, tab[i].name, len) == 0
6936 && p[len] == ':'
6937 && p[len + 1] != NUL)
6938 {
6939 s = p + len + 1;
6940#ifdef FEAT_MBYTE
6941 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006942 if (mb_char2cells(c1) > 1)
6943 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944#else
6945 c1 = *s++;
6946#endif
6947 if (tab[i].cp == &lcs_tab2)
6948 {
6949 if (*s == NUL)
6950 continue;
6951#ifdef FEAT_MBYTE
6952 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006953 if (mb_char2cells(c2) > 1)
6954 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955#else
6956 c2 = *s++;
6957#endif
6958 }
6959 if (*s == ',' || *s == NUL)
6960 {
6961 if (round)
6962 {
6963 if (tab[i].cp == &lcs_tab2)
6964 {
6965 lcs_tab1 = c1;
6966 lcs_tab2 = c2;
6967 }
6968 else
6969 *(tab[i].cp) = c1;
6970
6971 }
6972 p = s;
6973 break;
6974 }
6975 }
6976 }
6977
6978 if (i == entries)
6979 return e_invarg;
6980 if (*p == ',')
6981 ++p;
6982 }
6983 }
6984
6985 return NULL; /* no error */
6986}
6987
6988#ifdef FEAT_STL_OPT
6989/*
6990 * Check validity of options with the 'statusline' format.
6991 * Return error message or NULL.
6992 */
6993 char_u *
6994check_stl_option(s)
6995 char_u *s;
6996{
6997 int itemcnt = 0;
6998 int groupdepth = 0;
6999 static char_u errbuf[80];
7000
7001 while (*s && itemcnt < STL_MAX_ITEM)
7002 {
7003 /* Check for valid keys after % sequences */
7004 while (*s && *s != '%')
7005 s++;
7006 if (!*s)
7007 break;
7008 s++;
7009 if (*s != '%' && *s != ')')
7010 ++itemcnt;
7011 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7012 {
7013 s++;
7014 continue;
7015 }
7016 if (*s == ')')
7017 {
7018 s++;
7019 if (--groupdepth < 0)
7020 break;
7021 continue;
7022 }
7023 if (*s == '-')
7024 s++;
7025 while (VIM_ISDIGIT(*s))
7026 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007027 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007028 continue;
7029 if (*s == '.')
7030 {
7031 s++;
7032 while (*s && VIM_ISDIGIT(*s))
7033 s++;
7034 }
7035 if (*s == '(')
7036 {
7037 groupdepth++;
7038 continue;
7039 }
7040 if (vim_strchr(STL_ALL, *s) == NULL)
7041 {
7042 return illegal_char(errbuf, *s);
7043 }
7044 if (*s == '{')
7045 {
7046 s++;
7047 while (*s != '}' && *s)
7048 s++;
7049 if (*s != '}')
7050 return (char_u *)N_("E540: Unclosed expression sequence");
7051 }
7052 }
7053 if (itemcnt >= STL_MAX_ITEM)
7054 return (char_u *)N_("E541: too many items");
7055 if (groupdepth != 0)
7056 return (char_u *)N_("E542: unbalanced groups");
7057 return NULL;
7058}
7059#endif
7060
7061#ifdef FEAT_CLIPBOARD
7062/*
7063 * Extract the items in the 'clipboard' option and set global values.
7064 */
7065 static char_u *
7066check_clipboard_option()
7067{
7068 int new_unnamed = FALSE;
7069 int new_autoselect = FALSE;
7070 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007071 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072 regprog_T *new_exclude_prog = NULL;
7073 char_u *errmsg = NULL;
7074 char_u *p;
7075
7076 for (p = p_cb; *p != NUL; )
7077 {
7078 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7079 {
7080 new_unnamed = TRUE;
7081 p += 7;
7082 }
7083 else if (STRNCMP(p, "autoselect", 10) == 0
7084 && (p[10] == ',' || p[10] == NUL))
7085 {
7086 new_autoselect = TRUE;
7087 p += 10;
7088 }
7089 else if (STRNCMP(p, "autoselectml", 12) == 0
7090 && (p[12] == ',' || p[12] == NUL))
7091 {
7092 new_autoselectml = TRUE;
7093 p += 12;
7094 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007095 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7096 {
7097 new_html = TRUE;
7098 p += 4;
7099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7101 {
7102 p += 8;
7103 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7104 if (new_exclude_prog == NULL)
7105 errmsg = e_invarg;
7106 break;
7107 }
7108 else
7109 {
7110 errmsg = e_invarg;
7111 break;
7112 }
7113 if (*p == ',')
7114 ++p;
7115 }
7116 if (errmsg == NULL)
7117 {
7118 clip_unnamed = new_unnamed;
7119 clip_autoselect = new_autoselect;
7120 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007121 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 vim_free(clip_exclude_prog);
7123 clip_exclude_prog = new_exclude_prog;
7124 }
7125 else
7126 vim_free(new_exclude_prog);
7127
7128 return errmsg;
7129}
7130#endif
7131
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007132#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007133/*
7134 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7135 * Return error message when failed, NULL when OK.
7136 */
7137 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007138compile_cap_prog(buf)
7139 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007140{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007141 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007142 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007143
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007144 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007145 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007146 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007147 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007148 /* Prepend a ^ so that we only match at one column */
7149 re = concat_str((char_u *)"^", buf->b_p_spc);
7150 if (re != NULL)
7151 {
7152 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7153 if (buf->b_cap_prog == NULL)
7154 {
7155 buf->b_cap_prog = rp; /* restore the previous program */
7156 return e_invarg;
7157 }
7158 vim_free(re);
7159 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007160 }
7161
7162 vim_free(rp);
7163 return NULL;
7164}
7165#endif
7166
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007167#if defined(FEAT_EVAL) || defined(PROTO)
7168/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007169 * Set the scriptID for an option, taking care of setting the buffer- or
7170 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007171 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007172 static void
7173set_option_scriptID_idx(opt_idx, opt_flags, id)
7174 int opt_idx;
7175 int opt_flags;
7176 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007177{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007178 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7179 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007180
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007181 /* Remember where the option was set. For local options need to do that
7182 * in the buffer or window structure. */
7183 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007184 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007185 if (both || (opt_flags & OPT_LOCAL))
7186 {
7187 if (indir & PV_BUF)
7188 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7189 else if (indir & PV_WIN)
7190 curwin->w_p_scriptID[indir & PV_MASK] = id;
7191 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007192}
7193#endif
7194
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195/*
7196 * Set the value of a boolean option, and take care of side effects.
7197 * Returns NULL for success, or an error message for an error.
7198 */
7199 static char_u *
7200set_bool_option(opt_idx, varp, value, opt_flags)
7201 int opt_idx; /* index in options[] table */
7202 char_u *varp; /* pointer to the option variable */
7203 int value; /* new value */
7204 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7205{
7206 int old_value = *(int *)varp;
7207
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 /* Disallow changing some options from secure mode */
7209 if ((secure
7210#ifdef HAVE_SANDBOX
7211 || sandbox != 0
7212#endif
7213 ) && (options[opt_idx].flags & P_SECURE))
7214 return e_secure;
7215
7216 *(int *)varp = value; /* set the new value */
7217#ifdef FEAT_EVAL
7218 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007219 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220#endif
7221
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007222#ifdef FEAT_GUI
7223 need_mouse_correct = TRUE;
7224#endif
7225
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226 /* May set global value for local option. */
7227 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7228 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7229
7230 /*
7231 * Handle side effects of changing a bool option.
7232 */
7233
7234 /* 'compatible' */
7235 if ((int *)varp == &p_cp)
7236 {
7237 compatible_set();
7238 }
7239
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007240 /* 'list', 'number' */
7241 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007242 || (int *)varp == &curwin->w_p_nu
7243 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007244 {
7245 if (curwin->w_curswant != MAXCOL)
7246 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007247
7248 /* If 'number' is set, reset 'relativenumber'. */
7249 /* If 'relativenumber' is set, reset 'number'. */
7250 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7251 curwin->w_p_rnu = FALSE;
7252 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7253 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007254 }
7255
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256 else if ((int *)varp == &curbuf->b_p_ro)
7257 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007258 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7260 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007261
7262 /* when 'readonly' is set may give W10 again */
7263 if (curbuf->b_p_ro)
7264 curbuf->b_did_warn = FALSE;
7265
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007267 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268#endif
7269 }
7270
7271#ifdef FEAT_TITLE
7272 /* when 'modifiable' is changed, redraw the window title */
7273 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007274 {
7275 redraw_titles();
7276 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 /* when 'endofline' is changed, redraw the window title */
7278 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007279 {
7280 redraw_titles();
7281 }
7282# ifdef FEAT_MBYTE
7283 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007284 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007285 {
7286 redraw_titles();
7287 }
7288# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007289#endif
7290
7291 /* when 'bin' is set also set some other options */
7292 else if ((int *)varp == &curbuf->b_p_bin)
7293 {
7294 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7295#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007296 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007297#endif
7298 }
7299
7300#ifdef FEAT_AUTOCMD
7301 /* when 'buflisted' changes, trigger autocommands */
7302 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7303 {
7304 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7305 NULL, NULL, TRUE, curbuf);
7306 }
7307#endif
7308
7309 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7310 else if ((int *)varp == &curbuf->b_p_swf)
7311 {
7312 if (curbuf->b_p_swf && p_uc)
7313 ml_open_file(curbuf); /* create the swap file */
7314 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007315 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7316 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 mf_close_file(curbuf, TRUE); /* remove the swap file */
7318 }
7319
7320 /* when 'terse' is set change 'shortmess' */
7321 else if ((int *)varp == &p_terse)
7322 {
7323 char_u *p;
7324
7325 p = vim_strchr(p_shm, SHM_SEARCH);
7326
7327 /* insert 's' in p_shm */
7328 if (p_terse && p == NULL)
7329 {
7330 STRCPY(IObuff, p_shm);
7331 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007332 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333 }
7334 /* remove 's' from p_shm */
7335 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007336 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 }
7338
7339 /* when 'paste' is set or reset also change other options */
7340 else if ((int *)varp == &p_paste)
7341 {
7342 paste_option_changed();
7343 }
7344
7345 /* when 'insertmode' is set from an autocommand need to do work here */
7346 else if ((int *)varp == &p_im)
7347 {
7348 if (p_im)
7349 {
7350 if ((State & INSERT) == 0)
7351 need_start_insertmode = TRUE;
7352 stop_insert_mode = FALSE;
7353 }
7354 else
7355 {
7356 need_start_insertmode = FALSE;
7357 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007358 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 clear_cmdline = TRUE; /* remove "(insert)" */
7360 restart_edit = 0;
7361 }
7362 }
7363
7364 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7365 else if ((int *)varp == &p_ic && p_hls)
7366 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007367 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 }
7369
7370#ifdef FEAT_SEARCH_EXTRA
7371 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7372 else if ((int *)varp == &p_hls)
7373 {
7374 no_hlsearch = FALSE;
7375 }
7376#endif
7377
7378#ifdef FEAT_SCROLLBIND
7379 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7380 * at the end of normal_cmd() */
7381 else if ((int *)varp == &curwin->w_p_scb)
7382 {
7383 if (curwin->w_p_scb)
7384 do_check_scrollbind(FALSE);
7385 }
7386#endif
7387
7388#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7389 /* There can be only one window with 'previewwindow' set. */
7390 else if ((int *)varp == &curwin->w_p_pvw)
7391 {
7392 if (curwin->w_p_pvw)
7393 {
7394 win_T *win;
7395
7396 for (win = firstwin; win != NULL; win = win->w_next)
7397 if (win->w_p_pvw && win != curwin)
7398 {
7399 curwin->w_p_pvw = FALSE;
7400 return (char_u *)N_("E590: A preview window already exists");
7401 }
7402 }
7403 }
7404#endif
7405
7406 /* when 'textmode' is set or reset also change 'fileformat' */
7407 else if ((int *)varp == &curbuf->b_p_tx)
7408 {
7409 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7410 }
7411
7412 /* when 'textauto' is set or reset also change 'fileformats' */
7413 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007414 set_string_option_direct((char_u *)"ffs", -1,
7415 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007416 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007417
7418 /*
7419 * When 'lisp' option changes include/exclude '-' in
7420 * keyword characters.
7421 */
7422#ifdef FEAT_LISP
7423 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7424 {
7425 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7426 }
7427#endif
7428
7429#ifdef FEAT_TITLE
7430 /* when 'title' changed, may need to change the title; same for 'icon' */
7431 else if ((int *)varp == &p_title)
7432 {
7433 did_set_title(FALSE);
7434 }
7435
7436 else if ((int *)varp == &p_icon)
7437 {
7438 did_set_title(TRUE);
7439 }
7440#endif
7441
7442 else if ((int *)varp == &curbuf->b_changed)
7443 {
7444 if (!value)
7445 save_file_ff(curbuf); /* Buffer is unchanged */
7446#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007447 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448#endif
7449#ifdef FEAT_AUTOCMD
7450 modified_was_set = value;
7451#endif
7452 }
7453
7454#ifdef BACKSLASH_IN_FILENAME
7455 else if ((int *)varp == &p_ssl)
7456 {
7457 if (p_ssl)
7458 {
7459 psepc = '/';
7460 psepcN = '\\';
7461 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 }
7463 else
7464 {
7465 psepc = '\\';
7466 psepcN = '/';
7467 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007468 }
7469
7470 /* need to adjust the file name arguments and buffer names. */
7471 buflist_slash_adjust();
7472 alist_slash_adjust();
7473# ifdef FEAT_EVAL
7474 scriptnames_slash_adjust();
7475# endif
7476 }
7477#endif
7478
7479 /* If 'wrap' is set, set w_leftcol to zero. */
7480 else if ((int *)varp == &curwin->w_p_wrap)
7481 {
7482 if (curwin->w_p_wrap)
7483 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007484 if (curwin->w_curswant != MAXCOL)
7485 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 }
7487
7488#ifdef FEAT_WINDOWS
7489 else if ((int *)varp == &p_ea)
7490 {
7491 if (p_ea && !old_value)
7492 win_equal(curwin, FALSE, 0);
7493 }
7494#endif
7495
7496 else if ((int *)varp == &p_wiv)
7497 {
7498 /*
7499 * When 'weirdinvert' changed, set/reset 't_xs'.
7500 * Then set 'weirdinvert' according to value of 't_xs'.
7501 */
7502 if (p_wiv && !old_value)
7503 T_XS = (char_u *)"y";
7504 else if (!p_wiv && old_value)
7505 T_XS = empty_option;
7506 p_wiv = (*T_XS != NUL);
7507 }
7508
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007509#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 else if ((int *)varp == &p_beval)
7511 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007512 if (p_beval == TRUE)
7513 gui_mch_enable_beval_area(balloonEval);
7514 else
7515 gui_mch_disable_beval_area(balloonEval);
7516 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007517#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007519#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007520 else if ((int *)varp == &p_acd)
7521 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007522 /* Change directories when the 'acd' option is set now. */
7523 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524 }
7525#endif
7526
7527#ifdef FEAT_DIFF
7528 /* 'diff' */
7529 else if ((int *)varp == &curwin->w_p_diff)
7530 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007531 /* May add or remove the buffer from the list of diff buffers. */
7532 diff_buf_adjust(curwin);
7533# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 if (foldmethodIsDiff(curwin))
7535 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007536# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537 }
7538#endif
7539
7540#ifdef USE_IM_CONTROL
7541 /* 'imdisable' */
7542 else if ((int *)varp == &p_imdisable)
7543 {
7544 /* Only de-activate it here, it will be enabled when changing mode. */
7545 if (p_imdisable)
7546 im_set_active(FALSE);
7547 }
7548#endif
7549
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007550#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007551 /* 'spell' */
7552 else if ((int *)varp == &curwin->w_p_spell)
7553 {
7554 if (curwin->w_p_spell)
7555 {
7556 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007557
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007558 if (errmsg != NULL)
7559 EMSG(_(errmsg));
7560 }
7561 }
7562#endif
7563
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564#ifdef FEAT_FKMAP
7565 else if ((int *)varp == &p_altkeymap)
7566 {
7567 if (old_value != p_altkeymap)
7568 {
7569 if (!p_altkeymap)
7570 {
7571 p_hkmap = p_fkmap;
7572 p_fkmap = 0;
7573 }
7574 else
7575 {
7576 p_fkmap = p_hkmap;
7577 p_hkmap = 0;
7578 }
7579 (void)init_chartab();
7580 }
7581 }
7582
7583 /*
7584 * In case some second language keymapping options have changed, check
7585 * and correct the setting in a consistent way.
7586 */
7587
7588 /*
7589 * If hkmap or fkmap are set, reset Arabic keymapping.
7590 */
7591 if ((p_hkmap || p_fkmap) && p_altkeymap)
7592 {
7593 p_altkeymap = p_fkmap;
7594# ifdef FEAT_ARABIC
7595 curwin->w_p_arab = FALSE;
7596# endif
7597 (void)init_chartab();
7598 }
7599
7600 /*
7601 * If hkmap set, reset Farsi keymapping.
7602 */
7603 if (p_hkmap && p_altkeymap)
7604 {
7605 p_altkeymap = 0;
7606 p_fkmap = 0;
7607# ifdef FEAT_ARABIC
7608 curwin->w_p_arab = FALSE;
7609# endif
7610 (void)init_chartab();
7611 }
7612
7613 /*
7614 * If fkmap set, reset Hebrew keymapping.
7615 */
7616 if (p_fkmap && !p_altkeymap)
7617 {
7618 p_altkeymap = 1;
7619 p_hkmap = 0;
7620# ifdef FEAT_ARABIC
7621 curwin->w_p_arab = FALSE;
7622# endif
7623 (void)init_chartab();
7624 }
7625#endif
7626
7627#ifdef FEAT_ARABIC
7628 if ((int *)varp == &curwin->w_p_arab)
7629 {
7630 if (curwin->w_p_arab)
7631 {
7632 /*
7633 * 'arabic' is set, handle various sub-settings.
7634 */
7635 if (!p_tbidi)
7636 {
7637 /* set rightleft mode */
7638 if (!curwin->w_p_rl)
7639 {
7640 curwin->w_p_rl = TRUE;
7641 changed_window_setting();
7642 }
7643
7644 /* Enable Arabic shaping (major part of what Arabic requires) */
7645 if (!p_arshape)
7646 {
7647 p_arshape = TRUE;
7648 redraw_later_clear();
7649 }
7650 }
7651
7652 /* Arabic requires a utf-8 encoding, inform the user if its not
7653 * set. */
7654 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007655 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007656 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7657
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007658 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007659 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7660#ifdef FEAT_EVAL
7661 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7662#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664
7665# ifdef FEAT_MBYTE
7666 /* set 'delcombine' */
7667 p_deco = TRUE;
7668# endif
7669
7670# ifdef FEAT_KEYMAP
7671 /* Force-set the necessary keymap for arabic */
7672 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7673 OPT_LOCAL);
7674# endif
7675# ifdef FEAT_FKMAP
7676 p_altkeymap = 0;
7677 p_hkmap = 0;
7678 p_fkmap = 0;
7679 (void)init_chartab();
7680# endif
7681 }
7682 else
7683 {
7684 /*
7685 * 'arabic' is reset, handle various sub-settings.
7686 */
7687 if (!p_tbidi)
7688 {
7689 /* reset rightleft mode */
7690 if (curwin->w_p_rl)
7691 {
7692 curwin->w_p_rl = FALSE;
7693 changed_window_setting();
7694 }
7695
7696 /* 'arabicshape' isn't reset, it is a global option and
7697 * another window may still need it "on". */
7698 }
7699
7700 /* 'delcombine' isn't reset, it is a global option and another
7701 * window may still want it "on". */
7702
7703# ifdef FEAT_KEYMAP
7704 /* Revert to the default keymap */
7705 curbuf->b_p_iminsert = B_IMODE_NONE;
7706 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7707# endif
7708 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007709 if (curwin->w_curswant != MAXCOL)
7710 curwin->w_set_curswant = TRUE;
7711 }
7712
7713 else if ((int *)varp == &p_arshape)
7714 {
7715 if (curwin->w_curswant != MAXCOL)
7716 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717 }
7718#endif
7719
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007720#ifdef FEAT_LINEBREAK
7721 if ((int *)varp == &curwin->w_p_lbr)
7722 {
7723 if (curwin->w_curswant != MAXCOL)
7724 curwin->w_set_curswant = TRUE;
7725 }
7726#endif
7727
7728#ifdef FEAT_RIGHTLEFT
7729 if ((int *)varp == &curwin->w_p_rl)
7730 {
7731 if (curwin->w_curswant != MAXCOL)
7732 curwin->w_set_curswant = TRUE;
7733 }
7734#endif
7735
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 /*
7737 * End of handling side effects for bool options.
7738 */
7739
7740 options[opt_idx].flags |= P_WAS_SET;
7741
7742 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007743
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 check_redraw(options[opt_idx].flags);
7745
7746 return NULL;
7747}
7748
7749/*
7750 * Set the value of a number option, and take care of side effects.
7751 * Returns NULL for success, or an error message for an error.
7752 */
7753 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007754set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 int opt_idx; /* index in options[] table */
7756 char_u *varp; /* pointer to the option variable */
7757 long value; /* new value */
7758 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007759 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7761 OPT_MODELINE */
7762{
7763 char_u *errmsg = NULL;
7764 long old_value = *(long *)varp;
7765 long old_Rows = Rows; /* remember old Rows */
7766 long old_Columns = Columns; /* remember old Columns */
7767 long *pp = (long *)varp;
7768
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007769 /* Disallow changing some options from secure mode. */
7770 if ((secure
7771#ifdef HAVE_SANDBOX
7772 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007774 ) && (options[opt_idx].flags & P_SECURE))
7775 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776
7777 *pp = value;
7778#ifdef FEAT_EVAL
7779 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007780 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007782#ifdef FEAT_GUI
7783 need_mouse_correct = TRUE;
7784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785
7786 if (curbuf->b_p_sw <= 0)
7787 {
7788 errmsg = e_positive;
7789 curbuf->b_p_sw = curbuf->b_p_ts;
7790 }
7791
7792 /*
7793 * Number options that need some action when changed
7794 */
7795#ifdef FEAT_WINDOWS
7796 if (pp == &p_wh || pp == &p_hh)
7797 {
7798 if (p_wh < 1)
7799 {
7800 errmsg = e_positive;
7801 p_wh = 1;
7802 }
7803 if (p_wmh > p_wh)
7804 {
7805 errmsg = e_winheight;
7806 p_wh = p_wmh;
7807 }
7808 if (p_hh < 0)
7809 {
7810 errmsg = e_positive;
7811 p_hh = 0;
7812 }
7813
7814 /* Change window height NOW */
7815 if (lastwin != firstwin)
7816 {
7817 if (pp == &p_wh && curwin->w_height < p_wh)
7818 win_setheight((int)p_wh);
7819 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7820 win_setheight((int)p_hh);
7821 }
7822 }
7823
7824 /* 'winminheight' */
7825 else if (pp == &p_wmh)
7826 {
7827 if (p_wmh < 0)
7828 {
7829 errmsg = e_positive;
7830 p_wmh = 0;
7831 }
7832 if (p_wmh > p_wh)
7833 {
7834 errmsg = e_winheight;
7835 p_wmh = p_wh;
7836 }
7837 win_setminheight();
7838 }
7839
7840# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007841 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842 {
7843 if (p_wiw < 1)
7844 {
7845 errmsg = e_positive;
7846 p_wiw = 1;
7847 }
7848 if (p_wmw > p_wiw)
7849 {
7850 errmsg = e_winwidth;
7851 p_wiw = p_wmw;
7852 }
7853
7854 /* Change window width NOW */
7855 if (lastwin != firstwin && curwin->w_width < p_wiw)
7856 win_setwidth((int)p_wiw);
7857 }
7858
7859 /* 'winminwidth' */
7860 else if (pp == &p_wmw)
7861 {
7862 if (p_wmw < 0)
7863 {
7864 errmsg = e_positive;
7865 p_wmw = 0;
7866 }
7867 if (p_wmw > p_wiw)
7868 {
7869 errmsg = e_winwidth;
7870 p_wmw = p_wiw;
7871 }
7872 win_setminheight();
7873 }
7874# endif
7875
7876#endif
7877
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007878 else if (pp == &curbuf->b_p_cm)
7879 {
7880 if (curbuf->b_p_cm < 0)
7881 {
7882 errmsg = e_positive;
7883 curbuf->b_p_cm = 0;
7884 }
7885 if (curbuf->b_p_cm > 1)
7886 {
7887 errmsg = e_invarg;
7888 curbuf->b_p_cm = 1;
7889 }
7890 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
7891 curbuf->b_p_cm = 0;
7892 }
7893
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894#ifdef FEAT_WINDOWS
7895 /* (re)set last window status line */
7896 else if (pp == &p_ls)
7897 {
7898 last_status(FALSE);
7899 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007900
7901 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007902 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007903 {
7904 shell_new_rows(); /* recompute window positions and heights */
7905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906#endif
7907
7908#ifdef FEAT_GUI
7909 else if (pp == &p_linespace)
7910 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007911 /* Recompute gui.char_height and resize the Vim window to keep the
7912 * same number of lines. */
7913 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007914 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 }
7916#endif
7917
7918#ifdef FEAT_FOLDING
7919 /* 'foldlevel' */
7920 else if (pp == &curwin->w_p_fdl)
7921 {
7922 if (curwin->w_p_fdl < 0)
7923 curwin->w_p_fdl = 0;
7924 newFoldLevel();
7925 }
7926
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007927 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 else if (pp == &curwin->w_p_fml)
7929 {
7930 foldUpdateAll(curwin);
7931 }
7932
7933 /* 'foldnestmax' */
7934 else if (pp == &curwin->w_p_fdn)
7935 {
7936 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7937 foldUpdateAll(curwin);
7938 }
7939
7940 /* 'foldcolumn' */
7941 else if (pp == &curwin->w_p_fdc)
7942 {
7943 if (curwin->w_p_fdc < 0)
7944 {
7945 errmsg = e_positive;
7946 curwin->w_p_fdc = 0;
7947 }
7948 else if (curwin->w_p_fdc > 12)
7949 {
7950 errmsg = e_invarg;
7951 curwin->w_p_fdc = 12;
7952 }
7953 }
7954
7955 /* 'shiftwidth' or 'tabstop' */
7956 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7957 {
7958 if (foldmethodIsIndent(curwin))
7959 foldUpdateAll(curwin);
7960 }
7961#endif /* FEAT_FOLDING */
7962
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007963#ifdef FEAT_MBYTE
7964 /* 'maxcombine' */
7965 else if (pp == &p_mco)
7966 {
7967 if (p_mco > MAX_MCO)
7968 p_mco = MAX_MCO;
7969 else if (p_mco < 0)
7970 p_mco = 0;
7971 screenclear(); /* will re-allocate the screen */
7972 }
7973#endif
7974
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 else if (pp == &curbuf->b_p_iminsert)
7976 {
7977 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7978 {
7979 errmsg = e_invarg;
7980 curbuf->b_p_iminsert = B_IMODE_NONE;
7981 }
7982 p_iminsert = curbuf->b_p_iminsert;
7983 if (termcap_active) /* don't do this in the alternate screen */
7984 showmode();
7985#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7986 /* Show/unshow value of 'keymap' in status lines. */
7987 status_redraw_curbuf();
7988#endif
7989 }
7990
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007991 else if (pp == &p_window)
7992 {
7993 if (p_window < 1)
7994 p_window = 1;
7995 else if (p_window >= Rows)
7996 p_window = Rows - 1;
7997 }
7998
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 else if (pp == &curbuf->b_p_imsearch)
8000 {
8001 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8002 {
8003 errmsg = e_invarg;
8004 curbuf->b_p_imsearch = B_IMODE_NONE;
8005 }
8006 p_imsearch = curbuf->b_p_imsearch;
8007 }
8008
8009#ifdef FEAT_TITLE
8010 /* if 'titlelen' has changed, redraw the title */
8011 else if (pp == &p_titlelen)
8012 {
8013 if (p_titlelen < 0)
8014 {
8015 errmsg = e_positive;
8016 p_titlelen = 85;
8017 }
8018 if (starting != NO_SCREEN && old_value != p_titlelen)
8019 need_maketitle = TRUE;
8020 }
8021#endif
8022
8023 /* if p_ch changed value, change the command line height */
8024 else if (pp == &p_ch)
8025 {
8026 if (p_ch < 1)
8027 {
8028 errmsg = e_positive;
8029 p_ch = 1;
8030 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008031 if (p_ch > Rows - min_rows() + 1)
8032 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033
8034 /* Only compute the new window layout when startup has been
8035 * completed. Otherwise the frame sizes may be wrong. */
8036 if (p_ch != old_value && full_screen
8037#ifdef FEAT_GUI
8038 && !gui.starting
8039#endif
8040 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008041 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 }
8043
8044 /* when 'updatecount' changes from zero to non-zero, open swap files */
8045 else if (pp == &p_uc)
8046 {
8047 if (p_uc < 0)
8048 {
8049 errmsg = e_positive;
8050 p_uc = 100;
8051 }
8052 if (p_uc && !old_value)
8053 ml_open_files();
8054 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008055#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008056 else if (pp == &p_mzq)
8057 mzvim_reset_timer();
8058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059
8060 /* sync undo before 'undolevels' changes */
8061 else if (pp == &p_ul)
8062 {
8063 /* use the old value, otherwise u_sync() may not work properly */
8064 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008065 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 p_ul = value;
8067 }
8068
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008069#ifdef FEAT_LINEBREAK
8070 /* 'numberwidth' must be positive */
8071 else if (pp == &curwin->w_p_nuw)
8072 {
8073 if (curwin->w_p_nuw < 1)
8074 {
8075 errmsg = e_positive;
8076 curwin->w_p_nuw = 1;
8077 }
8078 if (curwin->w_p_nuw > 10)
8079 {
8080 errmsg = e_invarg;
8081 curwin->w_p_nuw = 10;
8082 }
8083 curwin->w_nrwidth_line_count = 0;
8084 }
8085#endif
8086
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 /*
8088 * Check the bounds for numeric options here
8089 */
8090 if (Rows < min_rows() && full_screen)
8091 {
8092 if (errbuf != NULL)
8093 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008094 vim_snprintf((char *)errbuf, errbuflen,
8095 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096 errmsg = errbuf;
8097 }
8098 Rows = min_rows();
8099 }
8100 if (Columns < MIN_COLUMNS && full_screen)
8101 {
8102 if (errbuf != NULL)
8103 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008104 vim_snprintf((char *)errbuf, errbuflen,
8105 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 errmsg = errbuf;
8107 }
8108 Columns = MIN_COLUMNS;
8109 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008110 /* Limit the values to avoid an overflow in Rows * Columns. */
8111 if (Columns > 10000)
8112 Columns = 10000;
8113 if (Rows > 1000)
8114 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115
8116#ifdef DJGPP
8117 /* avoid a crash by checking for a too large value of 'columns' */
8118 if (old_Columns != Columns && full_screen && term_console)
8119 mch_check_columns();
8120#endif
8121
8122 /*
8123 * If the screen (shell) height has been changed, assume it is the
8124 * physical screenheight.
8125 */
8126 if (old_Rows != Rows || old_Columns != Columns)
8127 {
8128 /* Changing the screen size is not allowed while updating the screen. */
8129 if (updating_screen)
8130 *pp = old_value;
8131 else if (full_screen
8132#ifdef FEAT_GUI
8133 && !gui.starting
8134#endif
8135 )
8136 set_shellsize((int)Columns, (int)Rows, TRUE);
8137 else
8138 {
8139 /* Postpone the resizing; check the size and cmdline position for
8140 * messages. */
8141 check_shellsize();
8142 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8143 cmdline_row = Rows - p_ch;
8144 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008145 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008146 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 }
8148
8149 if (curbuf->b_p_sts < 0)
8150 {
8151 errmsg = e_positive;
8152 curbuf->b_p_sts = 0;
8153 }
8154 if (curbuf->b_p_ts <= 0)
8155 {
8156 errmsg = e_positive;
8157 curbuf->b_p_ts = 8;
8158 }
8159 if (curbuf->b_p_tw < 0)
8160 {
8161 errmsg = e_positive;
8162 curbuf->b_p_tw = 0;
8163 }
8164 if (p_tm < 0)
8165 {
8166 errmsg = e_positive;
8167 p_tm = 0;
8168 }
8169 if ((curwin->w_p_scr <= 0
8170 || (curwin->w_p_scr > curwin->w_height
8171 && curwin->w_height > 0))
8172 && full_screen)
8173 {
8174 if (pp == &(curwin->w_p_scr))
8175 {
8176 if (curwin->w_p_scr != 0)
8177 errmsg = e_scroll;
8178 win_comp_scroll(curwin);
8179 }
8180 /* If 'scroll' became invalid because of a side effect silently adjust
8181 * it. */
8182 else if (curwin->w_p_scr <= 0)
8183 curwin->w_p_scr = 1;
8184 else /* curwin->w_p_scr > curwin->w_height */
8185 curwin->w_p_scr = curwin->w_height;
8186 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008187 if (p_hi < 0)
8188 {
8189 errmsg = e_positive;
8190 p_hi = 0;
8191 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 if (p_report < 0)
8193 {
8194 errmsg = e_positive;
8195 p_report = 1;
8196 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008197 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 {
8199 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8200 p_sj = Rows / 2;
8201 else
8202 {
8203 errmsg = e_scroll;
8204 p_sj = 1;
8205 }
8206 }
8207 if (p_so < 0 && full_screen)
8208 {
8209 errmsg = e_scroll;
8210 p_so = 0;
8211 }
8212 if (p_siso < 0 && full_screen)
8213 {
8214 errmsg = e_positive;
8215 p_siso = 0;
8216 }
8217#ifdef FEAT_CMDWIN
8218 if (p_cwh < 1)
8219 {
8220 errmsg = e_positive;
8221 p_cwh = 1;
8222 }
8223#endif
8224 if (p_ut < 0)
8225 {
8226 errmsg = e_positive;
8227 p_ut = 2000;
8228 }
8229 if (p_ss < 0)
8230 {
8231 errmsg = e_positive;
8232 p_ss = 0;
8233 }
8234
8235 /* May set global value for local option. */
8236 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8237 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8238
8239 options[opt_idx].flags |= P_WAS_SET;
8240
8241 comp_col(); /* in case 'columns' or 'ls' changed */
8242 if (curwin->w_curswant != MAXCOL)
8243 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8244 check_redraw(options[opt_idx].flags);
8245
8246 return errmsg;
8247}
8248
8249/*
8250 * Called after an option changed: check if something needs to be redrawn.
8251 */
8252 static void
8253check_redraw(flags)
8254 long_u flags;
8255{
8256 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8257 int clear = (flags & P_RCLR) == P_RCLR;
8258 int all = ((flags & P_RALL) == P_RALL || clear);
8259
8260#ifdef FEAT_WINDOWS
8261 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8262 status_redraw_all();
8263#endif
8264
8265 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8266 changed_window_setting();
8267 if (flags & P_RBUF)
8268 redraw_curbuf_later(NOT_VALID);
8269 if (clear)
8270 redraw_all_later(CLEAR);
8271 else if (all)
8272 redraw_all_later(NOT_VALID);
8273}
8274
8275/*
8276 * Find index for option 'arg'.
8277 * Return -1 if not found.
8278 */
8279 static int
8280findoption(arg)
8281 char_u *arg;
8282{
8283 int opt_idx;
8284 char *s, *p;
8285 static short quick_tab[27] = {0, 0}; /* quick access table */
8286 int is_term_opt;
8287
8288 /*
8289 * For first call: Initialize the quick-access table.
8290 * It contains the index for the first option that starts with a certain
8291 * letter. There are 26 letters, plus the first "t_" option.
8292 */
8293 if (quick_tab[1] == 0)
8294 {
8295 p = options[0].fullname;
8296 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8297 {
8298 if (s[0] != p[0])
8299 {
8300 if (s[0] == 't' && s[1] == '_')
8301 quick_tab[26] = opt_idx;
8302 else
8303 quick_tab[CharOrdLow(s[0])] = opt_idx;
8304 }
8305 p = s;
8306 }
8307 }
8308
8309 /*
8310 * Check for name starting with an illegal character.
8311 */
8312#ifdef EBCDIC
8313 if (!islower(arg[0]))
8314#else
8315 if (arg[0] < 'a' || arg[0] > 'z')
8316#endif
8317 return -1;
8318
8319 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8320 if (is_term_opt)
8321 opt_idx = quick_tab[26];
8322 else
8323 opt_idx = quick_tab[CharOrdLow(arg[0])];
8324 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8325 {
8326 if (STRCMP(arg, s) == 0) /* match full name */
8327 break;
8328 }
8329 if (s == NULL && !is_term_opt)
8330 {
8331 opt_idx = quick_tab[CharOrdLow(arg[0])];
8332 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8333 {
8334 s = options[opt_idx].shortname;
8335 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8336 break;
8337 s = NULL;
8338 }
8339 }
8340 if (s == NULL)
8341 opt_idx = -1;
8342 return opt_idx;
8343}
8344
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008345#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346/*
8347 * Get the value for an option.
8348 *
8349 * Returns:
8350 * Number or Toggle option: 1, *numval gets value.
8351 * String option: 0, *stringval gets allocated string.
8352 * Hidden Number or Toggle option: -1.
8353 * hidden String option: -2.
8354 * unknown option: -3.
8355 */
8356 int
8357get_option_value(name, numval, stringval, opt_flags)
8358 char_u *name;
8359 long *numval;
8360 char_u **stringval; /* NULL when only checking existance */
8361 int opt_flags;
8362{
8363 int opt_idx;
8364 char_u *varp;
8365
8366 opt_idx = findoption(name);
8367 if (opt_idx < 0) /* unknown option */
8368 return -3;
8369
8370 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8371
8372 if (options[opt_idx].flags & P_STRING)
8373 {
8374 if (varp == NULL) /* hidden option */
8375 return -2;
8376 if (stringval != NULL)
8377 {
8378#ifdef FEAT_CRYPT
8379 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008380 if ((char_u **)varp == &curbuf->b_p_key
8381 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 *stringval = vim_strsave((char_u *)"*****");
8383 else
8384#endif
8385 *stringval = vim_strsave(*(char_u **)(varp));
8386 }
8387 return 0;
8388 }
8389
8390 if (varp == NULL) /* hidden option */
8391 return -1;
8392 if (options[opt_idx].flags & P_NUM)
8393 *numval = *(long *)varp;
8394 else
8395 {
8396 /* Special case: 'modified' is b_changed, but we also want to consider
8397 * it set when 'ff' or 'fenc' changed. */
8398 if ((int *)varp == &curbuf->b_changed)
8399 *numval = curbufIsChanged();
8400 else
8401 *numval = *(int *)varp;
8402 }
8403 return 1;
8404}
8405#endif
8406
8407/*
8408 * Set the value of option "name".
8409 * Use "string" for string options, use "number" for other options.
8410 */
8411 void
8412set_option_value(name, number, string, opt_flags)
8413 char_u *name;
8414 long number;
8415 char_u *string;
8416 int opt_flags; /* OPT_LOCAL or 0 (both) */
8417{
8418 int opt_idx;
8419 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008420 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421
8422 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008423 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 EMSG2(_("E355: Unknown option: %s"), name);
8425 else
8426 {
8427 flags = options[opt_idx].flags;
8428#ifdef HAVE_SANDBOX
8429 /* Disallow changing some options in the sandbox */
8430 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008431 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008433 return;
8434 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008436 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 set_string_option(opt_idx, string, opt_flags);
8438 else
8439 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008440 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 if (varp != NULL) /* hidden option is not changed */
8442 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008443 if (number == 0 && string != NULL)
8444 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008445 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008446
8447 /* Either we are given a string or we are setting option
8448 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008449 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008450 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008451 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008452 {
8453 /* There's another character after zeros or the string
8454 * is empty. In both cases, we are trying to set a
8455 * num option using a string. */
8456 EMSG3(_("E521: Number required: &%s = '%s'"),
8457 name, string);
8458 return; /* do nothing as we hit an error */
8459
8460 }
8461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008463 (void)set_num_option(opt_idx, varp, number,
8464 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008466 (void)set_bool_option(opt_idx, varp, (int)number,
8467 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 }
8469 }
8470 }
8471}
8472
8473/*
8474 * Get the terminal code for a terminal option.
8475 * Returns NULL when not found.
8476 */
8477 char_u *
8478get_term_code(tname)
8479 char_u *tname;
8480{
8481 int opt_idx;
8482 char_u *varp;
8483
8484 if (tname[0] != 't' || tname[1] != '_' ||
8485 tname[2] == NUL || tname[3] == NUL)
8486 return NULL;
8487 if ((opt_idx = findoption(tname)) >= 0)
8488 {
8489 varp = get_varp(&(options[opt_idx]));
8490 if (varp != NULL)
8491 varp = *(char_u **)(varp);
8492 return varp;
8493 }
8494 return find_termcode(tname + 2);
8495}
8496
8497 char_u *
8498get_highlight_default()
8499{
8500 int i;
8501
8502 i = findoption((char_u *)"hl");
8503 if (i >= 0)
8504 return options[i].def_val[VI_DEFAULT];
8505 return (char_u *)NULL;
8506}
8507
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008508#if defined(FEAT_MBYTE) || defined(PROTO)
8509 char_u *
8510get_encoding_default()
8511{
8512 int i;
8513
8514 i = findoption((char_u *)"enc");
8515 if (i >= 0)
8516 return options[i].def_val[VI_DEFAULT];
8517 return (char_u *)NULL;
8518}
8519#endif
8520
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521/*
8522 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8523 */
8524 static int
8525find_key_option(arg)
8526 char_u *arg;
8527{
8528 int key;
8529 int modifiers;
8530
8531 /*
8532 * Don't use get_special_key_code() for t_xx, we don't want it to call
8533 * add_termcap_entry().
8534 */
8535 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8536 key = TERMCAP2KEY(arg[2], arg[3]);
8537 else
8538 {
8539 --arg; /* put arg at the '<' */
8540 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008541 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542 if (modifiers) /* can't handle modifiers here */
8543 key = 0;
8544 }
8545 return key;
8546}
8547
8548/*
8549 * if 'all' == 0: show changed options
8550 * if 'all' == 1: show all normal options
8551 * if 'all' == 2: show all terminal options
8552 */
8553 static void
8554showoptions(all, opt_flags)
8555 int all;
8556 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8557{
8558 struct vimoption *p;
8559 int col;
8560 int isterm;
8561 char_u *varp;
8562 struct vimoption **items;
8563 int item_count;
8564 int run;
8565 int row, rows;
8566 int cols;
8567 int i;
8568 int len;
8569
8570#define INC 20
8571#define GAP 3
8572
8573 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8574 PARAM_COUNT));
8575 if (items == NULL)
8576 return;
8577
8578 /* Highlight title */
8579 if (all == 2)
8580 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8581 else if (opt_flags & OPT_GLOBAL)
8582 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8583 else if (opt_flags & OPT_LOCAL)
8584 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8585 else
8586 MSG_PUTS_TITLE(_("\n--- Options ---"));
8587
8588 /*
8589 * do the loop two times:
8590 * 1. display the short items
8591 * 2. display the long items (only strings and numbers)
8592 */
8593 for (run = 1; run <= 2 && !got_int; ++run)
8594 {
8595 /*
8596 * collect the items in items[]
8597 */
8598 item_count = 0;
8599 for (p = &options[0]; p->fullname != NULL; p++)
8600 {
8601 varp = NULL;
8602 isterm = istermoption(p);
8603 if (opt_flags != 0)
8604 {
8605 if (p->indir != PV_NONE && !isterm)
8606 varp = get_varp_scope(p, opt_flags);
8607 }
8608 else
8609 varp = get_varp(p);
8610 if (varp != NULL
8611 && ((all == 2 && isterm)
8612 || (all == 1 && !isterm)
8613 || (all == 0 && !optval_default(p, varp))))
8614 {
8615 if (p->flags & P_BOOL)
8616 len = 1; /* a toggle option fits always */
8617 else
8618 {
8619 option_value2string(p, opt_flags);
8620 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8621 }
8622 if ((len <= INC - GAP && run == 1) ||
8623 (len > INC - GAP && run == 2))
8624 items[item_count++] = p;
8625 }
8626 }
8627
8628 /*
8629 * display the items
8630 */
8631 if (run == 1)
8632 {
8633 cols = (Columns + GAP - 3) / INC;
8634 if (cols == 0)
8635 cols = 1;
8636 rows = (item_count + cols - 1) / cols;
8637 }
8638 else /* run == 2 */
8639 rows = item_count;
8640 for (row = 0; row < rows && !got_int; ++row)
8641 {
8642 msg_putchar('\n'); /* go to next line */
8643 if (got_int) /* 'q' typed in more */
8644 break;
8645 col = 0;
8646 for (i = row; i < item_count; i += rows)
8647 {
8648 msg_col = col; /* make columns */
8649 showoneopt(items[i], opt_flags);
8650 col += INC;
8651 }
8652 out_flush();
8653 ui_breakcheck();
8654 }
8655 }
8656 vim_free(items);
8657}
8658
8659/*
8660 * Return TRUE if option "p" has its default value.
8661 */
8662 static int
8663optval_default(p, varp)
8664 struct vimoption *p;
8665 char_u *varp;
8666{
8667 int dvi;
8668
8669 if (varp == NULL)
8670 return TRUE; /* hidden option is always at default */
8671 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8672 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008673 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008675 /* the cast to long is required for Manx C, long_i is
8676 * needed for MSVC */
8677 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 /* P_STRING */
8679 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8680}
8681
8682/*
8683 * showoneopt: show the value of one option
8684 * must not be called with a hidden option!
8685 */
8686 static void
8687showoneopt(p, opt_flags)
8688 struct vimoption *p;
8689 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8690{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008691 char_u *varp;
8692 int save_silent = silent_mode;
8693
8694 silent_mode = FALSE;
8695 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696
8697 varp = get_varp_scope(p, opt_flags);
8698
8699 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8700 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8701 ? !curbufIsChanged() : !*(int *)varp))
8702 MSG_PUTS("no");
8703 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8704 MSG_PUTS("--");
8705 else
8706 MSG_PUTS(" ");
8707 MSG_PUTS(p->fullname);
8708 if (!(p->flags & P_BOOL))
8709 {
8710 msg_putchar('=');
8711 /* put value string in NameBuff */
8712 option_value2string(p, opt_flags);
8713 msg_outtrans(NameBuff);
8714 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008715
8716 silent_mode = save_silent;
8717 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718}
8719
8720/*
8721 * Write modified options as ":set" commands to a file.
8722 *
8723 * There are three values for "opt_flags":
8724 * OPT_GLOBAL: Write global option values and fresh values of
8725 * buffer-local options (used for start of a session
8726 * file).
8727 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8728 * curwin (used for a vimrc file).
8729 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8730 * and local values for window-local options of
8731 * curwin. Local values are also written when at the
8732 * default value, because a modeline or autocommand
8733 * may have set them when doing ":edit file" and the
8734 * user has set them back at the default or fresh
8735 * value.
8736 * When "local_only" is TRUE, don't write fresh
8737 * values, only local values (for ":mkview").
8738 * (fresh value = value used for a new buffer or window for a local option).
8739 *
8740 * Return FAIL on error, OK otherwise.
8741 */
8742 int
8743makeset(fd, opt_flags, local_only)
8744 FILE *fd;
8745 int opt_flags;
8746 int local_only;
8747{
8748 struct vimoption *p;
8749 char_u *varp; /* currently used value */
8750 char_u *varp_fresh; /* local value */
8751 char_u *varp_local = NULL; /* fresh value */
8752 char *cmd;
8753 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008754 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755
8756 /*
8757 * The options that don't have a default (terminal name, columns, lines)
8758 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008759 * Do the loop over "options[]" twice: once for options with the
8760 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008762 for (pri = 1; pri >= 0; --pri)
8763 {
8764 for (p = &options[0]; !istermoption(p); p++)
8765 if (!(p->flags & P_NO_MKRC)
8766 && !istermoption(p)
8767 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008768 {
8769 /* skip global option when only doing locals */
8770 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8771 continue;
8772
8773 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8774 * file, they are always buffer-specific. */
8775 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8776 continue;
8777
8778 /* Global values are only written when not at the default value. */
8779 varp = get_varp_scope(p, opt_flags);
8780 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8781 continue;
8782
8783 round = 2;
8784 if (p->indir != PV_NONE)
8785 {
8786 if (p->var == VAR_WIN)
8787 {
8788 /* skip window-local option when only doing globals */
8789 if (!(opt_flags & OPT_LOCAL))
8790 continue;
8791 /* When fresh value of window-local option is not at the
8792 * default, need to write it too. */
8793 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8794 {
8795 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8796 if (!optval_default(p, varp_fresh))
8797 {
8798 round = 1;
8799 varp_local = varp;
8800 varp = varp_fresh;
8801 }
8802 }
8803 }
8804 }
8805
8806 /* Round 1: fresh value for window-local options.
8807 * Round 2: other values */
8808 for ( ; round <= 2; varp = varp_local, ++round)
8809 {
8810 if (round == 1 || (opt_flags & OPT_GLOBAL))
8811 cmd = "set";
8812 else
8813 cmd = "setlocal";
8814
8815 if (p->flags & P_BOOL)
8816 {
8817 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8818 return FAIL;
8819 }
8820 else if (p->flags & P_NUM)
8821 {
8822 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8823 return FAIL;
8824 }
8825 else /* P_STRING */
8826 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008827#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8828 int do_endif = FALSE;
8829
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 /* Don't set 'syntax' and 'filetype' again if the value is
8831 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008832 if (
8833# if defined(FEAT_SYN_HL)
8834 p->indir == PV_SYN
8835# if defined(FEAT_AUTOCMD)
8836 ||
8837# endif
8838# endif
8839# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008840 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008841# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008842 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 {
8844 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8845 *(char_u **)(varp)) < 0
8846 || put_eol(fd) < 0)
8847 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008848 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008849 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8852 (p->flags & P_EXPAND) != 0) == FAIL)
8853 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008854#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8855 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 {
8857 if (put_line(fd, "endif") == FAIL)
8858 return FAIL;
8859 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 }
8862 }
8863 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008864 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 return OK;
8866}
8867
8868#if defined(FEAT_FOLDING) || defined(PROTO)
8869/*
8870 * Generate set commands for the local fold options only. Used when
8871 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8872 */
8873 int
8874makefoldset(fd)
8875 FILE *fd;
8876{
8877 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8878# ifdef FEAT_EVAL
8879 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8880 == FAIL
8881# endif
8882 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8883 == FAIL
8884 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8885 == FAIL
8886 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8887 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8888 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8889 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8890 )
8891 return FAIL;
8892
8893 return OK;
8894}
8895#endif
8896
8897 static int
8898put_setstring(fd, cmd, name, valuep, expand)
8899 FILE *fd;
8900 char *cmd;
8901 char *name;
8902 char_u **valuep;
8903 int expand;
8904{
8905 char_u *s;
8906 char_u buf[MAXPATHL];
8907
8908 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8909 return FAIL;
8910 if (*valuep != NULL)
8911 {
8912 /* Output 'pastetoggle' as key names. For other
8913 * options some characters have to be escaped with
8914 * CTRL-V or backslash */
8915 if (valuep == &p_pt)
8916 {
8917 s = *valuep;
8918 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00008919 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 return FAIL;
8921 }
8922 else if (expand)
8923 {
8924 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8925 if (put_escstr(fd, buf, 2) == FAIL)
8926 return FAIL;
8927 }
8928 else if (put_escstr(fd, *valuep, 2) == FAIL)
8929 return FAIL;
8930 }
8931 if (put_eol(fd) < 0)
8932 return FAIL;
8933 return OK;
8934}
8935
8936 static int
8937put_setnum(fd, cmd, name, valuep)
8938 FILE *fd;
8939 char *cmd;
8940 char *name;
8941 long *valuep;
8942{
8943 long wc;
8944
8945 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8946 return FAIL;
8947 if (wc_use_keyname((char_u *)valuep, &wc))
8948 {
8949 /* print 'wildchar' and 'wildcharm' as a key name */
8950 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8951 return FAIL;
8952 }
8953 else if (fprintf(fd, "%ld", *valuep) < 0)
8954 return FAIL;
8955 if (put_eol(fd) < 0)
8956 return FAIL;
8957 return OK;
8958}
8959
8960 static int
8961put_setbool(fd, cmd, name, value)
8962 FILE *fd;
8963 char *cmd;
8964 char *name;
8965 int value;
8966{
Bram Moolenaar893de922007-10-02 18:40:57 +00008967 if (value < 0) /* global/local option using global value */
8968 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8970 || put_eol(fd) < 0)
8971 return FAIL;
8972 return OK;
8973}
8974
8975/*
8976 * Clear all the terminal options.
8977 * If the option has been allocated, free the memory.
8978 * Terminal options are never hidden or indirect.
8979 */
8980 void
8981clear_termoptions()
8982{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 /*
8984 * Reset a few things before clearing the old options. This may cause
8985 * outputting a few things that the terminal doesn't understand, but the
8986 * screen will be cleared later, so this is OK.
8987 */
8988#ifdef FEAT_MOUSE_TTY
8989 mch_setmouse(FALSE); /* switch mouse off */
8990#endif
8991#ifdef FEAT_TITLE
8992 mch_restore_title(3); /* restore window titles */
8993#endif
8994#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8995 /* When starting the GUI close the display opened for the clipboard.
8996 * After restoring the title, because that will need the display. */
8997 if (gui.starting)
8998 clear_xterm_clip();
8999#endif
9000#ifdef WIN3264
9001 /*
9002 * Check if this is allowed now.
9003 */
9004 if (can_end_termcap_mode(FALSE) == TRUE)
9005#endif
9006 stoptermcap(); /* stop termcap mode */
9007
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009008 free_termoptions();
9009}
9010
9011 void
9012free_termoptions()
9013{
9014 struct vimoption *p;
9015
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 for (p = &options[0]; p->fullname != NULL; p++)
9017 if (istermoption(p))
9018 {
9019 if (p->flags & P_ALLOCED)
9020 free_string_option(*(char_u **)(p->var));
9021 if (p->flags & P_DEF_ALLOCED)
9022 free_string_option(p->def_val[VI_DEFAULT]);
9023 *(char_u **)(p->var) = empty_option;
9024 p->def_val[VI_DEFAULT] = empty_option;
9025 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9026 }
9027 clear_termcodes();
9028}
9029
9030/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009031 * Free the string for one term option, if it was allocated.
9032 * Set the string to empty_option and clear allocated flag.
9033 * "var" points to the option value.
9034 */
9035 void
9036free_one_termoption(var)
9037 char_u *var;
9038{
9039 struct vimoption *p;
9040
9041 for (p = &options[0]; p->fullname != NULL; p++)
9042 if (p->var == var)
9043 {
9044 if (p->flags & P_ALLOCED)
9045 free_string_option(*(char_u **)(p->var));
9046 *(char_u **)(p->var) = empty_option;
9047 p->flags &= ~P_ALLOCED;
9048 break;
9049 }
9050}
9051
9052/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053 * Set the terminal option defaults to the current value.
9054 * Used after setting the terminal name.
9055 */
9056 void
9057set_term_defaults()
9058{
9059 struct vimoption *p;
9060
9061 for (p = &options[0]; p->fullname != NULL; p++)
9062 {
9063 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9064 {
9065 if (p->flags & P_DEF_ALLOCED)
9066 {
9067 free_string_option(p->def_val[VI_DEFAULT]);
9068 p->flags &= ~P_DEF_ALLOCED;
9069 }
9070 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9071 if (p->flags & P_ALLOCED)
9072 {
9073 p->flags |= P_DEF_ALLOCED;
9074 p->flags &= ~P_ALLOCED; /* don't free the value now */
9075 }
9076 }
9077 }
9078}
9079
9080/*
9081 * return TRUE if 'p' starts with 't_'
9082 */
9083 static int
9084istermoption(p)
9085 struct vimoption *p;
9086{
9087 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9088}
9089
9090/*
9091 * Compute columns for ruler and shown command. 'sc_col' is also used to
9092 * decide what the maximum length of a message on the status line can be.
9093 * If there is a status line for the last window, 'sc_col' is independent
9094 * of 'ru_col'.
9095 */
9096
9097#define COL_RULER 17 /* columns needed by standard ruler */
9098
9099 void
9100comp_col()
9101{
9102#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9103 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9104
9105 sc_col = 0;
9106 ru_col = 0;
9107 if (p_ru)
9108 {
9109#ifdef FEAT_STL_OPT
9110 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9111#else
9112 ru_col = COL_RULER + 1;
9113#endif
9114 /* no last status line, adjust sc_col */
9115 if (!last_has_status)
9116 sc_col = ru_col;
9117 }
9118 if (p_sc)
9119 {
9120 sc_col += SHOWCMD_COLS;
9121 if (!p_ru || last_has_status) /* no need for separating space */
9122 ++sc_col;
9123 }
9124 sc_col = Columns - sc_col;
9125 ru_col = Columns - ru_col;
9126 if (sc_col <= 0) /* screen too narrow, will become a mess */
9127 sc_col = 1;
9128 if (ru_col <= 0)
9129 ru_col = 1;
9130#else
9131 sc_col = Columns;
9132 ru_col = Columns;
9133#endif
9134}
9135
9136/*
9137 * Get pointer to option variable, depending on local or global scope.
9138 */
9139 static char_u *
9140get_varp_scope(p, opt_flags)
9141 struct vimoption *p;
9142 int opt_flags;
9143{
9144 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9145 {
9146 if (p->var == VAR_WIN)
9147 return (char_u *)GLOBAL_WO(get_varp(p));
9148 return p->var;
9149 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009150 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 {
9152 switch ((int)p->indir)
9153 {
9154#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009155 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9156 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9157 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009159 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9160 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9161 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009162 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009163 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009165 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9166 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167#endif
9168#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009169 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9170 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009171#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009172#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9173 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9174#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009175#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009176 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178 }
9179 return NULL; /* "cannot happen" */
9180 }
9181 return get_varp(p);
9182}
9183
9184/*
9185 * Get pointer to option variable.
9186 */
9187 static char_u *
9188get_varp(p)
9189 struct vimoption *p;
9190{
9191 /* hidden option, always return NULL */
9192 if (p->var == NULL)
9193 return NULL;
9194
9195 switch ((int)p->indir)
9196 {
9197 case PV_NONE: return p->var;
9198
9199 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009200 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009202 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009204 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009206 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009207 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009208 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009209 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9210#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009211 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009212 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009213 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9215#endif
9216#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009217 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009219 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9221#endif
9222#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009223 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009225 case PV_GP: return *curbuf->b_p_gp != NUL
9226 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9227 case PV_MP: return *curbuf->b_p_mp != NUL
9228 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009230#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9231 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9232 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9233#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009234#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009235 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009236 ? (char_u *)&(curwin->w_p_stl) : p->var;
9237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009238
9239#ifdef FEAT_ARABIC
9240 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9241#endif
9242 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009243#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009244 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9245#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009246#ifdef FEAT_SYN_HL
9247 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9248 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250#ifdef FEAT_DIFF
9251 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9252#endif
9253#ifdef FEAT_FOLDING
9254 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9255 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9256 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9257 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9258 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9259 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9260 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9261# ifdef FEAT_EVAL
9262 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9263 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9264# endif
9265 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9266#endif
9267 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009268 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009269#ifdef FEAT_LINEBREAK
9270 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009272#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9274#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009275#ifdef FEAT_VERTSPLIT
9276 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9279 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9280#endif
9281#ifdef FEAT_RIGHTLEFT
9282 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9283 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9284#endif
9285 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9286 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9287#ifdef FEAT_LINEBREAK
9288 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9289#endif
9290#ifdef FEAT_SCROLLBIND
9291 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9292#endif
9293
9294 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9295 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9296#ifdef FEAT_MBYTE
9297 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9298#endif
9299#if defined(FEAT_QUICKFIX)
9300 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9301 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9302#endif
9303 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9304 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9305#ifdef FEAT_CINDENT
9306 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9307 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9308 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9309#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009310 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9312 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9313#endif
9314#ifdef FEAT_COMMENTS
9315 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9316#endif
9317#ifdef FEAT_FOLDING
9318 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9319#endif
9320#ifdef FEAT_INS_EXPAND
9321 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9322#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009323#ifdef FEAT_COMPL_FUNC
9324 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009325 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9328 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9329#ifdef FEAT_MBYTE
9330 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9331#endif
9332 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9333#ifdef FEAT_AUTOCMD
9334 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9335#endif
9336 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009337 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9339 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9340 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9341 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9342#ifdef FEAT_FIND_ID
9343# ifdef FEAT_EVAL
9344 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9345# endif
9346#endif
9347#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9348 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9349 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9350#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009351#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009352 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354#ifdef FEAT_CRYPT
9355 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9356#endif
9357#ifdef FEAT_LISP
9358 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9359#endif
9360 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9361 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9362 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9363 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9364 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9365#ifdef FEAT_OSFILETYPE
9366 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9367#endif
9368 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009369#ifdef FEAT_TEXTOBJ
9370 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9373#ifdef FEAT_SMARTINDENT
9374 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9375#endif
9376#ifndef SHORT_FNAME
9377 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9378#endif
9379 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9380#ifdef FEAT_SEARCHPATH
9381 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9382#endif
9383 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9384#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009385 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009386 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9387#endif
9388#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009389 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009390 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009391 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392#endif
9393 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9394 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9395 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9396 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9397 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9398#ifdef FEAT_KEYMAP
9399 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9400#endif
9401 default: EMSG(_("E356: get_varp ERROR"));
9402 }
9403 /* always return a valid pointer to avoid a crash! */
9404 return (char_u *)&(curbuf->b_p_wm);
9405}
9406
9407/*
9408 * Get the value of 'equalprg', either the buffer-local one or the global one.
9409 */
9410 char_u *
9411get_equalprg()
9412{
9413 if (*curbuf->b_p_ep == NUL)
9414 return p_ep;
9415 return curbuf->b_p_ep;
9416}
9417
9418#if defined(FEAT_WINDOWS) || defined(PROTO)
9419/*
9420 * Copy options from one window to another.
9421 * Used when splitting a window.
9422 */
9423 void
9424win_copy_options(wp_from, wp_to)
9425 win_T *wp_from;
9426 win_T *wp_to;
9427{
9428 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9429 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9430# ifdef FEAT_RIGHTLEFT
9431# ifdef FEAT_FKMAP
9432 /* Is this right? */
9433 wp_to->w_farsi = wp_from->w_farsi;
9434# endif
9435# endif
9436}
9437#endif
9438
9439/*
9440 * Copy the options from one winopt_T to another.
9441 * Doesn't free the old option values in "to", use clear_winopt() for that.
9442 * The 'scroll' option is not copied, because it depends on the window height.
9443 * The 'previewwindow' option is reset, there can be only one preview window.
9444 */
9445 void
9446copy_winopt(from, to)
9447 winopt_T *from;
9448 winopt_T *to;
9449{
9450#ifdef FEAT_ARABIC
9451 to->wo_arab = from->wo_arab;
9452#endif
9453 to->wo_list = from->wo_list;
9454 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009455 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009456#ifdef FEAT_LINEBREAK
9457 to->wo_nuw = from->wo_nuw;
9458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459#ifdef FEAT_RIGHTLEFT
9460 to->wo_rl = from->wo_rl;
9461 to->wo_rlc = vim_strsave(from->wo_rlc);
9462#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009463#ifdef FEAT_STL_OPT
9464 to->wo_stl = vim_strsave(from->wo_stl);
9465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466 to->wo_wrap = from->wo_wrap;
9467#ifdef FEAT_LINEBREAK
9468 to->wo_lbr = from->wo_lbr;
9469#endif
9470#ifdef FEAT_SCROLLBIND
9471 to->wo_scb = from->wo_scb;
9472#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009473#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009474 to->wo_spell = from->wo_spell;
9475#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009476#ifdef FEAT_SYN_HL
9477 to->wo_cuc = from->wo_cuc;
9478 to->wo_cul = from->wo_cul;
9479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480#ifdef FEAT_DIFF
9481 to->wo_diff = from->wo_diff;
9482#endif
9483#ifdef FEAT_FOLDING
9484 to->wo_fdc = from->wo_fdc;
9485 to->wo_fen = from->wo_fen;
9486 to->wo_fdi = vim_strsave(from->wo_fdi);
9487 to->wo_fml = from->wo_fml;
9488 to->wo_fdl = from->wo_fdl;
9489 to->wo_fdm = vim_strsave(from->wo_fdm);
9490 to->wo_fdn = from->wo_fdn;
9491# ifdef FEAT_EVAL
9492 to->wo_fde = vim_strsave(from->wo_fde);
9493 to->wo_fdt = vim_strsave(from->wo_fdt);
9494# endif
9495 to->wo_fmr = vim_strsave(from->wo_fmr);
9496#endif
9497 check_winopt(to); /* don't want NULL pointers */
9498}
9499
9500/*
9501 * Check string options in a window for a NULL value.
9502 */
9503 void
9504check_win_options(win)
9505 win_T *win;
9506{
9507 check_winopt(&win->w_onebuf_opt);
9508 check_winopt(&win->w_allbuf_opt);
9509}
9510
9511/*
9512 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9513 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514 void
9515check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009516 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009517{
9518#ifdef FEAT_FOLDING
9519 check_string_option(&wop->wo_fdi);
9520 check_string_option(&wop->wo_fdm);
9521# ifdef FEAT_EVAL
9522 check_string_option(&wop->wo_fde);
9523 check_string_option(&wop->wo_fdt);
9524# endif
9525 check_string_option(&wop->wo_fmr);
9526#endif
9527#ifdef FEAT_RIGHTLEFT
9528 check_string_option(&wop->wo_rlc);
9529#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009530#ifdef FEAT_STL_OPT
9531 check_string_option(&wop->wo_stl);
9532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533}
9534
9535/*
9536 * Free the allocated memory inside a winopt_T.
9537 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009538 void
9539clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009540 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541{
9542#ifdef FEAT_FOLDING
9543 clear_string_option(&wop->wo_fdi);
9544 clear_string_option(&wop->wo_fdm);
9545# ifdef FEAT_EVAL
9546 clear_string_option(&wop->wo_fde);
9547 clear_string_option(&wop->wo_fdt);
9548# endif
9549 clear_string_option(&wop->wo_fmr);
9550#endif
9551#ifdef FEAT_RIGHTLEFT
9552 clear_string_option(&wop->wo_rlc);
9553#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009554#ifdef FEAT_STL_OPT
9555 clear_string_option(&wop->wo_stl);
9556#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009557}
9558
9559/*
9560 * Copy global option values to local options for one buffer.
9561 * Used when creating a new buffer and sometimes when entering a buffer.
9562 * flags:
9563 * BCO_ENTER We will enter the buf buffer.
9564 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9565 * appropriate.
9566 * BCO_NOHELP Don't copy the values to a help buffer.
9567 */
9568 void
9569buf_copy_options(buf, flags)
9570 buf_T *buf;
9571 int flags;
9572{
9573 int should_copy = TRUE;
9574 char_u *save_p_isk = NULL; /* init for GCC */
9575 int dont_do_help;
9576 int did_isk = FALSE;
9577
9578 /*
9579 * Don't do anything of the buffer is invalid.
9580 */
9581 if (buf == NULL || !buf_valid(buf))
9582 return;
9583
9584 /*
9585 * Skip this when the option defaults have not been set yet. Happens when
9586 * main() allocates the first buffer.
9587 */
9588 if (p_cpo != NULL)
9589 {
9590 /*
9591 * Always copy when entering and 'cpo' contains 'S'.
9592 * Don't copy when already initialized.
9593 * Don't copy when 'cpo' contains 's' and not entering.
9594 * 'S' BCO_ENTER initialized 's' should_copy
9595 * yes yes X X TRUE
9596 * yes no yes X FALSE
9597 * no X yes X FALSE
9598 * X no no yes FALSE
9599 * X no no no TRUE
9600 * no yes no X TRUE
9601 */
9602 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9603 && (buf->b_p_initialized
9604 || (!(flags & BCO_ENTER)
9605 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9606 should_copy = FALSE;
9607
9608 if (should_copy || (flags & BCO_ALWAYS))
9609 {
9610 /* Don't copy the options specific to a help buffer when
9611 * BCO_NOHELP is given or the options were initialized already
9612 * (jumping back to a help file with CTRL-T or CTRL-O) */
9613 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9614 || buf->b_p_initialized;
9615 if (dont_do_help) /* don't free b_p_isk */
9616 {
9617 save_p_isk = buf->b_p_isk;
9618 buf->b_p_isk = NULL;
9619 }
9620 /*
9621 * Always free the allocated strings.
9622 * If not already initialized, set 'readonly' and copy 'fileformat'.
9623 */
9624 if (!buf->b_p_initialized)
9625 {
9626 free_buf_options(buf, TRUE);
9627 buf->b_p_ro = FALSE; /* don't copy readonly */
9628 buf->b_p_tx = p_tx;
9629#ifdef FEAT_MBYTE
9630 buf->b_p_fenc = vim_strsave(p_fenc);
9631#endif
9632 buf->b_p_ff = vim_strsave(p_ff);
9633#if defined(FEAT_QUICKFIX)
9634 buf->b_p_bh = empty_option;
9635 buf->b_p_bt = empty_option;
9636#endif
9637 }
9638 else
9639 free_buf_options(buf, FALSE);
9640
9641 buf->b_p_ai = p_ai;
9642 buf->b_p_ai_nopaste = p_ai_nopaste;
9643 buf->b_p_sw = p_sw;
9644 buf->b_p_tw = p_tw;
9645 buf->b_p_tw_nopaste = p_tw_nopaste;
9646 buf->b_p_tw_nobin = p_tw_nobin;
9647 buf->b_p_wm = p_wm;
9648 buf->b_p_wm_nopaste = p_wm_nopaste;
9649 buf->b_p_wm_nobin = p_wm_nobin;
9650 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009651#ifdef FEAT_MBYTE
9652 buf->b_p_bomb = p_bomb;
9653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 buf->b_p_et = p_et;
9655 buf->b_p_et_nobin = p_et_nobin;
9656 buf->b_p_ml = p_ml;
9657 buf->b_p_ml_nobin = p_ml_nobin;
9658 buf->b_p_inf = p_inf;
9659 buf->b_p_swf = p_swf;
9660#ifdef FEAT_INS_EXPAND
9661 buf->b_p_cpt = vim_strsave(p_cpt);
9662#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009663#ifdef FEAT_COMPL_FUNC
9664 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009665 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667 buf->b_p_sts = p_sts;
9668 buf->b_p_sts_nopaste = p_sts_nopaste;
9669#ifndef SHORT_FNAME
9670 buf->b_p_sn = p_sn;
9671#endif
9672#ifdef FEAT_COMMENTS
9673 buf->b_p_com = vim_strsave(p_com);
9674#endif
9675#ifdef FEAT_FOLDING
9676 buf->b_p_cms = vim_strsave(p_cms);
9677#endif
9678 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009679 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009680 buf->b_p_nf = vim_strsave(p_nf);
9681 buf->b_p_mps = vim_strsave(p_mps);
9682#ifdef FEAT_SMARTINDENT
9683 buf->b_p_si = p_si;
9684#endif
9685 buf->b_p_ci = p_ci;
9686#ifdef FEAT_CINDENT
9687 buf->b_p_cin = p_cin;
9688 buf->b_p_cink = vim_strsave(p_cink);
9689 buf->b_p_cino = vim_strsave(p_cino);
9690#endif
9691#ifdef FEAT_AUTOCMD
9692 /* Don't copy 'filetype', it must be detected */
9693 buf->b_p_ft = empty_option;
9694#endif
9695#ifdef FEAT_OSFILETYPE
9696 buf->b_p_oft = vim_strsave(p_oft);
9697#endif
9698 buf->b_p_pi = p_pi;
9699#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9700 buf->b_p_cinw = vim_strsave(p_cinw);
9701#endif
9702#ifdef FEAT_LISP
9703 buf->b_p_lisp = p_lisp;
9704#endif
9705#ifdef FEAT_SYN_HL
9706 /* Don't copy 'syntax', it must be set */
9707 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009708 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009709#endif
9710#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009711 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009712 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009713 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009714 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715#endif
9716#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9717 buf->b_p_inde = vim_strsave(p_inde);
9718 buf->b_p_indk = vim_strsave(p_indk);
9719#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009720#if defined(FEAT_EVAL)
9721 buf->b_p_fex = vim_strsave(p_fex);
9722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723#ifdef FEAT_CRYPT
9724 buf->b_p_key = vim_strsave(p_key);
9725#endif
9726#ifdef FEAT_SEARCHPATH
9727 buf->b_p_sua = vim_strsave(p_sua);
9728#endif
9729#ifdef FEAT_KEYMAP
9730 buf->b_p_keymap = vim_strsave(p_keymap);
9731 buf->b_kmap_state |= KEYMAP_INIT;
9732#endif
9733 /* This isn't really an option, but copying the langmap and IME
9734 * state from the current buffer is better than resetting it. */
9735 buf->b_p_iminsert = p_iminsert;
9736 buf->b_p_imsearch = p_imsearch;
9737
9738 /* options that are normally global but also have a local value
9739 * are not copied, start using the global value */
9740 buf->b_p_ar = -1;
9741#ifdef FEAT_QUICKFIX
9742 buf->b_p_gp = empty_option;
9743 buf->b_p_mp = empty_option;
9744 buf->b_p_efm = empty_option;
9745#endif
9746 buf->b_p_ep = empty_option;
9747 buf->b_p_kp = empty_option;
9748 buf->b_p_path = empty_option;
9749 buf->b_p_tags = empty_option;
9750#ifdef FEAT_FIND_ID
9751 buf->b_p_def = empty_option;
9752 buf->b_p_inc = empty_option;
9753# ifdef FEAT_EVAL
9754 buf->b_p_inex = vim_strsave(p_inex);
9755# endif
9756#endif
9757#ifdef FEAT_INS_EXPAND
9758 buf->b_p_dict = empty_option;
9759 buf->b_p_tsr = empty_option;
9760#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009761#ifdef FEAT_TEXTOBJ
9762 buf->b_p_qe = vim_strsave(p_qe);
9763#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009764#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9765 buf->b_p_bexpr = empty_option;
9766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767
9768 /*
9769 * Don't copy the options set by ex_help(), use the saved values,
9770 * when going from a help buffer to a non-help buffer.
9771 * Don't touch these at all when BCO_NOHELP is used and going from
9772 * or to a help buffer.
9773 */
9774 if (dont_do_help)
9775 buf->b_p_isk = save_p_isk;
9776 else
9777 {
9778 buf->b_p_isk = vim_strsave(p_isk);
9779 did_isk = TRUE;
9780 buf->b_p_ts = p_ts;
9781 buf->b_help = FALSE;
9782#ifdef FEAT_QUICKFIX
9783 if (buf->b_p_bt[0] == 'h')
9784 clear_string_option(&buf->b_p_bt);
9785#endif
9786 buf->b_p_ma = p_ma;
9787 }
9788 }
9789
9790 /*
9791 * When the options should be copied (ignoring BCO_ALWAYS), set the
9792 * flag that indicates that the options have been initialized.
9793 */
9794 if (should_copy)
9795 buf->b_p_initialized = TRUE;
9796 }
9797
9798 check_buf_options(buf); /* make sure we don't have NULLs */
9799 if (did_isk)
9800 (void)buf_init_chartab(buf, FALSE);
9801}
9802
9803/*
9804 * Reset the 'modifiable' option and its default value.
9805 */
9806 void
9807reset_modifiable()
9808{
9809 int opt_idx;
9810
9811 curbuf->b_p_ma = FALSE;
9812 p_ma = FALSE;
9813 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009814 if (opt_idx >= 0)
9815 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816}
9817
9818/*
9819 * Set the global value for 'iminsert' to the local value.
9820 */
9821 void
9822set_iminsert_global()
9823{
9824 p_iminsert = curbuf->b_p_iminsert;
9825}
9826
9827/*
9828 * Set the global value for 'imsearch' to the local value.
9829 */
9830 void
9831set_imsearch_global()
9832{
9833 p_imsearch = curbuf->b_p_imsearch;
9834}
9835
9836#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9837static int expand_option_idx = -1;
9838static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9839static int expand_option_flags = 0;
9840
9841 void
9842set_context_in_set_cmd(xp, arg, opt_flags)
9843 expand_T *xp;
9844 char_u *arg;
9845 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9846{
9847 int nextchar;
9848 long_u flags = 0; /* init for GCC */
9849 int opt_idx = 0; /* init for GCC */
9850 char_u *p;
9851 char_u *s;
9852 int is_term_option = FALSE;
9853 int key;
9854
9855 expand_option_flags = opt_flags;
9856
9857 xp->xp_context = EXPAND_SETTINGS;
9858 if (*arg == NUL)
9859 {
9860 xp->xp_pattern = arg;
9861 return;
9862 }
9863 p = arg + STRLEN(arg) - 1;
9864 if (*p == ' ' && *(p - 1) != '\\')
9865 {
9866 xp->xp_pattern = p + 1;
9867 return;
9868 }
9869 while (p > arg)
9870 {
9871 s = p;
9872 /* count number of backslashes before ' ' or ',' */
9873 if (*p == ' ' || *p == ',')
9874 {
9875 while (s > arg && *(s - 1) == '\\')
9876 --s;
9877 }
9878 /* break at a space with an even number of backslashes */
9879 if (*p == ' ' && ((p - s) & 1) == 0)
9880 {
9881 ++p;
9882 break;
9883 }
9884 --p;
9885 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00009886 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009887 {
9888 xp->xp_context = EXPAND_BOOL_SETTINGS;
9889 p += 2;
9890 }
9891 if (STRNCMP(p, "inv", 3) == 0)
9892 {
9893 xp->xp_context = EXPAND_BOOL_SETTINGS;
9894 p += 3;
9895 }
9896 xp->xp_pattern = arg = p;
9897 if (*arg == '<')
9898 {
9899 while (*p != '>')
9900 if (*p++ == NUL) /* expand terminal option name */
9901 return;
9902 key = get_special_key_code(arg + 1);
9903 if (key == 0) /* unknown name */
9904 {
9905 xp->xp_context = EXPAND_NOTHING;
9906 return;
9907 }
9908 nextchar = *++p;
9909 is_term_option = TRUE;
9910 expand_option_name[2] = KEY2TERMCAP0(key);
9911 expand_option_name[3] = KEY2TERMCAP1(key);
9912 }
9913 else
9914 {
9915 if (p[0] == 't' && p[1] == '_')
9916 {
9917 p += 2;
9918 if (*p != NUL)
9919 ++p;
9920 if (*p == NUL)
9921 return; /* expand option name */
9922 nextchar = *++p;
9923 is_term_option = TRUE;
9924 expand_option_name[2] = p[-2];
9925 expand_option_name[3] = p[-1];
9926 }
9927 else
9928 {
9929 /* Allow * wildcard */
9930 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9931 p++;
9932 if (*p == NUL)
9933 return;
9934 nextchar = *p;
9935 *p = NUL;
9936 opt_idx = findoption(arg);
9937 *p = nextchar;
9938 if (opt_idx == -1 || options[opt_idx].var == NULL)
9939 {
9940 xp->xp_context = EXPAND_NOTHING;
9941 return;
9942 }
9943 flags = options[opt_idx].flags;
9944 if (flags & P_BOOL)
9945 {
9946 xp->xp_context = EXPAND_NOTHING;
9947 return;
9948 }
9949 }
9950 }
9951 /* handle "-=" and "+=" */
9952 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9953 {
9954 ++p;
9955 nextchar = '=';
9956 }
9957 if ((nextchar != '=' && nextchar != ':')
9958 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9959 {
9960 xp->xp_context = EXPAND_UNSUCCESSFUL;
9961 return;
9962 }
9963 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9964 {
9965 xp->xp_context = EXPAND_OLD_SETTING;
9966 if (is_term_option)
9967 expand_option_idx = -1;
9968 else
9969 expand_option_idx = opt_idx;
9970 xp->xp_pattern = p + 1;
9971 return;
9972 }
9973 xp->xp_context = EXPAND_NOTHING;
9974 if (is_term_option || (flags & P_NUM))
9975 return;
9976
9977 xp->xp_pattern = p + 1;
9978
9979 if (flags & P_EXPAND)
9980 {
9981 p = options[opt_idx].var;
9982 if (p == (char_u *)&p_bdir
9983 || p == (char_u *)&p_dir
9984 || p == (char_u *)&p_path
9985 || p == (char_u *)&p_rtp
9986#ifdef FEAT_SEARCHPATH
9987 || p == (char_u *)&p_cdpath
9988#endif
9989#ifdef FEAT_SESSION
9990 || p == (char_u *)&p_vdir
9991#endif
9992 )
9993 {
9994 xp->xp_context = EXPAND_DIRECTORIES;
9995 if (p == (char_u *)&p_path
9996#ifdef FEAT_SEARCHPATH
9997 || p == (char_u *)&p_cdpath
9998#endif
9999 )
10000 xp->xp_backslash = XP_BS_THREE;
10001 else
10002 xp->xp_backslash = XP_BS_ONE;
10003 }
10004 else
10005 {
10006 xp->xp_context = EXPAND_FILES;
10007 /* for 'tags' need three backslashes for a space */
10008 if (p == (char_u *)&p_tags)
10009 xp->xp_backslash = XP_BS_THREE;
10010 else
10011 xp->xp_backslash = XP_BS_ONE;
10012 }
10013 }
10014
10015 /* For an option that is a list of file names, find the start of the
10016 * last file name. */
10017 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10018 {
10019 /* count number of backslashes before ' ' or ',' */
10020 if (*p == ' ' || *p == ',')
10021 {
10022 s = p;
10023 while (s > xp->xp_pattern && *(s - 1) == '\\')
10024 --s;
10025 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10026 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10027 {
10028 xp->xp_pattern = p + 1;
10029 break;
10030 }
10031 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010032
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010033#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010034 /* for 'spellsuggest' start at "file:" */
10035 if (options[opt_idx].var == (char_u *)&p_sps
10036 && STRNCMP(p, "file:", 5) == 0)
10037 {
10038 xp->xp_pattern = p + 5;
10039 break;
10040 }
10041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 }
10043
10044 return;
10045}
10046
10047 int
10048ExpandSettings(xp, regmatch, num_file, file)
10049 expand_T *xp;
10050 regmatch_T *regmatch;
10051 int *num_file;
10052 char_u ***file;
10053{
10054 int num_normal = 0; /* Nr of matching non-term-code settings */
10055 int num_term = 0; /* Nr of matching terminal code settings */
10056 int opt_idx;
10057 int match;
10058 int count = 0;
10059 char_u *str;
10060 int loop;
10061 int is_term_opt;
10062 char_u name_buf[MAX_KEY_NAME_LEN];
10063 static char *(names[]) = {"all", "termcap"};
10064 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10065
10066 /* do this loop twice:
10067 * loop == 0: count the number of matching options
10068 * loop == 1: copy the matching options into allocated memory
10069 */
10070 for (loop = 0; loop <= 1; ++loop)
10071 {
10072 regmatch->rm_ic = ic;
10073 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10074 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010075 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10076 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010077 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10078 {
10079 if (loop == 0)
10080 num_normal++;
10081 else
10082 (*file)[count++] = vim_strsave((char_u *)names[match]);
10083 }
10084 }
10085 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10086 opt_idx++)
10087 {
10088 if (options[opt_idx].var == NULL)
10089 continue;
10090 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10091 && !(options[opt_idx].flags & P_BOOL))
10092 continue;
10093 is_term_opt = istermoption(&options[opt_idx]);
10094 if (is_term_opt && num_normal > 0)
10095 continue;
10096 match = FALSE;
10097 if (vim_regexec(regmatch, str, (colnr_T)0)
10098 || (options[opt_idx].shortname != NULL
10099 && vim_regexec(regmatch,
10100 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10101 match = TRUE;
10102 else if (is_term_opt)
10103 {
10104 name_buf[0] = '<';
10105 name_buf[1] = 't';
10106 name_buf[2] = '_';
10107 name_buf[3] = str[2];
10108 name_buf[4] = str[3];
10109 name_buf[5] = '>';
10110 name_buf[6] = NUL;
10111 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10112 {
10113 match = TRUE;
10114 str = name_buf;
10115 }
10116 }
10117 if (match)
10118 {
10119 if (loop == 0)
10120 {
10121 if (is_term_opt)
10122 num_term++;
10123 else
10124 num_normal++;
10125 }
10126 else
10127 (*file)[count++] = vim_strsave(str);
10128 }
10129 }
10130 /*
10131 * Check terminal key codes, these are not in the option table
10132 */
10133 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10134 {
10135 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10136 {
10137 if (!isprint(str[0]) || !isprint(str[1]))
10138 continue;
10139
10140 name_buf[0] = 't';
10141 name_buf[1] = '_';
10142 name_buf[2] = str[0];
10143 name_buf[3] = str[1];
10144 name_buf[4] = NUL;
10145
10146 match = FALSE;
10147 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10148 match = TRUE;
10149 else
10150 {
10151 name_buf[0] = '<';
10152 name_buf[1] = 't';
10153 name_buf[2] = '_';
10154 name_buf[3] = str[0];
10155 name_buf[4] = str[1];
10156 name_buf[5] = '>';
10157 name_buf[6] = NUL;
10158
10159 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10160 match = TRUE;
10161 }
10162 if (match)
10163 {
10164 if (loop == 0)
10165 num_term++;
10166 else
10167 (*file)[count++] = vim_strsave(name_buf);
10168 }
10169 }
10170
10171 /*
10172 * Check special key names.
10173 */
10174 regmatch->rm_ic = TRUE; /* ignore case here */
10175 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10176 {
10177 name_buf[0] = '<';
10178 STRCPY(name_buf + 1, str);
10179 STRCAT(name_buf, ">");
10180
10181 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10182 {
10183 if (loop == 0)
10184 num_term++;
10185 else
10186 (*file)[count++] = vim_strsave(name_buf);
10187 }
10188 }
10189 }
10190 if (loop == 0)
10191 {
10192 if (num_normal > 0)
10193 *num_file = num_normal;
10194 else if (num_term > 0)
10195 *num_file = num_term;
10196 else
10197 return OK;
10198 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10199 if (*file == NULL)
10200 {
10201 *file = (char_u **)"";
10202 return FAIL;
10203 }
10204 }
10205 }
10206 return OK;
10207}
10208
10209 int
10210ExpandOldSetting(num_file, file)
10211 int *num_file;
10212 char_u ***file;
10213{
10214 char_u *var = NULL; /* init for GCC */
10215 char_u *buf;
10216
10217 *num_file = 0;
10218 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10219 if (*file == NULL)
10220 return FAIL;
10221
10222 /*
10223 * For a terminal key code expand_option_idx is < 0.
10224 */
10225 if (expand_option_idx < 0)
10226 {
10227 var = find_termcode(expand_option_name + 2);
10228 if (var == NULL)
10229 expand_option_idx = findoption(expand_option_name);
10230 }
10231
10232 if (expand_option_idx >= 0)
10233 {
10234 /* put string of option value in NameBuff */
10235 option_value2string(&options[expand_option_idx], expand_option_flags);
10236 var = NameBuff;
10237 }
10238 else if (var == NULL)
10239 var = (char_u *)"";
10240
10241 /* A backslash is required before some characters. This is the reverse of
10242 * what happens in do_set(). */
10243 buf = vim_strsave_escaped(var, escape_chars);
10244
10245 if (buf == NULL)
10246 {
10247 vim_free(*file);
10248 *file = NULL;
10249 return FAIL;
10250 }
10251
10252#ifdef BACKSLASH_IN_FILENAME
10253 /* For MS-Windows et al. we don't double backslashes at the start and
10254 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010255 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 if (var[0] == '\\' && var[1] == '\\'
10257 && expand_option_idx >= 0
10258 && (options[expand_option_idx].flags & P_EXPAND)
10259 && vim_isfilec(var[2])
10260 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010261 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262#endif
10263
10264 *file[0] = buf;
10265 *num_file = 1;
10266 return OK;
10267}
10268#endif
10269
10270/*
10271 * Get the value for the numeric or string option *opp in a nice format into
10272 * NameBuff[]. Must not be called with a hidden option!
10273 */
10274 static void
10275option_value2string(opp, opt_flags)
10276 struct vimoption *opp;
10277 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10278{
10279 char_u *varp;
10280
10281 varp = get_varp_scope(opp, opt_flags);
10282
10283 if (opp->flags & P_NUM)
10284 {
10285 long wc = 0;
10286
10287 if (wc_use_keyname(varp, &wc))
10288 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10289 else if (wc != 0)
10290 STRCPY(NameBuff, transchar((int)wc));
10291 else
10292 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10293 }
10294 else /* P_STRING */
10295 {
10296 varp = *(char_u **)(varp);
10297 if (varp == NULL) /* just in case */
10298 NameBuff[0] = NUL;
10299#ifdef FEAT_CRYPT
10300 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010301 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 STRCPY(NameBuff, "*****");
10303#endif
10304 else if (opp->flags & P_EXPAND)
10305 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10306 /* Translate 'pastetoggle' into special key names */
10307 else if ((char_u **)opp->var == &p_pt)
10308 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10309 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010310 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 }
10312}
10313
10314/*
10315 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10316 * printed as a keyname.
10317 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10318 */
10319 static int
10320wc_use_keyname(varp, wcp)
10321 char_u *varp;
10322 long *wcp;
10323{
10324 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10325 {
10326 *wcp = *(long *)varp;
10327 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10328 return TRUE;
10329 }
10330 return FALSE;
10331}
10332
10333#ifdef FEAT_LANGMAP
10334/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010335 * Any character has an equivalent 'langmap' character. This is used for
10336 * keyboards that have a special language mode that sends characters above
10337 * 128 (although other characters can be translated too). The "to" field is a
10338 * Vim command character. This avoids having to switch the keyboard back to
10339 * ASCII mode when leaving Insert mode.
10340 *
10341 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10342 * commands.
10343 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10344 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10345 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010347# ifdef FEAT_MBYTE
10348/*
10349 * With multi-byte support use growarray for 'langmap' chars >= 256
10350 */
10351typedef struct
10352{
10353 int from;
10354 int to;
10355} langmap_entry_T;
10356
10357static garray_T langmap_mapga;
10358static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359
10360/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010361 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10362 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010364 static void
10365langmap_set_entry(from, to)
10366 int from;
10367 int to;
10368{
10369 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10370 int a = 0;
10371 int b = langmap_mapga.ga_len;
10372
10373 /* Do a binary search for an existing entry. */
10374 while (a != b)
10375 {
10376 int i = (a + b) / 2;
10377 int d = entries[i].from - from;
10378
10379 if (d == 0)
10380 {
10381 entries[i].to = to;
10382 return;
10383 }
10384 if (d < 0)
10385 a = i + 1;
10386 else
10387 b = i;
10388 }
10389
10390 if (ga_grow(&langmap_mapga, 1) != OK)
10391 return; /* out of memory */
10392
10393 /* insert new entry at position "a" */
10394 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10395 mch_memmove(entries + 1, entries,
10396 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10397 ++langmap_mapga.ga_len;
10398 entries[0].from = from;
10399 entries[0].to = to;
10400}
10401
10402/*
10403 * Apply 'langmap' to multi-byte character "c" and return the result.
10404 */
10405 int
10406langmap_adjust_mb(c)
10407 int c;
10408{
10409 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10410 int a = 0;
10411 int b = langmap_mapga.ga_len;
10412
10413 while (a != b)
10414 {
10415 int i = (a + b) / 2;
10416 int d = entries[i].from - c;
10417
10418 if (d == 0)
10419 return entries[i].to; /* found matching entry */
10420 if (d < 0)
10421 a = i + 1;
10422 else
10423 b = i;
10424 }
10425 return c; /* no entry found, return "c" unmodified */
10426}
10427# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428
10429 static void
10430langmap_init()
10431{
10432 int i;
10433
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010434 for (i = 0; i < 256; i++)
10435 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10436# ifdef FEAT_MBYTE
10437 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10438# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439}
10440
10441/*
10442 * Called when langmap option is set; the language map can be
10443 * changed at any time!
10444 */
10445 static void
10446langmap_set()
10447{
10448 char_u *p;
10449 char_u *p2;
10450 int from, to;
10451
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010452#ifdef FEAT_MBYTE
10453 ga_clear(&langmap_mapga); /* clear the previous map first */
10454#endif
10455 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010456
10457 for (p = p_langmap; p[0] != NUL; )
10458 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010459 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10460 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461 {
10462 if (p2[0] == '\\' && p2[1] != NUL)
10463 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464 }
10465 if (p2[0] == ';')
10466 ++p2; /* abcd;ABCD form, p2 points to A */
10467 else
10468 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10469 while (p[0])
10470 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010471 if (p[0] == ',')
10472 {
10473 ++p;
10474 break;
10475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476 if (p[0] == '\\' && p[1] != NUL)
10477 ++p;
10478#ifdef FEAT_MBYTE
10479 from = (*mb_ptr2char)(p);
10480#else
10481 from = p[0];
10482#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010483 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484 if (p2 == NULL)
10485 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010486 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010487 if (p[0] != ',')
10488 {
10489 if (p[0] == '\\')
10490 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010492 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010494 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497 }
10498 else
10499 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010500 if (p2[0] != ',')
10501 {
10502 if (p2[0] == '\\')
10503 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010505 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010507 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 }
10511 if (to == NUL)
10512 {
10513 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10514 transchar(from));
10515 return;
10516 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010517
10518#ifdef FEAT_MBYTE
10519 if (from >= 256)
10520 langmap_set_entry(from, to);
10521 else
10522#endif
10523 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524
10525 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010526 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010527 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010529 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 if (*p == ';')
10531 {
10532 p = p2;
10533 if (p[0] != NUL)
10534 {
10535 if (p[0] != ',')
10536 {
10537 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10538 return;
10539 }
10540 ++p;
10541 }
10542 break;
10543 }
10544 }
10545 }
10546 }
10547}
10548#endif
10549
10550/*
10551 * Return TRUE if format option 'x' is in effect.
10552 * Take care of no formatting when 'paste' is set.
10553 */
10554 int
10555has_format_option(x)
10556 int x;
10557{
10558 if (p_paste)
10559 return FALSE;
10560 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10561}
10562
10563/*
10564 * Return TRUE if "x" is present in 'shortmess' option, or
10565 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10566 */
10567 int
10568shortmess(x)
10569 int x;
10570{
10571 return ( vim_strchr(p_shm, x) != NULL
10572 || (vim_strchr(p_shm, 'a') != NULL
10573 && vim_strchr((char_u *)SHM_A, x) != NULL));
10574}
10575
10576/*
10577 * paste_option_changed() - Called after p_paste was set or reset.
10578 */
10579 static void
10580paste_option_changed()
10581{
10582 static int old_p_paste = FALSE;
10583 static int save_sm = 0;
10584#ifdef FEAT_CMDL_INFO
10585 static int save_ru = 0;
10586#endif
10587#ifdef FEAT_RIGHTLEFT
10588 static int save_ri = 0;
10589 static int save_hkmap = 0;
10590#endif
10591 buf_T *buf;
10592
10593 if (p_paste)
10594 {
10595 /*
10596 * Paste switched from off to on.
10597 * Save the current values, so they can be restored later.
10598 */
10599 if (!old_p_paste)
10600 {
10601 /* save options for each buffer */
10602 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10603 {
10604 buf->b_p_tw_nopaste = buf->b_p_tw;
10605 buf->b_p_wm_nopaste = buf->b_p_wm;
10606 buf->b_p_sts_nopaste = buf->b_p_sts;
10607 buf->b_p_ai_nopaste = buf->b_p_ai;
10608 }
10609
10610 /* save global options */
10611 save_sm = p_sm;
10612#ifdef FEAT_CMDL_INFO
10613 save_ru = p_ru;
10614#endif
10615#ifdef FEAT_RIGHTLEFT
10616 save_ri = p_ri;
10617 save_hkmap = p_hkmap;
10618#endif
10619 /* save global values for local buffer options */
10620 p_tw_nopaste = p_tw;
10621 p_wm_nopaste = p_wm;
10622 p_sts_nopaste = p_sts;
10623 p_ai_nopaste = p_ai;
10624 }
10625
10626 /*
10627 * Always set the option values, also when 'paste' is set when it is
10628 * already on.
10629 */
10630 /* set options for each buffer */
10631 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10632 {
10633 buf->b_p_tw = 0; /* textwidth is 0 */
10634 buf->b_p_wm = 0; /* wrapmargin is 0 */
10635 buf->b_p_sts = 0; /* softtabstop is 0 */
10636 buf->b_p_ai = 0; /* no auto-indent */
10637 }
10638
10639 /* set global options */
10640 p_sm = 0; /* no showmatch */
10641#ifdef FEAT_CMDL_INFO
10642# ifdef FEAT_WINDOWS
10643 if (p_ru)
10644 status_redraw_all(); /* redraw to remove the ruler */
10645# endif
10646 p_ru = 0; /* no ruler */
10647#endif
10648#ifdef FEAT_RIGHTLEFT
10649 p_ri = 0; /* no reverse insert */
10650 p_hkmap = 0; /* no Hebrew keyboard */
10651#endif
10652 /* set global values for local buffer options */
10653 p_tw = 0;
10654 p_wm = 0;
10655 p_sts = 0;
10656 p_ai = 0;
10657 }
10658
10659 /*
10660 * Paste switched from on to off: Restore saved values.
10661 */
10662 else if (old_p_paste)
10663 {
10664 /* restore options for each buffer */
10665 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10666 {
10667 buf->b_p_tw = buf->b_p_tw_nopaste;
10668 buf->b_p_wm = buf->b_p_wm_nopaste;
10669 buf->b_p_sts = buf->b_p_sts_nopaste;
10670 buf->b_p_ai = buf->b_p_ai_nopaste;
10671 }
10672
10673 /* restore global options */
10674 p_sm = save_sm;
10675#ifdef FEAT_CMDL_INFO
10676# ifdef FEAT_WINDOWS
10677 if (p_ru != save_ru)
10678 status_redraw_all(); /* redraw to draw the ruler */
10679# endif
10680 p_ru = save_ru;
10681#endif
10682#ifdef FEAT_RIGHTLEFT
10683 p_ri = save_ri;
10684 p_hkmap = save_hkmap;
10685#endif
10686 /* set global values for local buffer options */
10687 p_tw = p_tw_nopaste;
10688 p_wm = p_wm_nopaste;
10689 p_sts = p_sts_nopaste;
10690 p_ai = p_ai_nopaste;
10691 }
10692
10693 old_p_paste = p_paste;
10694}
10695
10696/*
10697 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10698 *
10699 * Reset 'compatible' and set the values for options that didn't get set yet
10700 * to the Vim defaults.
10701 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010702 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703 */
10704 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010705vimrc_found(fname, envname)
10706 char_u *fname;
10707 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010709 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010710 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010711 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712
10713 if (!option_was_set((char_u *)"cp"))
10714 {
10715 p_cp = FALSE;
10716 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10717 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10718 set_option_default(opt_idx, OPT_FREE, FALSE);
10719 didset_options();
10720 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010721
10722 if (fname != NULL)
10723 {
10724 p = vim_getenv(envname, &dofree);
10725 if (p == NULL)
10726 {
10727 /* Set $MYVIMRC to the first vimrc file found. */
10728 p = FullName_save(fname, FALSE);
10729 if (p != NULL)
10730 {
10731 vim_setenv(envname, p);
10732 vim_free(p);
10733 }
10734 }
10735 else if (dofree)
10736 vim_free(p);
10737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738}
10739
10740/*
10741 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10742 */
10743 void
10744change_compatible(on)
10745 int on;
10746{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010747 int opt_idx;
10748
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749 if (p_cp != on)
10750 {
10751 p_cp = on;
10752 compatible_set();
10753 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010754 opt_idx = findoption((char_u *)"cp");
10755 if (opt_idx >= 0)
10756 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757}
10758
10759/*
10760 * Return TRUE when option "name" has been set.
10761 */
10762 int
10763option_was_set(name)
10764 char_u *name;
10765{
10766 int idx;
10767
10768 idx = findoption(name);
10769 if (idx < 0) /* unknown option */
10770 return FALSE;
10771 if (options[idx].flags & P_WAS_SET)
10772 return TRUE;
10773 return FALSE;
10774}
10775
10776/*
10777 * compatible_set() - Called when 'compatible' has been set or unset.
10778 *
10779 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10780 * flag) to a Vi compatible value.
10781 * When 'compatible' is unset: Set all options that have a different default
10782 * for Vim (without the P_VI_DEF flag) to that default.
10783 */
10784 static void
10785compatible_set()
10786{
10787 int opt_idx;
10788
10789 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10790 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10791 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10792 set_option_default(opt_idx, OPT_FREE, p_cp);
10793 didset_options();
10794}
10795
10796#ifdef FEAT_LINEBREAK
10797
10798# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10799 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010800 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801# endif
10802
10803/*
10804 * fill_breakat_flags() -- called when 'breakat' changes value.
10805 */
10806 static void
10807fill_breakat_flags()
10808{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010809 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810 int i;
10811
10812 for (i = 0; i < 256; i++)
10813 breakat_flags[i] = FALSE;
10814
10815 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010816 for (p = p_breakat; *p; p++)
10817 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818}
10819
10820# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010821 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822# endif
10823
10824#endif
10825
10826/*
10827 * Check an option that can be a range of string values.
10828 *
10829 * Return OK for correct value, FAIL otherwise.
10830 * Empty is always OK.
10831 */
10832 static int
10833check_opt_strings(val, values, list)
10834 char_u *val;
10835 char **values;
10836 int list; /* when TRUE: accept a list of values */
10837{
10838 return opt_strings_flags(val, values, NULL, list);
10839}
10840
10841/*
10842 * Handle an option that can be a range of string values.
10843 * Set a flag in "*flagp" for each string present.
10844 *
10845 * Return OK for correct value, FAIL otherwise.
10846 * Empty is always OK.
10847 */
10848 static int
10849opt_strings_flags(val, values, flagp, list)
10850 char_u *val; /* new value */
10851 char **values; /* array of valid string values */
10852 unsigned *flagp;
10853 int list; /* when TRUE: accept a list of values */
10854{
10855 int i;
10856 int len;
10857 unsigned new_flags = 0;
10858
10859 while (*val)
10860 {
10861 for (i = 0; ; ++i)
10862 {
10863 if (values[i] == NULL) /* val not found in values[] */
10864 return FAIL;
10865
10866 len = (int)STRLEN(values[i]);
10867 if (STRNCMP(values[i], val, len) == 0
10868 && ((list && val[len] == ',') || val[len] == NUL))
10869 {
10870 val += len + (val[len] == ',');
10871 new_flags |= (1 << i);
10872 break; /* check next item in val list */
10873 }
10874 }
10875 }
10876 if (flagp != NULL)
10877 *flagp = new_flags;
10878
10879 return OK;
10880}
10881
10882/*
10883 * Read the 'wildmode' option, fill wim_flags[].
10884 */
10885 static int
10886check_opt_wim()
10887{
10888 char_u new_wim_flags[4];
10889 char_u *p;
10890 int i;
10891 int idx = 0;
10892
10893 for (i = 0; i < 4; ++i)
10894 new_wim_flags[i] = 0;
10895
10896 for (p = p_wim; *p; ++p)
10897 {
10898 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10899 ;
10900 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10901 return FAIL;
10902 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10903 new_wim_flags[idx] |= WIM_LONGEST;
10904 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10905 new_wim_flags[idx] |= WIM_FULL;
10906 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10907 new_wim_flags[idx] |= WIM_LIST;
10908 else
10909 return FAIL;
10910 p += i;
10911 if (*p == NUL)
10912 break;
10913 if (*p == ',')
10914 {
10915 if (idx == 3)
10916 return FAIL;
10917 ++idx;
10918 }
10919 }
10920
10921 /* fill remaining entries with last flag */
10922 while (idx < 3)
10923 {
10924 new_wim_flags[idx + 1] = new_wim_flags[idx];
10925 ++idx;
10926 }
10927
10928 /* only when there are no errors, wim_flags[] is changed */
10929 for (i = 0; i < 4; ++i)
10930 wim_flags[i] = new_wim_flags[i];
10931 return OK;
10932}
10933
10934/*
10935 * Check if backspacing over something is allowed.
10936 */
10937 int
10938can_bs(what)
10939 int what; /* BS_INDENT, BS_EOL or BS_START */
10940{
10941 switch (*p_bs)
10942 {
10943 case '2': return TRUE;
10944 case '1': return (what != BS_START);
10945 case '0': return FALSE;
10946 }
10947 return vim_strchr(p_bs, what) != NULL;
10948}
10949
10950/*
10951 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10952 * the file must be considered changed when the value is different.
10953 */
10954 void
10955save_file_ff(buf)
10956 buf_T *buf;
10957{
10958 buf->b_start_ffc = *buf->b_p_ff;
10959 buf->b_start_eol = buf->b_p_eol;
10960#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010961 buf->b_start_bomb = buf->b_p_bomb;
10962
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 /* Only use free/alloc when necessary, they take time. */
10964 if (buf->b_start_fenc == NULL
10965 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10966 {
10967 vim_free(buf->b_start_fenc);
10968 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10969 }
10970#endif
10971}
10972
10973/*
10974 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10975 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010976 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
10977 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978 * Don't consider a new, empty buffer to be changed.
10979 */
10980 int
10981file_ff_differs(buf)
10982 buf_T *buf;
10983{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000010984 /* In a buffer that was never loaded the options are not valid. */
10985 if (buf->b_flags & BF_NEVERLOADED)
10986 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987 if ((buf->b_flags & BF_NEW)
10988 && buf->b_ml.ml_line_count == 1
10989 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10990 return FALSE;
10991 if (buf->b_start_ffc != *buf->b_p_ff)
10992 return TRUE;
10993 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10994 return TRUE;
10995#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010996 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
10997 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998 if (buf->b_start_fenc == NULL)
10999 return (*buf->b_p_fenc != NUL);
11000 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11001#else
11002 return FALSE;
11003#endif
11004}
11005
11006/*
11007 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11008 */
11009 int
11010check_ff_value(p)
11011 char_u *p;
11012{
11013 return check_opt_strings(p, p_ff_values, FALSE);
11014}