blob: c432869749b7a073c3317ec1b7de2c0a3730919f [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
80#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
99#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
100#define PV_ET OPT_BUF(BV_ET)
101#ifdef FEAT_MBYTE
102# define PV_FENC OPT_BUF(BV_FENC)
103#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000104#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
105# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
106#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
113#ifdef FEAT_AUTOCMD
114# define PV_FT OPT_BUF(BV_FT)
115#endif
116#define PV_IMI OPT_BUF(BV_IMI)
117#define PV_IMS OPT_BUF(BV_IMS)
118#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
119# define PV_INDE OPT_BUF(BV_INDE)
120# define PV_INDK OPT_BUF(BV_INDK)
121#endif
122#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
123# define PV_INEX OPT_BUF(BV_INEX)
124#endif
125#define PV_INF OPT_BUF(BV_INF)
126#define PV_ISK OPT_BUF(BV_ISK)
127#ifdef FEAT_CRYPT
128# define PV_KEY OPT_BUF(BV_KEY)
129#endif
130#ifdef FEAT_KEYMAP
131# define PV_KMAP OPT_BUF(BV_KMAP)
132#endif
133#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
134#ifdef FEAT_LISP
135# define PV_LISP OPT_BUF(BV_LISP)
136#endif
137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
142#ifdef FEAT_OSFILETYPE
143# define PV_OFT OPT_BUF(BV_OFT)
144#endif
145#ifdef FEAT_COMPL_FUNC
146# define PV_OFU OPT_BUF(BV_OFU)
147#endif
148#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
149#define PV_PI OPT_BUF(BV_PI)
150#ifdef FEAT_TEXTOBJ
151# define PV_QE OPT_BUF(BV_QE)
152#endif
153#define PV_RO OPT_BUF(BV_RO)
154#ifdef FEAT_SMARTINDENT
155# define PV_SI OPT_BUF(BV_SI)
156#endif
157#ifndef SHORT_FNAME
158# define PV_SN OPT_BUF(BV_SN)
159#endif
160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
179#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000180
181/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182 * Definition of the PV_ values for window-local options.
183 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185#define PV_LIST OPT_WIN(WV_LIST)
186#ifdef FEAT_ARABIC
187# define PV_ARAB OPT_WIN(WV_ARAB)
188#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189#ifdef FEAT_DIFF
190# define PV_DIFF OPT_WIN(WV_DIFF)
191#endif
192#ifdef FEAT_FOLDING
193# define PV_FDC OPT_WIN(WV_FDC)
194# define PV_FEN OPT_WIN(WV_FEN)
195# define PV_FDI OPT_WIN(WV_FDI)
196# define PV_FDL OPT_WIN(WV_FDL)
197# define PV_FDM OPT_WIN(WV_FDM)
198# define PV_FML OPT_WIN(WV_FML)
199# define PV_FDN OPT_WIN(WV_FDN)
200# ifdef FEAT_EVAL
201# define PV_FDE OPT_WIN(WV_FDE)
202# define PV_FDT OPT_WIN(WV_FDT)
203# endif
204# define PV_FMR OPT_WIN(WV_FMR)
205#endif
206#ifdef FEAT_LINEBREAK
207# define PV_LBR OPT_WIN(WV_LBR)
208#endif
209#define PV_NU OPT_WIN(WV_NU)
210#ifdef FEAT_LINEBREAK
211# define PV_NUW OPT_WIN(WV_NUW)
212#endif
213#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
214# define PV_PVW OPT_WIN(WV_PVW)
215#endif
216#ifdef FEAT_RIGHTLEFT
217# define PV_RL OPT_WIN(WV_RL)
218# define PV_RLC OPT_WIN(WV_RLC)
219#endif
220#ifdef FEAT_SCROLLBIND
221# define PV_SCBIND OPT_WIN(WV_SCBIND)
222#endif
223#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000224#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000225# define PV_SPELL OPT_WIN(WV_SPELL)
226#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000227#ifdef FEAT_SYN_HL
228# define PV_CUC OPT_WIN(WV_CUC)
229# define PV_CUL OPT_WIN(WV_CUL)
230#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#ifdef FEAT_STL_OPT
232# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
233#endif
234#ifdef FEAT_WINDOWS
235# define PV_WFH OPT_WIN(WV_WFH)
236#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000237#ifdef FEAT_VERTSPLIT
238# define PV_WFW OPT_WIN(WV_WFW)
239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000241
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242
243/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244typedef enum
245{
246 PV_NONE = 0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247} idopt_T;
248
249/*
250 * Options local to a window have a value local to a buffer and global to all
251 * buffers. Indicate this by setting "var" to VAR_WIN.
252 */
253#define VAR_WIN ((char_u *)-1)
254
255/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000256 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257 * Only to be used in option.c!
258 */
259static int p_ai;
260static int p_bin;
261#ifdef FEAT_MBYTE
262static int p_bomb;
263#endif
264#if defined(FEAT_QUICKFIX)
265static char_u *p_bh;
266static char_u *p_bt;
267#endif
268static int p_bl;
269static int p_ci;
270#ifdef FEAT_CINDENT
271static int p_cin;
272static char_u *p_cink;
273static char_u *p_cino;
274#endif
275#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
276static char_u *p_cinw;
277#endif
278#ifdef FEAT_COMMENTS
279static char_u *p_com;
280#endif
281#ifdef FEAT_FOLDING
282static char_u *p_cms;
283#endif
284#ifdef FEAT_INS_EXPAND
285static char_u *p_cpt;
286#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000287#ifdef FEAT_COMPL_FUNC
288static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000289static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000290#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291static int p_eol;
292static int p_et;
293#ifdef FEAT_MBYTE
294static char_u *p_fenc;
295#endif
296static char_u *p_ff;
297static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000298static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000299#ifdef FEAT_AUTOCMD
300static char_u *p_ft;
301#endif
302static long p_iminsert;
303static long p_imsearch;
304#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
305static char_u *p_inex;
306#endif
307#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
308static char_u *p_inde;
309static char_u *p_indk;
310#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000311#if defined(FEAT_EVAL)
312static char_u *p_fex;
313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_inf;
315static char_u *p_isk;
316#ifdef FEAT_CRYPT
317static char_u *p_key;
318#endif
319#ifdef FEAT_LISP
320static int p_lisp;
321#endif
322static int p_ml;
323static int p_ma;
324static int p_mod;
325static char_u *p_mps;
326static char_u *p_nf;
327#ifdef FEAT_OSFILETYPE
328static char_u *p_oft;
329#endif
330static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000331#ifdef FEAT_TEXTOBJ
332static char_u *p_qe;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_ro;
335#ifdef FEAT_SMARTINDENT
336static int p_si;
337#endif
338#ifndef SHORT_FNAME
339static int p_sn;
340#endif
341static long p_sts;
342#if defined(FEAT_SEARCHPATH)
343static char_u *p_sua;
344#endif
345static long p_sw;
346static int p_swf;
347#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000348static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000350#endif
351#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000352static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000353static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000354static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355#endif
356static long p_ts;
357static long p_tw;
358static int p_tx;
359static long p_wm;
360#ifdef FEAT_KEYMAP
361static char_u *p_keymap;
362#endif
363
364/* Saved values for when 'bin' is set. */
365static int p_et_nobin;
366static int p_ml_nobin;
367static long p_tw_nobin;
368static long p_wm_nobin;
369
370/* Saved values for when 'paste' is set */
371static long p_tw_nopaste;
372static long p_wm_nopaste;
373static long p_sts_nopaste;
374static int p_ai_nopaste;
375
376struct vimoption
377{
378 char *fullname; /* full option name */
379 char *shortname; /* permissible abbreviation */
380 long_u flags; /* see below */
381 char_u *var; /* global option: pointer to variable;
382 * window-local option: VAR_WIN;
383 * buffer-local option: global value */
384 idopt_T indir; /* global option: PV_NONE;
385 * local option: indirect option index */
386 char_u *def_val[2]; /* default values for variable (vi and vim) */
387#ifdef FEAT_EVAL
388 scid_T scriptID; /* script in which the option was last set */
389#endif
390};
391
392#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
393#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
394
395/*
396 * Flags
397 */
398#define P_BOOL 0x01 /* the option is boolean */
399#define P_NUM 0x02 /* the option is numeric */
400#define P_STRING 0x04 /* the option is a string */
401#define P_ALLOCED 0x08 /* the string option is in allocated memory,
402 must use vim_free() when assigning new
403 value. Not set if default is the same. */
404#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
405 never be used for local or hidden options! */
406#define P_NODEFAULT 0x40 /* don't set to default value */
407#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
408 use vim_free() when assigning new value */
409#define P_WAS_SET 0x100 /* option has been set/reset */
410#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
411#define P_VI_DEF 0x400 /* Use Vi default for Vim */
412#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
413
414 /* when option changed, what to display: */
415#define P_RSTAT 0x1000 /* redraw status lines */
416#define P_RWIN 0x2000 /* redraw current window */
417#define P_RBUF 0x4000 /* redraw current buffer */
418#define P_RALL 0x6000 /* redraw all windows */
419#define P_RCLR 0x7000 /* clear and redraw all */
420
421#define P_COMMA 0x8000 /* comma separated list */
422#define P_NODUP 0x10000L/* don't allow duplicate strings */
423#define P_FLAGLIST 0x20000L/* list of single-char flags */
424
425#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
426#define P_GETTEXT 0x80000L/* expand default value with _() */
427#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000428#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000429#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000430#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
431 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000433#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
434
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000435/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
436 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000437#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000438# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000439#else
440# define ISP_LATIN1 (char_u *)"@,161-255"
441#endif
442
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000443/* The 16 bit MS-DOS version is low on space, make the string as short as
444 * possible when compiling with few features. */
445#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
446 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
447 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
448# 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"
449#else
450# 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"
451#endif
452
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453/*
454 * options[] is initialized here.
455 * The order of the options MUST be alphabetic for ":set all" and findoption().
456 * All option names MUST start with a lowercase letter (for findoption()).
457 * Exception: "t_" options are at the end.
458 * The options with a NULL variable are 'hidden': a set command for them is
459 * ignored and they are not printed.
460 */
461static struct vimoption
462#ifdef FEAT_GUI_W16
463 _far
464#endif
465 options[] =
466{
467 {"aleph", "al", P_NUM|P_VI_DEF,
468#ifdef FEAT_RIGHTLEFT
469 (char_u *)&p_aleph, PV_NONE,
470#else
471 (char_u *)NULL, PV_NONE,
472#endif
473 {
474#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
475 (char_u *)128L,
476#else
477 (char_u *)224L,
478#endif
479 (char_u *)0L}},
480 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
481#if defined(FEAT_GUI) && defined(MACOS_X)
482 (char_u *)&p_antialias, PV_NONE,
483 {(char_u *)FALSE, (char_u *)FALSE}
484#else
485 (char_u *)NULL, PV_NONE,
486 {(char_u *)FALSE, (char_u *)FALSE}
487#endif
488 },
489 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
490#ifdef FEAT_ARABIC
491 (char_u *)VAR_WIN, PV_ARAB,
492#else
493 (char_u *)NULL, PV_NONE,
494#endif
495 {(char_u *)FALSE, (char_u *)0L}},
496 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
497#ifdef FEAT_ARABIC
498 (char_u *)&p_arshape, PV_NONE,
499#else
500 (char_u *)NULL, PV_NONE,
501#endif
502 {(char_u *)TRUE, (char_u *)0L}},
503 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
504#ifdef FEAT_RIGHTLEFT
505 (char_u *)&p_ari, PV_NONE,
506#else
507 (char_u *)NULL, PV_NONE,
508#endif
509 {(char_u *)FALSE, (char_u *)0L}},
510 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
511#ifdef FEAT_FKMAP
512 (char_u *)&p_altkeymap, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {(char_u *)FALSE, (char_u *)0L}},
517 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
518#if defined(FEAT_MBYTE)
519 (char_u *)&p_ambw, PV_NONE,
520 {(char_u *)"single", (char_u *)0L}
521#else
522 (char_u *)NULL, PV_NONE,
523 {(char_u *)0L, (char_u *)0L}
524#endif
525 },
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000526#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"autochdir", "acd", P_BOOL|P_VI_DEF,
528 (char_u *)&p_acd, PV_NONE,
529 {(char_u *)FALSE, (char_u *)0L}},
530#endif
531 {"autoindent", "ai", P_BOOL|P_VI_DEF,
532 (char_u *)&p_ai, PV_AI,
533 {(char_u *)FALSE, (char_u *)0L}},
534 {"autoprint", "ap", P_BOOL|P_VI_DEF,
535 (char_u *)NULL, PV_NONE,
536 {(char_u *)FALSE, (char_u *)0L}},
537 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000538 (char_u *)&p_ar, PV_AR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {(char_u *)FALSE, (char_u *)0L}},
540 {"autowrite", "aw", P_BOOL|P_VI_DEF,
541 (char_u *)&p_aw, PV_NONE,
542 {(char_u *)FALSE, (char_u *)0L}},
543 {"autowriteall","awa", P_BOOL|P_VI_DEF,
544 (char_u *)&p_awa, PV_NONE,
545 {(char_u *)FALSE, (char_u *)0L}},
546 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
547 (char_u *)&p_bg, PV_NONE,
548 {
549#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
550 (char_u *)"dark",
551#else
552 (char_u *)"light",
553#endif
554 (char_u *)0L}},
555 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
556 (char_u *)&p_bs, PV_NONE,
557 {(char_u *)"", (char_u *)0L}},
558 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
559 (char_u *)&p_bk, PV_NONE,
560 {(char_u *)FALSE, (char_u *)0L}},
561 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
562 (char_u *)&p_bkc, PV_NONE,
563#ifdef UNIX
564 {(char_u *)"yes", (char_u *)"auto"}
565#else
566 {(char_u *)"auto", (char_u *)"auto"}
567#endif
568 },
569 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
570 (char_u *)&p_bdir, PV_NONE,
571 {(char_u *)DFLT_BDIR, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000572 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 (char_u *)&p_bex, PV_NONE,
574 {
575#ifdef VMS
576 (char_u *)"_",
577#else
578 (char_u *)"~",
579#endif
580 (char_u *)0L}},
581 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
582#ifdef FEAT_WILDIGN
583 (char_u *)&p_bsk, PV_NONE,
584 {(char_u *)"", (char_u *)0L}
585#else
586 (char_u *)NULL, PV_NONE,
587 {(char_u *)0L, (char_u *)0L}
588#endif
589 },
590#ifdef FEAT_BEVAL
591 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
592 (char_u *)&p_bdlay, PV_NONE,
593 {(char_u *)600L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
595 (char_u *)&p_beval, PV_NONE,
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000596 {(char_u *)FALSE, (char_u *)0L}},
597# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000598 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000599 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000600 {(char_u *)"", (char_u *)0L}},
601# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602#endif
603 {"beautify", "bf", P_BOOL|P_VI_DEF,
604 (char_u *)NULL, PV_NONE,
605 {(char_u *)FALSE, (char_u *)0L}},
606 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
607 (char_u *)&p_bin, PV_BIN,
608 {(char_u *)FALSE, (char_u *)0L}},
609 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
610#ifdef MSDOS
611 (char_u *)&p_biosk, PV_NONE,
612#else
613 (char_u *)NULL, PV_NONE,
614#endif
615 {(char_u *)TRUE, (char_u *)0L}},
616 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
617#ifdef FEAT_MBYTE
618 (char_u *)&p_bomb, PV_BOMB,
619#else
620 (char_u *)NULL, PV_NONE,
621#endif
622 {(char_u *)FALSE, (char_u *)0L}},
623 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
624#ifdef FEAT_LINEBREAK
625 (char_u *)&p_breakat, PV_NONE,
626 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
627#else
628 (char_u *)NULL, PV_NONE,
629 {(char_u *)0L, (char_u *)0L}
630#endif
631 },
632 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
633#ifdef FEAT_BROWSE
634 (char_u *)&p_bsdir, PV_NONE,
635 {(char_u *)"last", (char_u *)0L}
636#else
637 (char_u *)NULL, PV_NONE,
638 {(char_u *)0L, (char_u *)0L}
639#endif
640 },
641 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
642#if defined(FEAT_QUICKFIX)
643 (char_u *)&p_bh, PV_BH,
644 {(char_u *)"", (char_u *)0L}
645#else
646 (char_u *)NULL, PV_NONE,
647 {(char_u *)0L, (char_u *)0L}
648#endif
649 },
650 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
651 (char_u *)&p_bl, PV_BL,
652 {(char_u *)1L, (char_u *)0L}
653 },
654 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
655#if defined(FEAT_QUICKFIX)
656 (char_u *)&p_bt, PV_BT,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 },
663 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000664#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 (char_u *)&p_cmp, PV_NONE,
666 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000667#else
668 (char_u *)NULL, PV_NONE,
669 {(char_u *)0L, (char_u *)0L}
670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 },
672 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
673#ifdef FEAT_SEARCHPATH
674 (char_u *)&p_cdpath, PV_NONE,
675 {(char_u *)",,", (char_u *)0L}
676#else
677 (char_u *)NULL, PV_NONE,
678 {(char_u *)0L, (char_u *)0L}
679#endif
680 },
681 {"cedit", NULL, P_STRING,
682#ifdef FEAT_CMDWIN
683 (char_u *)&p_cedit, PV_NONE,
684 {(char_u *)"", (char_u *)CTRL_F_STR}
685#else
686 (char_u *)NULL, PV_NONE,
687 {(char_u *)0L, (char_u *)0L}
688#endif
689 },
690 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
691#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
692 (char_u *)&p_ccv, PV_NONE,
693 {(char_u *)"", (char_u *)0L}
694#else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)0L, (char_u *)0L}
697#endif
698 },
699 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
700#ifdef FEAT_CINDENT
701 (char_u *)&p_cin, PV_CIN,
702#else
703 (char_u *)NULL, PV_NONE,
704#endif
705 {(char_u *)FALSE, (char_u *)0L}},
706 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
707#ifdef FEAT_CINDENT
708 (char_u *)&p_cink, PV_CINK,
709 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
714 },
715 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
716#ifdef FEAT_CINDENT
717 (char_u *)&p_cino, PV_CINO,
718#else
719 (char_u *)NULL, PV_NONE,
720#endif
721 {(char_u *)"", (char_u *)0L}},
722 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
723#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
724 (char_u *)&p_cinw, PV_CINW,
725 {(char_u *)"if,else,while,do,for,switch",
726 (char_u *)0L}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
731 },
732 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
733#ifdef FEAT_CLIPBOARD
734 (char_u *)&p_cb, PV_NONE,
735# ifdef FEAT_XCLIPBOARD
736 {(char_u *)"autoselect,exclude:cons\\|linux",
737 (char_u *)0L}
738# else
739 {(char_u *)"", (char_u *)0L}
740# endif
741#else
742 (char_u *)NULL, PV_NONE,
743 {(char_u *)"", (char_u *)0L}
744#endif
745 },
746 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
747 (char_u *)&p_ch, PV_NONE,
748 {(char_u *)1L, (char_u *)0L}},
749 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
750#ifdef FEAT_CMDWIN
751 (char_u *)&p_cwh, PV_NONE,
752#else
753 (char_u *)NULL, PV_NONE,
754#endif
755 {(char_u *)7L, (char_u *)0L}},
756 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
757 (char_u *)&Columns, PV_NONE,
758 {(char_u *)80L, (char_u *)0L}},
759 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
760#ifdef FEAT_COMMENTS
761 (char_u *)&p_com, PV_COM,
762 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
763 (char_u *)0L}
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
768 },
769 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
770#ifdef FEAT_FOLDING
771 (char_u *)&p_cms, PV_CMS,
772 {(char_u *)"/*%s*/", (char_u *)0L}
773#else
774 (char_u *)NULL, PV_NONE,
775 {(char_u *)0L, (char_u *)0L}
776#endif
777 },
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000778 /* P_PRI_MKRC isn't needed here, optval_default()
779 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780 {"compatible", "cp", P_BOOL|P_RALL,
781 (char_u *)&p_cp, PV_NONE,
782 {(char_u *)TRUE, (char_u *)FALSE}},
783 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
784#ifdef FEAT_INS_EXPAND
785 (char_u *)&p_cpt, PV_CPT,
786 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
791 },
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000792 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
793#ifdef FEAT_COMPL_FUNC
794 (char_u *)&p_cfu, PV_CFU,
795 {(char_u *)"", (char_u *)0L}
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)0L, (char_u *)0L}
799#endif
800 },
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000801 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
802#ifdef FEAT_INS_EXPAND
803 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000804 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000805#else
806 (char_u *)NULL, PV_NONE,
807 {(char_u *)0L, (char_u *)0L}
808#endif
809 },
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"confirm", "cf", P_BOOL|P_VI_DEF,
811#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
812 (char_u *)&p_confirm, PV_NONE,
813#else
814 (char_u *)NULL, PV_NONE,
815#endif
816 {(char_u *)FALSE, (char_u *)0L}},
817 {"conskey", "consk",P_BOOL|P_VI_DEF,
818#ifdef MSDOS
819 (char_u *)&p_consk, PV_NONE,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
823 {(char_u *)FALSE, (char_u *)0L}},
824 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
825 (char_u *)&p_ci, PV_CI,
826 {(char_u *)FALSE, (char_u *)0L}},
827 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
828 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000829 {(char_u *)CPO_VI, (char_u *)CPO_VIM}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
831#ifdef FEAT_CSCOPE
832 (char_u *)&p_cspc, PV_NONE,
833#else
834 (char_u *)NULL, PV_NONE,
835#endif
836 {(char_u *)0L, (char_u *)0L}},
837 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
838#ifdef FEAT_CSCOPE
839 (char_u *)&p_csprg, PV_NONE,
840 {(char_u *)"cscope", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
845 },
846 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
847#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
848 (char_u *)&p_csqf, PV_NONE,
849 {(char_u *)"", (char_u *)0L}
850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)0L, (char_u *)0L}
853#endif
854 },
855 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
856#ifdef FEAT_CSCOPE
857 (char_u *)&p_cst, PV_NONE,
858#else
859 (char_u *)NULL, PV_NONE,
860#endif
861 {(char_u *)0L, (char_u *)0L}},
862 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
863#ifdef FEAT_CSCOPE
864 (char_u *)&p_csto, PV_NONE,
865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)0L, (char_u *)0L}},
869 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
870#ifdef FEAT_CSCOPE
871 (char_u *)&p_csverbose, PV_NONE,
872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000876 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
877#ifdef FEAT_SYN_HL
878 (char_u *)VAR_WIN, PV_CUC,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
882 {(char_u *)FALSE, (char_u *)0L}},
883 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
884#ifdef FEAT_SYN_HL
885 (char_u *)VAR_WIN, PV_CUL,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
889 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"debug", NULL, P_STRING|P_VI_DEF,
891 (char_u *)&p_debug, PV_NONE,
892 {(char_u *)"", (char_u *)0L}},
893 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
894#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000895 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000896 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897#else
898 (char_u *)NULL, PV_NONE,
899 {(char_u *)NULL, (char_u *)0L}
900#endif
901 },
902 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
903#ifdef FEAT_MBYTE
904 (char_u *)&p_deco, PV_NONE,
905#else
906 (char_u *)NULL, PV_NONE,
907#endif
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000908 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
910#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000911 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912#else
913 (char_u *)NULL, PV_NONE,
914#endif
915 {(char_u *)"", (char_u *)0L}},
916 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
917#ifdef FEAT_DIFF
918 (char_u *)VAR_WIN, PV_DIFF,
919#else
920 (char_u *)NULL, PV_NONE,
921#endif
922 {(char_u *)FALSE, (char_u *)0L}},
923 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
924#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
925 (char_u *)&p_dex, PV_NONE,
926 {(char_u *)"", (char_u *)0L}
927#else
928 (char_u *)NULL, PV_NONE,
929 {(char_u *)0L, (char_u *)0L}
930#endif
931 },
932 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
933#ifdef FEAT_DIFF
934 (char_u *)&p_dip, PV_NONE,
935 {(char_u *)"filler", (char_u *)NULL}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)"", (char_u *)NULL}
939#endif
940 },
941 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
942#ifdef FEAT_DIGRAPHS
943 (char_u *)&p_dg, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
947 {(char_u *)FALSE, (char_u *)0L}},
948 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
949 (char_u *)&p_dir, PV_NONE,
950 {(char_u *)DFLT_DIR, (char_u *)0L}},
951 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
952 (char_u *)&p_dy, PV_NONE,
953 {(char_u *)"", (char_u *)0L}},
954 {"eadirection", "ead", P_STRING|P_VI_DEF,
955#ifdef FEAT_VERTSPLIT
956 (char_u *)&p_ead, PV_NONE,
957 {(char_u *)"both", (char_u *)0L}
958#else
959 (char_u *)NULL, PV_NONE,
960 {(char_u *)NULL, (char_u *)0L}
961#endif
962 },
963 {"edcompatible","ed", P_BOOL|P_VI_DEF,
964 (char_u *)&p_ed, PV_NONE,
965 {(char_u *)FALSE, (char_u *)0L}},
966 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
967#ifdef FEAT_MBYTE
968 (char_u *)&p_enc, PV_NONE,
969 {(char_u *)ENC_DFLT, (char_u *)0L}
970#else
971 (char_u *)NULL, PV_NONE,
972 {(char_u *)0L, (char_u *)0L}
973#endif
974 },
975 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
976 (char_u *)&p_eol, PV_EOL,
977 {(char_u *)TRUE, (char_u *)0L}},
978 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
979 (char_u *)&p_ea, PV_NONE,
980 {(char_u *)TRUE, (char_u *)0L}},
981 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000982 (char_u *)&p_ep, PV_EP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {(char_u *)"", (char_u *)0L}},
984 {"errorbells", "eb", P_BOOL|P_VI_DEF,
985 (char_u *)&p_eb, PV_NONE,
986 {(char_u *)FALSE, (char_u *)0L}},
987 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
988#ifdef FEAT_QUICKFIX
989 (char_u *)&p_ef, PV_NONE,
990 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
991#else
992 (char_u *)NULL, PV_NONE,
993 {(char_u *)NULL, (char_u *)0L}
994#endif
995 },
996 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
997#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000998 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {(char_u *)DFLT_EFM, (char_u *)0L},
1000#else
1001 (char_u *)NULL, PV_NONE,
1002 {(char_u *)NULL, (char_u *)0L}
1003#endif
1004 },
1005 {"esckeys", "ek", P_BOOL|P_VIM,
1006 (char_u *)&p_ek, PV_NONE,
1007 {(char_u *)FALSE, (char_u *)TRUE}},
1008 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1009#ifdef FEAT_AUTOCMD
1010 (char_u *)&p_ei, PV_NONE,
1011#else
1012 (char_u *)NULL, PV_NONE,
1013#endif
1014 {(char_u *)"", (char_u *)0L}},
1015 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1016 (char_u *)&p_et, PV_ET,
1017 {(char_u *)FALSE, (char_u *)0L}},
1018 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1019 (char_u *)&p_exrc, PV_NONE,
1020 {(char_u *)FALSE, (char_u *)0L}},
1021 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1022#ifdef FEAT_MBYTE
1023 (char_u *)&p_fenc, PV_FENC,
1024 {(char_u *)"", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)0L, (char_u *)0L}
1028#endif
1029 },
1030 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1031#ifdef FEAT_MBYTE
1032 (char_u *)&p_fencs, PV_NONE,
1033 {(char_u *)"ucs-bom", (char_u *)0L}
1034#else
1035 (char_u *)NULL, PV_NONE,
1036 {(char_u *)0L, (char_u *)0L}
1037#endif
1038 },
1039 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1040 (char_u *)&p_ff, PV_FF,
1041 {(char_u *)DFLT_FF, (char_u *)0L}},
1042 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1043 (char_u *)&p_ffs, PV_NONE,
1044 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001045 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046#ifdef FEAT_AUTOCMD
1047 (char_u *)&p_ft, PV_FT,
1048 {(char_u *)"", (char_u *)0L}
1049#else
1050 (char_u *)NULL, PV_NONE,
1051 {(char_u *)0L, (char_u *)0L}
1052#endif
1053 },
1054 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1055#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1056 (char_u *)&p_fcs, PV_NONE,
1057 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)"", (char_u *)0L}
1061#endif
1062 },
1063 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1064#ifdef FEAT_FKMAP
1065 (char_u *)&p_fkmap, PV_NONE,
1066#else
1067 (char_u *)NULL, PV_NONE,
1068#endif
1069 {(char_u *)FALSE, (char_u *)0L}},
1070 {"flash", "fl", P_BOOL|P_VI_DEF,
1071 (char_u *)NULL, PV_NONE,
1072 {(char_u *)FALSE, (char_u *)0L}},
1073#ifdef FEAT_FOLDING
1074 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1075 (char_u *)&p_fcl, PV_NONE,
1076 {(char_u *)"", (char_u *)0L}},
1077 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1078 (char_u *)VAR_WIN, PV_FDC,
1079 {(char_u *)FALSE, (char_u *)0L}},
1080 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1081 (char_u *)VAR_WIN, PV_FEN,
1082 {(char_u *)TRUE, (char_u *)0L}},
1083 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1084# ifdef FEAT_EVAL
1085 (char_u *)VAR_WIN, PV_FDE,
1086 {(char_u *)"0", (char_u *)NULL}
1087# else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)NULL, (char_u *)0L}
1090# endif
1091 },
1092 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1093 (char_u *)VAR_WIN, PV_FDI,
1094 {(char_u *)"#", (char_u *)NULL}},
1095 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1096 (char_u *)VAR_WIN, PV_FDL,
1097 {(char_u *)0L, (char_u *)0L}},
1098 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1099 (char_u *)&p_fdls, PV_NONE,
1100 {(char_u *)-1L, (char_u *)0L}},
1101 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1102 P_RWIN|P_COMMA|P_NODUP,
1103 (char_u *)VAR_WIN, PV_FMR,
1104 {(char_u *)"{{{,}}}", (char_u *)NULL}},
1105 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1106 (char_u *)VAR_WIN, PV_FDM,
1107 {(char_u *)"manual", (char_u *)NULL}},
1108 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1109 (char_u *)VAR_WIN, PV_FML,
1110 {(char_u *)1L, (char_u *)0L}},
1111 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1112 (char_u *)VAR_WIN, PV_FDN,
1113 {(char_u *)20L, (char_u *)0L}},
1114 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1115 (char_u *)&p_fdo, PV_NONE,
1116 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1117 (char_u *)0L}},
1118 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1119# ifdef FEAT_EVAL
1120 (char_u *)VAR_WIN, PV_FDT,
1121 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001122# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 (char_u *)NULL, PV_NONE,
1124 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001125# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 },
1127#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001128 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001129#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001130 (char_u *)&p_fex, PV_FEX,
1131 {(char_u *)"", (char_u *)0L}
1132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)0L, (char_u *)0L}
1135#endif
1136 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1138 (char_u *)&p_fo, PV_FO,
1139 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001140 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1141 (char_u *)&p_flp, PV_FLP,
1142 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1144 (char_u *)&p_fp, PV_NONE,
1145 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001146 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1147#ifdef HAVE_FSYNC
1148 (char_u *)&p_fs, PV_NONE,
1149 {(char_u *)TRUE, (char_u *)0L}
1150#else
1151 (char_u *)NULL, PV_NONE,
1152 {(char_u *)FALSE, (char_u *)0L}
1153#endif
1154 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1156 (char_u *)&p_gd, PV_NONE,
1157 {(char_u *)FALSE, (char_u *)0L}},
1158 {"graphic", "gr", P_BOOL|P_VI_DEF,
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)FALSE, (char_u *)0L}},
1161 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1162#ifdef FEAT_QUICKFIX
1163 (char_u *)&p_gefm, PV_NONE,
1164 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
1165#else
1166 (char_u *)NULL, PV_NONE,
1167 {(char_u *)NULL, (char_u *)0L}
1168#endif
1169 },
1170 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1171#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001172 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 {
1174# ifdef WIN3264
1175 /* may be changed to "grep -n" in os_win32.c */
1176 (char_u *)"findstr /n",
1177# else
1178# ifdef UNIX
1179 /* Add an extra file name so that grep will always
1180 * insert a file name in the match line. */
1181 (char_u *)"grep -n $* /dev/null",
1182# else
1183# ifdef VMS
1184 (char_u *)"SEARCH/NUMBERS ",
1185# else
1186 (char_u *)"grep -n ",
1187#endif
1188#endif
1189# endif
1190 (char_u *)0L},
1191#else
1192 (char_u *)NULL, PV_NONE,
1193 {(char_u *)NULL, (char_u *)0L}
1194#endif
1195 },
1196 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1197#ifdef CURSOR_SHAPE
1198 (char_u *)&p_guicursor, PV_NONE,
1199 {
1200# ifdef FEAT_GUI
1201 (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",
1202# else /* MSDOS or Win32 console */
1203 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1204# endif
1205 (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
1210 },
1211 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1212#ifdef FEAT_GUI
1213 (char_u *)&p_guifont, PV_NONE,
1214 {(char_u *)"", (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 },
1220 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1221#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1222 (char_u *)&p_guifontset, PV_NONE,
1223 {(char_u *)"", (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
1228 },
1229 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1230#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1231 (char_u *)&p_guifontwide, PV_NONE,
1232 {(char_u *)"", (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 },
1238 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001239#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)&p_ghr, PV_NONE,
1241#else
1242 (char_u *)NULL, PV_NONE,
1243#endif
1244 {(char_u *)50L, (char_u *)0L}},
1245 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001246#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 (char_u *)&p_go, PV_NONE,
1248# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001249 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001251 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252# endif
1253#else
1254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)NULL, (char_u *)0L}
1256#endif
1257 },
1258 {"guipty", NULL, P_BOOL|P_VI_DEF,
1259#if defined(FEAT_GUI)
1260 (char_u *)&p_guipty, PV_NONE,
1261#else
1262 (char_u *)NULL, PV_NONE,
1263#endif
1264 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001265 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001266#if defined(FEAT_GUI_TABLINE)
1267 (char_u *)&p_gtl, PV_NONE,
1268 {(char_u *)"", (char_u *)0L}
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
1273 },
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001274 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001275#if defined(FEAT_GUI_TABLINE)
1276 (char_u *)&p_gtt, PV_NONE,
1277 {(char_u *)"", (char_u *)0L}
1278#else
1279 (char_u *)NULL, PV_NONE,
1280 {(char_u *)NULL, (char_u *)0L}
1281#endif
1282 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1284 (char_u *)NULL, PV_NONE,
1285 {(char_u *)0L, (char_u *)0L}},
1286 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1287 (char_u *)&p_hf, PV_NONE,
1288 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1289 {"helpheight", "hh", P_NUM|P_VI_DEF,
1290#ifdef FEAT_WINDOWS
1291 (char_u *)&p_hh, PV_NONE,
1292#else
1293 (char_u *)NULL, PV_NONE,
1294#endif
1295 {(char_u *)20L, (char_u *)0L}},
1296 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1297#ifdef FEAT_MULTI_LANG
1298 (char_u *)&p_hlg, PV_NONE,
1299 {(char_u *)"", (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)0L, (char_u *)0L}
1303#endif
1304 },
1305 {"hidden", "hid", P_BOOL|P_VI_DEF,
1306 (char_u *)&p_hid, PV_NONE,
1307 {(char_u *)FALSE, (char_u *)0L}},
1308 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1309 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar3991dab2006-03-27 17:01:56 +00001310 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {"history", "hi", P_NUM|P_VIM,
1312 (char_u *)&p_hi, PV_NONE,
1313 {(char_u *)0L, (char_u *)20L}},
1314 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1315#ifdef FEAT_RIGHTLEFT
1316 (char_u *)&p_hkmap, PV_NONE,
1317#else
1318 (char_u *)NULL, PV_NONE,
1319#endif
1320 {(char_u *)FALSE, (char_u *)0L}},
1321 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1322#ifdef FEAT_RIGHTLEFT
1323 (char_u *)&p_hkmapp, PV_NONE,
1324#else
1325 (char_u *)NULL, PV_NONE,
1326#endif
1327 {(char_u *)FALSE, (char_u *)0L}},
1328 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1329 (char_u *)&p_hls, PV_NONE,
1330 {(char_u *)FALSE, (char_u *)0L}},
1331 {"icon", NULL, P_BOOL|P_VI_DEF,
1332#ifdef FEAT_TITLE
1333 (char_u *)&p_icon, PV_NONE,
1334#else
1335 (char_u *)NULL, PV_NONE,
1336#endif
1337 {(char_u *)FALSE, (char_u *)0L}},
1338 {"iconstring", NULL, P_STRING|P_VI_DEF,
1339#ifdef FEAT_TITLE
1340 (char_u *)&p_iconstring, PV_NONE,
1341#else
1342 (char_u *)NULL, PV_NONE,
1343#endif
1344 {(char_u *)"", (char_u *)0L}},
1345 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1346 (char_u *)&p_ic, PV_NONE,
1347 {(char_u *)FALSE, (char_u *)0L}},
1348 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001349#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 (char_u *)&p_imak, PV_NONE,
1351#else
1352 (char_u *)NULL, PV_NONE,
1353#endif
1354 {(char_u *)"", (char_u *)0L}},
1355 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1356#ifdef USE_IM_CONTROL
1357 (char_u *)&p_imcmdline, PV_NONE,
1358#else
1359 (char_u *)NULL, PV_NONE,
1360#endif
1361 {(char_u *)FALSE, (char_u *)0L}},
1362 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1363#ifdef USE_IM_CONTROL
1364 (char_u *)&p_imdisable, PV_NONE,
1365#else
1366 (char_u *)NULL, PV_NONE,
1367#endif
1368#ifdef __sgi
1369 {(char_u *)TRUE, (char_u *)0L}
1370#else
1371 {(char_u *)FALSE, (char_u *)0L}
1372#endif
1373 },
1374 {"iminsert", "imi", P_NUM|P_VI_DEF,
1375 (char_u *)&p_iminsert, PV_IMI,
1376#ifdef B_IMODE_IM
1377 {(char_u *)B_IMODE_IM, (char_u *)0L}
1378#else
1379 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1380#endif
1381 },
1382 {"imsearch", "ims", P_NUM|P_VI_DEF,
1383 (char_u *)&p_imsearch, PV_IMS,
1384#ifdef B_IMODE_IM
1385 {(char_u *)B_IMODE_IM, (char_u *)0L}
1386#else
1387 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1388#endif
1389 },
1390 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1391#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001392 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1394#else
1395 (char_u *)NULL, PV_NONE,
1396 {(char_u *)0L, (char_u *)0L}
1397#endif
1398 },
1399 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1400#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1401 (char_u *)&p_inex, PV_INEX,
1402 {(char_u *)"", (char_u *)0L}
1403#else
1404 (char_u *)NULL, PV_NONE,
1405 {(char_u *)0L, (char_u *)0L}
1406#endif
1407 },
1408 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1409 (char_u *)&p_is, PV_NONE,
1410 {(char_u *)FALSE, (char_u *)0L}},
1411 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1412#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1413 (char_u *)&p_inde, PV_INDE,
1414 {(char_u *)"", (char_u *)0L}
1415#else
1416 (char_u *)NULL, PV_NONE,
1417 {(char_u *)0L, (char_u *)0L}
1418#endif
1419 },
1420 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1421#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1422 (char_u *)&p_indk, PV_INDK,
1423 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)0L, (char_u *)0L}
1427#endif
1428 },
1429 {"infercase", "inf", P_BOOL|P_VI_DEF,
1430 (char_u *)&p_inf, PV_INF,
1431 {(char_u *)FALSE, (char_u *)0L}},
1432 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1433 (char_u *)&p_im, PV_NONE,
1434 {(char_u *)FALSE, (char_u *)0L}},
1435 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1436 (char_u *)&p_isf, PV_NONE,
1437 {
1438#ifdef BACKSLASH_IN_FILENAME
1439 /* Excluded are: & and ^ are special in cmd.exe
1440 * ( and ) are used in text separating fnames */
1441 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1442#else
1443# ifdef AMIGA
1444 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1445# else
1446# ifdef VMS
1447 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1448# else /* UNIX et al. */
1449# ifdef EBCDIC
1450 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1451# else
1452 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1453# endif
1454# endif
1455# endif
1456#endif
1457 (char_u *)0L}},
1458 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1459 (char_u *)&p_isi, PV_NONE,
1460 {
1461#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1462 (char_u *)"@,48-57,_,128-167,224-235",
1463#else
1464# ifdef EBCDIC
1465 /* TODO: EBCDIC Check this! @ == isalpha()*/
1466 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1467 "112-120,128,140-142,156,158,172,"
1468 "174,186,191,203-207,219-225,235-239,"
1469 "251-254",
1470# else
1471 (char_u *)"@,48-57,_,192-255",
1472# endif
1473#endif
1474 (char_u *)0L}},
1475 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1476 (char_u *)&p_isk, PV_ISK,
1477 {
1478#ifdef EBCDIC
1479 (char_u *)"@,240-249,_",
1480 /* TODO: EBCDIC Check this! @ == isalpha()*/
1481 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1482 "112-120,128,140-142,156,158,172,"
1483 "174,186,191,203-207,219-225,235-239,"
1484 "251-254",
1485#else
1486 (char_u *)"@,48-57,_",
1487# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1488 (char_u *)"@,48-57,_,128-167,224-235"
1489# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001490 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491# endif
1492#endif
1493 }},
1494 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1495 (char_u *)&p_isp, PV_NONE,
1496 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001497#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1498 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 || defined(VMS)
1500 (char_u *)"@,~-255",
1501#else
1502# ifdef EBCDIC
1503 /* all chars above 63 are printable */
1504 (char_u *)"63-255",
1505# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001506 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507# endif
1508#endif
1509 (char_u *)0L}},
1510 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1511 (char_u *)&p_js, PV_NONE,
1512 {(char_u *)TRUE, (char_u *)0L}},
1513 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1514#ifdef FEAT_CRYPT
1515 (char_u *)&p_key, PV_KEY,
1516 {(char_u *)"", (char_u *)0L}
1517#else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)0L, (char_u *)0L}
1520#endif
1521 },
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001522 {"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 +00001523#ifdef FEAT_KEYMAP
1524 (char_u *)&p_keymap, PV_KMAP,
1525 {(char_u *)"", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)"", (char_u *)0L}
1529#endif
1530 },
1531 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1532#ifdef FEAT_VISUAL
1533 (char_u *)&p_km, PV_NONE,
1534#else
1535 (char_u *)NULL, PV_NONE,
1536#endif
1537 {(char_u *)"", (char_u *)0L}},
1538 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001539 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {
1541#if defined(MSDOS) || defined(MSWIN)
1542 (char_u *)":help",
1543#else
1544#ifdef VMS
1545 (char_u *)"help",
1546#else
1547# if defined(OS2)
1548 (char_u *)"view /",
1549# else
1550# ifdef USEMAN_S
1551 (char_u *)"man -s",
1552# else
1553 (char_u *)"man",
1554# endif
1555# endif
1556#endif
1557#endif
1558 (char_u *)0L}},
1559 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1560#ifdef FEAT_LANGMAP
1561 (char_u *)&p_langmap, PV_NONE,
1562 {(char_u *)"", /* unmatched } */
1563#else
1564 (char_u *)NULL, PV_NONE,
1565 {(char_u *)NULL,
1566#endif
1567 (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001568 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1570 (char_u *)&p_lm, PV_NONE,
1571#else
1572 (char_u *)NULL, PV_NONE,
1573#endif
1574 {(char_u *)"", (char_u *)0L}},
1575 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1576#ifdef FEAT_WINDOWS
1577 (char_u *)&p_ls, PV_NONE,
1578#else
1579 (char_u *)NULL, PV_NONE,
1580#endif
1581 {(char_u *)1L, (char_u *)0L}},
1582 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1583 (char_u *)&p_lz, PV_NONE,
1584 {(char_u *)FALSE, (char_u *)0L}},
1585 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1586#ifdef FEAT_LINEBREAK
1587 (char_u *)VAR_WIN, PV_LBR,
1588#else
1589 (char_u *)NULL, PV_NONE,
1590#endif
1591 {(char_u *)FALSE, (char_u *)0L}},
1592 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1593 (char_u *)&Rows, PV_NONE,
1594 {
1595#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1596 (char_u *)25L,
1597#else
1598 (char_u *)24L,
1599#endif
1600 (char_u *)0L}},
1601 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1602#ifdef FEAT_GUI
1603 (char_u *)&p_linespace, PV_NONE,
1604#else
1605 (char_u *)NULL, PV_NONE,
1606#endif
1607#ifdef FEAT_GUI_W32
1608 {(char_u *)1L, (char_u *)0L}
1609#else
1610 {(char_u *)0L, (char_u *)0L}
1611#endif
1612 },
1613 {"lisp", NULL, P_BOOL|P_VI_DEF,
1614#ifdef FEAT_LISP
1615 (char_u *)&p_lisp, PV_LISP,
1616#else
1617 (char_u *)NULL, PV_NONE,
1618#endif
1619 {(char_u *)FALSE, (char_u *)0L}},
1620 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1621#ifdef FEAT_LISP
1622 (char_u *)&p_lispwords, PV_NONE,
1623 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1624#else
1625 (char_u *)NULL, PV_NONE,
1626 {(char_u *)"", (char_u *)0L}
1627#endif
1628 },
1629 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1630 (char_u *)VAR_WIN, PV_LIST,
1631 {(char_u *)FALSE, (char_u *)0L}},
1632 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1633 (char_u *)&p_lcs, PV_NONE,
1634 {(char_u *)"eol:$", (char_u *)0L}},
1635 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1636 (char_u *)&p_lpl, PV_NONE,
1637 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001638#ifdef FEAT_GUI_MAC
1639 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1640 (char_u *)&p_macatsui, PV_NONE,
1641 {(char_u *)TRUE, (char_u *)0L}},
1642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"magic", NULL, P_BOOL|P_VI_DEF,
1644 (char_u *)&p_magic, PV_NONE,
1645 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001646 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647#ifdef FEAT_QUICKFIX
1648 (char_u *)&p_mef, PV_NONE,
1649 {(char_u *)"", (char_u *)0L}
1650#else
1651 (char_u *)NULL, PV_NONE,
1652 {(char_u *)NULL, (char_u *)0L}
1653#endif
1654 },
1655 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1656#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001657 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658# ifdef VMS
1659 {(char_u *)"MMS", (char_u *)0L}
1660# else
1661 {(char_u *)"make", (char_u *)0L}
1662# endif
1663#else
1664 (char_u *)NULL, PV_NONE,
1665 {(char_u *)NULL, (char_u *)0L}
1666#endif
1667 },
1668 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1669 (char_u *)&p_mps, PV_MPS,
1670 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1671 {"matchtime", "mat", P_NUM|P_VI_DEF,
1672 (char_u *)&p_mat, PV_NONE,
1673 {(char_u *)5L, (char_u *)0L}},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001674 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1675#ifdef FEAT_MBYTE
1676 (char_u *)&p_mco, PV_NONE,
1677#else
1678 (char_u *)NULL, PV_NONE,
1679#endif
1680 {(char_u *)2, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1682#ifdef FEAT_EVAL
1683 (char_u *)&p_mfd, PV_NONE,
1684#else
1685 (char_u *)NULL, PV_NONE,
1686#endif
1687 {(char_u *)100L, (char_u *)0L}},
1688 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1689 (char_u *)&p_mmd, PV_NONE,
1690 {(char_u *)1000L, (char_u *)0L}},
1691 {"maxmem", "mm", P_NUM|P_VI_DEF,
1692 (char_u *)&p_mm, PV_NONE,
1693 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001694 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1695 (char_u *)&p_mmp, PV_NONE,
1696 {(char_u *)1000L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1698 (char_u *)&p_mmt, PV_NONE,
1699 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1700 {"menuitems", "mis", P_NUM|P_VI_DEF,
1701#ifdef FEAT_MENU
1702 (char_u *)&p_mis, PV_NONE,
1703#else
1704 (char_u *)NULL, PV_NONE,
1705#endif
1706 {(char_u *)25L, (char_u *)0L}},
1707 {"mesg", NULL, P_BOOL|P_VI_DEF,
1708 (char_u *)NULL, PV_NONE,
1709 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001710 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001711#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001712 (char_u *)&p_msm, PV_NONE,
1713 {(char_u *)"460000,2000,500", (char_u *)0L}
1714#else
1715 (char_u *)NULL, PV_NONE,
1716 {(char_u *)0L, (char_u *)0L}
1717#endif
1718 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"modeline", "ml", P_BOOL|P_VIM,
1720 (char_u *)&p_ml, PV_ML,
1721 {(char_u *)FALSE, (char_u *)TRUE}},
1722 {"modelines", "mls", P_NUM|P_VI_DEF,
1723 (char_u *)&p_mls, PV_NONE,
1724 {(char_u *)5L, (char_u *)0L}},
1725 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1726 (char_u *)&p_ma, PV_MA,
1727 {(char_u *)TRUE, (char_u *)0L}},
1728 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1729 (char_u *)&p_mod, PV_MOD,
1730 {(char_u *)FALSE, (char_u *)0L}},
1731 {"more", NULL, P_BOOL|P_VIM,
1732 (char_u *)&p_more, PV_NONE,
1733 {(char_u *)FALSE, (char_u *)TRUE}},
1734 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1735 (char_u *)&p_mouse, PV_NONE,
1736 {
1737#if defined(MSDOS) || defined(WIN3264)
1738 (char_u *)"a",
1739#else
1740 (char_u *)"",
1741#endif
1742 (char_u *)0L}},
1743 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1744#ifdef FEAT_GUI
1745 (char_u *)&p_mousef, PV_NONE,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
1749 {(char_u *)FALSE, (char_u *)0L}},
1750 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1751#ifdef FEAT_GUI
1752 (char_u *)&p_mh, PV_NONE,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
1756 {(char_u *)TRUE, (char_u *)0L}},
1757 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1758 (char_u *)&p_mousem, PV_NONE,
1759 {
1760#if defined(MSDOS) || defined(MSWIN)
1761 (char_u *)"popup",
1762#else
1763# if defined(MACOS)
1764 (char_u *)"popup_setpos",
1765# else
1766 (char_u *)"extend",
1767# endif
1768#endif
1769 (char_u *)0L}},
1770 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1771#ifdef FEAT_MOUSESHAPE
1772 (char_u *)&p_mouseshape, PV_NONE,
1773 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1774#else
1775 (char_u *)NULL, PV_NONE,
1776 {(char_u *)NULL, (char_u *)0L}
1777#endif
1778 },
1779 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1780 (char_u *)&p_mouset, PV_NONE,
1781 {(char_u *)500L, (char_u *)0L}},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001782 {"mzquantum", "mzq", P_NUM,
1783#ifdef FEAT_MZSCHEME
1784 (char_u *)&p_mzq, PV_NONE,
1785#else
1786 (char_u *)NULL, PV_NONE,
1787#endif
1788 {(char_u *)100L, (char_u *)100L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"novice", NULL, P_BOOL|P_VI_DEF,
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)FALSE, (char_u *)0L}},
1792 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1793 (char_u *)&p_nf, PV_NF,
1794 {(char_u *)"octal,hex", (char_u *)0L}},
1795 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1796 (char_u *)VAR_WIN, PV_NU,
1797 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001798 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1799#ifdef FEAT_LINEBREAK
1800 (char_u *)VAR_WIN, PV_NUW,
1801#else
1802 (char_u *)NULL, PV_NONE,
1803#endif
1804 {(char_u *)8L, (char_u *)4L}},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001805 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001806#ifdef FEAT_COMPL_FUNC
1807 (char_u *)&p_ofu, PV_OFU,
1808 {(char_u *)"", (char_u *)0L}
1809#else
1810 (char_u *)NULL, PV_NONE,
1811 {(char_u *)0L, (char_u *)0L}
1812#endif
1813 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {"open", NULL, P_BOOL|P_VI_DEF,
1815 (char_u *)NULL, PV_NONE,
1816 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001817 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1818#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1819 (char_u *)&p_odev, PV_NONE,
1820#else
1821 (char_u *)NULL, PV_NONE,
1822#endif
1823 {(char_u *)FALSE, (char_u *)FALSE}
1824 },
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001825 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1826 (char_u *)&p_opfunc, PV_NONE,
1827 {(char_u *)"", (char_u *)0L} },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"optimize", "opt", P_BOOL|P_VI_DEF,
1829 (char_u *)NULL, PV_NONE,
1830 {(char_u *)FALSE, (char_u *)0L}},
1831 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1832#ifdef FEAT_OSFILETYPE
1833 (char_u *)&p_oft, PV_OFT,
1834 {(char_u *)DFLT_OFT, (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)0L, (char_u *)0L}
1838#endif
1839 },
1840 {"paragraphs", "para", P_STRING|P_VI_DEF,
1841 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001842 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
1843 (char_u *)0L}},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001844 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 (char_u *)&p_paste, PV_NONE,
1846 {(char_u *)FALSE, (char_u *)0L}},
1847 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1848 (char_u *)&p_pt, PV_NONE,
1849 {(char_u *)"", (char_u *)0L}},
1850 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1851#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1852 (char_u *)&p_pex, PV_NONE,
1853 {(char_u *)"", (char_u *)0L}
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)0L, (char_u *)0L}
1857#endif
1858 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001859 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 (char_u *)&p_pm, PV_NONE,
1861 {(char_u *)"", (char_u *)0L}},
1862 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001863 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {
1865#if defined AMIGA || defined MSDOS || defined MSWIN
1866 (char_u *)".,,",
1867#else
1868# if defined(__EMX__)
1869 (char_u *)".,/emx/include,,",
1870# else /* Unix, probably */
1871 (char_u *)".,/usr/include,,",
1872# endif
1873#endif
1874 (char_u *)0L}},
1875 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1876 (char_u *)&p_pi, PV_PI,
1877 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001878 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1880 (char_u *)&p_pvh, PV_NONE,
1881#else
1882 (char_u *)NULL, PV_NONE,
1883#endif
1884 {(char_u *)12L, (char_u *)0L}},
1885 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1886#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1887 (char_u *)VAR_WIN, PV_PVW,
1888#else
1889 (char_u *)NULL, PV_NONE,
1890#endif
1891 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001892 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893#ifdef FEAT_PRINTER
1894 (char_u *)&p_pdev, PV_NONE,
1895 {(char_u *)"", (char_u *)0L}
1896#else
1897 (char_u *)NULL, PV_NONE,
1898 {(char_u *)NULL, (char_u *)0L}
1899#endif
1900 },
1901 {"printencoding", "penc", P_STRING|P_VI_DEF,
1902#ifdef FEAT_POSTSCRIPT
1903 (char_u *)&p_penc, PV_NONE,
1904 {(char_u *)"", (char_u *)0L}
1905#else
1906 (char_u *)NULL, PV_NONE,
1907 {(char_u *)NULL, (char_u *)0L}
1908#endif
1909 },
1910 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1911#ifdef FEAT_POSTSCRIPT
1912 (char_u *)&p_pexpr, PV_NONE,
1913 {(char_u *)"", (char_u *)0L}
1914#else
1915 (char_u *)NULL, PV_NONE,
1916 {(char_u *)NULL, (char_u *)0L}
1917#endif
1918 },
1919 {"printfont", "pfn", P_STRING|P_VI_DEF,
1920#ifdef FEAT_PRINTER
1921 (char_u *)&p_pfn, PV_NONE,
1922 {
1923# ifdef MSWIN
1924 (char_u *)"Courier_New:h10",
1925# else
1926 (char_u *)"courier",
1927# endif
1928 (char_u *)0L}
1929#else
1930 (char_u *)NULL, PV_NONE,
1931 {(char_u *)NULL, (char_u *)0L}
1932#endif
1933 },
1934 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1935#ifdef FEAT_PRINTER
1936 (char_u *)&p_header, PV_NONE,
1937 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1938#else
1939 (char_u *)NULL, PV_NONE,
1940 {(char_u *)NULL, (char_u *)0L}
1941#endif
1942 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001943 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1944#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1945 (char_u *)&p_pmcs, PV_NONE,
1946 {(char_u *)"", (char_u *)0L}
1947#else
1948 (char_u *)NULL, PV_NONE,
1949 {(char_u *)NULL, (char_u *)0L}
1950#endif
1951 },
1952 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1953#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1954 (char_u *)&p_pmfn, PV_NONE,
1955 {(char_u *)"", (char_u *)0L}
1956#else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)NULL, (char_u *)0L}
1959#endif
1960 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1962#ifdef FEAT_PRINTER
1963 (char_u *)&p_popt, PV_NONE,
1964 {(char_u *)"", (char_u *)0L}
1965#else
1966 (char_u *)NULL, PV_NONE,
1967 {(char_u *)NULL, (char_u *)0L}
1968#endif
1969 },
1970 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001971 (char_u *)&p_prompt, PV_NONE,
1972 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00001973 {"pumheight", "ph", P_NUM|P_VI_DEF,
1974#ifdef FEAT_INS_EXPAND
1975 (char_u *)&p_ph, PV_NONE,
1976#else
1977 (char_u *)NULL, PV_NONE,
1978#endif
1979 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001980 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1981#ifdef FEAT_TEXTOBJ
1982 (char_u *)&p_qe, PV_QE,
1983 {(char_u *)"\\", (char_u *)0L}
1984#else
1985 (char_u *)NULL, PV_NONE,
1986 {(char_u *)NULL, (char_u *)0L}
1987#endif
1988 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1990 (char_u *)&p_ro, PV_RO,
1991 {(char_u *)FALSE, (char_u *)0L}},
1992 {"redraw", NULL, P_BOOL|P_VI_DEF,
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00001995 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
1996#ifdef FEAT_RELTIME
1997 (char_u *)&p_rdt, PV_NONE,
1998#else
1999 (char_u *)NULL, PV_NONE,
2000#endif
2001 {(char_u *)2000L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"remap", NULL, P_BOOL|P_VI_DEF,
2003 (char_u *)&p_remap, PV_NONE,
2004 {(char_u *)TRUE, (char_u *)0L}},
2005 {"report", NULL, P_NUM|P_VI_DEF,
2006 (char_u *)&p_report, PV_NONE,
2007 {(char_u *)2L, (char_u *)0L}},
2008 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2009#ifdef WIN3264
2010 (char_u *)&p_rs, PV_NONE,
2011#else
2012 (char_u *)NULL, PV_NONE,
2013#endif
2014 {(char_u *)TRUE, (char_u *)0L}},
2015 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2016#ifdef FEAT_RIGHTLEFT
2017 (char_u *)&p_ri, PV_NONE,
2018#else
2019 (char_u *)NULL, PV_NONE,
2020#endif
2021 {(char_u *)FALSE, (char_u *)0L}},
2022 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2023#ifdef FEAT_RIGHTLEFT
2024 (char_u *)VAR_WIN, PV_RL,
2025#else
2026 (char_u *)NULL, PV_NONE,
2027#endif
2028 {(char_u *)FALSE, (char_u *)0L}},
2029 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2030#ifdef FEAT_RIGHTLEFT
2031 (char_u *)VAR_WIN, PV_RLC,
2032 {(char_u *)"search", (char_u *)NULL}
2033#else
2034 (char_u *)NULL, PV_NONE,
2035 {(char_u *)NULL, (char_u *)0L}
2036#endif
2037 },
2038 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2039#ifdef FEAT_CMDL_INFO
2040 (char_u *)&p_ru, PV_NONE,
2041#else
2042 (char_u *)NULL, PV_NONE,
2043#endif
2044 {(char_u *)FALSE, (char_u *)0L}},
2045 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2046#ifdef FEAT_STL_OPT
2047 (char_u *)&p_ruf, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
2051 {(char_u *)"", (char_u *)0L}},
2052 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2053 (char_u *)&p_rtp, PV_NONE,
2054 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
2055 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2056 (char_u *)VAR_WIN, PV_SCROLL,
2057 {(char_u *)12L, (char_u *)0L}},
2058 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2059#ifdef FEAT_SCROLLBIND
2060 (char_u *)VAR_WIN, PV_SCBIND,
2061#else
2062 (char_u *)NULL, PV_NONE,
2063#endif
2064 {(char_u *)FALSE, (char_u *)0L}},
2065 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2066 (char_u *)&p_sj, PV_NONE,
2067 {(char_u *)1L, (char_u *)0L}},
2068 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2069 (char_u *)&p_so, PV_NONE,
2070 {(char_u *)0L, (char_u *)0L}},
2071 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2072#ifdef FEAT_SCROLLBIND
2073 (char_u *)&p_sbo, PV_NONE,
2074 {(char_u *)"ver,jump", (char_u *)0L}
2075#else
2076 (char_u *)NULL, PV_NONE,
2077 {(char_u *)0L, (char_u *)0L}
2078#endif
2079 },
2080 {"sections", "sect", P_STRING|P_VI_DEF,
2081 (char_u *)&p_sections, PV_NONE,
2082 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
2083 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2084 (char_u *)&p_secure, PV_NONE,
2085 {(char_u *)FALSE, (char_u *)0L}},
2086 {"selection", "sel", P_STRING|P_VI_DEF,
2087#ifdef FEAT_VISUAL
2088 (char_u *)&p_sel, PV_NONE,
2089#else
2090 (char_u *)NULL, PV_NONE,
2091#endif
2092 {(char_u *)"inclusive", (char_u *)0L}},
2093 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2094#ifdef FEAT_VISUAL
2095 (char_u *)&p_slm, PV_NONE,
2096#else
2097 (char_u *)NULL, PV_NONE,
2098#endif
2099 {(char_u *)"", (char_u *)0L}},
2100 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2101#ifdef FEAT_SESSION
2102 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002103 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)0L, (char_u *)0L}
2108#endif
2109 },
2110 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2111 (char_u *)&p_sh, PV_NONE,
2112 {
2113#ifdef VMS
2114 (char_u *)"-",
2115#else
2116# if defined(MSDOS)
2117 (char_u *)"command",
2118# else
2119# if defined(WIN16)
2120 (char_u *)"command.com",
2121# else
2122# if defined(WIN3264)
2123 (char_u *)"", /* set in set_init_1() */
2124# else
2125# if defined(OS2)
2126 (char_u *)"cmd.exe",
2127# else
2128# if defined(ARCHIE)
2129 (char_u *)"gos",
2130# else
2131 (char_u *)"sh",
2132# endif
2133# endif
2134# endif
2135# endif
2136# endif
2137#endif /* VMS */
2138 (char_u *)0L}},
2139 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2140 (char_u *)&p_shcf, PV_NONE,
2141 {
2142#if defined(MSDOS) || defined(MSWIN)
2143 (char_u *)"/c",
2144#else
2145# if defined(OS2)
2146 (char_u *)"/c",
2147# else
2148 (char_u *)"-c",
2149# endif
2150#endif
2151 (char_u *)0L}},
2152 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2153#ifdef FEAT_QUICKFIX
2154 (char_u *)&p_sp, PV_NONE,
2155 {
2156#if defined(UNIX) || defined(OS2)
2157# ifdef ARCHIE
2158 (char_u *)"2>",
2159# else
2160 (char_u *)"| tee",
2161# endif
2162#else
2163 (char_u *)">",
2164#endif
2165 (char_u *)0L}
2166#else
2167 (char_u *)NULL, PV_NONE,
2168 {(char_u *)0L, (char_u *)0L}
2169#endif
2170 },
2171 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2172 (char_u *)&p_shq, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}},
2174 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2175 (char_u *)&p_srr, PV_NONE,
2176 {(char_u *)">", (char_u *)0L}},
2177 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2178#ifdef BACKSLASH_IN_FILENAME
2179 (char_u *)&p_ssl, PV_NONE,
2180#else
2181 (char_u *)NULL, PV_NONE,
2182#endif
2183 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002184 {"shelltemp", "stmp", P_BOOL,
2185 (char_u *)&p_stmp, PV_NONE,
2186 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"shelltype", "st", P_NUM|P_VI_DEF,
2188#ifdef AMIGA
2189 (char_u *)&p_st, PV_NONE,
2190#else
2191 (char_u *)NULL, PV_NONE,
2192#endif
2193 {(char_u *)0L, (char_u *)0L}},
2194 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2195 (char_u *)&p_sxq, PV_NONE,
2196 {
2197#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2198 (char_u *)"\"",
2199#else
2200 (char_u *)"",
2201#endif
2202 (char_u *)0L}},
2203 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2204 (char_u *)&p_sr, PV_NONE,
2205 {(char_u *)FALSE, (char_u *)0L}},
2206 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2207 (char_u *)&p_sw, PV_SW,
2208 {(char_u *)8L, (char_u *)0L}},
2209 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2210 (char_u *)&p_shm, PV_NONE,
2211 {(char_u *)"", (char_u *)"filnxtToO"}},
2212 {"shortname", "sn", P_BOOL|P_VI_DEF,
2213#ifdef SHORT_FNAME
2214 (char_u *)NULL, PV_NONE,
2215#else
2216 (char_u *)&p_sn, PV_SN,
2217#endif
2218 {(char_u *)FALSE, (char_u *)0L}},
2219 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2220#ifdef FEAT_LINEBREAK
2221 (char_u *)&p_sbr, PV_NONE,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
2225 {(char_u *)"", (char_u *)0L}},
2226 {"showcmd", "sc", P_BOOL|P_VIM,
2227#ifdef FEAT_CMDL_INFO
2228 (char_u *)&p_sc, PV_NONE,
2229#else
2230 (char_u *)NULL, PV_NONE,
2231#endif
2232 {(char_u *)FALSE,
2233#ifdef UNIX
2234 (char_u *)FALSE
2235#else
2236 (char_u *)TRUE
2237#endif
2238 }},
2239 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2240 (char_u *)&p_sft, PV_NONE,
2241 {(char_u *)FALSE, (char_u *)0L}},
2242 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2243 (char_u *)&p_sm, PV_NONE,
2244 {(char_u *)FALSE, (char_u *)0L}},
2245 {"showmode", "smd", P_BOOL|P_VIM,
2246 (char_u *)&p_smd, PV_NONE,
2247 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002248 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2249#ifdef FEAT_WINDOWS
2250 (char_u *)&p_stal, PV_NONE,
2251#else
2252 (char_u *)NULL, PV_NONE,
2253#endif
2254 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2256 (char_u *)&p_ss, PV_NONE,
2257 {(char_u *)0L, (char_u *)0L}},
2258 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2259 (char_u *)&p_siso, PV_NONE,
2260 {(char_u *)0L, (char_u *)0L}},
2261 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)FALSE, (char_u *)0L}},
2264 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2265 (char_u *)&p_scs, PV_NONE,
2266 {(char_u *)FALSE, (char_u *)0L}},
2267 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2268#ifdef FEAT_SMARTINDENT
2269 (char_u *)&p_si, PV_SI,
2270#else
2271 (char_u *)NULL, PV_NONE,
2272#endif
2273 {(char_u *)FALSE, (char_u *)0L}},
2274 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2275 (char_u *)&p_sta, PV_NONE,
2276 {(char_u *)FALSE, (char_u *)0L}},
2277 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2278 (char_u *)&p_sts, PV_STS,
2279 {(char_u *)0L, (char_u *)0L}},
2280 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2281 (char_u *)NULL, PV_NONE,
2282 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002283 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002284#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002285 (char_u *)VAR_WIN, PV_SPELL,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
2289 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002290 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002291#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002292 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002293 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002294#else
2295 (char_u *)NULL, PV_NONE,
2296 {(char_u *)0L, (char_u *)0L}
2297#endif
2298 },
2299 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002300#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002301 (char_u *)&p_spf, PV_SPF,
2302 {(char_u *)"", (char_u *)0L}
2303#else
2304 (char_u *)NULL, PV_NONE,
2305 {(char_u *)0L, (char_u *)0L}
2306#endif
2307 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002308 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002309#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002310 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002311 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002312#else
2313 (char_u *)NULL, PV_NONE,
2314 {(char_u *)0L, (char_u *)0L}
2315#endif
2316 },
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002317 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002318#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002319 (char_u *)&p_sps, PV_NONE,
2320 {(char_u *)"best", (char_u *)0L}
2321#else
2322 (char_u *)NULL, PV_NONE,
2323 {(char_u *)0L, (char_u *)0L}
2324#endif
2325 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2327#ifdef FEAT_WINDOWS
2328 (char_u *)&p_sb, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
2332 {(char_u *)FALSE, (char_u *)0L}},
2333 {"splitright", "spr", P_BOOL|P_VI_DEF,
2334#ifdef FEAT_VERTSPLIT
2335 (char_u *)&p_spr, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
2339 {(char_u *)FALSE, (char_u *)0L}},
2340 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2341 (char_u *)&p_sol, PV_NONE,
2342 {(char_u *)TRUE, (char_u *)0L}},
2343 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2344#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002345 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
2349 {(char_u *)"", (char_u *)0L}},
2350 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2351 (char_u *)&p_su, PV_NONE,
2352 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2353 (char_u *)0L}},
2354 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002355#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 (char_u *)&p_sua, PV_SUA,
2357 {(char_u *)"", (char_u *)0L}
2358#else
2359 (char_u *)NULL, PV_NONE,
2360 {(char_u *)0L, (char_u *)0L}
2361#endif
2362 },
2363 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2364 (char_u *)&p_swf, PV_SWF,
2365 {(char_u *)TRUE, (char_u *)0L}},
2366 {"swapsync", "sws", P_STRING|P_VI_DEF,
2367 (char_u *)&p_sws, PV_NONE,
2368 {(char_u *)"fsync", (char_u *)0L}},
2369 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2370 (char_u *)&p_swb, PV_NONE,
2371 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002372 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2373#ifdef FEAT_SYN_HL
2374 (char_u *)&p_smc, PV_SMC,
2375 {(char_u *)3000L, (char_u *)0L}
2376#else
2377 (char_u *)NULL, PV_NONE,
2378 {(char_u *)0L, (char_u *)0L}
2379#endif
2380 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002381 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382#ifdef FEAT_SYN_HL
2383 (char_u *)&p_syn, PV_SYN,
2384 {(char_u *)"", (char_u *)0L}
2385#else
2386 (char_u *)NULL, PV_NONE,
2387 {(char_u *)0L, (char_u *)0L}
2388#endif
2389 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002390 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2391#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002392 (char_u *)&p_tal, PV_NONE,
2393#else
2394 (char_u *)NULL, PV_NONE,
2395#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002396 {(char_u *)"", (char_u *)0L}},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002397 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2398#ifdef FEAT_WINDOWS
2399 (char_u *)&p_tpm, PV_NONE,
2400#else
2401 (char_u *)NULL, PV_NONE,
2402#endif
2403 {(char_u *)10L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2405 (char_u *)&p_ts, PV_TS,
2406 {(char_u *)8L, (char_u *)0L}},
2407 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2408 (char_u *)&p_tbs, PV_NONE,
2409#ifdef VMS /* binary searching doesn't appear to work on VMS */
2410 {(char_u *)0L, (char_u *)0L}
2411#else
2412 {(char_u *)TRUE, (char_u *)0L}
2413#endif
2414 },
2415 {"taglength", "tl", P_NUM|P_VI_DEF,
2416 (char_u *)&p_tl, PV_NONE,
2417 {(char_u *)0L, (char_u *)0L}},
2418 {"tagrelative", "tr", P_BOOL|P_VIM,
2419 (char_u *)&p_tr, PV_NONE,
2420 {(char_u *)FALSE, (char_u *)TRUE}},
2421 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002422 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {
2424#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2425 (char_u *)"./tags,./TAGS,tags,TAGS",
2426#else
2427 (char_u *)"./tags,tags",
2428#endif
2429 (char_u *)0L}},
2430 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2431 (char_u *)&p_tgst, PV_NONE,
2432 {(char_u *)TRUE, (char_u *)0L}},
2433 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2434 (char_u *)&T_NAME, PV_NONE,
2435 {(char_u *)"", (char_u *)0L}},
2436 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2437#ifdef FEAT_ARABIC
2438 (char_u *)&p_tbidi, PV_NONE,
2439#else
2440 (char_u *)NULL, PV_NONE,
2441#endif
2442 {(char_u *)FALSE, (char_u *)0L}},
2443 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2444#ifdef FEAT_MBYTE
2445 (char_u *)&p_tenc, PV_NONE,
2446 {(char_u *)"", (char_u *)0L}
2447#else
2448 (char_u *)NULL, PV_NONE,
2449 {(char_u *)0L, (char_u *)0L}
2450#endif
2451 },
2452 {"terse", NULL, P_BOOL|P_VI_DEF,
2453 (char_u *)&p_terse, PV_NONE,
2454 {(char_u *)FALSE, (char_u *)0L}},
2455 {"textauto", "ta", P_BOOL|P_VIM,
2456 (char_u *)&p_ta, PV_NONE,
2457 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2458 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2459 (char_u *)&p_tx, PV_TX,
2460 {
2461#ifdef USE_CRNL
2462 (char_u *)TRUE,
2463#else
2464 (char_u *)FALSE,
2465#endif
2466 (char_u *)0L}},
2467 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2468 (char_u *)&p_tw, PV_TW,
2469 {(char_u *)0L, (char_u *)0L}},
2470 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2471#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002472 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
2476 {(char_u *)"", (char_u *)0L}},
2477 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2478 (char_u *)&p_to, PV_NONE,
2479 {(char_u *)FALSE, (char_u *)0L}},
2480 {"timeout", "to", P_BOOL|P_VI_DEF,
2481 (char_u *)&p_timeout, PV_NONE,
2482 {(char_u *)TRUE, (char_u *)0L}},
2483 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2484 (char_u *)&p_tm, PV_NONE,
2485 {(char_u *)1000L, (char_u *)0L}},
2486 {"title", NULL, P_BOOL|P_VI_DEF,
2487#ifdef FEAT_TITLE
2488 (char_u *)&p_title, PV_NONE,
2489#else
2490 (char_u *)NULL, PV_NONE,
2491#endif
2492 {(char_u *)FALSE, (char_u *)0L}},
2493 {"titlelen", NULL, P_NUM|P_VI_DEF,
2494#ifdef FEAT_TITLE
2495 (char_u *)&p_titlelen, PV_NONE,
2496#else
2497 (char_u *)NULL, PV_NONE,
2498#endif
2499 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002500 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501#ifdef FEAT_TITLE
2502 (char_u *)&p_titleold, PV_NONE,
2503 {(char_u *)N_("Thanks for flying Vim"),
2504 (char_u *)0L}
2505#else
2506 (char_u *)NULL, PV_NONE,
2507 {(char_u *)0L, (char_u *)0L}
2508#endif
2509 },
2510 {"titlestring", NULL, P_STRING|P_VI_DEF,
2511#ifdef FEAT_TITLE
2512 (char_u *)&p_titlestring, PV_NONE,
2513#else
2514 (char_u *)NULL, PV_NONE,
2515#endif
2516 {(char_u *)"", (char_u *)0L}},
2517#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2518 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2519 (char_u *)&p_toolbar, PV_NONE,
2520 {(char_u *)"icons,tooltips", (char_u *)0L}},
2521#endif
2522#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2523 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2524 (char_u *)&p_tbis, PV_NONE,
2525 {(char_u *)"small", (char_u *)0L}},
2526#endif
2527 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2528 (char_u *)&p_ttimeout, PV_NONE,
2529 {(char_u *)FALSE, (char_u *)0L}},
2530 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2531 (char_u *)&p_ttm, PV_NONE,
2532 {(char_u *)-1L, (char_u *)0L}},
2533 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2534 (char_u *)&p_tbi, PV_NONE,
2535 {(char_u *)TRUE, (char_u *)0L}},
2536 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2537 (char_u *)&p_tf, PV_NONE,
2538 {(char_u *)FALSE, (char_u *)0L}},
2539 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2540#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2541 (char_u *)&p_ttym, PV_NONE,
2542#else
2543 (char_u *)NULL, PV_NONE,
2544#endif
2545 {(char_u *)"", (char_u *)0L}},
2546 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2547 (char_u *)&p_ttyscroll, PV_NONE,
2548 {(char_u *)999L, (char_u *)0L}},
2549 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2550 (char_u *)&T_NAME, PV_NONE,
2551 {(char_u *)"", (char_u *)0L}},
2552 {"undolevels", "ul", P_NUM|P_VI_DEF,
2553 (char_u *)&p_ul, PV_NONE,
2554 {
2555#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2556 (char_u *)1000L,
2557#else
2558 (char_u *)100L,
2559#endif
2560 (char_u *)0L}},
2561 {"updatecount", "uc", P_NUM|P_VI_DEF,
2562 (char_u *)&p_uc, PV_NONE,
2563 {(char_u *)200L, (char_u *)0L}},
2564 {"updatetime", "ut", P_NUM|P_VI_DEF,
2565 (char_u *)&p_ut, PV_NONE,
2566 {(char_u *)4000L, (char_u *)0L}},
2567 {"verbose", "vbs", P_NUM|P_VI_DEF,
2568 (char_u *)&p_verbose, PV_NONE,
2569 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002570 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2571 (char_u *)&p_vfile, PV_NONE,
2572 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2574#ifdef FEAT_SESSION
2575 (char_u *)&p_vdir, PV_NONE,
2576 {(char_u *)DFLT_VDIR, (char_u *)0L}
2577#else
2578 (char_u *)NULL, PV_NONE,
2579 {(char_u *)0L, (char_u *)0L}
2580#endif
2581 },
2582 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2583#ifdef FEAT_SESSION
2584 (char_u *)&p_vop, PV_NONE,
2585 {(char_u *)"folds,options,cursor", (char_u *)0L}
2586#else
2587 (char_u *)NULL, PV_NONE,
2588 {(char_u *)0L, (char_u *)0L}
2589#endif
2590 },
2591 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2592#ifdef FEAT_VIMINFO
2593 (char_u *)&p_viminfo, PV_NONE,
2594#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2595 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2596#else
2597# ifdef AMIGA
2598 {(char_u *)"",
2599 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2600# else
2601 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2602# endif
2603#endif
2604#else
2605 (char_u *)NULL, PV_NONE,
2606 {(char_u *)0L, (char_u *)0L}
2607#endif
2608 },
2609 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2610#ifdef FEAT_VIRTUALEDIT
2611 (char_u *)&p_ve, PV_NONE,
2612 {(char_u *)"", (char_u *)""}
2613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
2617 },
2618 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2619 (char_u *)&p_vb, PV_NONE,
2620 {(char_u *)FALSE, (char_u *)0L}},
2621 {"w300", NULL, P_NUM|P_VI_DEF,
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}},
2624 {"w1200", NULL, P_NUM|P_VI_DEF,
2625 (char_u *)NULL, PV_NONE,
2626 {(char_u *)0L, (char_u *)0L}},
2627 {"w9600", NULL, P_NUM|P_VI_DEF,
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}},
2630 {"warn", NULL, P_BOOL|P_VI_DEF,
2631 (char_u *)&p_warn, PV_NONE,
2632 {(char_u *)TRUE, (char_u *)0L}},
2633 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2634 (char_u *)&p_wiv, PV_NONE,
2635 {(char_u *)FALSE, (char_u *)0L}},
2636 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2637 (char_u *)&p_ww, PV_NONE,
2638 {(char_u *)"", (char_u *)"b,s"}},
2639 {"wildchar", "wc", P_NUM|P_VIM,
2640 (char_u *)&p_wc, PV_NONE,
2641 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2642 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2643 (char_u *)&p_wcm, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}},
2645 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2646#ifdef FEAT_WILDIGN
2647 (char_u *)&p_wig, PV_NONE,
2648#else
2649 (char_u *)NULL, PV_NONE,
2650#endif
2651 {(char_u *)"", (char_u *)0L}},
2652 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2653#ifdef FEAT_WILDMENU
2654 (char_u *)&p_wmnu, PV_NONE,
2655#else
2656 (char_u *)NULL, PV_NONE,
2657#endif
2658 {(char_u *)FALSE, (char_u *)0L}},
2659 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2660 (char_u *)&p_wim, PV_NONE,
2661 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002662 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2663#ifdef FEAT_CMDL_COMPL
2664 (char_u *)&p_wop, PV_NONE,
2665 {(char_u *)"", (char_u *)0L}
2666#else
2667 (char_u *)NULL, PV_NONE,
2668 {(char_u *)NULL, (char_u *)0L}
2669#endif
2670 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2672#ifdef FEAT_WAK
2673 (char_u *)&p_wak, PV_NONE,
2674 {(char_u *)"menu", (char_u *)0L}
2675#else
2676 (char_u *)NULL, PV_NONE,
2677 {(char_u *)NULL, (char_u *)0L}
2678#endif
2679 },
2680 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002681 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {(char_u *)0L, (char_u *)0L}},
2683 {"winheight", "wh", P_NUM|P_VI_DEF,
2684#ifdef FEAT_WINDOWS
2685 (char_u *)&p_wh, PV_NONE,
2686#else
2687 (char_u *)NULL, PV_NONE,
2688#endif
2689 {(char_u *)1L, (char_u *)0L}},
2690 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002691#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 (char_u *)VAR_WIN, PV_WFH,
2693#else
2694 (char_u *)NULL, PV_NONE,
2695#endif
2696 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002697 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2698#ifdef FEAT_VERTSPLIT
2699 (char_u *)VAR_WIN, PV_WFW,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
2703 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2705#ifdef FEAT_WINDOWS
2706 (char_u *)&p_wmh, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
2710 {(char_u *)1L, (char_u *)0L}},
2711 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2712#ifdef FEAT_VERTSPLIT
2713 (char_u *)&p_wmw, PV_NONE,
2714#else
2715 (char_u *)NULL, PV_NONE,
2716#endif
2717 {(char_u *)1L, (char_u *)0L}},
2718 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2719#ifdef FEAT_VERTSPLIT
2720 (char_u *)&p_wiw, PV_NONE,
2721#else
2722 (char_u *)NULL, PV_NONE,
2723#endif
2724 {(char_u *)20L, (char_u *)0L}},
2725 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2726 (char_u *)VAR_WIN, PV_WRAP,
2727 {(char_u *)TRUE, (char_u *)0L}},
2728 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2729 (char_u *)&p_wm, PV_WM,
2730 {(char_u *)0L, (char_u *)0L}},
2731 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2732 (char_u *)&p_ws, PV_NONE,
2733 {(char_u *)TRUE, (char_u *)0L}},
2734 {"write", NULL, P_BOOL|P_VI_DEF,
2735 (char_u *)&p_write, PV_NONE,
2736 {(char_u *)TRUE, (char_u *)0L}},
2737 {"writeany", "wa", P_BOOL|P_VI_DEF,
2738 (char_u *)&p_wa, PV_NONE,
2739 {(char_u *)FALSE, (char_u *)0L}},
2740 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2741 (char_u *)&p_wb, PV_NONE,
2742 {
2743#ifdef FEAT_WRITEBACKUP
2744 (char_u *)TRUE,
2745#else
2746 (char_u *)FALSE,
2747#endif
2748 (char_u *)0L}},
2749 {"writedelay", "wd", P_NUM|P_VI_DEF,
2750 (char_u *)&p_wd, PV_NONE,
2751 {(char_u *)0L, (char_u *)0L}},
2752
2753/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002754#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 (char_u *)&vvv, PV_NONE, \
2756 {(char_u *)"", (char_u *)0L}},
2757
2758 p_term("t_AB", T_CAB)
2759 p_term("t_AF", T_CAF)
2760 p_term("t_AL", T_CAL)
2761 p_term("t_al", T_AL)
2762 p_term("t_bc", T_BC)
2763 p_term("t_cd", T_CD)
2764 p_term("t_ce", T_CE)
2765 p_term("t_cl", T_CL)
2766 p_term("t_cm", T_CM)
2767 p_term("t_Co", T_CCO)
2768 p_term("t_CS", T_CCS)
2769 p_term("t_cs", T_CS)
2770#ifdef FEAT_VERTSPLIT
2771 p_term("t_CV", T_CSV)
2772#endif
2773 p_term("t_ut", T_UT)
2774 p_term("t_da", T_DA)
2775 p_term("t_db", T_DB)
2776 p_term("t_DL", T_CDL)
2777 p_term("t_dl", T_DL)
2778 p_term("t_fs", T_FS)
2779 p_term("t_IE", T_CIE)
2780 p_term("t_IS", T_CIS)
2781 p_term("t_ke", T_KE)
2782 p_term("t_ks", T_KS)
2783 p_term("t_le", T_LE)
2784 p_term("t_mb", T_MB)
2785 p_term("t_md", T_MD)
2786 p_term("t_me", T_ME)
2787 p_term("t_mr", T_MR)
2788 p_term("t_ms", T_MS)
2789 p_term("t_nd", T_ND)
2790 p_term("t_op", T_OP)
2791 p_term("t_RI", T_CRI)
2792 p_term("t_RV", T_CRV)
2793 p_term("t_Sb", T_CSB)
2794 p_term("t_Sf", T_CSF)
2795 p_term("t_se", T_SE)
2796 p_term("t_so", T_SO)
2797 p_term("t_sr", T_SR)
2798 p_term("t_ts", T_TS)
2799 p_term("t_te", T_TE)
2800 p_term("t_ti", T_TI)
2801 p_term("t_ue", T_UE)
2802 p_term("t_us", T_US)
2803 p_term("t_vb", T_VB)
2804 p_term("t_ve", T_VE)
2805 p_term("t_vi", T_VI)
2806 p_term("t_vs", T_VS)
2807 p_term("t_WP", T_CWP)
2808 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002809 p_term("t_SI", T_CSI)
2810 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 p_term("t_xs", T_XS)
2812 p_term("t_ZH", T_CZH)
2813 p_term("t_ZR", T_CZR)
2814
2815/* terminal key codes are not in here */
2816
2817 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2818};
2819
2820#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2821
2822#ifdef FEAT_MBYTE
2823static char *(p_ambw_values[]) = {"single", "double", NULL};
2824#endif
2825static char *(p_bg_values[]) = {"light", "dark", NULL};
2826static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2827static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002828#ifdef FEAT_CMDL_COMPL
2829static char *(p_wop_values[]) = {"tagfile", NULL};
2830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#ifdef FEAT_WAK
2832static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2833#endif
2834static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2835#ifdef FEAT_VISUAL
2836static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2837static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2838#endif
2839#ifdef FEAT_VISUAL
2840static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2841#endif
2842#ifdef FEAT_BROWSE
2843static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2844#endif
2845#ifdef FEAT_SCROLLBIND
2846static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2847#endif
Bram Moolenaar779b74b2006-04-10 14:55:34 +00002848static char *(p_swb_values[]) = {"useopen", "usetab", "split", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00002849static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850#ifdef FEAT_VERTSPLIT
2851static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2852#endif
2853#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002854# ifdef FEAT_AUTOCMD
2855static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2856# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002858# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2860#endif
2861static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2862#ifdef FEAT_FOLDING
2863static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002864# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002866# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 NULL};
2868static char *(p_fcl_values[]) = {"all", NULL};
2869#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002870#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002871static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002872#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873
2874static void set_option_default __ARGS((int, int opt_flags, int compatible));
2875static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002876static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002877static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878static char_u *illegal_char __ARGS((char_u *, int));
2879static int string_to_key __ARGS((char_u *arg));
2880#ifdef FEAT_CMDWIN
2881static char_u *check_cedit __ARGS((void));
2882#endif
2883#ifdef FEAT_TITLE
2884static void did_set_title __ARGS((int icon));
2885#endif
2886static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2887static void didset_options __ARGS((void));
2888static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002889#if defined(FEAT_EVAL) || defined(PROTO)
2890static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2891#else
2892# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2895static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2896static 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));
2897static char_u *set_chars_option __ARGS((char_u **varp));
2898#ifdef FEAT_CLIPBOARD
2899static char_u *check_clipboard_option __ARGS((void));
2900#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002901#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002902static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002903#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002904#ifdef FEAT_EVAL
2905static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002908static 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 +00002909static void check_redraw __ARGS((long_u flags));
2910static int findoption __ARGS((char_u *));
2911static int find_key_option __ARGS((char_u *));
2912static void showoptions __ARGS((int all, int opt_flags));
2913static int optval_default __ARGS((struct vimoption *, char_u *varp));
2914static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2915static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2916static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2917static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2918static int istermoption __ARGS((struct vimoption *));
2919static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2920static char_u *get_varp __ARGS((struct vimoption *));
2921static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2922static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2923#ifdef FEAT_LANGMAP
2924static void langmap_init __ARGS((void));
2925static void langmap_set __ARGS((void));
2926#endif
2927static void paste_option_changed __ARGS((void));
2928static void compatible_set __ARGS((void));
2929#ifdef FEAT_LINEBREAK
2930static void fill_breakat_flags __ARGS((void));
2931#endif
2932static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2933static int check_opt_strings __ARGS((char_u *val, char **values, int));
2934static int check_opt_wim __ARGS((void));
2935
2936/*
2937 * Initialize the options, first part.
2938 *
2939 * Called only once from main(), just after creating the first buffer.
2940 */
2941 void
2942set_init_1()
2943{
2944 char_u *p;
2945 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00002946 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947
2948#ifdef FEAT_LANGMAP
2949 langmap_init();
2950#endif
2951
2952 /* Be Vi compatible by default */
2953 p_cp = TRUE;
2954
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002955 /* Use POSIX compatibility when $VIM_POSIX is set. */
2956 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002957 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002958 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002959 set_string_default("shm", (char_u *)"A");
2960 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002961
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 /*
2963 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002964 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002966 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2968# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002969 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002971 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002973 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974# endif
2975#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002976 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 set_string_default("sh", p);
2978
2979#ifdef FEAT_WILDIGN
2980 /*
2981 * Set the default for 'backupskip' to include environment variables for
2982 * temp files.
2983 */
2984 {
2985# ifdef UNIX
2986 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2987# else
2988 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2989# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002990 int len;
2991 garray_T ga;
2992 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993
2994 ga_init2(&ga, 1, 100);
2995 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2996 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002997 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998# ifdef UNIX
2999 if (*names[n] == NUL)
3000 p = (char_u *)"/tmp";
3001 else
3002# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003003 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 if (p != NULL && *p != NUL)
3005 {
3006 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003007 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 if (ga_grow(&ga, len) == OK)
3009 {
3010 if (ga.ga_len > 0)
3011 STRCAT(ga.ga_data, ",");
3012 STRCAT(ga.ga_data, p);
3013 add_pathsep(ga.ga_data);
3014 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 ga.ga_len += len;
3016 }
3017 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003018 if (mustfree)
3019 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 }
3021 if (ga.ga_data != NULL)
3022 {
3023 set_string_default("bsk", ga.ga_data);
3024 vim_free(ga.ga_data);
3025 }
3026 }
3027#endif
3028
3029 /*
3030 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3031 */
3032 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003033 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003035#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3036 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3037#endif
3038 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003040 /* Use amount of memory available at this moment. */
3041 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#else
3043# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003044 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003045 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003047 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048# endif
3049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003051 opt_idx = findoption((char_u *)"maxmem");
3052 if (opt_idx >= 0)
3053 {
3054#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3055 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3056 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3057#endif
3058 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3059 }
3060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 }
3062
3063#ifdef FEAT_GUI_W32
3064 /* force 'shortname' for Win32s */
3065 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003066 {
3067 opt_idx = findoption((char_u *)"shortname");
3068 if (opt_idx >= 0)
3069 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071#endif
3072
3073#ifdef FEAT_SEARCHPATH
3074 {
3075 char_u *cdpath;
3076 char_u *buf;
3077 int i;
3078 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003079 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080
3081 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003082 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 if (cdpath != NULL)
3084 {
3085 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3086 if (buf != NULL)
3087 {
3088 buf[0] = ','; /* start with ",", current dir first */
3089 j = 1;
3090 for (i = 0; cdpath[i] != NUL; ++i)
3091 {
3092 if (vim_ispathlistsep(cdpath[i]))
3093 buf[j++] = ',';
3094 else
3095 {
3096 if (cdpath[i] == ' ' || cdpath[i] == ',')
3097 buf[j++] = '\\';
3098 buf[j++] = cdpath[i];
3099 }
3100 }
3101 buf[j] = NUL;
3102 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003103 if (opt_idx >= 0)
3104 {
3105 options[opt_idx].def_val[VI_DEFAULT] = buf;
3106 options[opt_idx].flags |= P_DEF_ALLOCED;
3107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003109 if (mustfree)
3110 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 }
3112 }
3113#endif
3114
3115#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3116 /* Set print encoding on platforms that don't default to latin1 */
3117 set_string_default("penc",
3118# if defined(MSWIN) || defined(OS2)
3119 (char_u *)"cp1252"
3120# else
3121# ifdef VMS
3122 (char_u *)"dec-mcs"
3123# else
3124# ifdef EBCDIC
3125 (char_u *)"ebcdic-uk"
3126# else
3127# ifdef MAC
3128 (char_u *)"mac-roman"
3129# else /* HPUX */
3130 (char_u *)"hp-roman8"
3131# endif
3132# endif
3133# endif
3134# endif
3135 );
3136#endif
3137
3138#ifdef FEAT_POSTSCRIPT
3139 /* 'printexpr' must be allocated to be able to evaluate it. */
3140 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003141# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3142 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143# else
3144# ifdef VMS
3145 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3146
3147# else
3148 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3149# endif
3150# endif
3151 );
3152#endif
3153
3154 /*
3155 * Set all the options (except the terminal options) to their default
3156 * value. Also set the global value for local options.
3157 */
3158 set_options_default(0);
3159
3160#ifdef FEAT_GUI
3161 if (found_reverse_arg)
3162 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3163#endif
3164
3165 curbuf->b_p_initialized = TRUE;
3166 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3167 check_buf_options(curbuf);
3168 check_win_options(curwin);
3169 check_options();
3170
3171 /* Must be before option_expand(), because that one needs vim_isIDc() */
3172 didset_options();
3173
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003174#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003175 /* Use the current chartab for the generic chartab. */
3176 init_spell_chartab();
3177#endif
3178
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179#ifdef FEAT_LINEBREAK
3180 /*
3181 * initialize the table for 'breakat'.
3182 */
3183 fill_breakat_flags();
3184#endif
3185
3186 /*
3187 * Expand environment variables and things like "~" for the defaults.
3188 * If option_expand() returns non-NULL the variable is expanded. This can
3189 * only happen for non-indirect options.
3190 * Also set the default to the expanded value, so ":set" does not list
3191 * them.
3192 * Don't set the P_ALLOCED flag, because we don't want to free the
3193 * default.
3194 */
3195 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3196 {
3197 if ((options[opt_idx].flags & P_GETTEXT)
3198 && options[opt_idx].var != NULL)
3199 p = (char_u *)_(*(char **)options[opt_idx].var);
3200 else
3201 p = option_expand(opt_idx, NULL);
3202 if (p != NULL && (p = vim_strsave(p)) != NULL)
3203 {
3204 *(char_u **)options[opt_idx].var = p;
3205 /* VIMEXP
3206 * Defaults for all expanded options are currently the same for Vi
3207 * and Vim. When this changes, add some code here! Also need to
3208 * split P_DEF_ALLOCED in two.
3209 */
3210 if (options[opt_idx].flags & P_DEF_ALLOCED)
3211 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3212 options[opt_idx].def_val[VI_DEFAULT] = p;
3213 options[opt_idx].flags |= P_DEF_ALLOCED;
3214 }
3215 }
3216
3217 /* Initialize the highlight_attr[] table. */
3218 highlight_changed();
3219
3220 save_file_ff(curbuf); /* Buffer is unchanged */
3221
3222 /* Parse default for 'wildmode' */
3223 check_opt_wim();
3224
3225#if defined(FEAT_ARABIC)
3226 /* Detect use of mlterm.
3227 * Mlterm is a terminal emulator akin to xterm that has some special
3228 * abilities (bidi namely).
3229 * NOTE: mlterm's author is being asked to 'set' a variable
3230 * instead of an environment variable due to inheritance.
3231 */
3232 if (mch_getenv((char_u *)"MLTERM") != NULL)
3233 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3234#endif
3235
3236#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3237 /* Parse default for 'fillchars'. */
3238 (void)set_chars_option(&p_fcs);
3239#endif
3240
3241#ifdef FEAT_CLIPBOARD
3242 /* Parse default for 'clipboard' */
3243 (void)check_clipboard_option();
3244#endif
3245
3246#ifdef FEAT_MBYTE
3247# if defined(WIN3264) && defined(FEAT_GETTEXT)
3248 /*
3249 * If $LANG isn't set, try to get a good value for it. This makes the
3250 * right language be used automatically. Don't do this for English.
3251 */
3252 if (mch_getenv((char_u *)"LANG") == NULL)
3253 {
3254 char buf[20];
3255
3256 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3257 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3258 * only the first two. */
3259 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3260 (LPTSTR)buf, 20);
3261 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3262 {
3263 /* There are a few exceptions (probably more) */
3264 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3265 STRCPY(buf, "zh_TW");
3266 else if (STRNICMP(buf, "chs", 3) == 0
3267 || STRNICMP(buf, "zhc", 3) == 0)
3268 STRCPY(buf, "zh_CN");
3269 else if (STRNICMP(buf, "jp", 2) == 0)
3270 STRCPY(buf, "ja");
3271 else
3272 buf[2] = NUL; /* truncate to two-letter code */
3273 vim_setenv("LANG", buf);
3274 }
3275 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003276# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003277# ifdef MACOS_CONVERT
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003278 if (mch_getenv((char_u *)"LANG") == NULL)
3279 {
3280 char buf[20];
3281 if (LocaleRefGetPartString(NULL,
3282 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3283 kLocaleRegionMask | kLocaleRegionVariantMask,
3284 sizeof buf, buf) == noErr && *buf)
3285 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003286 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003287# ifdef HAVE_LOCALE_H
3288 setlocale(LC_ALL, "");
3289# endif
3290 }
3291 }
3292# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293# endif
3294
3295 /* enc_locale() will try to find the encoding of the current locale. */
3296 p = enc_locale();
3297 if (p != NULL)
3298 {
3299 char_u *save_enc;
3300
3301 /* Try setting 'encoding' and check if the value is valid.
3302 * If not, go back to the default "latin1". */
3303 save_enc = p_enc;
3304 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003305 if (STRCMP(p_enc, "gb18030") == 0)
3306 {
3307 /* We don't support "gb18030", but "cp936" is a good substitute
3308 * for practical purposes, thus use that. It's not an alias to
3309 * still support conversion between gb18030 and utf-8. */
3310 p_enc = vim_strsave((char_u *)"cp936");
3311 vim_free(p);
3312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 if (mb_init() == NULL)
3314 {
3315 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003316 if (opt_idx >= 0)
3317 {
3318 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3319 options[opt_idx].flags |= P_DEF_ALLOCED;
3320 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003322#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3323 || defined(VMS)
3324 if (STRCMP(p_enc, "latin1") == 0
3325# ifdef FEAT_MBYTE
3326 || enc_utf8
3327# endif
3328 )
3329 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003330 /* Adjust the default for 'isprint' and 'iskeyword' to match
3331 * latin1. Also set the defaults for when 'nocompatible' is
3332 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003333 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003334 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003335 set_string_option_direct((char_u *)"isk", -1,
3336 ISK_LATIN1, OPT_FREE, SID_NONE);
3337 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003338 if (opt_idx >= 0)
3339 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003340 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003341 if (opt_idx >= 0)
3342 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003343 (void)init_chartab();
3344 }
3345#endif
3346
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347# if defined(WIN3264) && !defined(FEAT_GUI)
3348 /* Win32 console: When GetACP() returns a different value from
3349 * GetConsoleCP() set 'termencoding'. */
3350 if (GetACP() != GetConsoleCP())
3351 {
3352 char buf[50];
3353
3354 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3355 p_tenc = vim_strsave((char_u *)buf);
3356 if (p_tenc != NULL)
3357 {
3358 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003359 if (opt_idx >= 0)
3360 {
3361 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3362 options[opt_idx].flags |= P_DEF_ALLOCED;
3363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 convert_setup(&input_conv, p_tenc, p_enc);
3365 convert_setup(&output_conv, p_enc, p_tenc);
3366 }
3367 else
3368 p_tenc = empty_option;
3369 }
3370# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003371# if defined(WIN3264) && defined(FEAT_MBYTE)
3372 /* $HOME may have characters in active code page. */
3373 init_homedir();
3374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 }
3376 else
3377 {
3378 vim_free(p_enc);
3379 p_enc = save_enc;
3380 }
3381 }
3382#endif
3383
3384#ifdef FEAT_MULTI_LANG
3385 /* Set the default for 'helplang'. */
3386 set_helplang_default(get_mess_lang());
3387#endif
3388}
3389
3390/*
3391 * Set an option to its default value.
3392 * This does not take care of side effects!
3393 */
3394 static void
3395set_option_default(opt_idx, opt_flags, compatible)
3396 int opt_idx;
3397 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3398 int compatible; /* use Vi default value */
3399{
3400 char_u *varp; /* pointer to variable for current option */
3401 int dvi; /* index in def_val[] */
3402 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003403 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3405
3406 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3407 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003408 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 {
3410 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3411 if (flags & P_STRING)
3412 {
3413 /* Use set_string_option_direct() for local options to handle
3414 * freeing and allocating the value. */
3415 if (options[opt_idx].indir != PV_NONE)
3416 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003417 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 else
3419 {
3420 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3421 free_string_option(*(char_u **)(varp));
3422 *(char_u **)varp = options[opt_idx].def_val[dvi];
3423 options[opt_idx].flags &= ~P_ALLOCED;
3424 }
3425 }
3426 else if (flags & P_NUM)
3427 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003428 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 win_comp_scroll(curwin);
3430 else
3431 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003432 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 /* May also set global value for local option. */
3434 if (both)
3435 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3436 *(long *)varp;
3437 }
3438 }
3439 else /* P_BOOL */
3440 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003441 /* the cast to long is required for Manx C, long_i is needed for
3442 * MSVC */
3443 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003444#ifdef UNIX
3445 /* 'modeline' defaults to off for root */
3446 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3447 *(int *)varp = FALSE;
3448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 /* May also set global value for local option. */
3450 if (both)
3451 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3452 *(int *)varp;
3453 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003454
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003455 /* The default value is not insecure. */
3456 flagsp = insecure_flag(opt_idx, opt_flags);
3457 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 }
3459
3460#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003461 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462#endif
3463}
3464
3465/*
3466 * Set all options (except terminal options) to their default value.
3467 */
3468 static void
3469set_options_default(opt_flags)
3470 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3471{
3472 int i;
3473#ifdef FEAT_WINDOWS
3474 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003475 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476#endif
3477
3478 for (i = 0; !istermoption(&options[i]); i++)
3479 if (!(options[i].flags & P_NODEFAULT))
3480 set_option_default(i, opt_flags, p_cp);
3481
3482#ifdef FEAT_WINDOWS
3483 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003484 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485 win_comp_scroll(wp);
3486#else
3487 win_comp_scroll(curwin);
3488#endif
3489}
3490
3491/*
3492 * Set the Vi-default value of a string option.
3493 * Used for 'sh', 'backupskip' and 'term'.
3494 */
3495 void
3496set_string_default(name, val)
3497 char *name;
3498 char_u *val;
3499{
3500 char_u *p;
3501 int opt_idx;
3502
3503 p = vim_strsave(val);
3504 if (p != NULL) /* we don't want a NULL */
3505 {
3506 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003507 if (opt_idx >= 0)
3508 {
3509 if (options[opt_idx].flags & P_DEF_ALLOCED)
3510 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3511 options[opt_idx].def_val[VI_DEFAULT] = p;
3512 options[opt_idx].flags |= P_DEF_ALLOCED;
3513 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 }
3515}
3516
3517/*
3518 * Set the Vi-default value of a number option.
3519 * Used for 'lines' and 'columns'.
3520 */
3521 void
3522set_number_default(name, val)
3523 char *name;
3524 long val;
3525{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003526 int opt_idx;
3527
3528 opt_idx = findoption((char_u *)name);
3529 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003530 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531}
3532
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003533#if defined(EXITFREE) || defined(PROTO)
3534/*
3535 * Free all options.
3536 */
3537 void
3538free_all_options()
3539{
3540 int i;
3541
3542 for (i = 0; !istermoption(&options[i]); i++)
3543 {
3544 if (options[i].indir == PV_NONE)
3545 {
3546 /* global option: free value and default value. */
3547 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3548 free_string_option(*(char_u **)options[i].var);
3549 if (options[i].flags & P_DEF_ALLOCED)
3550 free_string_option(options[i].def_val[VI_DEFAULT]);
3551 }
3552 else if (options[i].var != VAR_WIN
3553 && (options[i].flags & P_STRING))
3554 /* buffer-local option: free global value */
3555 free_string_option(*(char_u **)options[i].var);
3556 }
3557}
3558#endif
3559
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561/*
3562 * Initialize the options, part two: After getting Rows and Columns and
3563 * setting 'term'.
3564 */
3565 void
3566set_init_2()
3567{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003568 int idx;
3569
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570 /*
3571 * 'scroll' defaults to half the window height. Note that this default is
3572 * wrong when the window height changes.
3573 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003574 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003575 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003576 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003577 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 comp_col();
3579
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003580 /*
3581 * 'window' is only for backwards compatibility with Vi.
3582 * Default is Rows - 1.
3583 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003584 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003585 p_window = Rows - 1;
3586 set_number_default("window", Rows - 1);
3587
Bram Moolenaarf740b292006-02-16 22:11:02 +00003588 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003590 /*
3591 * If 'background' wasn't set by the user, try guessing the value,
3592 * depending on the terminal name. Only need to check for terminals
3593 * with a dark background, that can handle color.
3594 */
3595 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003596 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3597 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003599 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003600 /* don't mark it as set, when starting the GUI it may be
3601 * changed again */
3602 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 }
3604#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003605
3606#ifdef CURSOR_SHAPE
3607 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3608#endif
3609#ifdef FEAT_MOUSESHAPE
3610 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3611#endif
3612#ifdef FEAT_PRINTER
3613 (void)parse_printoptions(); /* parse 'printoptions' default value */
3614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615}
3616
3617/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003618 * Return "dark" or "light" depending on the kind of terminal.
3619 * This is just guessing! Recognized are:
3620 * "linux" Linux console
3621 * "screen.linux" Linux console with screen
3622 * "cygwin" Cygwin shell
3623 * "putty" Putty program
3624 * We also check the COLORFGBG environment variable, which is set by
3625 * rxvt and derivatives. This variable contains either two or three
3626 * values separated by semicolons; we want the last value in either
3627 * case. If this value is 0-6 or 8, our background is dark.
3628 */
3629 static char_u *
3630term_bg_default()
3631{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003632#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3633 /* DOS console nearly always black */
3634 return (char_u *)"dark";
3635#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003636 char_u *p;
3637
Bram Moolenaarf740b292006-02-16 22:11:02 +00003638 if (STRCMP(T_NAME, "linux") == 0
3639 || STRCMP(T_NAME, "screen.linux") == 0
3640 || STRCMP(T_NAME, "cygwin") == 0
3641 || STRCMP(T_NAME, "putty") == 0
3642 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3643 && (p = vim_strrchr(p, ';')) != NULL
3644 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3645 && p[2] == NUL))
3646 return (char_u *)"dark";
3647 return (char_u *)"light";
3648#endif
3649}
3650
3651/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 * Initialize the options, part three: After reading the .vimrc
3653 */
3654 void
3655set_init_3()
3656{
3657#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3658/*
3659 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3660 * This is done after other initializations, where 'shell' might have been
3661 * set, but only if they have not been set before.
3662 */
3663 char_u *p;
3664 int idx_srr;
3665 int do_srr;
3666#ifdef FEAT_QUICKFIX
3667 int idx_sp;
3668 int do_sp;
3669#endif
3670
3671 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003672 if (idx_srr < 0)
3673 do_srr = FALSE;
3674 else
3675 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676#ifdef FEAT_QUICKFIX
3677 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (idx_sp < 0)
3679 do_sp = FALSE;
3680 else
3681 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682#endif
3683
3684 /*
3685 * Isolate the name of the shell:
3686 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3687 * - Remove any argument. E.g., "csh -f" -> "csh".
3688 */
3689 p = gettail(p_sh);
3690 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3691 if (p != NULL)
3692 {
3693 /*
3694 * Default for p_sp is "| tee", for p_srr is ">".
3695 * For known shells it is changed here to include stderr.
3696 */
3697 if ( fnamecmp(p, "csh") == 0
3698 || fnamecmp(p, "tcsh") == 0
3699# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3700 || fnamecmp(p, "csh.exe") == 0
3701 || fnamecmp(p, "tcsh.exe") == 0
3702# endif
3703 )
3704 {
3705#if defined(FEAT_QUICKFIX)
3706 if (do_sp)
3707 {
3708# ifdef WIN3264
3709 p_sp = (char_u *)">&";
3710# else
3711 p_sp = (char_u *)"|& tee";
3712# endif
3713 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3714 }
3715#endif
3716 if (do_srr)
3717 {
3718 p_srr = (char_u *)">&";
3719 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3720 }
3721 }
3722 else
3723# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3724 if ( fnamecmp(p, "sh") == 0
3725 || fnamecmp(p, "ksh") == 0
3726 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003727 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 || fnamecmp(p, "bash") == 0
3729# ifdef WIN3264
3730 || fnamecmp(p, "cmd") == 0
3731 || fnamecmp(p, "sh.exe") == 0
3732 || fnamecmp(p, "ksh.exe") == 0
3733 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003734 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 || fnamecmp(p, "bash.exe") == 0
3736 || fnamecmp(p, "cmd.exe") == 0
3737# endif
3738 )
3739# endif
3740 {
3741#if defined(FEAT_QUICKFIX)
3742 if (do_sp)
3743 {
3744# ifdef WIN3264
3745 p_sp = (char_u *)">%s 2>&1";
3746# else
3747 p_sp = (char_u *)"2>&1| tee";
3748# endif
3749 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3750 }
3751#endif
3752 if (do_srr)
3753 {
3754 p_srr = (char_u *)">%s 2>&1";
3755 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3756 }
3757 }
3758 vim_free(p);
3759 }
3760#endif
3761
3762#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3763 /*
3764 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3765 * This is done after other initializations, where 'shell' might have been
3766 * set, but only if they have not been set before. Default for p_shcf is
3767 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3768 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3769 * command.com. And for Win32 we need to set p_sxq instead.
3770 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003771 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 {
3773 int idx3;
3774
3775 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003776 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 {
3778 p_shcf = (char_u *)"-c";
3779 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3780 }
3781
3782# ifndef DJGPP
3783# ifdef WIN3264
3784 /* Somehow Win32 requires the quotes around the redirection too */
3785 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003786 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 {
3788 p_sxq = (char_u *)"\"";
3789 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3790 }
3791# else
3792 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003793 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 {
3795 p_shq = (char_u *)"\"";
3796 options[idx3].def_val[VI_DEFAULT] = p_shq;
3797 }
3798# endif
3799# endif
3800 }
3801#endif
3802
3803#ifdef FEAT_TITLE
3804 set_title_defaults();
3805#endif
3806}
3807
3808#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3809/*
3810 * When 'helplang' is still at its default value, set it to "lang".
3811 * Only the first two characters of "lang" are used.
3812 */
3813 void
3814set_helplang_default(lang)
3815 char_u *lang;
3816{
3817 int idx;
3818
3819 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3820 return;
3821 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003822 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 {
3824 if (options[idx].flags & P_ALLOCED)
3825 free_string_option(p_hlg);
3826 p_hlg = vim_strsave(lang);
3827 if (p_hlg == NULL)
3828 p_hlg = empty_option;
3829 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003830 {
3831 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3832 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3833 {
3834 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3835 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003838 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 options[idx].flags |= P_ALLOCED;
3840 }
3841}
3842#endif
3843
3844#ifdef FEAT_GUI
3845static char_u *gui_bg_default __ARGS((void));
3846
3847 static char_u *
3848gui_bg_default()
3849{
3850 if (gui_get_lightness(gui.back_pixel) < 127)
3851 return (char_u *)"dark";
3852 return (char_u *)"light";
3853}
3854
3855/*
3856 * Option initializations that can only be done after opening the GUI window.
3857 */
3858 void
3859init_gui_options()
3860{
3861 /* Set the 'background' option according to the lightness of the
3862 * background color, unless the user has set it already. */
3863 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3864 {
3865 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3866 highlight_changed();
3867 }
3868}
3869#endif
3870
3871#ifdef FEAT_TITLE
3872/*
3873 * 'title' and 'icon' only default to true if they have not been set or reset
3874 * in .vimrc and we can read the old value.
3875 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3876 * they can be reset. This reduces startup time when using X on a remote
3877 * machine.
3878 */
3879 void
3880set_title_defaults()
3881{
3882 int idx1;
3883 long val;
3884
3885 /*
3886 * If GUI is (going to be) used, we can always set the window title and
3887 * icon name. Saves a bit of time, because the X11 display server does
3888 * not need to be contacted.
3889 */
3890 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003891 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 {
3893#ifdef FEAT_GUI
3894 if (gui.starting || gui.in_use)
3895 val = TRUE;
3896 else
3897#endif
3898 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003899 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 p_title = val;
3901 }
3902 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003903 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 {
3905#ifdef FEAT_GUI
3906 if (gui.starting || gui.in_use)
3907 val = TRUE;
3908 else
3909#endif
3910 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003911 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 p_icon = val;
3913 }
3914}
3915#endif
3916
3917/*
3918 * Parse 'arg' for option settings.
3919 *
3920 * 'arg' may be IObuff, but only when no errors can be present and option
3921 * does not need to be expanded with option_expand().
3922 * "opt_flags":
3923 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003924 * OPT_GLOBAL for ":setglobal"
3925 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003927 * OPT_WINONLY to only set window-local options
3928 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 *
3930 * returns FAIL if an error is detected, OK otherwise
3931 */
3932 int
3933do_set(arg, opt_flags)
3934 char_u *arg; /* option string (may be written to!) */
3935 int opt_flags;
3936{
3937 int opt_idx;
3938 char_u *errmsg;
3939 char_u errbuf[80];
3940 char_u *startarg;
3941 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3942 int nextchar; /* next non-white char after option name */
3943 int afterchar; /* character just after option name */
3944 int len;
3945 int i;
3946 long value;
3947 int key;
3948 long_u flags; /* flags for current option */
3949 char_u *varp = NULL; /* pointer to variable for current option */
3950 int did_show = FALSE; /* already showed one value */
3951 int adding; /* "opt+=arg" */
3952 int prepending; /* "opt^=arg" */
3953 int removing; /* "opt-=arg" */
3954 int cp_val = 0;
3955 char_u key_name[2];
3956
3957 if (*arg == NUL)
3958 {
3959 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003960 did_show = TRUE;
3961 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 }
3963
3964 while (*arg != NUL) /* loop to process all options */
3965 {
3966 errmsg = NULL;
3967 startarg = arg; /* remember for error message */
3968
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003969 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3970 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 {
3972 /*
3973 * ":set all" show all options.
3974 * ":set all&" set all options to their default value.
3975 */
3976 arg += 3;
3977 if (*arg == '&')
3978 {
3979 ++arg;
3980 /* Only for :set command set global value of local options. */
3981 set_options_default(OPT_FREE | opt_flags);
3982 }
3983 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003984 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003986 did_show = TRUE;
3987 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003989 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 {
3991 showoptions(2, opt_flags);
3992 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003993 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 arg += 7;
3995 }
3996 else
3997 {
3998 prefix = 1;
3999 if (STRNCMP(arg, "no", 2) == 0)
4000 {
4001 prefix = 0;
4002 arg += 2;
4003 }
4004 else if (STRNCMP(arg, "inv", 3) == 0)
4005 {
4006 prefix = 2;
4007 arg += 3;
4008 }
4009
4010 /* find end of name */
4011 key = 0;
4012 if (*arg == '<')
4013 {
4014 nextchar = 0;
4015 opt_idx = -1;
4016 /* look out for <t_>;> */
4017 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4018 len = 5;
4019 else
4020 {
4021 len = 1;
4022 while (arg[len] != NUL && arg[len] != '>')
4023 ++len;
4024 }
4025 if (arg[len] != '>')
4026 {
4027 errmsg = e_invarg;
4028 goto skip;
4029 }
4030 arg[len] = NUL; /* put NUL after name */
4031 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4032 opt_idx = findoption(arg + 1);
4033 arg[len++] = '>'; /* restore '>' */
4034 if (opt_idx == -1)
4035 key = find_key_option(arg + 1);
4036 }
4037 else
4038 {
4039 len = 0;
4040 /*
4041 * The two characters after "t_" may not be alphanumeric.
4042 */
4043 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4044 len = 4;
4045 else
4046 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4047 ++len;
4048 nextchar = arg[len];
4049 arg[len] = NUL; /* put NUL after name */
4050 opt_idx = findoption(arg);
4051 arg[len] = nextchar; /* restore nextchar */
4052 if (opt_idx == -1)
4053 key = find_key_option(arg);
4054 }
4055
4056 /* remember character after option name */
4057 afterchar = arg[len];
4058
4059 /* skip white space, allow ":set ai ?" */
4060 while (vim_iswhite(arg[len]))
4061 ++len;
4062
4063 adding = FALSE;
4064 prepending = FALSE;
4065 removing = FALSE;
4066 if (arg[len] != NUL && arg[len + 1] == '=')
4067 {
4068 if (arg[len] == '+')
4069 {
4070 adding = TRUE; /* "+=" */
4071 ++len;
4072 }
4073 else if (arg[len] == '^')
4074 {
4075 prepending = TRUE; /* "^=" */
4076 ++len;
4077 }
4078 else if (arg[len] == '-')
4079 {
4080 removing = TRUE; /* "-=" */
4081 ++len;
4082 }
4083 }
4084 nextchar = arg[len];
4085
4086 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4087 {
4088 errmsg = (char_u *)N_("E518: Unknown option");
4089 goto skip;
4090 }
4091
4092 if (opt_idx >= 0)
4093 {
4094 if (options[opt_idx].var == NULL) /* hidden option: skip */
4095 {
4096 /* Only give an error message when requesting the value of
4097 * a hidden option, ignore setting it. */
4098 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4099 && (!(options[opt_idx].flags & P_BOOL)
4100 || nextchar == '?'))
4101 errmsg = (char_u *)N_("E519: Option not supported");
4102 goto skip;
4103 }
4104
4105 flags = options[opt_idx].flags;
4106 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4107 }
4108 else
4109 {
4110 flags = P_STRING;
4111 if (key < 0)
4112 {
4113 key_name[0] = KEY2TERMCAP0(key);
4114 key_name[1] = KEY2TERMCAP1(key);
4115 }
4116 else
4117 {
4118 key_name[0] = KS_KEY;
4119 key_name[1] = (key & 0xff);
4120 }
4121 }
4122
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004123 /* Skip all options that are not window-local (used when showing
4124 * an already loaded buffer in a window). */
4125 if ((opt_flags & OPT_WINONLY)
4126 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4127 goto skip;
4128
Bram Moolenaara3227e22006-03-08 21:32:40 +00004129 /* Skip all options that are window-local (used for :vimgrep). */
4130 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4131 && options[opt_idx].var == VAR_WIN)
4132 goto skip;
4133
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 /* Disallow changing some options from modelines */
4135 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
4136 {
4137 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4138 goto skip;
4139 }
4140
4141#ifdef HAVE_SANDBOX
4142 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004143 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145 errmsg = (char_u *)_(e_sandbox);
4146 goto skip;
4147 }
4148#endif
4149
4150 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4151 {
4152 arg += len;
4153 cp_val = p_cp;
4154 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4155 {
4156 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4157 {
4158 cp_val = FALSE;
4159 arg += 3;
4160 }
4161 else /* "opt&vi": set to Vi default */
4162 {
4163 cp_val = TRUE;
4164 arg += 2;
4165 }
4166 }
4167 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4168 && arg[1] != NUL && !vim_iswhite(arg[1]))
4169 {
4170 errmsg = e_trailing;
4171 goto skip;
4172 }
4173 }
4174
4175 /*
4176 * allow '=' and ':' as MSDOS command.com allows only one
4177 * '=' character per "set" command line. grrr. (jw)
4178 */
4179 if (nextchar == '?'
4180 || (prefix == 1
4181 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4182 && !(flags & P_BOOL)))
4183 {
4184 /*
4185 * print value
4186 */
4187 if (did_show)
4188 msg_putchar('\n'); /* cursor below last one */
4189 else
4190 {
4191 gotocmdline(TRUE); /* cursor at status line */
4192 did_show = TRUE; /* remember that we did a line */
4193 }
4194 if (opt_idx >= 0)
4195 {
4196 showoneopt(&options[opt_idx], opt_flags);
4197#ifdef FEAT_EVAL
4198 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004199 {
4200 /* Mention where the option was last set. */
4201 if (varp == options[opt_idx].var)
4202 last_set_msg(options[opt_idx].scriptID);
4203 else if ((int)options[opt_idx].indir & PV_WIN)
4204 last_set_msg(curwin->w_p_scriptID[
4205 (int)options[opt_idx].indir & PV_MASK]);
4206 else if ((int)options[opt_idx].indir & PV_BUF)
4207 last_set_msg(curbuf->b_p_scriptID[
4208 (int)options[opt_idx].indir & PV_MASK]);
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#endif
4211 }
4212 else
4213 {
4214 char_u *p;
4215
4216 p = find_termcode(key_name);
4217 if (p == NULL)
4218 {
4219 errmsg = (char_u *)N_("E518: Unknown option");
4220 goto skip;
4221 }
4222 else
4223 (void)show_one_termcode(key_name, p, TRUE);
4224 }
4225 if (nextchar != '?'
4226 && nextchar != NUL && !vim_iswhite(afterchar))
4227 errmsg = e_trailing;
4228 }
4229 else
4230 {
4231 if (flags & P_BOOL) /* boolean */
4232 {
4233 if (nextchar == '=' || nextchar == ':')
4234 {
4235 errmsg = e_invarg;
4236 goto skip;
4237 }
4238
4239 /*
4240 * ":set opt!": invert
4241 * ":set opt&": reset to default value
4242 * ":set opt<": reset to global value
4243 */
4244 if (nextchar == '!')
4245 value = *(int *)(varp) ^ 1;
4246 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004247 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 ((flags & P_VI_DEF) || cp_val)
4249 ? VI_DEFAULT : VIM_DEFAULT];
4250 else if (nextchar == '<')
4251 {
4252 /* For 'autoread' -1 means to use global value. */
4253 if ((int *)varp == &curbuf->b_p_ar
4254 && opt_flags == OPT_LOCAL)
4255 value = -1;
4256 else
4257 value = *(int *)get_varp_scope(&(options[opt_idx]),
4258 OPT_GLOBAL);
4259 }
4260 else
4261 {
4262 /*
4263 * ":set invopt": invert
4264 * ":set opt" or ":set noopt": set or reset
4265 */
4266 if (nextchar != NUL && !vim_iswhite(afterchar))
4267 {
4268 errmsg = e_trailing;
4269 goto skip;
4270 }
4271 if (prefix == 2) /* inv */
4272 value = *(int *)(varp) ^ 1;
4273 else
4274 value = prefix;
4275 }
4276
4277 errmsg = set_bool_option(opt_idx, varp, (int)value,
4278 opt_flags);
4279 }
4280 else /* numeric or string */
4281 {
4282 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4283 || prefix != 1)
4284 {
4285 errmsg = e_invarg;
4286 goto skip;
4287 }
4288
4289 if (flags & P_NUM) /* numeric */
4290 {
4291 /*
4292 * Different ways to set a number option:
4293 * & set to default value
4294 * < set to global value
4295 * <xx> accept special key codes for 'wildchar'
4296 * c accept any non-digit for 'wildchar'
4297 * [-]0-9 set number
4298 * other error
4299 */
4300 ++arg;
4301 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004302 value = (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 value = *(long *)get_varp_scope(&(options[opt_idx]),
4307 OPT_GLOBAL);
4308 else if (((long *)varp == &p_wc
4309 || (long *)varp == &p_wcm)
4310 && (*arg == '<'
4311 || *arg == '^'
4312 || ((!arg[1] || vim_iswhite(arg[1]))
4313 && !VIM_ISDIGIT(*arg))))
4314 {
4315 value = string_to_key(arg);
4316 if (value == 0 && (long *)varp != &p_wcm)
4317 {
4318 errmsg = e_invarg;
4319 goto skip;
4320 }
4321 }
4322 /* allow negative numbers (for 'undolevels') */
4323 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4324 {
4325 i = 0;
4326 if (*arg == '-')
4327 i = 1;
4328#ifdef HAVE_STRTOL
4329 value = strtol((char *)arg, NULL, 0);
4330 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4331 i += 2;
4332#else
4333 value = atol((char *)arg);
4334#endif
4335 while (VIM_ISDIGIT(arg[i]))
4336 ++i;
4337 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4338 {
4339 errmsg = e_invarg;
4340 goto skip;
4341 }
4342 }
4343 else
4344 {
4345 errmsg = (char_u *)N_("E521: Number required after =");
4346 goto skip;
4347 }
4348
4349 if (adding)
4350 value = *(long *)varp + value;
4351 if (prepending)
4352 value = *(long *)varp * value;
4353 if (removing)
4354 value = *(long *)varp - value;
4355 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004356 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 }
4358 else if (opt_idx >= 0) /* string */
4359 {
4360 char_u *save_arg = NULL;
4361 char_u *s = NULL;
4362 char_u *oldval; /* previous value if *varp */
4363 char_u *newval;
4364 char_u *origval;
4365 unsigned newlen;
4366 int comma;
4367 int bs;
4368 int new_value_alloced; /* new string option
4369 was allocated */
4370
4371 /* When using ":set opt=val" for a global option
4372 * with a local value the local value will be
4373 * reset, use the global value here. */
4374 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004375 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 varp = options[opt_idx].var;
4377
4378 /* The old value is kept until we are sure that the
4379 * new value is valid. */
4380 oldval = *(char_u **)varp;
4381 if (nextchar == '&') /* set to default val */
4382 {
4383 newval = options[opt_idx].def_val[
4384 ((flags & P_VI_DEF) || cp_val)
4385 ? VI_DEFAULT : VIM_DEFAULT];
4386 if ((char_u **)varp == &p_bg)
4387 {
4388 /* guess the value of 'background' */
4389#ifdef FEAT_GUI
4390 if (gui.in_use)
4391 newval = gui_bg_default();
4392 else
4393#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004394 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004395 }
4396
4397 /* expand environment variables and ~ (since the
4398 * default value was already expanded, only
4399 * required when an environment variable was set
4400 * later */
4401 if (newval == NULL)
4402 newval = empty_option;
4403 else
4404 {
4405 s = option_expand(opt_idx, newval);
4406 if (s == NULL)
4407 s = newval;
4408 newval = vim_strsave(s);
4409 }
4410 new_value_alloced = TRUE;
4411 }
4412 else if (nextchar == '<') /* set to global val */
4413 {
4414 newval = vim_strsave(*(char_u **)get_varp_scope(
4415 &(options[opt_idx]), OPT_GLOBAL));
4416 new_value_alloced = TRUE;
4417 }
4418 else
4419 {
4420 ++arg; /* jump to after the '=' or ':' */
4421
4422 /*
4423 * Set 'keywordprg' to ":help" if an empty
4424 * value was passed to :set by the user.
4425 * Misuse errbuf[] for the resulting string.
4426 */
4427 if (varp == (char_u *)&p_kp
4428 && (*arg == NUL || *arg == ' '))
4429 {
4430 STRCPY(errbuf, ":help");
4431 save_arg = arg;
4432 arg = errbuf;
4433 }
4434 /*
4435 * Convert 'whichwrap' number to string, for
4436 * backwards compatibility with Vim 3.0.
4437 * Misuse errbuf[] for the resulting string.
4438 */
4439 else if (varp == (char_u *)&p_ww
4440 && VIM_ISDIGIT(*arg))
4441 {
4442 *errbuf = NUL;
4443 i = getdigits(&arg);
4444 if (i & 1)
4445 STRCAT(errbuf, "b,");
4446 if (i & 2)
4447 STRCAT(errbuf, "s,");
4448 if (i & 4)
4449 STRCAT(errbuf, "h,l,");
4450 if (i & 8)
4451 STRCAT(errbuf, "<,>,");
4452 if (i & 16)
4453 STRCAT(errbuf, "[,],");
4454 if (*errbuf != NUL) /* remove trailing , */
4455 errbuf[STRLEN(errbuf) - 1] = NUL;
4456 save_arg = arg;
4457 arg = errbuf;
4458 }
4459 /*
4460 * Remove '>' before 'dir' and 'bdir', for
4461 * backwards compatibility with version 3.0
4462 */
4463 else if ( *arg == '>'
4464 && (varp == (char_u *)&p_dir
4465 || varp == (char_u *)&p_bdir))
4466 {
4467 ++arg;
4468 }
4469
4470 /* When setting the local value of a global
4471 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004472 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473 && (opt_flags & OPT_LOCAL))
4474 origval = *(char_u **)get_varp(
4475 &options[opt_idx]);
4476 else
4477 origval = oldval;
4478
4479 /*
4480 * Copy the new string into allocated memory.
4481 * Can't use set_string_option_direct(), because
4482 * we need to remove the backslashes.
4483 */
4484 /* get a bit too much */
4485 newlen = (unsigned)STRLEN(arg) + 1;
4486 if (adding || prepending || removing)
4487 newlen += (unsigned)STRLEN(origval) + 1;
4488 newval = alloc(newlen);
4489 if (newval == NULL) /* out of mem, don't change */
4490 break;
4491 s = newval;
4492
4493 /*
4494 * Copy the string, skip over escaped chars.
4495 * For MS-DOS and WIN32 backslashes before normal
4496 * file name characters are not removed, and keep
4497 * backslash at start, for "\\machine\path", but
4498 * do remove it for "\\\\machine\\path".
4499 * The reverse is found in ExpandOldSetting().
4500 */
4501 while (*arg && !vim_iswhite(*arg))
4502 {
4503 if (*arg == '\\' && arg[1] != NUL
4504#ifdef BACKSLASH_IN_FILENAME
4505 && !((flags & P_EXPAND)
4506 && vim_isfilec(arg[1])
4507 && (arg[1] != '\\'
4508 || (s == newval
4509 && arg[2] != '\\')))
4510#endif
4511 )
4512 ++arg; /* remove backslash */
4513#ifdef FEAT_MBYTE
4514 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004515 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 {
4517 /* copy multibyte char */
4518 mch_memmove(s, arg, (size_t)i);
4519 arg += i;
4520 s += i;
4521 }
4522 else
4523#endif
4524 *s++ = *arg++;
4525 }
4526 *s = NUL;
4527
4528 /*
4529 * Expand environment variables and ~.
4530 * Don't do it when adding without inserting a
4531 * comma.
4532 */
4533 if (!(adding || prepending || removing)
4534 || (flags & P_COMMA))
4535 {
4536 s = option_expand(opt_idx, newval);
4537 if (s != NULL)
4538 {
4539 vim_free(newval);
4540 newlen = (unsigned)STRLEN(s) + 1;
4541 if (adding || prepending || removing)
4542 newlen += (unsigned)STRLEN(origval) + 1;
4543 newval = alloc(newlen);
4544 if (newval == NULL)
4545 break;
4546 STRCPY(newval, s);
4547 }
4548 }
4549
4550 /* locate newval[] in origval[] when removing it
4551 * and when adding to avoid duplicates */
4552 i = 0; /* init for GCC */
4553 if (removing || (flags & P_NODUP))
4554 {
4555 i = (int)STRLEN(newval);
4556 bs = 0;
4557 for (s = origval; *s; ++s)
4558 {
4559 if ((!(flags & P_COMMA)
4560 || s == origval
4561 || (s[-1] == ',' && !(bs & 1)))
4562 && STRNCMP(s, newval, i) == 0
4563 && (!(flags & P_COMMA)
4564 || s[i] == ','
4565 || s[i] == NUL))
4566 break;
4567 /* Count backspaces. Only a comma with an
4568 * even number of backspaces before it is
4569 * recognized as a separator */
4570 if (s > origval && s[-1] == '\\')
4571 ++bs;
4572 else
4573 bs = 0;
4574 }
4575
4576 /* do not add if already there */
4577 if ((adding || prepending) && *s)
4578 {
4579 prepending = FALSE;
4580 adding = FALSE;
4581 STRCPY(newval, origval);
4582 }
4583 }
4584
4585 /* concatenate the two strings; add a ',' if
4586 * needed */
4587 if (adding || prepending)
4588 {
4589 comma = ((flags & P_COMMA) && *origval != NUL
4590 && *newval != NUL);
4591 if (adding)
4592 {
4593 i = (int)STRLEN(origval);
4594 mch_memmove(newval + i + comma, newval,
4595 STRLEN(newval) + 1);
4596 mch_memmove(newval, origval, (size_t)i);
4597 }
4598 else
4599 {
4600 i = (int)STRLEN(newval);
4601 mch_memmove(newval + i + comma, origval,
4602 STRLEN(origval) + 1);
4603 }
4604 if (comma)
4605 newval[i] = ',';
4606 }
4607
4608 /* Remove newval[] from origval[]. (Note: "i" has
4609 * been set above and is used here). */
4610 if (removing)
4611 {
4612 STRCPY(newval, origval);
4613 if (*s)
4614 {
4615 /* may need to remove a comma */
4616 if (flags & P_COMMA)
4617 {
4618 if (s == origval)
4619 {
4620 /* include comma after string */
4621 if (s[i] == ',')
4622 ++i;
4623 }
4624 else
4625 {
4626 /* include comma before string */
4627 --s;
4628 ++i;
4629 }
4630 }
4631 mch_memmove(newval + (s - origval), s + i,
4632 STRLEN(s + i) + 1);
4633 }
4634 }
4635
4636 if (flags & P_FLAGLIST)
4637 {
4638 /* Remove flags that appear twice. */
4639 for (s = newval; *s; ++s)
4640 if ((!(flags & P_COMMA) || *s != ',')
4641 && vim_strchr(s + 1, *s) != NULL)
4642 {
Bram Moolenaar3afaae42007-07-24 12:58:01 +00004643 mch_memmove(s, s + 1, STRLEN(s));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 --s;
4645 }
4646 }
4647
4648 if (save_arg != NULL) /* number for 'whichwrap' */
4649 arg = save_arg;
4650 new_value_alloced = TRUE;
4651 }
4652
4653 /* Set the new value. */
4654 *(char_u **)(varp) = newval;
4655
4656 /* Handle side effects, and set the global value for
4657 * ":set" on local options. */
4658 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4659 new_value_alloced, oldval, errbuf, opt_flags);
4660
4661 /* If error detected, print the error message. */
4662 if (errmsg != NULL)
4663 goto skip;
4664 }
4665 else /* key code option */
4666 {
4667 char_u *p;
4668
4669 if (nextchar == '&')
4670 {
4671 if (add_termcap_entry(key_name, TRUE) == FAIL)
4672 errmsg = (char_u *)N_("E522: Not found in termcap");
4673 }
4674 else
4675 {
4676 ++arg; /* jump to after the '=' or ':' */
4677 for (p = arg; *p && !vim_iswhite(*p); ++p)
4678 if (*p == '\\' && p[1] != NUL)
4679 ++p;
4680 nextchar = *p;
4681 *p = NUL;
4682 add_termcode(key_name, arg, FALSE);
4683 *p = nextchar;
4684 }
4685 if (full_screen)
4686 ttest(FALSE);
4687 redraw_all_later(CLEAR);
4688 }
4689 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004690
Bram Moolenaar071d4272004-06-13 20:20:40 +00004691 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004692 did_set_option(opt_idx, opt_flags,
4693 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 }
4695
4696skip:
4697 /*
4698 * Advance to next argument.
4699 * - skip until a blank found, taking care of backslashes
4700 * - skip blanks
4701 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4702 */
4703 for (i = 0; i < 2 ; ++i)
4704 {
4705 while (*arg != NUL && !vim_iswhite(*arg))
4706 if (*arg++ == '\\' && *arg != NUL)
4707 ++arg;
4708 arg = skipwhite(arg);
4709 if (*arg != '=')
4710 break;
4711 }
4712 }
4713
4714 if (errmsg != NULL)
4715 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004716 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004717 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004718 if (i + (arg - startarg) < IOSIZE)
4719 {
4720 /* append the argument with the error */
4721 STRCAT(IObuff, ": ");
4722 mch_memmove(IObuff + i, startarg, (arg - startarg));
4723 IObuff[i + (arg - startarg)] = NUL;
4724 }
4725 /* make sure all characters are printable */
4726 trans_characters(IObuff, IOSIZE);
4727
4728 ++no_wait_return; /* wait_return done later */
4729 emsg(IObuff); /* show error highlighted */
4730 --no_wait_return;
4731
4732 return FAIL;
4733 }
4734
4735 arg = skipwhite(arg);
4736 }
4737
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004738theend:
4739 if (silent_mode && did_show)
4740 {
4741 /* After displaying option values in silent mode. */
4742 silent_mode = FALSE;
4743 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4744 msg_putchar('\n');
4745 cursor_on(); /* msg_start() switches it off */
4746 out_flush();
4747 silent_mode = TRUE;
4748 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4749 }
4750
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 return OK;
4752}
4753
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004754/*
4755 * Call this when an option has been given a new value through a user command.
4756 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4757 */
4758 static void
4759did_set_option(opt_idx, opt_flags, new_value)
4760 int opt_idx;
4761 int opt_flags; /* possibly with OPT_MODELINE */
4762 int new_value; /* value was replaced completely */
4763{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004764 long_u *p;
4765
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004766 options[opt_idx].flags |= P_WAS_SET;
4767
4768 /* When an option is set in the sandbox, from a modeline or in secure mode
4769 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004770 * flag. */
4771 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004772 if (secure
4773#ifdef HAVE_SANDBOX
4774 || sandbox != 0
4775#endif
4776 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004777 *p = *p | P_INSECURE;
4778 else if (new_value)
4779 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004780}
4781
Bram Moolenaar071d4272004-06-13 20:20:40 +00004782 static char_u *
4783illegal_char(errbuf, c)
4784 char_u *errbuf;
4785 int c;
4786{
4787 if (errbuf == NULL)
4788 return (char_u *)"";
4789 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004790 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004791 return errbuf;
4792}
4793
4794/*
4795 * Convert a key name or string into a key value.
4796 * Used for 'wildchar' and 'cedit' options.
4797 */
4798 static int
4799string_to_key(arg)
4800 char_u *arg;
4801{
4802 if (*arg == '<')
4803 return find_key_option(arg + 1);
4804 if (*arg == '^')
4805 return Ctrl_chr(arg[1]);
4806 return *arg;
4807}
4808
4809#ifdef FEAT_CMDWIN
4810/*
4811 * Check value of 'cedit' and set cedit_key.
4812 * Returns NULL if value is OK, error message otherwise.
4813 */
4814 static char_u *
4815check_cedit()
4816{
4817 int n;
4818
4819 if (*p_cedit == NUL)
4820 cedit_key = -1;
4821 else
4822 {
4823 n = string_to_key(p_cedit);
4824 if (vim_isprintc(n))
4825 return e_invarg;
4826 cedit_key = n;
4827 }
4828 return NULL;
4829}
4830#endif
4831
4832#ifdef FEAT_TITLE
4833/*
4834 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4835 * maketitle() to create and display it.
4836 * When switching the title or icon off, call mch_restore_title() to get
4837 * the old value back.
4838 */
4839 static void
4840did_set_title(icon)
4841 int icon; /* Did set icon instead of title */
4842{
4843 if (starting != NO_SCREEN
4844#ifdef FEAT_GUI
4845 && !gui.starting
4846#endif
4847 )
4848 {
4849 maketitle();
4850 if (icon)
4851 {
4852 if (!p_icon)
4853 mch_restore_title(2);
4854 }
4855 else
4856 {
4857 if (!p_title)
4858 mch_restore_title(1);
4859 }
4860 }
4861}
4862#endif
4863
4864/*
4865 * set_options_bin - called when 'bin' changes value.
4866 */
4867 void
4868set_options_bin(oldval, newval, opt_flags)
4869 int oldval;
4870 int newval;
4871 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4872{
4873 /*
4874 * The option values that are changed when 'bin' changes are
4875 * copied when 'bin is set and restored when 'bin' is reset.
4876 */
4877 if (newval)
4878 {
4879 if (!oldval) /* switched on */
4880 {
4881 if (!(opt_flags & OPT_GLOBAL))
4882 {
4883 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4884 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4885 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4886 curbuf->b_p_et_nobin = curbuf->b_p_et;
4887 }
4888 if (!(opt_flags & OPT_LOCAL))
4889 {
4890 p_tw_nobin = p_tw;
4891 p_wm_nobin = p_wm;
4892 p_ml_nobin = p_ml;
4893 p_et_nobin = p_et;
4894 }
4895 }
4896
4897 if (!(opt_flags & OPT_GLOBAL))
4898 {
4899 curbuf->b_p_tw = 0; /* no automatic line wrap */
4900 curbuf->b_p_wm = 0; /* no automatic line wrap */
4901 curbuf->b_p_ml = 0; /* no modelines */
4902 curbuf->b_p_et = 0; /* no expandtab */
4903 }
4904 if (!(opt_flags & OPT_LOCAL))
4905 {
4906 p_tw = 0;
4907 p_wm = 0;
4908 p_ml = FALSE;
4909 p_et = FALSE;
4910 p_bin = TRUE; /* needed when called for the "-b" argument */
4911 }
4912 }
4913 else if (oldval) /* switched off */
4914 {
4915 if (!(opt_flags & OPT_GLOBAL))
4916 {
4917 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4918 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4919 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4920 curbuf->b_p_et = curbuf->b_p_et_nobin;
4921 }
4922 if (!(opt_flags & OPT_LOCAL))
4923 {
4924 p_tw = p_tw_nobin;
4925 p_wm = p_wm_nobin;
4926 p_ml = p_ml_nobin;
4927 p_et = p_et_nobin;
4928 }
4929 }
4930}
4931
4932#ifdef FEAT_VIMINFO
4933/*
4934 * Find the parameter represented by the given character (eg ', :, ", or /),
4935 * and return its associated value in the 'viminfo' string.
4936 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004937 * If the parameter is not specified in the string or there is no following
4938 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 */
4940 int
4941get_viminfo_parameter(type)
4942 int type;
4943{
4944 char_u *p;
4945
4946 p = find_viminfo_parameter(type);
4947 if (p != NULL && VIM_ISDIGIT(*p))
4948 return atoi((char *)p);
4949 return -1;
4950}
4951
4952/*
4953 * Find the parameter represented by the given character (eg ''', ':', '"', or
4954 * '/') in the 'viminfo' option and return a pointer to the string after it.
4955 * Return NULL if the parameter is not specified in the string.
4956 */
4957 char_u *
4958find_viminfo_parameter(type)
4959 int type;
4960{
4961 char_u *p;
4962
4963 for (p = p_viminfo; *p; ++p)
4964 {
4965 if (*p == type)
4966 return p + 1;
4967 if (*p == 'n') /* 'n' is always the last one */
4968 break;
4969 p = vim_strchr(p, ','); /* skip until next ',' */
4970 if (p == NULL) /* hit the end without finding parameter */
4971 break;
4972 }
4973 return NULL;
4974}
4975#endif
4976
4977/*
4978 * Expand environment variables for some string options.
4979 * These string options cannot be indirect!
4980 * If "val" is NULL expand the current value of the option.
4981 * Return pointer to NameBuff, or NULL when not expanded.
4982 */
4983 static char_u *
4984option_expand(opt_idx, val)
4985 int opt_idx;
4986 char_u *val;
4987{
4988 /* if option doesn't need expansion nothing to do */
4989 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4990 return NULL;
4991
4992 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4993 * expand_env() would truncate the string. */
4994 if (val != NULL && STRLEN(val) > MAXPATHL)
4995 return NULL;
4996
4997 if (val == NULL)
4998 val = *(char_u **)options[opt_idx].var;
4999
5000 /*
5001 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5002 * Escape spaces when expanding 'tags', they are used to separate file
5003 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005004 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005005 */
5006 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005007 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005008#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005009 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5010#endif
5011 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5013 return NULL;
5014
5015 return NameBuff;
5016}
5017
5018/*
5019 * After setting various option values: recompute variables that depend on
5020 * option values.
5021 */
5022 static void
5023didset_options()
5024{
5025 /* initialize the table for 'iskeyword' et.al. */
5026 (void)init_chartab();
5027
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005028#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005029 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005031 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5032#ifdef FEAT_SESSION
5033 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5034 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5035#endif
5036#ifdef FEAT_FOLDING
5037 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5038#endif
5039 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5040#ifdef FEAT_VIRTUALEDIT
5041 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5042#endif
5043#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5044 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5045#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005046#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005047 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005048 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005049 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5052 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5053#endif
5054#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5055 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5056#endif
5057#ifdef FEAT_CMDWIN
5058 /* set cedit_key */
5059 (void)check_cedit();
5060#endif
5061}
5062
5063/*
5064 * Check for string options that are NULL (normally only termcap options).
5065 */
5066 void
5067check_options()
5068{
5069 int opt_idx;
5070
5071 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5072 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5073 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5074}
5075
5076/*
5077 * Check string options in a buffer for NULL value.
5078 */
5079 void
5080check_buf_options(buf)
5081 buf_T *buf;
5082{
5083#if defined(FEAT_QUICKFIX)
5084 check_string_option(&buf->b_p_bh);
5085 check_string_option(&buf->b_p_bt);
5086#endif
5087#ifdef FEAT_MBYTE
5088 check_string_option(&buf->b_p_fenc);
5089#endif
5090 check_string_option(&buf->b_p_ff);
5091#ifdef FEAT_FIND_ID
5092 check_string_option(&buf->b_p_def);
5093 check_string_option(&buf->b_p_inc);
5094# ifdef FEAT_EVAL
5095 check_string_option(&buf->b_p_inex);
5096# endif
5097#endif
5098#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5099 check_string_option(&buf->b_p_inde);
5100 check_string_option(&buf->b_p_indk);
5101#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005102#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5103 check_string_option(&buf->b_p_bexpr);
5104#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005105#if defined(FEAT_EVAL)
5106 check_string_option(&buf->b_p_fex);
5107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108#ifdef FEAT_CRYPT
5109 check_string_option(&buf->b_p_key);
5110#endif
5111 check_string_option(&buf->b_p_kp);
5112 check_string_option(&buf->b_p_mps);
5113 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005114 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005115 check_string_option(&buf->b_p_isk);
5116#ifdef FEAT_COMMENTS
5117 check_string_option(&buf->b_p_com);
5118#endif
5119#ifdef FEAT_FOLDING
5120 check_string_option(&buf->b_p_cms);
5121#endif
5122 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005123#ifdef FEAT_TEXTOBJ
5124 check_string_option(&buf->b_p_qe);
5125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126#ifdef FEAT_SYN_HL
5127 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005128#endif
5129#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005130 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005131 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005132 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133#endif
5134#ifdef FEAT_SEARCHPATH
5135 check_string_option(&buf->b_p_sua);
5136#endif
5137#ifdef FEAT_CINDENT
5138 check_string_option(&buf->b_p_cink);
5139 check_string_option(&buf->b_p_cino);
5140#endif
5141#ifdef FEAT_AUTOCMD
5142 check_string_option(&buf->b_p_ft);
5143#endif
5144#ifdef FEAT_OSFILETYPE
5145 check_string_option(&buf->b_p_oft);
5146#endif
5147#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5148 check_string_option(&buf->b_p_cinw);
5149#endif
5150#ifdef FEAT_INS_EXPAND
5151 check_string_option(&buf->b_p_cpt);
5152#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005153#ifdef FEAT_COMPL_FUNC
5154 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005155 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157#ifdef FEAT_KEYMAP
5158 check_string_option(&buf->b_p_keymap);
5159#endif
5160#ifdef FEAT_QUICKFIX
5161 check_string_option(&buf->b_p_gp);
5162 check_string_option(&buf->b_p_mp);
5163 check_string_option(&buf->b_p_efm);
5164#endif
5165 check_string_option(&buf->b_p_ep);
5166 check_string_option(&buf->b_p_path);
5167 check_string_option(&buf->b_p_tags);
5168#ifdef FEAT_INS_EXPAND
5169 check_string_option(&buf->b_p_dict);
5170 check_string_option(&buf->b_p_tsr);
5171#endif
5172}
5173
5174/*
5175 * Free the string allocated for an option.
5176 * Checks for the string being empty_option. This may happen if we're out of
5177 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5178 * check_options().
5179 * Does NOT check for P_ALLOCED flag!
5180 */
5181 void
5182free_string_option(p)
5183 char_u *p;
5184{
5185 if (p != empty_option)
5186 vim_free(p);
5187}
5188
5189 void
5190clear_string_option(pp)
5191 char_u **pp;
5192{
5193 if (*pp != empty_option)
5194 vim_free(*pp);
5195 *pp = empty_option;
5196}
5197
5198 static void
5199check_string_option(pp)
5200 char_u **pp;
5201{
5202 if (*pp == NULL)
5203 *pp = empty_option;
5204}
5205
5206/*
5207 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5208 */
5209 void
5210set_term_option_alloced(p)
5211 char_u **p;
5212{
5213 int opt_idx;
5214
5215 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5216 if (options[opt_idx].var == (char_u *)p)
5217 {
5218 options[opt_idx].flags |= P_ALLOCED;
5219 return;
5220 }
5221 return; /* cannot happen: didn't find it! */
5222}
5223
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005224#if defined(FEAT_EVAL) || defined(PROTO)
5225/*
5226 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5227 * Return FALSE when it wasn't.
5228 * Return -1 for an unknown option.
5229 */
5230 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005231was_set_insecurely(opt, opt_flags)
5232 char_u *opt;
5233 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005234{
5235 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005236 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005237
5238 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005239 {
5240 flagp = insecure_flag(idx, opt_flags);
5241 return (*flagp & P_INSECURE) != 0;
5242 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005243 EMSG2(_(e_intern2), "was_set_insecurely()");
5244 return -1;
5245}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005246
5247/*
5248 * Get a pointer to the flags used for the P_INSECURE flag of option
5249 * "opt_idx". For some local options a local flags field is used.
5250 */
5251 static long_u *
5252insecure_flag(opt_idx, opt_flags)
5253 int opt_idx;
5254 int opt_flags;
5255{
5256 if (opt_flags & OPT_LOCAL)
5257 switch ((int)options[opt_idx].indir)
5258 {
5259#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005260 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005261#endif
5262#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005263# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005264 case PV_FDE: return &curwin->w_p_fde_flags;
5265 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005266# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005267# ifdef FEAT_BEVAL
5268 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5269# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005270# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005271 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005272# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005273 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005274# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005275 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005276# endif
5277#endif
5278 }
5279
5280 /* Nothing special, return global flags field. */
5281 return &options[opt_idx].flags;
5282}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005283#endif
5284
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285/*
5286 * Set a string option to a new value (without checking the effect).
5287 * The string is copied into allocated memory.
5288 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005289 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005290 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005292/*ARGSUSED*/
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005294set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295 char_u *name;
5296 int opt_idx;
5297 char_u *val;
5298 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005299 int set_sid;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300{
5301 char_u *s;
5302 char_u **varp;
5303 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005304 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305
Bram Moolenaar89d40322006-08-29 15:30:07 +00005306 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005308 idx = findoption(name);
5309 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005310 {
5311 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005314 }
5315
Bram Moolenaar89d40322006-08-29 15:30:07 +00005316 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 return;
5318
5319 s = vim_strsave(val);
5320 if (s != NULL)
5321 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005322 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005324 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 free_string_option(*varp);
5326 *varp = s;
5327
5328 /* For buffer/window local option may also set the global value. */
5329 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005330 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331
Bram Moolenaar89d40322006-08-29 15:30:07 +00005332 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333
5334 /* When setting both values of a global option with a local value,
5335 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005336 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337 {
5338 free_string_option(*varp);
5339 *varp = empty_option;
5340 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005341# ifdef FEAT_EVAL
5342 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005343 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005344 set_sid == 0 ? current_SID : set_sid);
5345# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 }
5347}
5348
5349/*
5350 * Set global value for string option when it's a local option.
5351 */
5352 static void
5353set_string_option_global(opt_idx, varp)
5354 int opt_idx; /* option index */
5355 char_u **varp; /* pointer to option variable */
5356{
5357 char_u **p, *s;
5358
5359 /* the global value is always allocated */
5360 if (options[opt_idx].var == VAR_WIN)
5361 p = (char_u **)GLOBAL_WO(varp);
5362 else
5363 p = (char_u **)options[opt_idx].var;
5364 if (options[opt_idx].indir != PV_NONE
5365 && p != varp
5366 && (s = vim_strsave(*varp)) != NULL)
5367 {
5368 free_string_option(*p);
5369 *p = s;
5370 }
5371}
5372
5373/*
5374 * Set a string option to a new value, and handle the effects.
5375 */
5376 static void
5377set_string_option(opt_idx, value, opt_flags)
5378 int opt_idx;
5379 char_u *value;
5380 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5381{
5382 char_u *s;
5383 char_u **varp;
5384 char_u *oldval;
5385
5386 if (options[opt_idx].var == NULL) /* don't set hidden option */
5387 return;
5388
5389 s = vim_strsave(value);
5390 if (s != NULL)
5391 {
5392 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5393 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005394 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395 ? OPT_GLOBAL : OPT_LOCAL)
5396 : opt_flags);
5397 oldval = *varp;
5398 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005399 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5400 opt_flags) == NULL)
5401 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005402 }
5403}
5404
5405/*
5406 * Handle string options that need some action to perform when changed.
5407 * Returns NULL for success, or an error message for an error.
5408 */
5409 static char_u *
5410did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5411 opt_flags)
5412 int opt_idx; /* index in options[] table */
5413 char_u **varp; /* pointer to the option variable */
5414 int new_value_alloced; /* new value was allocated */
5415 char_u *oldval; /* previous value of the option */
5416 char_u *errbuf; /* buffer for errors, or NULL */
5417 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5418{
5419 char_u *errmsg = NULL;
5420 char_u *s, *p;
5421 int did_chartab = FALSE;
5422 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005423 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424
5425 /* Get the global option to compare with, otherwise we would have to check
5426 * two values for all local options. */
5427 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5428
5429 /* Disallow changing some options from secure mode */
5430 if ((secure
5431#ifdef HAVE_SANDBOX
5432 || sandbox != 0
5433#endif
5434 ) && (options[opt_idx].flags & P_SECURE))
5435 {
5436 errmsg = e_secure;
5437 }
5438
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005439 /* Check for a "normal" file name in some options. Disallow a path
5440 * separator (slash and/or backslash), wildcards and characters that are
5441 * often illegal in a file name. */
5442 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005443 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005444 {
5445 errmsg = e_invarg;
5446 }
5447
Bram Moolenaar071d4272004-06-13 20:20:40 +00005448 /* 'term' */
5449 else if (varp == &T_NAME)
5450 {
5451 if (T_NAME[0] == NUL)
5452 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5453#ifdef FEAT_GUI
5454 if (gui.in_use)
5455 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5456 else if (term_is_gui(T_NAME))
5457 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5458#endif
5459 else if (set_termname(T_NAME) == FAIL)
5460 errmsg = (char_u *)N_("E522: Not found in termcap");
5461 else
5462 /* Screen colors may have changed. */
5463 redraw_later_clear();
5464 }
5465
5466 /* 'backupcopy' */
5467 else if (varp == &p_bkc)
5468 {
5469 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5470 errmsg = e_invarg;
5471 if (((bkc_flags & BKC_AUTO) != 0)
5472 + ((bkc_flags & BKC_YES) != 0)
5473 + ((bkc_flags & BKC_NO) != 0) != 1)
5474 {
5475 /* Must have exactly one of "auto", "yes" and "no". */
5476 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5477 errmsg = e_invarg;
5478 }
5479 }
5480
5481 /* 'backupext' and 'patchmode' */
5482 else if (varp == &p_bex || varp == &p_pm)
5483 {
5484 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5485 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5486 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5487 }
5488
5489 /*
5490 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5491 * If the new option is invalid, use old value. 'lisp' option: refill
5492 * chartab[] for '-' char
5493 */
5494 else if ( varp == &p_isi
5495 || varp == &(curbuf->b_p_isk)
5496 || varp == &p_isp
5497 || varp == &p_isf)
5498 {
5499 if (init_chartab() == FAIL)
5500 {
5501 did_chartab = TRUE; /* need to restore it below */
5502 errmsg = e_invarg; /* error in value */
5503 }
5504 }
5505
5506 /* 'helpfile' */
5507 else if (varp == &p_hf)
5508 {
5509 /* May compute new values for $VIM and $VIMRUNTIME */
5510 if (didset_vim)
5511 {
5512 vim_setenv((char_u *)"VIM", (char_u *)"");
5513 didset_vim = FALSE;
5514 }
5515 if (didset_vimruntime)
5516 {
5517 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5518 didset_vimruntime = FALSE;
5519 }
5520 }
5521
5522#ifdef FEAT_MULTI_LANG
5523 /* 'helplang' */
5524 else if (varp == &p_hlg)
5525 {
5526 /* Check for "", "ab", "ab,cd", etc. */
5527 for (s = p_hlg; *s != NUL; s += 3)
5528 {
5529 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5530 {
5531 errmsg = e_invarg;
5532 break;
5533 }
5534 if (s[2] == NUL)
5535 break;
5536 }
5537 }
5538#endif
5539
5540 /* 'highlight' */
5541 else if (varp == &p_hl)
5542 {
5543 if (highlight_changed() == FAIL)
5544 errmsg = e_invarg; /* invalid flags */
5545 }
5546
5547 /* 'nrformats' */
5548 else if (gvarp == &p_nf)
5549 {
5550 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5551 errmsg = e_invarg;
5552 }
5553
5554#ifdef FEAT_SESSION
5555 /* 'sessionoptions' */
5556 else if (varp == &p_ssop)
5557 {
5558 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5559 errmsg = e_invarg;
5560 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5561 {
5562 /* Don't allow both "sesdir" and "curdir". */
5563 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5564 errmsg = e_invarg;
5565 }
5566 }
5567 /* 'viewoptions' */
5568 else if (varp == &p_vop)
5569 {
5570 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5571 errmsg = e_invarg;
5572 }
5573#endif
5574
5575 /* 'scrollopt' */
5576#ifdef FEAT_SCROLLBIND
5577 else if (varp == &p_sbo)
5578 {
5579 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5580 errmsg = e_invarg;
5581 }
5582#endif
5583
5584 /* 'ambiwidth' */
5585#ifdef FEAT_MBYTE
5586 else if (varp == &p_ambw)
5587 {
5588 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5589 errmsg = e_invarg;
5590 }
5591#endif
5592
5593 /* 'background' */
5594 else if (varp == &p_bg)
5595 {
5596 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5597 {
5598#ifdef FEAT_EVAL
5599 int dark = (*p_bg == 'd');
5600#endif
5601
5602 init_highlight(FALSE, FALSE);
5603
5604#ifdef FEAT_EVAL
5605 if (dark != (*p_bg == 'd')
5606 && get_var_value((char_u *)"g:colors_name") != NULL)
5607 {
5608 /* The color scheme must have set 'background' back to another
5609 * value, that's not what we want here. Disable the color
5610 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005611 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612 free_string_option(p_bg);
5613 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5614 check_string_option(&p_bg);
5615 init_highlight(FALSE, FALSE);
5616 }
5617#endif
5618 }
5619 else
5620 errmsg = e_invarg;
5621 }
5622
5623 /* 'wildmode' */
5624 else if (varp == &p_wim)
5625 {
5626 if (check_opt_wim() == FAIL)
5627 errmsg = e_invarg;
5628 }
5629
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005630#ifdef FEAT_CMDL_COMPL
5631 /* 'wildoptions' */
5632 else if (varp == &p_wop)
5633 {
5634 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5635 errmsg = e_invarg;
5636 }
5637#endif
5638
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639#ifdef FEAT_WAK
5640 /* 'winaltkeys' */
5641 else if (varp == &p_wak)
5642 {
5643 if (*p_wak == NUL
5644 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5645 errmsg = e_invarg;
5646# ifdef FEAT_MENU
5647# ifdef FEAT_GUI_MOTIF
5648 else if (gui.in_use)
5649 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5650# else
5651# ifdef FEAT_GUI_GTK
5652 else if (gui.in_use)
5653 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5654# endif
5655# endif
5656# endif
5657 }
5658#endif
5659
5660#ifdef FEAT_AUTOCMD
5661 /* 'eventignore' */
5662 else if (varp == &p_ei)
5663 {
5664 if (check_ei() == FAIL)
5665 errmsg = e_invarg;
5666 }
5667#endif
5668
5669#ifdef FEAT_MBYTE
5670 /* 'encoding' and 'fileencoding' */
5671 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5672 {
5673 if (gvarp == &p_fenc)
5674 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005675 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 errmsg = e_modifiable;
5677 else if (vim_strchr(*varp, ',') != NULL)
5678 /* No comma allowed in 'fileencoding'; catches confusing it
5679 * with 'fileencodings'. */
5680 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005682 {
5683# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 /* May show a "+" in the title now. */
5685 need_maketitle = TRUE;
5686# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005687 /* Add 'fileencoding' to the swap file. */
5688 ml_setflags(curbuf);
5689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 }
5691 if (errmsg == NULL)
5692 {
5693 /* canonize the value, so that STRCMP() can be used on it */
5694 p = enc_canonize(*varp);
5695 if (p != NULL)
5696 {
5697 vim_free(*varp);
5698 *varp = p;
5699 }
5700 if (varp == &p_enc)
5701 {
5702 errmsg = mb_init();
5703# ifdef FEAT_TITLE
5704 need_maketitle = TRUE;
5705# endif
5706 }
5707 }
5708
5709# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5710 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5711 {
5712 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5713 if (STRCMP(p_tenc, "utf-8") != 0)
5714 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5715 }
5716# endif
5717
5718 if (errmsg == NULL)
5719 {
5720# ifdef FEAT_KEYMAP
5721 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5722 * (with another encoding). */
5723 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5724 (void)keymap_init();
5725# endif
5726
5727 /* When 'termencoding' is not empty and 'encoding' changes or when
5728 * 'termencoding' changes, need to setup for keyboard input and
5729 * display output conversion. */
5730 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5731 {
5732 convert_setup(&input_conv, p_tenc, p_enc);
5733 convert_setup(&output_conv, p_enc, p_tenc);
5734 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005735
5736# if defined(WIN3264) && defined(FEAT_MBYTE)
5737 /* $HOME may have characters in active code page. */
5738 if (varp == &p_enc)
5739 init_homedir();
5740# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741 }
5742 }
5743#endif
5744
5745#if defined(FEAT_POSTSCRIPT)
5746 else if (varp == &p_penc)
5747 {
5748 /* Canonize printencoding if VIM standard one */
5749 p = enc_canonize(p_penc);
5750 if (p != NULL)
5751 {
5752 vim_free(p_penc);
5753 p_penc = p;
5754 }
5755 else
5756 {
5757 /* Ensure lower case and '-' for '_' */
5758 for (s = p_penc; *s != NUL; s++)
5759 {
5760 if (*s == '_')
5761 *s = '-';
5762 else
5763 *s = TOLOWER_ASC(*s);
5764 }
5765 }
5766 }
5767#endif
5768
Bram Moolenaar9372a112005-12-06 19:59:18 +00005769#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770 else if (varp == &p_imak)
5771 {
5772 if (gui.in_use && !im_xim_isvalid_imactivate())
5773 errmsg = e_invarg;
5774 }
5775#endif
5776
5777#ifdef FEAT_KEYMAP
5778 else if (varp == &curbuf->b_p_keymap)
5779 {
5780 /* load or unload key mapping tables */
5781 errmsg = keymap_init();
5782
5783 /* When successfully installed a new keymap switch on using it. */
5784 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5785 {
5786 curbuf->b_p_iminsert = B_IMODE_LMAP;
5787 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5788 curbuf->b_p_imsearch = B_IMODE_LMAP;
5789 set_iminsert_global();
5790 set_imsearch_global();
5791# ifdef FEAT_WINDOWS
5792 status_redraw_curbuf();
5793# endif
5794 }
5795 }
5796#endif
5797
5798 /* 'fileformat' */
5799 else if (gvarp == &p_ff)
5800 {
5801 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5802 errmsg = e_modifiable;
5803 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5804 errmsg = e_invarg;
5805 else
5806 {
5807 /* may also change 'textmode' */
5808 if (get_fileformat(curbuf) == EOL_DOS)
5809 curbuf->b_p_tx = TRUE;
5810 else
5811 curbuf->b_p_tx = FALSE;
5812#ifdef FEAT_TITLE
5813 need_maketitle = TRUE;
5814#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005815 /* update flag in swap file */
5816 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005817 }
5818 }
5819
5820 /* 'fileformats' */
5821 else if (varp == &p_ffs)
5822 {
5823 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5824 errmsg = e_invarg;
5825 else
5826 {
5827 /* also change 'textauto' */
5828 if (*p_ffs == NUL)
5829 p_ta = FALSE;
5830 else
5831 p_ta = TRUE;
5832 }
5833 }
5834
5835#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5836 /* 'cryptkey' */
5837 else if (gvarp == &p_key)
5838 {
5839 /* Make sure the ":set" command doesn't show the new value in the
5840 * history. */
5841 remove_key_from_history();
5842 }
5843#endif
5844
5845 /* 'matchpairs' */
5846 else if (gvarp == &p_mps)
5847 {
5848 /* Check for "x:y,x:y" */
5849 for (p = *varp; *p != NUL; p += 4)
5850 {
5851 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5852 {
5853 errmsg = e_invarg;
5854 break;
5855 }
5856 if (p[3] == NUL)
5857 break;
5858 }
5859 }
5860
5861#ifdef FEAT_COMMENTS
5862 /* 'comments' */
5863 else if (gvarp == &p_com)
5864 {
5865 for (s = *varp; *s; )
5866 {
5867 while (*s && *s != ':')
5868 {
5869 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5870 && !VIM_ISDIGIT(*s) && *s != '-')
5871 {
5872 errmsg = illegal_char(errbuf, *s);
5873 break;
5874 }
5875 ++s;
5876 }
5877 if (*s++ == NUL)
5878 errmsg = (char_u *)N_("E524: Missing colon");
5879 else if (*s == ',' || *s == NUL)
5880 errmsg = (char_u *)N_("E525: Zero length string");
5881 if (errmsg != NULL)
5882 break;
5883 while (*s && *s != ',')
5884 {
5885 if (*s == '\\' && s[1] != NUL)
5886 ++s;
5887 ++s;
5888 }
5889 s = skip_to_option_part(s);
5890 }
5891 }
5892#endif
5893
5894 /* 'listchars' */
5895 else if (varp == &p_lcs)
5896 {
5897 errmsg = set_chars_option(varp);
5898 }
5899
5900#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5901 /* 'fillchars' */
5902 else if (varp == &p_fcs)
5903 {
5904 errmsg = set_chars_option(varp);
5905 }
5906#endif
5907
5908#ifdef FEAT_CMDWIN
5909 /* 'cedit' */
5910 else if (varp == &p_cedit)
5911 {
5912 errmsg = check_cedit();
5913 }
5914#endif
5915
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005916 /* 'verbosefile' */
5917 else if (varp == &p_vfile)
5918 {
5919 verbose_stop();
5920 if (*p_vfile != NUL && verbose_open() == FAIL)
5921 errmsg = e_invarg;
5922 }
5923
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924#ifdef FEAT_VIMINFO
5925 /* 'viminfo' */
5926 else if (varp == &p_viminfo)
5927 {
5928 for (s = p_viminfo; *s;)
5929 {
5930 /* Check it's a valid character */
5931 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5932 {
5933 errmsg = illegal_char(errbuf, *s);
5934 break;
5935 }
5936 if (*s == 'n') /* name is always last one */
5937 {
5938 break;
5939 }
5940 else if (*s == 'r') /* skip until next ',' */
5941 {
5942 while (*++s && *s != ',')
5943 ;
5944 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005945 else if (*s == '%')
5946 {
5947 /* optional number */
5948 while (vim_isdigit(*++s))
5949 ;
5950 }
5951 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005952 ++s; /* no extra chars */
5953 else /* must have a number */
5954 {
5955 while (vim_isdigit(*++s))
5956 ;
5957
5958 if (!VIM_ISDIGIT(*(s - 1)))
5959 {
5960 if (errbuf != NULL)
5961 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005962 sprintf((char *)errbuf,
5963 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964 transchar_byte(*(s - 1)));
5965 errmsg = errbuf;
5966 }
5967 else
5968 errmsg = (char_u *)"";
5969 break;
5970 }
5971 }
5972 if (*s == ',')
5973 ++s;
5974 else if (*s)
5975 {
5976 if (errbuf != NULL)
5977 errmsg = (char_u *)N_("E527: Missing comma");
5978 else
5979 errmsg = (char_u *)"";
5980 break;
5981 }
5982 }
5983 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5984 errmsg = (char_u *)N_("E528: Must specify a ' value");
5985 }
5986#endif /* FEAT_VIMINFO */
5987
5988 /* terminal options */
5989 else if (istermoption(&options[opt_idx]) && full_screen)
5990 {
5991 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5992 if (varp == &T_CCO)
5993 {
5994 t_colors = atoi((char *)T_CCO);
5995 if (t_colors <= 1)
5996 {
5997 if (new_value_alloced)
5998 vim_free(T_CCO);
5999 T_CCO = empty_option;
6000 }
6001 /* We now have a different color setup, initialize it again. */
6002 init_highlight(TRUE, FALSE);
6003 }
6004 ttest(FALSE);
6005 if (varp == &T_ME)
6006 {
6007 out_str(T_ME);
6008 redraw_later(CLEAR);
6009#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6010 /* Since t_me has been set, this probably means that the user
6011 * wants to use this as default colors. Need to reset default
6012 * background/foreground colors. */
6013 mch_set_normal_colors();
6014#endif
6015 }
6016 }
6017
6018#ifdef FEAT_LINEBREAK
6019 /* 'showbreak' */
6020 else if (varp == &p_sbr)
6021 {
6022 for (s = p_sbr; *s; )
6023 {
6024 if (ptr2cells(s) != 1)
6025 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006026 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027 }
6028 }
6029#endif
6030
6031#ifdef FEAT_GUI
6032 /* 'guifont' */
6033 else if (varp == &p_guifont)
6034 {
6035 if (gui.in_use)
6036 {
6037 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006038# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039 /*
6040 * Put up a font dialog and let the user select a new value.
6041 * If this is cancelled go back to the old value but don't
6042 * give an error message.
6043 */
6044 if (STRCMP(p, "*") == 0)
6045 {
6046 p = gui_mch_font_dialog(oldval);
6047
6048 if (new_value_alloced)
6049 free_string_option(p_guifont);
6050
6051 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6052 new_value_alloced = TRUE;
6053 }
6054# endif
6055 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6056 {
6057# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6058 if (STRCMP(p_guifont, "*") == 0)
6059 {
6060 /* Dialog was cancelled: Keep the old value without giving
6061 * an error message. */
6062 if (new_value_alloced)
6063 free_string_option(p_guifont);
6064 p_guifont = vim_strsave(oldval);
6065 new_value_alloced = TRUE;
6066 }
6067 else
6068# endif
6069 errmsg = (char_u *)N_("E596: Invalid font(s)");
6070 }
6071 }
6072 }
6073# ifdef FEAT_XFONTSET
6074 else if (varp == &p_guifontset)
6075 {
6076 if (STRCMP(p_guifontset, "*") == 0)
6077 errmsg = (char_u *)N_("E597: can't select fontset");
6078 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6079 errmsg = (char_u *)N_("E598: Invalid fontset");
6080 }
6081# endif
6082# ifdef FEAT_MBYTE
6083 else if (varp == &p_guifontwide)
6084 {
6085 if (STRCMP(p_guifontwide, "*") == 0)
6086 errmsg = (char_u *)N_("E533: can't select wide font");
6087 else if (gui_get_wide_font() == FAIL)
6088 errmsg = (char_u *)N_("E534: Invalid wide font");
6089 }
6090# endif
6091#endif
6092
6093#ifdef CURSOR_SHAPE
6094 /* 'guicursor' */
6095 else if (varp == &p_guicursor)
6096 errmsg = parse_shape_opt(SHAPE_CURSOR);
6097#endif
6098
6099#ifdef FEAT_MOUSESHAPE
6100 /* 'mouseshape' */
6101 else if (varp == &p_mouseshape)
6102 {
6103 errmsg = parse_shape_opt(SHAPE_MOUSE);
6104 update_mouseshape(-1);
6105 }
6106#endif
6107
6108#ifdef FEAT_PRINTER
6109 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006110 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006111# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006112 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006113 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006114# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115#endif
6116
6117#ifdef FEAT_LANGMAP
6118 /* 'langmap' */
6119 else if (varp == &p_langmap)
6120 langmap_set();
6121#endif
6122
6123#ifdef FEAT_LINEBREAK
6124 /* 'breakat' */
6125 else if (varp == &p_breakat)
6126 fill_breakat_flags();
6127#endif
6128
6129#ifdef FEAT_TITLE
6130 /* 'titlestring' and 'iconstring' */
6131 else if (varp == &p_titlestring || varp == &p_iconstring)
6132 {
6133# ifdef FEAT_STL_OPT
6134 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6135
6136 /* NULL => statusline syntax */
6137 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6138 stl_syntax |= flagval;
6139 else
6140 stl_syntax &= ~flagval;
6141# endif
6142 did_set_title(varp == &p_iconstring);
6143
6144 }
6145#endif
6146
6147#ifdef FEAT_GUI
6148 /* 'guioptions' */
6149 else if (varp == &p_go)
6150 gui_init_which_components(oldval);
6151#endif
6152
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006153#if defined(FEAT_GUI_TABLINE)
6154 /* 'guitablabel' */
6155 else if (varp == &p_gtl)
Bram Moolenaar18144c82006-04-12 21:52:12 +00006156 redraw_tabline = TRUE;
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006157#endif
6158
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6160 /* 'ttymouse' */
6161 else if (varp == &p_ttym)
6162 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006163 /* Switch the mouse off before changing the escape sequences used for
6164 * that. */
6165 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006166 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6167 errmsg = e_invarg;
6168 else
6169 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006170 if (termcap_active)
6171 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172 }
6173#endif
6174
6175#ifdef FEAT_VISUAL
6176 /* 'selection' */
6177 else if (varp == &p_sel)
6178 {
6179 if (*p_sel == NUL
6180 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6181 errmsg = e_invarg;
6182 }
6183
6184 /* 'selectmode' */
6185 else if (varp == &p_slm)
6186 {
6187 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6188 errmsg = e_invarg;
6189 }
6190#endif
6191
6192#ifdef FEAT_BROWSE
6193 /* 'browsedir' */
6194 else if (varp == &p_bsdir)
6195 {
6196 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6197 && !mch_isdir(p_bsdir))
6198 errmsg = e_invarg;
6199 }
6200#endif
6201
6202#ifdef FEAT_VISUAL
6203 /* 'keymodel' */
6204 else if (varp == &p_km)
6205 {
6206 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6207 errmsg = e_invarg;
6208 else
6209 {
6210 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6211 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6212 }
6213 }
6214#endif
6215
6216 /* 'mousemodel' */
6217 else if (varp == &p_mousem)
6218 {
6219 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6220 errmsg = e_invarg;
6221#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6222 else if (*p_mousem != *oldval)
6223 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6224 * to create or delete the popup menus. */
6225 gui_motif_update_mousemodel(root_menu);
6226#endif
6227 }
6228
6229 /* 'switchbuf' */
6230 else if (varp == &p_swb)
6231 {
6232 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
6233 errmsg = e_invarg;
6234 }
6235
6236 /* 'debug' */
6237 else if (varp == &p_debug)
6238 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006239 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 errmsg = e_invarg;
6241 }
6242
6243 /* 'display' */
6244 else if (varp == &p_dy)
6245 {
6246 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6247 errmsg = e_invarg;
6248 else
6249 (void)init_chartab();
6250
6251 }
6252
6253#ifdef FEAT_VERTSPLIT
6254 /* 'eadirection' */
6255 else if (varp == &p_ead)
6256 {
6257 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6258 errmsg = e_invarg;
6259 }
6260#endif
6261
6262#ifdef FEAT_CLIPBOARD
6263 /* 'clipboard' */
6264 else if (varp == &p_cb)
6265 errmsg = check_clipboard_option();
6266#endif
6267
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006268#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006269 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6270 * buffer in which 'spell' is set load the wordlists. */
6271 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006272 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006273 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006274 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006275
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006276 if (varp == &(curbuf->b_p_spf))
6277 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006278 l = (int)STRLEN(curbuf->b_p_spf);
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006279 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6280 ".add") != 0))
6281 errmsg = e_invarg;
6282 }
6283
6284 if (errmsg == NULL)
6285 {
6286 FOR_ALL_WINDOWS(wp)
6287 if (wp->w_buffer == curbuf && wp->w_p_spell)
6288 {
6289 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006290# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006291 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006292# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006293 }
6294 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006295 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006296 /* When 'spellcapcheck' is set compile the regexp program. */
6297 else if (varp == &(curbuf->b_p_spc))
6298 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006299 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006300 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006301 /* 'spellsuggest' */
6302 else if (varp == &p_sps)
6303 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006304 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006305 errmsg = e_invarg;
6306 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006307 /* 'mkspellmem' */
6308 else if (varp == &p_msm)
6309 {
6310 if (spell_check_msm() != OK)
6311 errmsg = e_invarg;
6312 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006313#endif
6314
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315#ifdef FEAT_QUICKFIX
6316 /* When 'bufhidden' is set, check for valid value. */
6317 else if (gvarp == &p_bh)
6318 {
6319 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6320 errmsg = e_invarg;
6321 }
6322
6323 /* When 'buftype' is set, check for valid value. */
6324 else if (gvarp == &p_bt)
6325 {
6326 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6327 errmsg = e_invarg;
6328 else
6329 {
6330# ifdef FEAT_WINDOWS
6331 if (curwin->w_status_height)
6332 {
6333 curwin->w_redr_status = TRUE;
6334 redraw_later(VALID);
6335 }
6336# endif
6337 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6338 }
6339 }
6340#endif
6341
6342#ifdef FEAT_STL_OPT
6343 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006344 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 {
6346 int wid;
6347
6348 if (varp == &p_ruf) /* reset ru_wid first */
6349 ru_wid = 0;
6350 s = *varp;
6351 if (varp == &p_ruf && *s == '%')
6352 {
6353 /* set ru_wid if 'ruf' starts with "%99(" */
6354 if (*++s == '-') /* ignore a '-' */
6355 s++;
6356 wid = getdigits(&s);
6357 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6358 ru_wid = wid;
6359 else
6360 errmsg = check_stl_option(p_ruf);
6361 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006362 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006363 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006365 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366 comp_col();
6367 }
6368#endif
6369
6370#ifdef FEAT_INS_EXPAND
6371 /* check if it is a valid value for 'complete' -- Acevedo */
6372 else if (gvarp == &p_cpt)
6373 {
6374 for (s = *varp; *s;)
6375 {
6376 while(*s == ',' || *s == ' ')
6377 s++;
6378 if (!*s)
6379 break;
6380 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6381 {
6382 errmsg = illegal_char(errbuf, *s);
6383 break;
6384 }
6385 if (*++s != NUL && *s != ',' && *s != ' ')
6386 {
6387 if (s[-1] == 'k' || s[-1] == 's')
6388 {
6389 /* skip optional filename after 'k' and 's' */
6390 while (*s && *s != ',' && *s != ' ')
6391 {
6392 if (*s == '\\')
6393 ++s;
6394 ++s;
6395 }
6396 }
6397 else
6398 {
6399 if (errbuf != NULL)
6400 {
6401 sprintf((char *)errbuf,
6402 _("E535: Illegal character after <%c>"),
6403 *--s);
6404 errmsg = errbuf;
6405 }
6406 else
6407 errmsg = (char_u *)"";
6408 break;
6409 }
6410 }
6411 }
6412 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006413
6414 /* 'completeopt' */
6415 else if (varp == &p_cot)
6416 {
6417 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6418 errmsg = e_invarg;
6419 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420#endif /* FEAT_INS_EXPAND */
6421
6422
6423#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6424 else if (varp == &p_toolbar)
6425 {
6426 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6427 &toolbar_flags, TRUE) != OK)
6428 errmsg = e_invarg;
6429 else
6430 {
6431 out_flush();
6432 gui_mch_show_toolbar((toolbar_flags &
6433 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6434 }
6435 }
6436#endif
6437
6438#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6439 /* 'toolbariconsize': GTK+ 2 only */
6440 else if (varp == &p_tbis)
6441 {
6442 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6443 errmsg = e_invarg;
6444 else
6445 {
6446 out_flush();
6447 gui_mch_show_toolbar((toolbar_flags &
6448 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6449 }
6450 }
6451#endif
6452
6453 /* 'pastetoggle': translate key codes like in a mapping */
6454 else if (varp == &p_pt)
6455 {
6456 if (*p_pt)
6457 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006458 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 if (p != NULL)
6460 {
6461 if (new_value_alloced)
6462 free_string_option(p_pt);
6463 p_pt = p;
6464 new_value_alloced = TRUE;
6465 }
6466 }
6467 }
6468
6469 /* 'backspace' */
6470 else if (varp == &p_bs)
6471 {
6472 if (VIM_ISDIGIT(*p_bs))
6473 {
6474 if (*p_bs >'2' || p_bs[1] != NUL)
6475 errmsg = e_invarg;
6476 }
6477 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6478 errmsg = e_invarg;
6479 }
6480
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006481#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482 /* 'casemap' */
6483 else if (varp == &p_cmp)
6484 {
6485 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6486 errmsg = e_invarg;
6487 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489
6490#ifdef FEAT_DIFF
6491 /* 'diffopt' */
6492 else if (varp == &p_dip)
6493 {
6494 if (diffopt_changed() == FAIL)
6495 errmsg = e_invarg;
6496 }
6497#endif
6498
6499#ifdef FEAT_FOLDING
6500 /* 'foldmethod' */
6501 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6502 {
6503 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6504 || *curwin->w_p_fdm == NUL)
6505 errmsg = e_invarg;
6506 else
6507 foldUpdateAll(curwin);
6508 }
6509# ifdef FEAT_EVAL
6510 /* 'foldexpr' */
6511 else if (varp == &curwin->w_p_fde)
6512 {
6513 if (foldmethodIsExpr(curwin))
6514 foldUpdateAll(curwin);
6515 }
6516# endif
6517 /* 'foldmarker' */
6518 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6519 {
6520 p = vim_strchr(*varp, ',');
6521 if (p == NULL)
6522 errmsg = (char_u *)N_("E536: comma required");
6523 else if (p == *varp || p[1] == NUL)
6524 errmsg = e_invarg;
6525 else if (foldmethodIsMarker(curwin))
6526 foldUpdateAll(curwin);
6527 }
6528 /* 'commentstring' */
6529 else if (gvarp == &p_cms)
6530 {
6531 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6532 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6533 }
6534 /* 'foldopen' */
6535 else if (varp == &p_fdo)
6536 {
6537 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6538 errmsg = e_invarg;
6539 }
6540 /* 'foldclose' */
6541 else if (varp == &p_fcl)
6542 {
6543 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6544 errmsg = e_invarg;
6545 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006546 /* 'foldignore' */
6547 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6548 {
6549 if (foldmethodIsIndent(curwin))
6550 foldUpdateAll(curwin);
6551 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552#endif
6553
6554#ifdef FEAT_VIRTUALEDIT
6555 /* 'virtualedit' */
6556 else if (varp == &p_ve)
6557 {
6558 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6559 errmsg = e_invarg;
6560 else if (STRCMP(p_ve, oldval) != 0)
6561 {
6562 /* Recompute cursor position in case the new 've' setting
6563 * changes something. */
6564 validate_virtcol();
6565 coladvance(curwin->w_virtcol);
6566 }
6567 }
6568#endif
6569
6570#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6571 else if (varp == &p_csqf)
6572 {
6573 if (p_csqf != NULL)
6574 {
6575 p = p_csqf;
6576 while (*p != NUL)
6577 {
6578 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6579 || p[1] == NUL
6580 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6581 || (p[2] != NUL && p[2] != ','))
6582 {
6583 errmsg = e_invarg;
6584 break;
6585 }
6586 else if (p[2] == NUL)
6587 break;
6588 else
6589 p += 3;
6590 }
6591 }
6592 }
6593#endif
6594
6595 /* Options that are a list of flags. */
6596 else
6597 {
6598 p = NULL;
6599 if (varp == &p_ww)
6600 p = (char_u *)WW_ALL;
6601 if (varp == &p_shm)
6602 p = (char_u *)SHM_ALL;
6603 else if (varp == &(p_cpo))
6604 p = (char_u *)CPO_ALL;
6605 else if (varp == &(curbuf->b_p_fo))
6606 p = (char_u *)FO_ALL;
6607 else if (varp == &p_mouse)
6608 {
6609#ifdef FEAT_MOUSE
6610 p = (char_u *)MOUSE_ALL;
6611#else
6612 if (*p_mouse != NUL)
6613 errmsg = (char_u *)N_("E538: No mouse support");
6614#endif
6615 }
6616#if defined(FEAT_GUI)
6617 else if (varp == &p_go)
6618 p = (char_u *)GO_ALL;
6619#endif
6620 if (p != NULL)
6621 {
6622 for (s = *varp; *s; ++s)
6623 if (vim_strchr(p, *s) == NULL)
6624 {
6625 errmsg = illegal_char(errbuf, *s);
6626 break;
6627 }
6628 }
6629 }
6630
6631 /*
6632 * If error detected, restore the previous value.
6633 */
6634 if (errmsg != NULL)
6635 {
6636 if (new_value_alloced)
6637 free_string_option(*varp);
6638 *varp = oldval;
6639 /*
6640 * When resetting some values, need to act on it.
6641 */
6642 if (did_chartab)
6643 (void)init_chartab();
6644 if (varp == &p_hl)
6645 (void)highlight_changed();
6646 }
6647 else
6648 {
6649#ifdef FEAT_EVAL
6650 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006651 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006652#endif
6653 /*
6654 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006655 * Use "free_oldval", because recursiveness may change the flags under
6656 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006658 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659 free_string_option(oldval);
6660 if (new_value_alloced)
6661 options[opt_idx].flags |= P_ALLOCED;
6662 else
6663 options[opt_idx].flags &= ~P_ALLOCED;
6664
6665 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006666 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006667 {
6668 /* global option with local value set to use global value; free
6669 * the local value and make it empty */
6670 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6671 free_string_option(*(char_u **)p);
6672 *(char_u **)p = empty_option;
6673 }
6674
6675 /* May set global value for local option. */
6676 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6677 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006678
6679#ifdef FEAT_AUTOCMD
6680 /*
6681 * Trigger the autocommand only after setting the flags.
6682 */
6683# ifdef FEAT_SYN_HL
6684 /* When 'syntax' is set, load the syntax of that name */
6685 if (varp == &(curbuf->b_p_syn))
6686 {
6687 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6688 curbuf->b_fname, TRUE, curbuf);
6689 }
6690# endif
6691 else if (varp == &(curbuf->b_p_ft))
6692 {
6693 /* 'filetype' is set, trigger the FileType autocommand */
6694 did_filetype = TRUE;
6695 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6696 curbuf->b_fname, TRUE, curbuf);
6697 }
6698#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006699#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006700 if (varp == &(curbuf->b_p_spl))
6701 {
6702 char_u fname[200];
6703
6704 /*
6705 * Source the spell/LANG.vim in 'runtimepath'.
6706 * They could set 'spellcapcheck' depending on the language.
6707 * Use the first name in 'spelllang' up to '_region' or
6708 * '.encoding'.
6709 */
6710 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6711 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6712 break;
6713 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6714 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6715 source_runtime(fname, TRUE);
6716 }
6717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 }
6719
6720#ifdef FEAT_MOUSE
6721 if (varp == &p_mouse)
6722 {
6723# ifdef FEAT_MOUSE_TTY
6724 if (*p_mouse == NUL)
6725 mch_setmouse(FALSE); /* switch mouse off */
6726 else
6727# endif
6728 setmouse(); /* in case 'mouse' changed */
6729 }
6730#endif
6731
6732 if (curwin->w_curswant != MAXCOL)
6733 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6734 check_redraw(options[opt_idx].flags);
6735
6736 return errmsg;
6737}
6738
6739/*
6740 * Handle setting 'listchars' or 'fillchars'.
6741 * Returns error message, NULL if it's OK.
6742 */
6743 static char_u *
6744set_chars_option(varp)
6745 char_u **varp;
6746{
6747 int round, i, len, entries;
6748 char_u *p, *s;
6749 int c1, c2 = 0;
6750 struct charstab
6751 {
6752 int *cp;
6753 char *name;
6754 };
6755#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6756 static struct charstab filltab[] =
6757 {
6758 {&fill_stl, "stl"},
6759 {&fill_stlnc, "stlnc"},
6760 {&fill_vert, "vert"},
6761 {&fill_fold, "fold"},
6762 {&fill_diff, "diff"},
6763 };
6764#endif
6765 static struct charstab lcstab[] =
6766 {
6767 {&lcs_eol, "eol"},
6768 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006769 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 {&lcs_prec, "precedes"},
6771 {&lcs_tab2, "tab"},
6772 {&lcs_trail, "trail"},
6773 };
6774 struct charstab *tab;
6775
6776#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6777 if (varp == &p_lcs)
6778#endif
6779 {
6780 tab = lcstab;
6781 entries = sizeof(lcstab) / sizeof(struct charstab);
6782 }
6783#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6784 else
6785 {
6786 tab = filltab;
6787 entries = sizeof(filltab) / sizeof(struct charstab);
6788 }
6789#endif
6790
6791 /* first round: check for valid value, second round: assign values */
6792 for (round = 0; round <= 1; ++round)
6793 {
6794 if (round)
6795 {
6796 /* After checking that the value is valid: set defaults: space for
6797 * 'fillchars', NUL for 'listchars' */
6798 for (i = 0; i < entries; ++i)
6799 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6800 if (varp == &p_lcs)
6801 lcs_tab1 = NUL;
6802#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6803 else
6804 fill_diff = '-';
6805#endif
6806 }
6807 p = *varp;
6808 while (*p)
6809 {
6810 for (i = 0; i < entries; ++i)
6811 {
6812 len = (int)STRLEN(tab[i].name);
6813 if (STRNCMP(p, tab[i].name, len) == 0
6814 && p[len] == ':'
6815 && p[len + 1] != NUL)
6816 {
6817 s = p + len + 1;
6818#ifdef FEAT_MBYTE
6819 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006820 if (mb_char2cells(c1) > 1)
6821 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822#else
6823 c1 = *s++;
6824#endif
6825 if (tab[i].cp == &lcs_tab2)
6826 {
6827 if (*s == NUL)
6828 continue;
6829#ifdef FEAT_MBYTE
6830 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006831 if (mb_char2cells(c2) > 1)
6832 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006833#else
6834 c2 = *s++;
6835#endif
6836 }
6837 if (*s == ',' || *s == NUL)
6838 {
6839 if (round)
6840 {
6841 if (tab[i].cp == &lcs_tab2)
6842 {
6843 lcs_tab1 = c1;
6844 lcs_tab2 = c2;
6845 }
6846 else
6847 *(tab[i].cp) = c1;
6848
6849 }
6850 p = s;
6851 break;
6852 }
6853 }
6854 }
6855
6856 if (i == entries)
6857 return e_invarg;
6858 if (*p == ',')
6859 ++p;
6860 }
6861 }
6862
6863 return NULL; /* no error */
6864}
6865
6866#ifdef FEAT_STL_OPT
6867/*
6868 * Check validity of options with the 'statusline' format.
6869 * Return error message or NULL.
6870 */
6871 char_u *
6872check_stl_option(s)
6873 char_u *s;
6874{
6875 int itemcnt = 0;
6876 int groupdepth = 0;
6877 static char_u errbuf[80];
6878
6879 while (*s && itemcnt < STL_MAX_ITEM)
6880 {
6881 /* Check for valid keys after % sequences */
6882 while (*s && *s != '%')
6883 s++;
6884 if (!*s)
6885 break;
6886 s++;
6887 if (*s != '%' && *s != ')')
6888 ++itemcnt;
6889 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6890 {
6891 s++;
6892 continue;
6893 }
6894 if (*s == ')')
6895 {
6896 s++;
6897 if (--groupdepth < 0)
6898 break;
6899 continue;
6900 }
6901 if (*s == '-')
6902 s++;
6903 while (VIM_ISDIGIT(*s))
6904 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006905 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 continue;
6907 if (*s == '.')
6908 {
6909 s++;
6910 while (*s && VIM_ISDIGIT(*s))
6911 s++;
6912 }
6913 if (*s == '(')
6914 {
6915 groupdepth++;
6916 continue;
6917 }
6918 if (vim_strchr(STL_ALL, *s) == NULL)
6919 {
6920 return illegal_char(errbuf, *s);
6921 }
6922 if (*s == '{')
6923 {
6924 s++;
6925 while (*s != '}' && *s)
6926 s++;
6927 if (*s != '}')
6928 return (char_u *)N_("E540: Unclosed expression sequence");
6929 }
6930 }
6931 if (itemcnt >= STL_MAX_ITEM)
6932 return (char_u *)N_("E541: too many items");
6933 if (groupdepth != 0)
6934 return (char_u *)N_("E542: unbalanced groups");
6935 return NULL;
6936}
6937#endif
6938
6939#ifdef FEAT_CLIPBOARD
6940/*
6941 * Extract the items in the 'clipboard' option and set global values.
6942 */
6943 static char_u *
6944check_clipboard_option()
6945{
6946 int new_unnamed = FALSE;
6947 int new_autoselect = FALSE;
6948 int new_autoselectml = FALSE;
6949 regprog_T *new_exclude_prog = NULL;
6950 char_u *errmsg = NULL;
6951 char_u *p;
6952
6953 for (p = p_cb; *p != NUL; )
6954 {
6955 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6956 {
6957 new_unnamed = TRUE;
6958 p += 7;
6959 }
6960 else if (STRNCMP(p, "autoselect", 10) == 0
6961 && (p[10] == ',' || p[10] == NUL))
6962 {
6963 new_autoselect = TRUE;
6964 p += 10;
6965 }
6966 else if (STRNCMP(p, "autoselectml", 12) == 0
6967 && (p[12] == ',' || p[12] == NUL))
6968 {
6969 new_autoselectml = TRUE;
6970 p += 12;
6971 }
6972 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6973 {
6974 p += 8;
6975 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6976 if (new_exclude_prog == NULL)
6977 errmsg = e_invarg;
6978 break;
6979 }
6980 else
6981 {
6982 errmsg = e_invarg;
6983 break;
6984 }
6985 if (*p == ',')
6986 ++p;
6987 }
6988 if (errmsg == NULL)
6989 {
6990 clip_unnamed = new_unnamed;
6991 clip_autoselect = new_autoselect;
6992 clip_autoselectml = new_autoselectml;
6993 vim_free(clip_exclude_prog);
6994 clip_exclude_prog = new_exclude_prog;
6995 }
6996 else
6997 vim_free(new_exclude_prog);
6998
6999 return errmsg;
7000}
7001#endif
7002
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007003#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007004/*
7005 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7006 * Return error message when failed, NULL when OK.
7007 */
7008 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007009compile_cap_prog(buf)
7010 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007011{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007012 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007013 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007014
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007015 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007016 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007017 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007018 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007019 /* Prepend a ^ so that we only match at one column */
7020 re = concat_str((char_u *)"^", buf->b_p_spc);
7021 if (re != NULL)
7022 {
7023 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7024 if (buf->b_cap_prog == NULL)
7025 {
7026 buf->b_cap_prog = rp; /* restore the previous program */
7027 return e_invarg;
7028 }
7029 vim_free(re);
7030 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007031 }
7032
7033 vim_free(rp);
7034 return NULL;
7035}
7036#endif
7037
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007038#if defined(FEAT_EVAL) || defined(PROTO)
7039/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007040 * Set the scriptID for an option, taking care of setting the buffer- or
7041 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007042 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007043 static void
7044set_option_scriptID_idx(opt_idx, opt_flags, id)
7045 int opt_idx;
7046 int opt_flags;
7047 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007048{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007049 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7050 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007051
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007052 /* Remember where the option was set. For local options need to do that
7053 * in the buffer or window structure. */
7054 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007055 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007056 if (both || (opt_flags & OPT_LOCAL))
7057 {
7058 if (indir & PV_BUF)
7059 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7060 else if (indir & PV_WIN)
7061 curwin->w_p_scriptID[indir & PV_MASK] = id;
7062 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007063}
7064#endif
7065
Bram Moolenaar071d4272004-06-13 20:20:40 +00007066/*
7067 * Set the value of a boolean option, and take care of side effects.
7068 * Returns NULL for success, or an error message for an error.
7069 */
7070 static char_u *
7071set_bool_option(opt_idx, varp, value, opt_flags)
7072 int opt_idx; /* index in options[] table */
7073 char_u *varp; /* pointer to the option variable */
7074 int value; /* new value */
7075 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7076{
7077 int old_value = *(int *)varp;
7078
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 /* Disallow changing some options from secure mode */
7080 if ((secure
7081#ifdef HAVE_SANDBOX
7082 || sandbox != 0
7083#endif
7084 ) && (options[opt_idx].flags & P_SECURE))
7085 return e_secure;
7086
7087 *(int *)varp = value; /* set the new value */
7088#ifdef FEAT_EVAL
7089 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007090 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091#endif
7092
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007093#ifdef FEAT_GUI
7094 need_mouse_correct = TRUE;
7095#endif
7096
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 /* May set global value for local option. */
7098 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7099 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7100
7101 /*
7102 * Handle side effects of changing a bool option.
7103 */
7104
7105 /* 'compatible' */
7106 if ((int *)varp == &p_cp)
7107 {
7108 compatible_set();
7109 }
7110
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 else if ((int *)varp == &curbuf->b_p_ro)
7112 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007113 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7115 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007116
7117 /* when 'readonly' is set may give W10 again */
7118 if (curbuf->b_p_ro)
7119 curbuf->b_did_warn = FALSE;
7120
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121#ifdef FEAT_TITLE
7122 need_maketitle = TRUE;
7123#endif
7124 }
7125
7126#ifdef FEAT_TITLE
7127 /* when 'modifiable' is changed, redraw the window title */
7128 else if ((int *)varp == &curbuf->b_p_ma)
7129 need_maketitle = TRUE;
7130 /* when 'endofline' is changed, redraw the window title */
7131 else if ((int *)varp == &curbuf->b_p_eol)
7132 need_maketitle = TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007133#ifdef FEAT_MBYTE
7134 /* when 'bomb' is changed, redraw the window title */
7135 else if ((int *)varp == &curbuf->b_p_bomb)
7136 need_maketitle = TRUE;
7137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138#endif
7139
7140 /* when 'bin' is set also set some other options */
7141 else if ((int *)varp == &curbuf->b_p_bin)
7142 {
7143 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7144#ifdef FEAT_TITLE
7145 need_maketitle = TRUE;
7146#endif
7147 }
7148
7149#ifdef FEAT_AUTOCMD
7150 /* when 'buflisted' changes, trigger autocommands */
7151 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7152 {
7153 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7154 NULL, NULL, TRUE, curbuf);
7155 }
7156#endif
7157
7158 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7159 else if ((int *)varp == &curbuf->b_p_swf)
7160 {
7161 if (curbuf->b_p_swf && p_uc)
7162 ml_open_file(curbuf); /* create the swap file */
7163 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007164 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7165 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166 mf_close_file(curbuf, TRUE); /* remove the swap file */
7167 }
7168
7169 /* when 'terse' is set change 'shortmess' */
7170 else if ((int *)varp == &p_terse)
7171 {
7172 char_u *p;
7173
7174 p = vim_strchr(p_shm, SHM_SEARCH);
7175
7176 /* insert 's' in p_shm */
7177 if (p_terse && p == NULL)
7178 {
7179 STRCPY(IObuff, p_shm);
7180 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007181 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007182 }
7183 /* remove 's' from p_shm */
7184 else if (!p_terse && p != NULL)
7185 mch_memmove(p, p + 1, STRLEN(p));
7186 }
7187
7188 /* when 'paste' is set or reset also change other options */
7189 else if ((int *)varp == &p_paste)
7190 {
7191 paste_option_changed();
7192 }
7193
7194 /* when 'insertmode' is set from an autocommand need to do work here */
7195 else if ((int *)varp == &p_im)
7196 {
7197 if (p_im)
7198 {
7199 if ((State & INSERT) == 0)
7200 need_start_insertmode = TRUE;
7201 stop_insert_mode = FALSE;
7202 }
7203 else
7204 {
7205 need_start_insertmode = FALSE;
7206 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007207 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 clear_cmdline = TRUE; /* remove "(insert)" */
7209 restart_edit = 0;
7210 }
7211 }
7212
7213 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7214 else if ((int *)varp == &p_ic && p_hls)
7215 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007216 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007217 }
7218
7219#ifdef FEAT_SEARCH_EXTRA
7220 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7221 else if ((int *)varp == &p_hls)
7222 {
7223 no_hlsearch = FALSE;
7224 }
7225#endif
7226
7227#ifdef FEAT_SCROLLBIND
7228 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7229 * at the end of normal_cmd() */
7230 else if ((int *)varp == &curwin->w_p_scb)
7231 {
7232 if (curwin->w_p_scb)
7233 do_check_scrollbind(FALSE);
7234 }
7235#endif
7236
7237#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7238 /* There can be only one window with 'previewwindow' set. */
7239 else if ((int *)varp == &curwin->w_p_pvw)
7240 {
7241 if (curwin->w_p_pvw)
7242 {
7243 win_T *win;
7244
7245 for (win = firstwin; win != NULL; win = win->w_next)
7246 if (win->w_p_pvw && win != curwin)
7247 {
7248 curwin->w_p_pvw = FALSE;
7249 return (char_u *)N_("E590: A preview window already exists");
7250 }
7251 }
7252 }
7253#endif
7254
7255 /* when 'textmode' is set or reset also change 'fileformat' */
7256 else if ((int *)varp == &curbuf->b_p_tx)
7257 {
7258 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7259 }
7260
7261 /* when 'textauto' is set or reset also change 'fileformats' */
7262 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 set_string_option_direct((char_u *)"ffs", -1,
7264 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007265 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266
7267 /*
7268 * When 'lisp' option changes include/exclude '-' in
7269 * keyword characters.
7270 */
7271#ifdef FEAT_LISP
7272 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7273 {
7274 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7275 }
7276#endif
7277
7278#ifdef FEAT_TITLE
7279 /* when 'title' changed, may need to change the title; same for 'icon' */
7280 else if ((int *)varp == &p_title)
7281 {
7282 did_set_title(FALSE);
7283 }
7284
7285 else if ((int *)varp == &p_icon)
7286 {
7287 did_set_title(TRUE);
7288 }
7289#endif
7290
7291 else if ((int *)varp == &curbuf->b_changed)
7292 {
7293 if (!value)
7294 save_file_ff(curbuf); /* Buffer is unchanged */
7295#ifdef FEAT_TITLE
7296 need_maketitle = TRUE;
7297#endif
7298#ifdef FEAT_AUTOCMD
7299 modified_was_set = value;
7300#endif
7301 }
7302
7303#ifdef BACKSLASH_IN_FILENAME
7304 else if ((int *)varp == &p_ssl)
7305 {
7306 if (p_ssl)
7307 {
7308 psepc = '/';
7309 psepcN = '\\';
7310 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 }
7312 else
7313 {
7314 psepc = '\\';
7315 psepcN = '/';
7316 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 }
7318
7319 /* need to adjust the file name arguments and buffer names. */
7320 buflist_slash_adjust();
7321 alist_slash_adjust();
7322# ifdef FEAT_EVAL
7323 scriptnames_slash_adjust();
7324# endif
7325 }
7326#endif
7327
7328 /* If 'wrap' is set, set w_leftcol to zero. */
7329 else if ((int *)varp == &curwin->w_p_wrap)
7330 {
7331 if (curwin->w_p_wrap)
7332 curwin->w_leftcol = 0;
7333 }
7334
7335#ifdef FEAT_WINDOWS
7336 else if ((int *)varp == &p_ea)
7337 {
7338 if (p_ea && !old_value)
7339 win_equal(curwin, FALSE, 0);
7340 }
7341#endif
7342
7343 else if ((int *)varp == &p_wiv)
7344 {
7345 /*
7346 * When 'weirdinvert' changed, set/reset 't_xs'.
7347 * Then set 'weirdinvert' according to value of 't_xs'.
7348 */
7349 if (p_wiv && !old_value)
7350 T_XS = (char_u *)"y";
7351 else if (!p_wiv && old_value)
7352 T_XS = empty_option;
7353 p_wiv = (*T_XS != NUL);
7354 }
7355
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007356#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357 else if ((int *)varp == &p_beval)
7358 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 if (p_beval == TRUE)
7360 gui_mch_enable_beval_area(balloonEval);
7361 else
7362 gui_mch_disable_beval_area(balloonEval);
7363 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007365
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007366#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 else if ((int *)varp == &p_acd)
7368 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007369 /* Change directories when the 'acd' option is set now. */
7370 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371 }
7372#endif
7373
7374#ifdef FEAT_DIFF
7375 /* 'diff' */
7376 else if ((int *)varp == &curwin->w_p_diff)
7377 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007378 /* May add or remove the buffer from the list of diff buffers. */
7379 diff_buf_adjust(curwin);
7380# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007381 if (foldmethodIsDiff(curwin))
7382 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007384 }
7385#endif
7386
7387#ifdef USE_IM_CONTROL
7388 /* 'imdisable' */
7389 else if ((int *)varp == &p_imdisable)
7390 {
7391 /* Only de-activate it here, it will be enabled when changing mode. */
7392 if (p_imdisable)
7393 im_set_active(FALSE);
7394 }
7395#endif
7396
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007397#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007398 /* 'spell' */
7399 else if ((int *)varp == &curwin->w_p_spell)
7400 {
7401 if (curwin->w_p_spell)
7402 {
7403 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007404
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007405 if (errmsg != NULL)
7406 EMSG(_(errmsg));
7407 }
7408 }
7409#endif
7410
Bram Moolenaar071d4272004-06-13 20:20:40 +00007411#ifdef FEAT_FKMAP
7412 else if ((int *)varp == &p_altkeymap)
7413 {
7414 if (old_value != p_altkeymap)
7415 {
7416 if (!p_altkeymap)
7417 {
7418 p_hkmap = p_fkmap;
7419 p_fkmap = 0;
7420 }
7421 else
7422 {
7423 p_fkmap = p_hkmap;
7424 p_hkmap = 0;
7425 }
7426 (void)init_chartab();
7427 }
7428 }
7429
7430 /*
7431 * In case some second language keymapping options have changed, check
7432 * and correct the setting in a consistent way.
7433 */
7434
7435 /*
7436 * If hkmap or fkmap are set, reset Arabic keymapping.
7437 */
7438 if ((p_hkmap || p_fkmap) && p_altkeymap)
7439 {
7440 p_altkeymap = p_fkmap;
7441# ifdef FEAT_ARABIC
7442 curwin->w_p_arab = FALSE;
7443# endif
7444 (void)init_chartab();
7445 }
7446
7447 /*
7448 * If hkmap set, reset Farsi keymapping.
7449 */
7450 if (p_hkmap && p_altkeymap)
7451 {
7452 p_altkeymap = 0;
7453 p_fkmap = 0;
7454# ifdef FEAT_ARABIC
7455 curwin->w_p_arab = FALSE;
7456# endif
7457 (void)init_chartab();
7458 }
7459
7460 /*
7461 * If fkmap set, reset Hebrew keymapping.
7462 */
7463 if (p_fkmap && !p_altkeymap)
7464 {
7465 p_altkeymap = 1;
7466 p_hkmap = 0;
7467# ifdef FEAT_ARABIC
7468 curwin->w_p_arab = FALSE;
7469# endif
7470 (void)init_chartab();
7471 }
7472#endif
7473
7474#ifdef FEAT_ARABIC
7475 if ((int *)varp == &curwin->w_p_arab)
7476 {
7477 if (curwin->w_p_arab)
7478 {
7479 /*
7480 * 'arabic' is set, handle various sub-settings.
7481 */
7482 if (!p_tbidi)
7483 {
7484 /* set rightleft mode */
7485 if (!curwin->w_p_rl)
7486 {
7487 curwin->w_p_rl = TRUE;
7488 changed_window_setting();
7489 }
7490
7491 /* Enable Arabic shaping (major part of what Arabic requires) */
7492 if (!p_arshape)
7493 {
7494 p_arshape = TRUE;
7495 redraw_later_clear();
7496 }
7497 }
7498
7499 /* Arabic requires a utf-8 encoding, inform the user if its not
7500 * set. */
7501 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007502 {
7503 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7505 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507
7508# ifdef FEAT_MBYTE
7509 /* set 'delcombine' */
7510 p_deco = TRUE;
7511# endif
7512
7513# ifdef FEAT_KEYMAP
7514 /* Force-set the necessary keymap for arabic */
7515 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7516 OPT_LOCAL);
7517# endif
7518# ifdef FEAT_FKMAP
7519 p_altkeymap = 0;
7520 p_hkmap = 0;
7521 p_fkmap = 0;
7522 (void)init_chartab();
7523# endif
7524 }
7525 else
7526 {
7527 /*
7528 * 'arabic' is reset, handle various sub-settings.
7529 */
7530 if (!p_tbidi)
7531 {
7532 /* reset rightleft mode */
7533 if (curwin->w_p_rl)
7534 {
7535 curwin->w_p_rl = FALSE;
7536 changed_window_setting();
7537 }
7538
7539 /* 'arabicshape' isn't reset, it is a global option and
7540 * another window may still need it "on". */
7541 }
7542
7543 /* 'delcombine' isn't reset, it is a global option and another
7544 * window may still want it "on". */
7545
7546# ifdef FEAT_KEYMAP
7547 /* Revert to the default keymap */
7548 curbuf->b_p_iminsert = B_IMODE_NONE;
7549 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7550# endif
7551 }
7552 }
7553#endif
7554
7555 /*
7556 * End of handling side effects for bool options.
7557 */
7558
7559 options[opt_idx].flags |= P_WAS_SET;
7560
7561 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7562 if (curwin->w_curswant != MAXCOL)
7563 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7564 check_redraw(options[opt_idx].flags);
7565
7566 return NULL;
7567}
7568
7569/*
7570 * Set the value of a number option, and take care of side effects.
7571 * Returns NULL for success, or an error message for an error.
7572 */
7573 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007574set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575 int opt_idx; /* index in options[] table */
7576 char_u *varp; /* pointer to the option variable */
7577 long value; /* new value */
7578 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007579 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7581 OPT_MODELINE */
7582{
7583 char_u *errmsg = NULL;
7584 long old_value = *(long *)varp;
7585 long old_Rows = Rows; /* remember old Rows */
7586 long old_Columns = Columns; /* remember old Columns */
7587 long *pp = (long *)varp;
7588
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007589 /* Disallow changing some options from secure mode. */
7590 if ((secure
7591#ifdef HAVE_SANDBOX
7592 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007593#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007594 ) && (options[opt_idx].flags & P_SECURE))
7595 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596
7597 *pp = value;
7598#ifdef FEAT_EVAL
7599 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007600 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007602#ifdef FEAT_GUI
7603 need_mouse_correct = TRUE;
7604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605
7606 if (curbuf->b_p_sw <= 0)
7607 {
7608 errmsg = e_positive;
7609 curbuf->b_p_sw = curbuf->b_p_ts;
7610 }
7611
7612 /*
7613 * Number options that need some action when changed
7614 */
7615#ifdef FEAT_WINDOWS
7616 if (pp == &p_wh || pp == &p_hh)
7617 {
7618 if (p_wh < 1)
7619 {
7620 errmsg = e_positive;
7621 p_wh = 1;
7622 }
7623 if (p_wmh > p_wh)
7624 {
7625 errmsg = e_winheight;
7626 p_wh = p_wmh;
7627 }
7628 if (p_hh < 0)
7629 {
7630 errmsg = e_positive;
7631 p_hh = 0;
7632 }
7633
7634 /* Change window height NOW */
7635 if (lastwin != firstwin)
7636 {
7637 if (pp == &p_wh && curwin->w_height < p_wh)
7638 win_setheight((int)p_wh);
7639 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7640 win_setheight((int)p_hh);
7641 }
7642 }
7643
7644 /* 'winminheight' */
7645 else if (pp == &p_wmh)
7646 {
7647 if (p_wmh < 0)
7648 {
7649 errmsg = e_positive;
7650 p_wmh = 0;
7651 }
7652 if (p_wmh > p_wh)
7653 {
7654 errmsg = e_winheight;
7655 p_wmh = p_wh;
7656 }
7657 win_setminheight();
7658 }
7659
7660# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007661 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 {
7663 if (p_wiw < 1)
7664 {
7665 errmsg = e_positive;
7666 p_wiw = 1;
7667 }
7668 if (p_wmw > p_wiw)
7669 {
7670 errmsg = e_winwidth;
7671 p_wiw = p_wmw;
7672 }
7673
7674 /* Change window width NOW */
7675 if (lastwin != firstwin && curwin->w_width < p_wiw)
7676 win_setwidth((int)p_wiw);
7677 }
7678
7679 /* 'winminwidth' */
7680 else if (pp == &p_wmw)
7681 {
7682 if (p_wmw < 0)
7683 {
7684 errmsg = e_positive;
7685 p_wmw = 0;
7686 }
7687 if (p_wmw > p_wiw)
7688 {
7689 errmsg = e_winwidth;
7690 p_wmw = p_wiw;
7691 }
7692 win_setminheight();
7693 }
7694# endif
7695
7696#endif
7697
7698#ifdef FEAT_WINDOWS
7699 /* (re)set last window status line */
7700 else if (pp == &p_ls)
7701 {
7702 last_status(FALSE);
7703 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007704
7705 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007706 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007707 {
7708 shell_new_rows(); /* recompute window positions and heights */
7709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710#endif
7711
7712#ifdef FEAT_GUI
7713 else if (pp == &p_linespace)
7714 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007715 /* Recompute gui.char_height and resize the Vim window to keep the
7716 * same number of lines. */
7717 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007718 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007719 }
7720#endif
7721
7722#ifdef FEAT_FOLDING
7723 /* 'foldlevel' */
7724 else if (pp == &curwin->w_p_fdl)
7725 {
7726 if (curwin->w_p_fdl < 0)
7727 curwin->w_p_fdl = 0;
7728 newFoldLevel();
7729 }
7730
7731 /* 'foldminlevel' */
7732 else if (pp == &curwin->w_p_fml)
7733 {
7734 foldUpdateAll(curwin);
7735 }
7736
7737 /* 'foldnestmax' */
7738 else if (pp == &curwin->w_p_fdn)
7739 {
7740 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7741 foldUpdateAll(curwin);
7742 }
7743
7744 /* 'foldcolumn' */
7745 else if (pp == &curwin->w_p_fdc)
7746 {
7747 if (curwin->w_p_fdc < 0)
7748 {
7749 errmsg = e_positive;
7750 curwin->w_p_fdc = 0;
7751 }
7752 else if (curwin->w_p_fdc > 12)
7753 {
7754 errmsg = e_invarg;
7755 curwin->w_p_fdc = 12;
7756 }
7757 }
7758
7759 /* 'shiftwidth' or 'tabstop' */
7760 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7761 {
7762 if (foldmethodIsIndent(curwin))
7763 foldUpdateAll(curwin);
7764 }
7765#endif /* FEAT_FOLDING */
7766
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007767#ifdef FEAT_MBYTE
7768 /* 'maxcombine' */
7769 else if (pp == &p_mco)
7770 {
7771 if (p_mco > MAX_MCO)
7772 p_mco = MAX_MCO;
7773 else if (p_mco < 0)
7774 p_mco = 0;
7775 screenclear(); /* will re-allocate the screen */
7776 }
7777#endif
7778
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 else if (pp == &curbuf->b_p_iminsert)
7780 {
7781 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7782 {
7783 errmsg = e_invarg;
7784 curbuf->b_p_iminsert = B_IMODE_NONE;
7785 }
7786 p_iminsert = curbuf->b_p_iminsert;
7787 if (termcap_active) /* don't do this in the alternate screen */
7788 showmode();
7789#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7790 /* Show/unshow value of 'keymap' in status lines. */
7791 status_redraw_curbuf();
7792#endif
7793 }
7794
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007795 else if (pp == &p_window)
7796 {
7797 if (p_window < 1)
7798 p_window = 1;
7799 else if (p_window >= Rows)
7800 p_window = Rows - 1;
7801 }
7802
Bram Moolenaar071d4272004-06-13 20:20:40 +00007803 else if (pp == &curbuf->b_p_imsearch)
7804 {
7805 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7806 {
7807 errmsg = e_invarg;
7808 curbuf->b_p_imsearch = B_IMODE_NONE;
7809 }
7810 p_imsearch = curbuf->b_p_imsearch;
7811 }
7812
7813#ifdef FEAT_TITLE
7814 /* if 'titlelen' has changed, redraw the title */
7815 else if (pp == &p_titlelen)
7816 {
7817 if (p_titlelen < 0)
7818 {
7819 errmsg = e_positive;
7820 p_titlelen = 85;
7821 }
7822 if (starting != NO_SCREEN && old_value != p_titlelen)
7823 need_maketitle = TRUE;
7824 }
7825#endif
7826
7827 /* if p_ch changed value, change the command line height */
7828 else if (pp == &p_ch)
7829 {
7830 if (p_ch < 1)
7831 {
7832 errmsg = e_positive;
7833 p_ch = 1;
7834 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00007835 if (p_ch > Rows - min_rows() + 1)
7836 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837
7838 /* Only compute the new window layout when startup has been
7839 * completed. Otherwise the frame sizes may be wrong. */
7840 if (p_ch != old_value && full_screen
7841#ifdef FEAT_GUI
7842 && !gui.starting
7843#endif
7844 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00007845 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 }
7847
7848 /* when 'updatecount' changes from zero to non-zero, open swap files */
7849 else if (pp == &p_uc)
7850 {
7851 if (p_uc < 0)
7852 {
7853 errmsg = e_positive;
7854 p_uc = 100;
7855 }
7856 if (p_uc && !old_value)
7857 ml_open_files();
7858 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007859#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007860 else if (pp == &p_mzq)
7861 mzvim_reset_timer();
7862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863
7864 /* sync undo before 'undolevels' changes */
7865 else if (pp == &p_ul)
7866 {
7867 /* use the old value, otherwise u_sync() may not work properly */
7868 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00007869 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 p_ul = value;
7871 }
7872
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007873#ifdef FEAT_LINEBREAK
7874 /* 'numberwidth' must be positive */
7875 else if (pp == &curwin->w_p_nuw)
7876 {
7877 if (curwin->w_p_nuw < 1)
7878 {
7879 errmsg = e_positive;
7880 curwin->w_p_nuw = 1;
7881 }
7882 if (curwin->w_p_nuw > 10)
7883 {
7884 errmsg = e_invarg;
7885 curwin->w_p_nuw = 10;
7886 }
7887 curwin->w_nrwidth_line_count = 0;
7888 }
7889#endif
7890
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 /*
7892 * Check the bounds for numeric options here
7893 */
7894 if (Rows < min_rows() && full_screen)
7895 {
7896 if (errbuf != NULL)
7897 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007898 vim_snprintf((char *)errbuf, errbuflen,
7899 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 errmsg = errbuf;
7901 }
7902 Rows = min_rows();
7903 }
7904 if (Columns < MIN_COLUMNS && full_screen)
7905 {
7906 if (errbuf != NULL)
7907 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007908 vim_snprintf((char *)errbuf, errbuflen,
7909 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 errmsg = errbuf;
7911 }
7912 Columns = MIN_COLUMNS;
7913 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007914 /* Limit the values to avoid an overflow in Rows * Columns. */
7915 if (Columns > 10000)
7916 Columns = 10000;
7917 if (Rows > 1000)
7918 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919
7920#ifdef DJGPP
7921 /* avoid a crash by checking for a too large value of 'columns' */
7922 if (old_Columns != Columns && full_screen && term_console)
7923 mch_check_columns();
7924#endif
7925
7926 /*
7927 * If the screen (shell) height has been changed, assume it is the
7928 * physical screenheight.
7929 */
7930 if (old_Rows != Rows || old_Columns != Columns)
7931 {
7932 /* Changing the screen size is not allowed while updating the screen. */
7933 if (updating_screen)
7934 *pp = old_value;
7935 else if (full_screen
7936#ifdef FEAT_GUI
7937 && !gui.starting
7938#endif
7939 )
7940 set_shellsize((int)Columns, (int)Rows, TRUE);
7941 else
7942 {
7943 /* Postpone the resizing; check the size and cmdline position for
7944 * messages. */
7945 check_shellsize();
7946 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7947 cmdline_row = Rows - p_ch;
7948 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00007949 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007950 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951 }
7952
7953 if (curbuf->b_p_sts < 0)
7954 {
7955 errmsg = e_positive;
7956 curbuf->b_p_sts = 0;
7957 }
7958 if (curbuf->b_p_ts <= 0)
7959 {
7960 errmsg = e_positive;
7961 curbuf->b_p_ts = 8;
7962 }
7963 if (curbuf->b_p_tw < 0)
7964 {
7965 errmsg = e_positive;
7966 curbuf->b_p_tw = 0;
7967 }
7968 if (p_tm < 0)
7969 {
7970 errmsg = e_positive;
7971 p_tm = 0;
7972 }
7973 if ((curwin->w_p_scr <= 0
7974 || (curwin->w_p_scr > curwin->w_height
7975 && curwin->w_height > 0))
7976 && full_screen)
7977 {
7978 if (pp == &(curwin->w_p_scr))
7979 {
7980 if (curwin->w_p_scr != 0)
7981 errmsg = e_scroll;
7982 win_comp_scroll(curwin);
7983 }
7984 /* If 'scroll' became invalid because of a side effect silently adjust
7985 * it. */
7986 else if (curwin->w_p_scr <= 0)
7987 curwin->w_p_scr = 1;
7988 else /* curwin->w_p_scr > curwin->w_height */
7989 curwin->w_p_scr = curwin->w_height;
7990 }
7991 if (p_report < 0)
7992 {
7993 errmsg = e_positive;
7994 p_report = 1;
7995 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007996 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 {
7998 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7999 p_sj = Rows / 2;
8000 else
8001 {
8002 errmsg = e_scroll;
8003 p_sj = 1;
8004 }
8005 }
8006 if (p_so < 0 && full_screen)
8007 {
8008 errmsg = e_scroll;
8009 p_so = 0;
8010 }
8011 if (p_siso < 0 && full_screen)
8012 {
8013 errmsg = e_positive;
8014 p_siso = 0;
8015 }
8016#ifdef FEAT_CMDWIN
8017 if (p_cwh < 1)
8018 {
8019 errmsg = e_positive;
8020 p_cwh = 1;
8021 }
8022#endif
8023 if (p_ut < 0)
8024 {
8025 errmsg = e_positive;
8026 p_ut = 2000;
8027 }
8028 if (p_ss < 0)
8029 {
8030 errmsg = e_positive;
8031 p_ss = 0;
8032 }
8033
8034 /* May set global value for local option. */
8035 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8036 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8037
8038 options[opt_idx].flags |= P_WAS_SET;
8039
8040 comp_col(); /* in case 'columns' or 'ls' changed */
8041 if (curwin->w_curswant != MAXCOL)
8042 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8043 check_redraw(options[opt_idx].flags);
8044
8045 return errmsg;
8046}
8047
8048/*
8049 * Called after an option changed: check if something needs to be redrawn.
8050 */
8051 static void
8052check_redraw(flags)
8053 long_u flags;
8054{
8055 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8056 int clear = (flags & P_RCLR) == P_RCLR;
8057 int all = ((flags & P_RALL) == P_RALL || clear);
8058
8059#ifdef FEAT_WINDOWS
8060 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8061 status_redraw_all();
8062#endif
8063
8064 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8065 changed_window_setting();
8066 if (flags & P_RBUF)
8067 redraw_curbuf_later(NOT_VALID);
8068 if (clear)
8069 redraw_all_later(CLEAR);
8070 else if (all)
8071 redraw_all_later(NOT_VALID);
8072}
8073
8074/*
8075 * Find index for option 'arg'.
8076 * Return -1 if not found.
8077 */
8078 static int
8079findoption(arg)
8080 char_u *arg;
8081{
8082 int opt_idx;
8083 char *s, *p;
8084 static short quick_tab[27] = {0, 0}; /* quick access table */
8085 int is_term_opt;
8086
8087 /*
8088 * For first call: Initialize the quick-access table.
8089 * It contains the index for the first option that starts with a certain
8090 * letter. There are 26 letters, plus the first "t_" option.
8091 */
8092 if (quick_tab[1] == 0)
8093 {
8094 p = options[0].fullname;
8095 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8096 {
8097 if (s[0] != p[0])
8098 {
8099 if (s[0] == 't' && s[1] == '_')
8100 quick_tab[26] = opt_idx;
8101 else
8102 quick_tab[CharOrdLow(s[0])] = opt_idx;
8103 }
8104 p = s;
8105 }
8106 }
8107
8108 /*
8109 * Check for name starting with an illegal character.
8110 */
8111#ifdef EBCDIC
8112 if (!islower(arg[0]))
8113#else
8114 if (arg[0] < 'a' || arg[0] > 'z')
8115#endif
8116 return -1;
8117
8118 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8119 if (is_term_opt)
8120 opt_idx = quick_tab[26];
8121 else
8122 opt_idx = quick_tab[CharOrdLow(arg[0])];
8123 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8124 {
8125 if (STRCMP(arg, s) == 0) /* match full name */
8126 break;
8127 }
8128 if (s == NULL && !is_term_opt)
8129 {
8130 opt_idx = quick_tab[CharOrdLow(arg[0])];
8131 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8132 {
8133 s = options[opt_idx].shortname;
8134 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8135 break;
8136 s = NULL;
8137 }
8138 }
8139 if (s == NULL)
8140 opt_idx = -1;
8141 return opt_idx;
8142}
8143
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008144#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145/*
8146 * Get the value for an option.
8147 *
8148 * Returns:
8149 * Number or Toggle option: 1, *numval gets value.
8150 * String option: 0, *stringval gets allocated string.
8151 * Hidden Number or Toggle option: -1.
8152 * hidden String option: -2.
8153 * unknown option: -3.
8154 */
8155 int
8156get_option_value(name, numval, stringval, opt_flags)
8157 char_u *name;
8158 long *numval;
8159 char_u **stringval; /* NULL when only checking existance */
8160 int opt_flags;
8161{
8162 int opt_idx;
8163 char_u *varp;
8164
8165 opt_idx = findoption(name);
8166 if (opt_idx < 0) /* unknown option */
8167 return -3;
8168
8169 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8170
8171 if (options[opt_idx].flags & P_STRING)
8172 {
8173 if (varp == NULL) /* hidden option */
8174 return -2;
8175 if (stringval != NULL)
8176 {
8177#ifdef FEAT_CRYPT
8178 /* never return the value of the crypt key */
8179 if ((char_u **)varp == &curbuf->b_p_key)
8180 *stringval = vim_strsave((char_u *)"*****");
8181 else
8182#endif
8183 *stringval = vim_strsave(*(char_u **)(varp));
8184 }
8185 return 0;
8186 }
8187
8188 if (varp == NULL) /* hidden option */
8189 return -1;
8190 if (options[opt_idx].flags & P_NUM)
8191 *numval = *(long *)varp;
8192 else
8193 {
8194 /* Special case: 'modified' is b_changed, but we also want to consider
8195 * it set when 'ff' or 'fenc' changed. */
8196 if ((int *)varp == &curbuf->b_changed)
8197 *numval = curbufIsChanged();
8198 else
8199 *numval = *(int *)varp;
8200 }
8201 return 1;
8202}
8203#endif
8204
8205/*
8206 * Set the value of option "name".
8207 * Use "string" for string options, use "number" for other options.
8208 */
8209 void
8210set_option_value(name, number, string, opt_flags)
8211 char_u *name;
8212 long number;
8213 char_u *string;
8214 int opt_flags; /* OPT_LOCAL or 0 (both) */
8215{
8216 int opt_idx;
8217 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008218 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219
8220 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008221 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 EMSG2(_("E355: Unknown option: %s"), name);
8223 else
8224 {
8225 flags = options[opt_idx].flags;
8226#ifdef HAVE_SANDBOX
8227 /* Disallow changing some options in the sandbox */
8228 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008229 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008230 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008231 return;
8232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008234 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008235 set_string_option(opt_idx, string, opt_flags);
8236 else
8237 {
8238 varp = get_varp(&options[opt_idx]);
8239 if (varp != NULL) /* hidden option is not changed */
8240 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008241 if (number == 0 && string != NULL)
8242 {
8243 int index;
8244
8245 /* Either we are given a string or we are setting option
8246 * to zero. */
8247 for (index = 0; string[index] == '0'; ++index)
8248 ;
8249 if (string[index] != NUL || index == 0)
8250 {
8251 /* There's another character after zeros or the string
8252 * is empty. In both cases, we are trying to set a
8253 * num option using a string. */
8254 EMSG3(_("E521: Number required: &%s = '%s'"),
8255 name, string);
8256 return; /* do nothing as we hit an error */
8257
8258 }
8259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008261 (void)set_num_option(opt_idx, varp, number,
8262 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008264 (void)set_bool_option(opt_idx, varp, (int)number,
8265 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008266 }
8267 }
8268 }
8269}
8270
8271/*
8272 * Get the terminal code for a terminal option.
8273 * Returns NULL when not found.
8274 */
8275 char_u *
8276get_term_code(tname)
8277 char_u *tname;
8278{
8279 int opt_idx;
8280 char_u *varp;
8281
8282 if (tname[0] != 't' || tname[1] != '_' ||
8283 tname[2] == NUL || tname[3] == NUL)
8284 return NULL;
8285 if ((opt_idx = findoption(tname)) >= 0)
8286 {
8287 varp = get_varp(&(options[opt_idx]));
8288 if (varp != NULL)
8289 varp = *(char_u **)(varp);
8290 return varp;
8291 }
8292 return find_termcode(tname + 2);
8293}
8294
8295 char_u *
8296get_highlight_default()
8297{
8298 int i;
8299
8300 i = findoption((char_u *)"hl");
8301 if (i >= 0)
8302 return options[i].def_val[VI_DEFAULT];
8303 return (char_u *)NULL;
8304}
8305
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008306#if defined(FEAT_MBYTE) || defined(PROTO)
8307 char_u *
8308get_encoding_default()
8309{
8310 int i;
8311
8312 i = findoption((char_u *)"enc");
8313 if (i >= 0)
8314 return options[i].def_val[VI_DEFAULT];
8315 return (char_u *)NULL;
8316}
8317#endif
8318
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319/*
8320 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8321 */
8322 static int
8323find_key_option(arg)
8324 char_u *arg;
8325{
8326 int key;
8327 int modifiers;
8328
8329 /*
8330 * Don't use get_special_key_code() for t_xx, we don't want it to call
8331 * add_termcap_entry().
8332 */
8333 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8334 key = TERMCAP2KEY(arg[2], arg[3]);
8335 else
8336 {
8337 --arg; /* put arg at the '<' */
8338 modifiers = 0;
8339 key = find_special_key(&arg, &modifiers, TRUE);
8340 if (modifiers) /* can't handle modifiers here */
8341 key = 0;
8342 }
8343 return key;
8344}
8345
8346/*
8347 * if 'all' == 0: show changed options
8348 * if 'all' == 1: show all normal options
8349 * if 'all' == 2: show all terminal options
8350 */
8351 static void
8352showoptions(all, opt_flags)
8353 int all;
8354 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8355{
8356 struct vimoption *p;
8357 int col;
8358 int isterm;
8359 char_u *varp;
8360 struct vimoption **items;
8361 int item_count;
8362 int run;
8363 int row, rows;
8364 int cols;
8365 int i;
8366 int len;
8367
8368#define INC 20
8369#define GAP 3
8370
8371 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8372 PARAM_COUNT));
8373 if (items == NULL)
8374 return;
8375
8376 /* Highlight title */
8377 if (all == 2)
8378 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8379 else if (opt_flags & OPT_GLOBAL)
8380 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8381 else if (opt_flags & OPT_LOCAL)
8382 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8383 else
8384 MSG_PUTS_TITLE(_("\n--- Options ---"));
8385
8386 /*
8387 * do the loop two times:
8388 * 1. display the short items
8389 * 2. display the long items (only strings and numbers)
8390 */
8391 for (run = 1; run <= 2 && !got_int; ++run)
8392 {
8393 /*
8394 * collect the items in items[]
8395 */
8396 item_count = 0;
8397 for (p = &options[0]; p->fullname != NULL; p++)
8398 {
8399 varp = NULL;
8400 isterm = istermoption(p);
8401 if (opt_flags != 0)
8402 {
8403 if (p->indir != PV_NONE && !isterm)
8404 varp = get_varp_scope(p, opt_flags);
8405 }
8406 else
8407 varp = get_varp(p);
8408 if (varp != NULL
8409 && ((all == 2 && isterm)
8410 || (all == 1 && !isterm)
8411 || (all == 0 && !optval_default(p, varp))))
8412 {
8413 if (p->flags & P_BOOL)
8414 len = 1; /* a toggle option fits always */
8415 else
8416 {
8417 option_value2string(p, opt_flags);
8418 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8419 }
8420 if ((len <= INC - GAP && run == 1) ||
8421 (len > INC - GAP && run == 2))
8422 items[item_count++] = p;
8423 }
8424 }
8425
8426 /*
8427 * display the items
8428 */
8429 if (run == 1)
8430 {
8431 cols = (Columns + GAP - 3) / INC;
8432 if (cols == 0)
8433 cols = 1;
8434 rows = (item_count + cols - 1) / cols;
8435 }
8436 else /* run == 2 */
8437 rows = item_count;
8438 for (row = 0; row < rows && !got_int; ++row)
8439 {
8440 msg_putchar('\n'); /* go to next line */
8441 if (got_int) /* 'q' typed in more */
8442 break;
8443 col = 0;
8444 for (i = row; i < item_count; i += rows)
8445 {
8446 msg_col = col; /* make columns */
8447 showoneopt(items[i], opt_flags);
8448 col += INC;
8449 }
8450 out_flush();
8451 ui_breakcheck();
8452 }
8453 }
8454 vim_free(items);
8455}
8456
8457/*
8458 * Return TRUE if option "p" has its default value.
8459 */
8460 static int
8461optval_default(p, varp)
8462 struct vimoption *p;
8463 char_u *varp;
8464{
8465 int dvi;
8466
8467 if (varp == NULL)
8468 return TRUE; /* hidden option is always at default */
8469 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8470 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008471 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008473 /* the cast to long is required for Manx C, long_i is
8474 * needed for MSVC */
8475 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 /* P_STRING */
8477 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8478}
8479
8480/*
8481 * showoneopt: show the value of one option
8482 * must not be called with a hidden option!
8483 */
8484 static void
8485showoneopt(p, opt_flags)
8486 struct vimoption *p;
8487 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8488{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008489 char_u *varp;
8490 int save_silent = silent_mode;
8491
8492 silent_mode = FALSE;
8493 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494
8495 varp = get_varp_scope(p, opt_flags);
8496
8497 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8498 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8499 ? !curbufIsChanged() : !*(int *)varp))
8500 MSG_PUTS("no");
8501 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8502 MSG_PUTS("--");
8503 else
8504 MSG_PUTS(" ");
8505 MSG_PUTS(p->fullname);
8506 if (!(p->flags & P_BOOL))
8507 {
8508 msg_putchar('=');
8509 /* put value string in NameBuff */
8510 option_value2string(p, opt_flags);
8511 msg_outtrans(NameBuff);
8512 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008513
8514 silent_mode = save_silent;
8515 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516}
8517
8518/*
8519 * Write modified options as ":set" commands to a file.
8520 *
8521 * There are three values for "opt_flags":
8522 * OPT_GLOBAL: Write global option values and fresh values of
8523 * buffer-local options (used for start of a session
8524 * file).
8525 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8526 * curwin (used for a vimrc file).
8527 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8528 * and local values for window-local options of
8529 * curwin. Local values are also written when at the
8530 * default value, because a modeline or autocommand
8531 * may have set them when doing ":edit file" and the
8532 * user has set them back at the default or fresh
8533 * value.
8534 * When "local_only" is TRUE, don't write fresh
8535 * values, only local values (for ":mkview").
8536 * (fresh value = value used for a new buffer or window for a local option).
8537 *
8538 * Return FAIL on error, OK otherwise.
8539 */
8540 int
8541makeset(fd, opt_flags, local_only)
8542 FILE *fd;
8543 int opt_flags;
8544 int local_only;
8545{
8546 struct vimoption *p;
8547 char_u *varp; /* currently used value */
8548 char_u *varp_fresh; /* local value */
8549 char_u *varp_local = NULL; /* fresh value */
8550 char *cmd;
8551 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008552 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553
8554 /*
8555 * The options that don't have a default (terminal name, columns, lines)
8556 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008557 * Do the loop over "options[]" twice: once for options with the
8558 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008560 for (pri = 1; pri >= 0; --pri)
8561 {
8562 for (p = &options[0]; !istermoption(p); p++)
8563 if (!(p->flags & P_NO_MKRC)
8564 && !istermoption(p)
8565 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 {
8567 /* skip global option when only doing locals */
8568 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8569 continue;
8570
8571 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8572 * file, they are always buffer-specific. */
8573 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8574 continue;
8575
8576 /* Global values are only written when not at the default value. */
8577 varp = get_varp_scope(p, opt_flags);
8578 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8579 continue;
8580
8581 round = 2;
8582 if (p->indir != PV_NONE)
8583 {
8584 if (p->var == VAR_WIN)
8585 {
8586 /* skip window-local option when only doing globals */
8587 if (!(opt_flags & OPT_LOCAL))
8588 continue;
8589 /* When fresh value of window-local option is not at the
8590 * default, need to write it too. */
8591 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8592 {
8593 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8594 if (!optval_default(p, varp_fresh))
8595 {
8596 round = 1;
8597 varp_local = varp;
8598 varp = varp_fresh;
8599 }
8600 }
8601 }
8602 }
8603
8604 /* Round 1: fresh value for window-local options.
8605 * Round 2: other values */
8606 for ( ; round <= 2; varp = varp_local, ++round)
8607 {
8608 if (round == 1 || (opt_flags & OPT_GLOBAL))
8609 cmd = "set";
8610 else
8611 cmd = "setlocal";
8612
8613 if (p->flags & P_BOOL)
8614 {
8615 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8616 return FAIL;
8617 }
8618 else if (p->flags & P_NUM)
8619 {
8620 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8621 return FAIL;
8622 }
8623 else /* P_STRING */
8624 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008625#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8626 int do_endif = FALSE;
8627
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 /* Don't set 'syntax' and 'filetype' again if the value is
8629 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008630 if (
8631# if defined(FEAT_SYN_HL)
8632 p->indir == PV_SYN
8633# if defined(FEAT_AUTOCMD)
8634 ||
8635# endif
8636# endif
8637# if defined(FEAT_AUTOCMD)
8638 p->indir == PV_FT)
8639# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 {
8641 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8642 *(char_u **)(varp)) < 0
8643 || put_eol(fd) < 0)
8644 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008645 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8649 (p->flags & P_EXPAND) != 0) == FAIL)
8650 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008651#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8652 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 {
8654 if (put_line(fd, "endif") == FAIL)
8655 return FAIL;
8656 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008657#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 }
8659 }
8660 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 return OK;
8663}
8664
8665#if defined(FEAT_FOLDING) || defined(PROTO)
8666/*
8667 * Generate set commands for the local fold options only. Used when
8668 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8669 */
8670 int
8671makefoldset(fd)
8672 FILE *fd;
8673{
8674 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8675# ifdef FEAT_EVAL
8676 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8677 == FAIL
8678# endif
8679 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8680 == FAIL
8681 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8682 == FAIL
8683 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8684 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8685 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8686 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8687 )
8688 return FAIL;
8689
8690 return OK;
8691}
8692#endif
8693
8694 static int
8695put_setstring(fd, cmd, name, valuep, expand)
8696 FILE *fd;
8697 char *cmd;
8698 char *name;
8699 char_u **valuep;
8700 int expand;
8701{
8702 char_u *s;
8703 char_u buf[MAXPATHL];
8704
8705 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8706 return FAIL;
8707 if (*valuep != NULL)
8708 {
8709 /* Output 'pastetoggle' as key names. For other
8710 * options some characters have to be escaped with
8711 * CTRL-V or backslash */
8712 if (valuep == &p_pt)
8713 {
8714 s = *valuep;
8715 while (*s != NUL)
8716 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8717 return FAIL;
8718 }
8719 else if (expand)
8720 {
8721 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8722 if (put_escstr(fd, buf, 2) == FAIL)
8723 return FAIL;
8724 }
8725 else if (put_escstr(fd, *valuep, 2) == FAIL)
8726 return FAIL;
8727 }
8728 if (put_eol(fd) < 0)
8729 return FAIL;
8730 return OK;
8731}
8732
8733 static int
8734put_setnum(fd, cmd, name, valuep)
8735 FILE *fd;
8736 char *cmd;
8737 char *name;
8738 long *valuep;
8739{
8740 long wc;
8741
8742 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8743 return FAIL;
8744 if (wc_use_keyname((char_u *)valuep, &wc))
8745 {
8746 /* print 'wildchar' and 'wildcharm' as a key name */
8747 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8748 return FAIL;
8749 }
8750 else if (fprintf(fd, "%ld", *valuep) < 0)
8751 return FAIL;
8752 if (put_eol(fd) < 0)
8753 return FAIL;
8754 return OK;
8755}
8756
8757 static int
8758put_setbool(fd, cmd, name, value)
8759 FILE *fd;
8760 char *cmd;
8761 char *name;
8762 int value;
8763{
Bram Moolenaar893de922007-10-02 18:40:57 +00008764 if (value < 0) /* global/local option using global value */
8765 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8767 || put_eol(fd) < 0)
8768 return FAIL;
8769 return OK;
8770}
8771
8772/*
8773 * Clear all the terminal options.
8774 * If the option has been allocated, free the memory.
8775 * Terminal options are never hidden or indirect.
8776 */
8777 void
8778clear_termoptions()
8779{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 /*
8781 * Reset a few things before clearing the old options. This may cause
8782 * outputting a few things that the terminal doesn't understand, but the
8783 * screen will be cleared later, so this is OK.
8784 */
8785#ifdef FEAT_MOUSE_TTY
8786 mch_setmouse(FALSE); /* switch mouse off */
8787#endif
8788#ifdef FEAT_TITLE
8789 mch_restore_title(3); /* restore window titles */
8790#endif
8791#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8792 /* When starting the GUI close the display opened for the clipboard.
8793 * After restoring the title, because that will need the display. */
8794 if (gui.starting)
8795 clear_xterm_clip();
8796#endif
8797#ifdef WIN3264
8798 /*
8799 * Check if this is allowed now.
8800 */
8801 if (can_end_termcap_mode(FALSE) == TRUE)
8802#endif
8803 stoptermcap(); /* stop termcap mode */
8804
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008805 free_termoptions();
8806}
8807
8808 void
8809free_termoptions()
8810{
8811 struct vimoption *p;
8812
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 for (p = &options[0]; p->fullname != NULL; p++)
8814 if (istermoption(p))
8815 {
8816 if (p->flags & P_ALLOCED)
8817 free_string_option(*(char_u **)(p->var));
8818 if (p->flags & P_DEF_ALLOCED)
8819 free_string_option(p->def_val[VI_DEFAULT]);
8820 *(char_u **)(p->var) = empty_option;
8821 p->def_val[VI_DEFAULT] = empty_option;
8822 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8823 }
8824 clear_termcodes();
8825}
8826
8827/*
8828 * Set the terminal option defaults to the current value.
8829 * Used after setting the terminal name.
8830 */
8831 void
8832set_term_defaults()
8833{
8834 struct vimoption *p;
8835
8836 for (p = &options[0]; p->fullname != NULL; p++)
8837 {
8838 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8839 {
8840 if (p->flags & P_DEF_ALLOCED)
8841 {
8842 free_string_option(p->def_val[VI_DEFAULT]);
8843 p->flags &= ~P_DEF_ALLOCED;
8844 }
8845 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8846 if (p->flags & P_ALLOCED)
8847 {
8848 p->flags |= P_DEF_ALLOCED;
8849 p->flags &= ~P_ALLOCED; /* don't free the value now */
8850 }
8851 }
8852 }
8853}
8854
8855/*
8856 * return TRUE if 'p' starts with 't_'
8857 */
8858 static int
8859istermoption(p)
8860 struct vimoption *p;
8861{
8862 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8863}
8864
8865/*
8866 * Compute columns for ruler and shown command. 'sc_col' is also used to
8867 * decide what the maximum length of a message on the status line can be.
8868 * If there is a status line for the last window, 'sc_col' is independent
8869 * of 'ru_col'.
8870 */
8871
8872#define COL_RULER 17 /* columns needed by standard ruler */
8873
8874 void
8875comp_col()
8876{
8877#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8878 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8879
8880 sc_col = 0;
8881 ru_col = 0;
8882 if (p_ru)
8883 {
8884#ifdef FEAT_STL_OPT
8885 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8886#else
8887 ru_col = COL_RULER + 1;
8888#endif
8889 /* no last status line, adjust sc_col */
8890 if (!last_has_status)
8891 sc_col = ru_col;
8892 }
8893 if (p_sc)
8894 {
8895 sc_col += SHOWCMD_COLS;
8896 if (!p_ru || last_has_status) /* no need for separating space */
8897 ++sc_col;
8898 }
8899 sc_col = Columns - sc_col;
8900 ru_col = Columns - ru_col;
8901 if (sc_col <= 0) /* screen too narrow, will become a mess */
8902 sc_col = 1;
8903 if (ru_col <= 0)
8904 ru_col = 1;
8905#else
8906 sc_col = Columns;
8907 ru_col = Columns;
8908#endif
8909}
8910
8911/*
8912 * Get pointer to option variable, depending on local or global scope.
8913 */
8914 static char_u *
8915get_varp_scope(p, opt_flags)
8916 struct vimoption *p;
8917 int opt_flags;
8918{
8919 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8920 {
8921 if (p->var == VAR_WIN)
8922 return (char_u *)GLOBAL_WO(get_varp(p));
8923 return p->var;
8924 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008925 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 {
8927 switch ((int)p->indir)
8928 {
8929#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008930 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
8931 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
8932 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008934 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
8935 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
8936 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008937 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008938 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008940 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
8941 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942#endif
8943#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008944 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
8945 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00008947#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
8948 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
8949#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008950#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008951 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953 }
8954 return NULL; /* "cannot happen" */
8955 }
8956 return get_varp(p);
8957}
8958
8959/*
8960 * Get pointer to option variable.
8961 */
8962 static char_u *
8963get_varp(p)
8964 struct vimoption *p;
8965{
8966 /* hidden option, always return NULL */
8967 if (p->var == NULL)
8968 return NULL;
8969
8970 switch ((int)p->indir)
8971 {
8972 case PV_NONE: return p->var;
8973
8974 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008975 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008977 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008979 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008981 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008982 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008983 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008984 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8985#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008986 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008987 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008988 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8990#endif
8991#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008992 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008994 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8996#endif
8997#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008998 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009000 case PV_GP: return *curbuf->b_p_gp != NUL
9001 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9002 case PV_MP: return *curbuf->b_p_mp != NUL
9003 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009005#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9006 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9007 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9008#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009009#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009010 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009011 ? (char_u *)&(curwin->w_p_stl) : p->var;
9012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013
9014#ifdef FEAT_ARABIC
9015 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9016#endif
9017 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009018#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009019 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9020#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009021#ifdef FEAT_SYN_HL
9022 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9023 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025#ifdef FEAT_DIFF
9026 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9027#endif
9028#ifdef FEAT_FOLDING
9029 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9030 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9031 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9032 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9033 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9034 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9035 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9036# ifdef FEAT_EVAL
9037 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9038 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9039# endif
9040 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9041#endif
9042 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009043#ifdef FEAT_LINEBREAK
9044 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9045#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009046#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9048#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009049#ifdef FEAT_VERTSPLIT
9050 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9053 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9054#endif
9055#ifdef FEAT_RIGHTLEFT
9056 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9057 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9058#endif
9059 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9060 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9061#ifdef FEAT_LINEBREAK
9062 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9063#endif
9064#ifdef FEAT_SCROLLBIND
9065 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9066#endif
9067
9068 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9069 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9070#ifdef FEAT_MBYTE
9071 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9072#endif
9073#if defined(FEAT_QUICKFIX)
9074 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9075 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9076#endif
9077 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9078 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9079#ifdef FEAT_CINDENT
9080 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9081 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9082 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9083#endif
9084#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9085 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9086#endif
9087#ifdef FEAT_COMMENTS
9088 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9089#endif
9090#ifdef FEAT_FOLDING
9091 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9092#endif
9093#ifdef FEAT_INS_EXPAND
9094 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9095#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009096#ifdef FEAT_COMPL_FUNC
9097 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009098 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9101 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9102#ifdef FEAT_MBYTE
9103 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9104#endif
9105 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9106#ifdef FEAT_AUTOCMD
9107 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9108#endif
9109 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009110 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9112 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9113 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9114 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9115#ifdef FEAT_FIND_ID
9116# ifdef FEAT_EVAL
9117 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9118# endif
9119#endif
9120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9121 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9122 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9123#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009124#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009125 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127#ifdef FEAT_CRYPT
9128 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9129#endif
9130#ifdef FEAT_LISP
9131 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9132#endif
9133 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9134 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9135 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9136 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9137 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9138#ifdef FEAT_OSFILETYPE
9139 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9140#endif
9141 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009142#ifdef FEAT_TEXTOBJ
9143 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9146#ifdef FEAT_SMARTINDENT
9147 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9148#endif
9149#ifndef SHORT_FNAME
9150 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9151#endif
9152 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9153#ifdef FEAT_SEARCHPATH
9154 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9155#endif
9156 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9157#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009158 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009159 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9160#endif
9161#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009162 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009163 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009164 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165#endif
9166 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9167 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9168 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9169 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9170 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9171#ifdef FEAT_KEYMAP
9172 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9173#endif
9174 default: EMSG(_("E356: get_varp ERROR"));
9175 }
9176 /* always return a valid pointer to avoid a crash! */
9177 return (char_u *)&(curbuf->b_p_wm);
9178}
9179
9180/*
9181 * Get the value of 'equalprg', either the buffer-local one or the global one.
9182 */
9183 char_u *
9184get_equalprg()
9185{
9186 if (*curbuf->b_p_ep == NUL)
9187 return p_ep;
9188 return curbuf->b_p_ep;
9189}
9190
9191#if defined(FEAT_WINDOWS) || defined(PROTO)
9192/*
9193 * Copy options from one window to another.
9194 * Used when splitting a window.
9195 */
9196 void
9197win_copy_options(wp_from, wp_to)
9198 win_T *wp_from;
9199 win_T *wp_to;
9200{
9201 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9202 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9203# ifdef FEAT_RIGHTLEFT
9204# ifdef FEAT_FKMAP
9205 /* Is this right? */
9206 wp_to->w_farsi = wp_from->w_farsi;
9207# endif
9208# endif
9209}
9210#endif
9211
9212/*
9213 * Copy the options from one winopt_T to another.
9214 * Doesn't free the old option values in "to", use clear_winopt() for that.
9215 * The 'scroll' option is not copied, because it depends on the window height.
9216 * The 'previewwindow' option is reset, there can be only one preview window.
9217 */
9218 void
9219copy_winopt(from, to)
9220 winopt_T *from;
9221 winopt_T *to;
9222{
9223#ifdef FEAT_ARABIC
9224 to->wo_arab = from->wo_arab;
9225#endif
9226 to->wo_list = from->wo_list;
9227 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009228#ifdef FEAT_LINEBREAK
9229 to->wo_nuw = from->wo_nuw;
9230#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231#ifdef FEAT_RIGHTLEFT
9232 to->wo_rl = from->wo_rl;
9233 to->wo_rlc = vim_strsave(from->wo_rlc);
9234#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009235#ifdef FEAT_STL_OPT
9236 to->wo_stl = vim_strsave(from->wo_stl);
9237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009238 to->wo_wrap = from->wo_wrap;
9239#ifdef FEAT_LINEBREAK
9240 to->wo_lbr = from->wo_lbr;
9241#endif
9242#ifdef FEAT_SCROLLBIND
9243 to->wo_scb = from->wo_scb;
9244#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009245#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009246 to->wo_spell = from->wo_spell;
9247#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009248#ifdef FEAT_SYN_HL
9249 to->wo_cuc = from->wo_cuc;
9250 to->wo_cul = from->wo_cul;
9251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009252#ifdef FEAT_DIFF
9253 to->wo_diff = from->wo_diff;
9254#endif
9255#ifdef FEAT_FOLDING
9256 to->wo_fdc = from->wo_fdc;
9257 to->wo_fen = from->wo_fen;
9258 to->wo_fdi = vim_strsave(from->wo_fdi);
9259 to->wo_fml = from->wo_fml;
9260 to->wo_fdl = from->wo_fdl;
9261 to->wo_fdm = vim_strsave(from->wo_fdm);
9262 to->wo_fdn = from->wo_fdn;
9263# ifdef FEAT_EVAL
9264 to->wo_fde = vim_strsave(from->wo_fde);
9265 to->wo_fdt = vim_strsave(from->wo_fdt);
9266# endif
9267 to->wo_fmr = vim_strsave(from->wo_fmr);
9268#endif
9269 check_winopt(to); /* don't want NULL pointers */
9270}
9271
9272/*
9273 * Check string options in a window for a NULL value.
9274 */
9275 void
9276check_win_options(win)
9277 win_T *win;
9278{
9279 check_winopt(&win->w_onebuf_opt);
9280 check_winopt(&win->w_allbuf_opt);
9281}
9282
9283/*
9284 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9285 */
9286/*ARGSUSED*/
9287 void
9288check_winopt(wop)
9289 winopt_T *wop;
9290{
9291#ifdef FEAT_FOLDING
9292 check_string_option(&wop->wo_fdi);
9293 check_string_option(&wop->wo_fdm);
9294# ifdef FEAT_EVAL
9295 check_string_option(&wop->wo_fde);
9296 check_string_option(&wop->wo_fdt);
9297# endif
9298 check_string_option(&wop->wo_fmr);
9299#endif
9300#ifdef FEAT_RIGHTLEFT
9301 check_string_option(&wop->wo_rlc);
9302#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009303#ifdef FEAT_STL_OPT
9304 check_string_option(&wop->wo_stl);
9305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306}
9307
9308/*
9309 * Free the allocated memory inside a winopt_T.
9310 */
9311/*ARGSUSED*/
9312 void
9313clear_winopt(wop)
9314 winopt_T *wop;
9315{
9316#ifdef FEAT_FOLDING
9317 clear_string_option(&wop->wo_fdi);
9318 clear_string_option(&wop->wo_fdm);
9319# ifdef FEAT_EVAL
9320 clear_string_option(&wop->wo_fde);
9321 clear_string_option(&wop->wo_fdt);
9322# endif
9323 clear_string_option(&wop->wo_fmr);
9324#endif
9325#ifdef FEAT_RIGHTLEFT
9326 clear_string_option(&wop->wo_rlc);
9327#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009328#ifdef FEAT_STL_OPT
9329 clear_string_option(&wop->wo_stl);
9330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331}
9332
9333/*
9334 * Copy global option values to local options for one buffer.
9335 * Used when creating a new buffer and sometimes when entering a buffer.
9336 * flags:
9337 * BCO_ENTER We will enter the buf buffer.
9338 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9339 * appropriate.
9340 * BCO_NOHELP Don't copy the values to a help buffer.
9341 */
9342 void
9343buf_copy_options(buf, flags)
9344 buf_T *buf;
9345 int flags;
9346{
9347 int should_copy = TRUE;
9348 char_u *save_p_isk = NULL; /* init for GCC */
9349 int dont_do_help;
9350 int did_isk = FALSE;
9351
9352 /*
9353 * Don't do anything of the buffer is invalid.
9354 */
9355 if (buf == NULL || !buf_valid(buf))
9356 return;
9357
9358 /*
9359 * Skip this when the option defaults have not been set yet. Happens when
9360 * main() allocates the first buffer.
9361 */
9362 if (p_cpo != NULL)
9363 {
9364 /*
9365 * Always copy when entering and 'cpo' contains 'S'.
9366 * Don't copy when already initialized.
9367 * Don't copy when 'cpo' contains 's' and not entering.
9368 * 'S' BCO_ENTER initialized 's' should_copy
9369 * yes yes X X TRUE
9370 * yes no yes X FALSE
9371 * no X yes X FALSE
9372 * X no no yes FALSE
9373 * X no no no TRUE
9374 * no yes no X TRUE
9375 */
9376 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9377 && (buf->b_p_initialized
9378 || (!(flags & BCO_ENTER)
9379 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9380 should_copy = FALSE;
9381
9382 if (should_copy || (flags & BCO_ALWAYS))
9383 {
9384 /* Don't copy the options specific to a help buffer when
9385 * BCO_NOHELP is given or the options were initialized already
9386 * (jumping back to a help file with CTRL-T or CTRL-O) */
9387 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9388 || buf->b_p_initialized;
9389 if (dont_do_help) /* don't free b_p_isk */
9390 {
9391 save_p_isk = buf->b_p_isk;
9392 buf->b_p_isk = NULL;
9393 }
9394 /*
9395 * Always free the allocated strings.
9396 * If not already initialized, set 'readonly' and copy 'fileformat'.
9397 */
9398 if (!buf->b_p_initialized)
9399 {
9400 free_buf_options(buf, TRUE);
9401 buf->b_p_ro = FALSE; /* don't copy readonly */
9402 buf->b_p_tx = p_tx;
9403#ifdef FEAT_MBYTE
9404 buf->b_p_fenc = vim_strsave(p_fenc);
9405#endif
9406 buf->b_p_ff = vim_strsave(p_ff);
9407#if defined(FEAT_QUICKFIX)
9408 buf->b_p_bh = empty_option;
9409 buf->b_p_bt = empty_option;
9410#endif
9411 }
9412 else
9413 free_buf_options(buf, FALSE);
9414
9415 buf->b_p_ai = p_ai;
9416 buf->b_p_ai_nopaste = p_ai_nopaste;
9417 buf->b_p_sw = p_sw;
9418 buf->b_p_tw = p_tw;
9419 buf->b_p_tw_nopaste = p_tw_nopaste;
9420 buf->b_p_tw_nobin = p_tw_nobin;
9421 buf->b_p_wm = p_wm;
9422 buf->b_p_wm_nopaste = p_wm_nopaste;
9423 buf->b_p_wm_nobin = p_wm_nobin;
9424 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009425#ifdef FEAT_MBYTE
9426 buf->b_p_bomb = p_bomb;
9427#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009428 buf->b_p_et = p_et;
9429 buf->b_p_et_nobin = p_et_nobin;
9430 buf->b_p_ml = p_ml;
9431 buf->b_p_ml_nobin = p_ml_nobin;
9432 buf->b_p_inf = p_inf;
9433 buf->b_p_swf = p_swf;
9434#ifdef FEAT_INS_EXPAND
9435 buf->b_p_cpt = vim_strsave(p_cpt);
9436#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009437#ifdef FEAT_COMPL_FUNC
9438 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009439 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441 buf->b_p_sts = p_sts;
9442 buf->b_p_sts_nopaste = p_sts_nopaste;
9443#ifndef SHORT_FNAME
9444 buf->b_p_sn = p_sn;
9445#endif
9446#ifdef FEAT_COMMENTS
9447 buf->b_p_com = vim_strsave(p_com);
9448#endif
9449#ifdef FEAT_FOLDING
9450 buf->b_p_cms = vim_strsave(p_cms);
9451#endif
9452 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009453 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 buf->b_p_nf = vim_strsave(p_nf);
9455 buf->b_p_mps = vim_strsave(p_mps);
9456#ifdef FEAT_SMARTINDENT
9457 buf->b_p_si = p_si;
9458#endif
9459 buf->b_p_ci = p_ci;
9460#ifdef FEAT_CINDENT
9461 buf->b_p_cin = p_cin;
9462 buf->b_p_cink = vim_strsave(p_cink);
9463 buf->b_p_cino = vim_strsave(p_cino);
9464#endif
9465#ifdef FEAT_AUTOCMD
9466 /* Don't copy 'filetype', it must be detected */
9467 buf->b_p_ft = empty_option;
9468#endif
9469#ifdef FEAT_OSFILETYPE
9470 buf->b_p_oft = vim_strsave(p_oft);
9471#endif
9472 buf->b_p_pi = p_pi;
9473#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9474 buf->b_p_cinw = vim_strsave(p_cinw);
9475#endif
9476#ifdef FEAT_LISP
9477 buf->b_p_lisp = p_lisp;
9478#endif
9479#ifdef FEAT_SYN_HL
9480 /* Don't copy 'syntax', it must be set */
9481 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009482 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009483#endif
9484#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009485 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009486 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009487 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009488 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489#endif
9490#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9491 buf->b_p_inde = vim_strsave(p_inde);
9492 buf->b_p_indk = vim_strsave(p_indk);
9493#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009494#if defined(FEAT_EVAL)
9495 buf->b_p_fex = vim_strsave(p_fex);
9496#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497#ifdef FEAT_CRYPT
9498 buf->b_p_key = vim_strsave(p_key);
9499#endif
9500#ifdef FEAT_SEARCHPATH
9501 buf->b_p_sua = vim_strsave(p_sua);
9502#endif
9503#ifdef FEAT_KEYMAP
9504 buf->b_p_keymap = vim_strsave(p_keymap);
9505 buf->b_kmap_state |= KEYMAP_INIT;
9506#endif
9507 /* This isn't really an option, but copying the langmap and IME
9508 * state from the current buffer is better than resetting it. */
9509 buf->b_p_iminsert = p_iminsert;
9510 buf->b_p_imsearch = p_imsearch;
9511
9512 /* options that are normally global but also have a local value
9513 * are not copied, start using the global value */
9514 buf->b_p_ar = -1;
9515#ifdef FEAT_QUICKFIX
9516 buf->b_p_gp = empty_option;
9517 buf->b_p_mp = empty_option;
9518 buf->b_p_efm = empty_option;
9519#endif
9520 buf->b_p_ep = empty_option;
9521 buf->b_p_kp = empty_option;
9522 buf->b_p_path = empty_option;
9523 buf->b_p_tags = empty_option;
9524#ifdef FEAT_FIND_ID
9525 buf->b_p_def = empty_option;
9526 buf->b_p_inc = empty_option;
9527# ifdef FEAT_EVAL
9528 buf->b_p_inex = vim_strsave(p_inex);
9529# endif
9530#endif
9531#ifdef FEAT_INS_EXPAND
9532 buf->b_p_dict = empty_option;
9533 buf->b_p_tsr = empty_option;
9534#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009535#ifdef FEAT_TEXTOBJ
9536 buf->b_p_qe = vim_strsave(p_qe);
9537#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009538#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9539 buf->b_p_bexpr = empty_option;
9540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541
9542 /*
9543 * Don't copy the options set by ex_help(), use the saved values,
9544 * when going from a help buffer to a non-help buffer.
9545 * Don't touch these at all when BCO_NOHELP is used and going from
9546 * or to a help buffer.
9547 */
9548 if (dont_do_help)
9549 buf->b_p_isk = save_p_isk;
9550 else
9551 {
9552 buf->b_p_isk = vim_strsave(p_isk);
9553 did_isk = TRUE;
9554 buf->b_p_ts = p_ts;
9555 buf->b_help = FALSE;
9556#ifdef FEAT_QUICKFIX
9557 if (buf->b_p_bt[0] == 'h')
9558 clear_string_option(&buf->b_p_bt);
9559#endif
9560 buf->b_p_ma = p_ma;
9561 }
9562 }
9563
9564 /*
9565 * When the options should be copied (ignoring BCO_ALWAYS), set the
9566 * flag that indicates that the options have been initialized.
9567 */
9568 if (should_copy)
9569 buf->b_p_initialized = TRUE;
9570 }
9571
9572 check_buf_options(buf); /* make sure we don't have NULLs */
9573 if (did_isk)
9574 (void)buf_init_chartab(buf, FALSE);
9575}
9576
9577/*
9578 * Reset the 'modifiable' option and its default value.
9579 */
9580 void
9581reset_modifiable()
9582{
9583 int opt_idx;
9584
9585 curbuf->b_p_ma = FALSE;
9586 p_ma = FALSE;
9587 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009588 if (opt_idx >= 0)
9589 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590}
9591
9592/*
9593 * Set the global value for 'iminsert' to the local value.
9594 */
9595 void
9596set_iminsert_global()
9597{
9598 p_iminsert = curbuf->b_p_iminsert;
9599}
9600
9601/*
9602 * Set the global value for 'imsearch' to the local value.
9603 */
9604 void
9605set_imsearch_global()
9606{
9607 p_imsearch = curbuf->b_p_imsearch;
9608}
9609
9610#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9611static int expand_option_idx = -1;
9612static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9613static int expand_option_flags = 0;
9614
9615 void
9616set_context_in_set_cmd(xp, arg, opt_flags)
9617 expand_T *xp;
9618 char_u *arg;
9619 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9620{
9621 int nextchar;
9622 long_u flags = 0; /* init for GCC */
9623 int opt_idx = 0; /* init for GCC */
9624 char_u *p;
9625 char_u *s;
9626 int is_term_option = FALSE;
9627 int key;
9628
9629 expand_option_flags = opt_flags;
9630
9631 xp->xp_context = EXPAND_SETTINGS;
9632 if (*arg == NUL)
9633 {
9634 xp->xp_pattern = arg;
9635 return;
9636 }
9637 p = arg + STRLEN(arg) - 1;
9638 if (*p == ' ' && *(p - 1) != '\\')
9639 {
9640 xp->xp_pattern = p + 1;
9641 return;
9642 }
9643 while (p > arg)
9644 {
9645 s = p;
9646 /* count number of backslashes before ' ' or ',' */
9647 if (*p == ' ' || *p == ',')
9648 {
9649 while (s > arg && *(s - 1) == '\\')
9650 --s;
9651 }
9652 /* break at a space with an even number of backslashes */
9653 if (*p == ' ' && ((p - s) & 1) == 0)
9654 {
9655 ++p;
9656 break;
9657 }
9658 --p;
9659 }
9660 if (STRNCMP(p, "no", 2) == 0)
9661 {
9662 xp->xp_context = EXPAND_BOOL_SETTINGS;
9663 p += 2;
9664 }
9665 if (STRNCMP(p, "inv", 3) == 0)
9666 {
9667 xp->xp_context = EXPAND_BOOL_SETTINGS;
9668 p += 3;
9669 }
9670 xp->xp_pattern = arg = p;
9671 if (*arg == '<')
9672 {
9673 while (*p != '>')
9674 if (*p++ == NUL) /* expand terminal option name */
9675 return;
9676 key = get_special_key_code(arg + 1);
9677 if (key == 0) /* unknown name */
9678 {
9679 xp->xp_context = EXPAND_NOTHING;
9680 return;
9681 }
9682 nextchar = *++p;
9683 is_term_option = TRUE;
9684 expand_option_name[2] = KEY2TERMCAP0(key);
9685 expand_option_name[3] = KEY2TERMCAP1(key);
9686 }
9687 else
9688 {
9689 if (p[0] == 't' && p[1] == '_')
9690 {
9691 p += 2;
9692 if (*p != NUL)
9693 ++p;
9694 if (*p == NUL)
9695 return; /* expand option name */
9696 nextchar = *++p;
9697 is_term_option = TRUE;
9698 expand_option_name[2] = p[-2];
9699 expand_option_name[3] = p[-1];
9700 }
9701 else
9702 {
9703 /* Allow * wildcard */
9704 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9705 p++;
9706 if (*p == NUL)
9707 return;
9708 nextchar = *p;
9709 *p = NUL;
9710 opt_idx = findoption(arg);
9711 *p = nextchar;
9712 if (opt_idx == -1 || options[opt_idx].var == NULL)
9713 {
9714 xp->xp_context = EXPAND_NOTHING;
9715 return;
9716 }
9717 flags = options[opt_idx].flags;
9718 if (flags & P_BOOL)
9719 {
9720 xp->xp_context = EXPAND_NOTHING;
9721 return;
9722 }
9723 }
9724 }
9725 /* handle "-=" and "+=" */
9726 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9727 {
9728 ++p;
9729 nextchar = '=';
9730 }
9731 if ((nextchar != '=' && nextchar != ':')
9732 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9733 {
9734 xp->xp_context = EXPAND_UNSUCCESSFUL;
9735 return;
9736 }
9737 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9738 {
9739 xp->xp_context = EXPAND_OLD_SETTING;
9740 if (is_term_option)
9741 expand_option_idx = -1;
9742 else
9743 expand_option_idx = opt_idx;
9744 xp->xp_pattern = p + 1;
9745 return;
9746 }
9747 xp->xp_context = EXPAND_NOTHING;
9748 if (is_term_option || (flags & P_NUM))
9749 return;
9750
9751 xp->xp_pattern = p + 1;
9752
9753 if (flags & P_EXPAND)
9754 {
9755 p = options[opt_idx].var;
9756 if (p == (char_u *)&p_bdir
9757 || p == (char_u *)&p_dir
9758 || p == (char_u *)&p_path
9759 || p == (char_u *)&p_rtp
9760#ifdef FEAT_SEARCHPATH
9761 || p == (char_u *)&p_cdpath
9762#endif
9763#ifdef FEAT_SESSION
9764 || p == (char_u *)&p_vdir
9765#endif
9766 )
9767 {
9768 xp->xp_context = EXPAND_DIRECTORIES;
9769 if (p == (char_u *)&p_path
9770#ifdef FEAT_SEARCHPATH
9771 || p == (char_u *)&p_cdpath
9772#endif
9773 )
9774 xp->xp_backslash = XP_BS_THREE;
9775 else
9776 xp->xp_backslash = XP_BS_ONE;
9777 }
9778 else
9779 {
9780 xp->xp_context = EXPAND_FILES;
9781 /* for 'tags' need three backslashes for a space */
9782 if (p == (char_u *)&p_tags)
9783 xp->xp_backslash = XP_BS_THREE;
9784 else
9785 xp->xp_backslash = XP_BS_ONE;
9786 }
9787 }
9788
9789 /* For an option that is a list of file names, find the start of the
9790 * last file name. */
9791 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9792 {
9793 /* count number of backslashes before ' ' or ',' */
9794 if (*p == ' ' || *p == ',')
9795 {
9796 s = p;
9797 while (s > xp->xp_pattern && *(s - 1) == '\\')
9798 --s;
9799 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9800 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9801 {
9802 xp->xp_pattern = p + 1;
9803 break;
9804 }
9805 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009806
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009807#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009808 /* for 'spellsuggest' start at "file:" */
9809 if (options[opt_idx].var == (char_u *)&p_sps
9810 && STRNCMP(p, "file:", 5) == 0)
9811 {
9812 xp->xp_pattern = p + 5;
9813 break;
9814 }
9815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 }
9817
9818 return;
9819}
9820
9821 int
9822ExpandSettings(xp, regmatch, num_file, file)
9823 expand_T *xp;
9824 regmatch_T *regmatch;
9825 int *num_file;
9826 char_u ***file;
9827{
9828 int num_normal = 0; /* Nr of matching non-term-code settings */
9829 int num_term = 0; /* Nr of matching terminal code settings */
9830 int opt_idx;
9831 int match;
9832 int count = 0;
9833 char_u *str;
9834 int loop;
9835 int is_term_opt;
9836 char_u name_buf[MAX_KEY_NAME_LEN];
9837 static char *(names[]) = {"all", "termcap"};
9838 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9839
9840 /* do this loop twice:
9841 * loop == 0: count the number of matching options
9842 * loop == 1: copy the matching options into allocated memory
9843 */
9844 for (loop = 0; loop <= 1; ++loop)
9845 {
9846 regmatch->rm_ic = ic;
9847 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9848 {
9849 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9850 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9851 {
9852 if (loop == 0)
9853 num_normal++;
9854 else
9855 (*file)[count++] = vim_strsave((char_u *)names[match]);
9856 }
9857 }
9858 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9859 opt_idx++)
9860 {
9861 if (options[opt_idx].var == NULL)
9862 continue;
9863 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9864 && !(options[opt_idx].flags & P_BOOL))
9865 continue;
9866 is_term_opt = istermoption(&options[opt_idx]);
9867 if (is_term_opt && num_normal > 0)
9868 continue;
9869 match = FALSE;
9870 if (vim_regexec(regmatch, str, (colnr_T)0)
9871 || (options[opt_idx].shortname != NULL
9872 && vim_regexec(regmatch,
9873 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9874 match = TRUE;
9875 else if (is_term_opt)
9876 {
9877 name_buf[0] = '<';
9878 name_buf[1] = 't';
9879 name_buf[2] = '_';
9880 name_buf[3] = str[2];
9881 name_buf[4] = str[3];
9882 name_buf[5] = '>';
9883 name_buf[6] = NUL;
9884 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9885 {
9886 match = TRUE;
9887 str = name_buf;
9888 }
9889 }
9890 if (match)
9891 {
9892 if (loop == 0)
9893 {
9894 if (is_term_opt)
9895 num_term++;
9896 else
9897 num_normal++;
9898 }
9899 else
9900 (*file)[count++] = vim_strsave(str);
9901 }
9902 }
9903 /*
9904 * Check terminal key codes, these are not in the option table
9905 */
9906 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9907 {
9908 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9909 {
9910 if (!isprint(str[0]) || !isprint(str[1]))
9911 continue;
9912
9913 name_buf[0] = 't';
9914 name_buf[1] = '_';
9915 name_buf[2] = str[0];
9916 name_buf[3] = str[1];
9917 name_buf[4] = NUL;
9918
9919 match = FALSE;
9920 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9921 match = TRUE;
9922 else
9923 {
9924 name_buf[0] = '<';
9925 name_buf[1] = 't';
9926 name_buf[2] = '_';
9927 name_buf[3] = str[0];
9928 name_buf[4] = str[1];
9929 name_buf[5] = '>';
9930 name_buf[6] = NUL;
9931
9932 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9933 match = TRUE;
9934 }
9935 if (match)
9936 {
9937 if (loop == 0)
9938 num_term++;
9939 else
9940 (*file)[count++] = vim_strsave(name_buf);
9941 }
9942 }
9943
9944 /*
9945 * Check special key names.
9946 */
9947 regmatch->rm_ic = TRUE; /* ignore case here */
9948 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9949 {
9950 name_buf[0] = '<';
9951 STRCPY(name_buf + 1, str);
9952 STRCAT(name_buf, ">");
9953
9954 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9955 {
9956 if (loop == 0)
9957 num_term++;
9958 else
9959 (*file)[count++] = vim_strsave(name_buf);
9960 }
9961 }
9962 }
9963 if (loop == 0)
9964 {
9965 if (num_normal > 0)
9966 *num_file = num_normal;
9967 else if (num_term > 0)
9968 *num_file = num_term;
9969 else
9970 return OK;
9971 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9972 if (*file == NULL)
9973 {
9974 *file = (char_u **)"";
9975 return FAIL;
9976 }
9977 }
9978 }
9979 return OK;
9980}
9981
9982 int
9983ExpandOldSetting(num_file, file)
9984 int *num_file;
9985 char_u ***file;
9986{
9987 char_u *var = NULL; /* init for GCC */
9988 char_u *buf;
9989
9990 *num_file = 0;
9991 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9992 if (*file == NULL)
9993 return FAIL;
9994
9995 /*
9996 * For a terminal key code expand_option_idx is < 0.
9997 */
9998 if (expand_option_idx < 0)
9999 {
10000 var = find_termcode(expand_option_name + 2);
10001 if (var == NULL)
10002 expand_option_idx = findoption(expand_option_name);
10003 }
10004
10005 if (expand_option_idx >= 0)
10006 {
10007 /* put string of option value in NameBuff */
10008 option_value2string(&options[expand_option_idx], expand_option_flags);
10009 var = NameBuff;
10010 }
10011 else if (var == NULL)
10012 var = (char_u *)"";
10013
10014 /* A backslash is required before some characters. This is the reverse of
10015 * what happens in do_set(). */
10016 buf = vim_strsave_escaped(var, escape_chars);
10017
10018 if (buf == NULL)
10019 {
10020 vim_free(*file);
10021 *file = NULL;
10022 return FAIL;
10023 }
10024
10025#ifdef BACKSLASH_IN_FILENAME
10026 /* For MS-Windows et al. we don't double backslashes at the start and
10027 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010028 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 if (var[0] == '\\' && var[1] == '\\'
10030 && expand_option_idx >= 0
10031 && (options[expand_option_idx].flags & P_EXPAND)
10032 && vim_isfilec(var[2])
10033 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
10034 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035#endif
10036
10037 *file[0] = buf;
10038 *num_file = 1;
10039 return OK;
10040}
10041#endif
10042
10043/*
10044 * Get the value for the numeric or string option *opp in a nice format into
10045 * NameBuff[]. Must not be called with a hidden option!
10046 */
10047 static void
10048option_value2string(opp, opt_flags)
10049 struct vimoption *opp;
10050 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10051{
10052 char_u *varp;
10053
10054 varp = get_varp_scope(opp, opt_flags);
10055
10056 if (opp->flags & P_NUM)
10057 {
10058 long wc = 0;
10059
10060 if (wc_use_keyname(varp, &wc))
10061 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10062 else if (wc != 0)
10063 STRCPY(NameBuff, transchar((int)wc));
10064 else
10065 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10066 }
10067 else /* P_STRING */
10068 {
10069 varp = *(char_u **)(varp);
10070 if (varp == NULL) /* just in case */
10071 NameBuff[0] = NUL;
10072#ifdef FEAT_CRYPT
10073 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010074 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075 STRCPY(NameBuff, "*****");
10076#endif
10077 else if (opp->flags & P_EXPAND)
10078 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10079 /* Translate 'pastetoggle' into special key names */
10080 else if ((char_u **)opp->var == &p_pt)
10081 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10082 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010083 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 }
10085}
10086
10087/*
10088 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10089 * printed as a keyname.
10090 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10091 */
10092 static int
10093wc_use_keyname(varp, wcp)
10094 char_u *varp;
10095 long *wcp;
10096{
10097 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10098 {
10099 *wcp = *(long *)varp;
10100 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10101 return TRUE;
10102 }
10103 return FALSE;
10104}
10105
10106#ifdef FEAT_LANGMAP
10107/*
10108 * Any character has an equivalent character. This is used for keyboards that
10109 * have a special language mode that sends characters above 128 (although
10110 * other characters can be translated too).
10111 */
10112
10113/*
10114 * char_u langmap_mapchar[256];
10115 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
10116 * "translate" native lang chars in normal mode or some cases of
10117 * insert mode without having to tediously switch lang mode back&forth.
10118 */
10119
10120 static void
10121langmap_init()
10122{
10123 int i;
10124
10125 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
10126 langmap_mapchar[i] = i;
10127}
10128
10129/*
10130 * Called when langmap option is set; the language map can be
10131 * changed at any time!
10132 */
10133 static void
10134langmap_set()
10135{
10136 char_u *p;
10137 char_u *p2;
10138 int from, to;
10139
10140 langmap_init(); /* back to one-to-one map first */
10141
10142 for (p = p_langmap; p[0] != NUL; )
10143 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010144 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10145 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 {
10147 if (p2[0] == '\\' && p2[1] != NUL)
10148 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 }
10150 if (p2[0] == ';')
10151 ++p2; /* abcd;ABCD form, p2 points to A */
10152 else
10153 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10154 while (p[0])
10155 {
10156 if (p[0] == '\\' && p[1] != NUL)
10157 ++p;
10158#ifdef FEAT_MBYTE
10159 from = (*mb_ptr2char)(p);
10160#else
10161 from = p[0];
10162#endif
10163 if (p2 == NULL)
10164 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010165 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 if (p[0] == '\\')
10167 ++p;
10168#ifdef FEAT_MBYTE
10169 to = (*mb_ptr2char)(p);
10170#else
10171 to = p[0];
10172#endif
10173 }
10174 else
10175 {
10176 if (p2[0] == '\\')
10177 ++p2;
10178#ifdef FEAT_MBYTE
10179 to = (*mb_ptr2char)(p2);
10180#else
10181 to = p2[0];
10182#endif
10183 }
10184 if (to == NUL)
10185 {
10186 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10187 transchar(from));
10188 return;
10189 }
10190 langmap_mapchar[from & 255] = to;
10191
10192 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010193 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 if (p2 == NULL)
10195 {
10196 if (p[0] == ',')
10197 {
10198 ++p;
10199 break;
10200 }
10201 }
10202 else
10203 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010204 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 if (*p == ';')
10206 {
10207 p = p2;
10208 if (p[0] != NUL)
10209 {
10210 if (p[0] != ',')
10211 {
10212 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10213 return;
10214 }
10215 ++p;
10216 }
10217 break;
10218 }
10219 }
10220 }
10221 }
10222}
10223#endif
10224
10225/*
10226 * Return TRUE if format option 'x' is in effect.
10227 * Take care of no formatting when 'paste' is set.
10228 */
10229 int
10230has_format_option(x)
10231 int x;
10232{
10233 if (p_paste)
10234 return FALSE;
10235 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10236}
10237
10238/*
10239 * Return TRUE if "x" is present in 'shortmess' option, or
10240 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10241 */
10242 int
10243shortmess(x)
10244 int x;
10245{
10246 return ( vim_strchr(p_shm, x) != NULL
10247 || (vim_strchr(p_shm, 'a') != NULL
10248 && vim_strchr((char_u *)SHM_A, x) != NULL));
10249}
10250
10251/*
10252 * paste_option_changed() - Called after p_paste was set or reset.
10253 */
10254 static void
10255paste_option_changed()
10256{
10257 static int old_p_paste = FALSE;
10258 static int save_sm = 0;
10259#ifdef FEAT_CMDL_INFO
10260 static int save_ru = 0;
10261#endif
10262#ifdef FEAT_RIGHTLEFT
10263 static int save_ri = 0;
10264 static int save_hkmap = 0;
10265#endif
10266 buf_T *buf;
10267
10268 if (p_paste)
10269 {
10270 /*
10271 * Paste switched from off to on.
10272 * Save the current values, so they can be restored later.
10273 */
10274 if (!old_p_paste)
10275 {
10276 /* save options for each buffer */
10277 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10278 {
10279 buf->b_p_tw_nopaste = buf->b_p_tw;
10280 buf->b_p_wm_nopaste = buf->b_p_wm;
10281 buf->b_p_sts_nopaste = buf->b_p_sts;
10282 buf->b_p_ai_nopaste = buf->b_p_ai;
10283 }
10284
10285 /* save global options */
10286 save_sm = p_sm;
10287#ifdef FEAT_CMDL_INFO
10288 save_ru = p_ru;
10289#endif
10290#ifdef FEAT_RIGHTLEFT
10291 save_ri = p_ri;
10292 save_hkmap = p_hkmap;
10293#endif
10294 /* save global values for local buffer options */
10295 p_tw_nopaste = p_tw;
10296 p_wm_nopaste = p_wm;
10297 p_sts_nopaste = p_sts;
10298 p_ai_nopaste = p_ai;
10299 }
10300
10301 /*
10302 * Always set the option values, also when 'paste' is set when it is
10303 * already on.
10304 */
10305 /* set options for each buffer */
10306 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10307 {
10308 buf->b_p_tw = 0; /* textwidth is 0 */
10309 buf->b_p_wm = 0; /* wrapmargin is 0 */
10310 buf->b_p_sts = 0; /* softtabstop is 0 */
10311 buf->b_p_ai = 0; /* no auto-indent */
10312 }
10313
10314 /* set global options */
10315 p_sm = 0; /* no showmatch */
10316#ifdef FEAT_CMDL_INFO
10317# ifdef FEAT_WINDOWS
10318 if (p_ru)
10319 status_redraw_all(); /* redraw to remove the ruler */
10320# endif
10321 p_ru = 0; /* no ruler */
10322#endif
10323#ifdef FEAT_RIGHTLEFT
10324 p_ri = 0; /* no reverse insert */
10325 p_hkmap = 0; /* no Hebrew keyboard */
10326#endif
10327 /* set global values for local buffer options */
10328 p_tw = 0;
10329 p_wm = 0;
10330 p_sts = 0;
10331 p_ai = 0;
10332 }
10333
10334 /*
10335 * Paste switched from on to off: Restore saved values.
10336 */
10337 else if (old_p_paste)
10338 {
10339 /* restore options for each buffer */
10340 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10341 {
10342 buf->b_p_tw = buf->b_p_tw_nopaste;
10343 buf->b_p_wm = buf->b_p_wm_nopaste;
10344 buf->b_p_sts = buf->b_p_sts_nopaste;
10345 buf->b_p_ai = buf->b_p_ai_nopaste;
10346 }
10347
10348 /* restore global options */
10349 p_sm = save_sm;
10350#ifdef FEAT_CMDL_INFO
10351# ifdef FEAT_WINDOWS
10352 if (p_ru != save_ru)
10353 status_redraw_all(); /* redraw to draw the ruler */
10354# endif
10355 p_ru = save_ru;
10356#endif
10357#ifdef FEAT_RIGHTLEFT
10358 p_ri = save_ri;
10359 p_hkmap = save_hkmap;
10360#endif
10361 /* set global values for local buffer options */
10362 p_tw = p_tw_nopaste;
10363 p_wm = p_wm_nopaste;
10364 p_sts = p_sts_nopaste;
10365 p_ai = p_ai_nopaste;
10366 }
10367
10368 old_p_paste = p_paste;
10369}
10370
10371/*
10372 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10373 *
10374 * Reset 'compatible' and set the values for options that didn't get set yet
10375 * to the Vim defaults.
10376 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010377 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010378 */
10379 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010380vimrc_found(fname, envname)
10381 char_u *fname;
10382 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010384 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010385 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010386 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387
10388 if (!option_was_set((char_u *)"cp"))
10389 {
10390 p_cp = FALSE;
10391 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10392 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10393 set_option_default(opt_idx, OPT_FREE, FALSE);
10394 didset_options();
10395 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010396
10397 if (fname != NULL)
10398 {
10399 p = vim_getenv(envname, &dofree);
10400 if (p == NULL)
10401 {
10402 /* Set $MYVIMRC to the first vimrc file found. */
10403 p = FullName_save(fname, FALSE);
10404 if (p != NULL)
10405 {
10406 vim_setenv(envname, p);
10407 vim_free(p);
10408 }
10409 }
10410 else if (dofree)
10411 vim_free(p);
10412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413}
10414
10415/*
10416 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10417 */
10418 void
10419change_compatible(on)
10420 int on;
10421{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010422 int opt_idx;
10423
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424 if (p_cp != on)
10425 {
10426 p_cp = on;
10427 compatible_set();
10428 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010429 opt_idx = findoption((char_u *)"cp");
10430 if (opt_idx >= 0)
10431 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432}
10433
10434/*
10435 * Return TRUE when option "name" has been set.
10436 */
10437 int
10438option_was_set(name)
10439 char_u *name;
10440{
10441 int idx;
10442
10443 idx = findoption(name);
10444 if (idx < 0) /* unknown option */
10445 return FALSE;
10446 if (options[idx].flags & P_WAS_SET)
10447 return TRUE;
10448 return FALSE;
10449}
10450
10451/*
10452 * compatible_set() - Called when 'compatible' has been set or unset.
10453 *
10454 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10455 * flag) to a Vi compatible value.
10456 * When 'compatible' is unset: Set all options that have a different default
10457 * for Vim (without the P_VI_DEF flag) to that default.
10458 */
10459 static void
10460compatible_set()
10461{
10462 int opt_idx;
10463
10464 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10465 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10466 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10467 set_option_default(opt_idx, OPT_FREE, p_cp);
10468 didset_options();
10469}
10470
10471#ifdef FEAT_LINEBREAK
10472
10473# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10474 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010475 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476# endif
10477
10478/*
10479 * fill_breakat_flags() -- called when 'breakat' changes value.
10480 */
10481 static void
10482fill_breakat_flags()
10483{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010484 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485 int i;
10486
10487 for (i = 0; i < 256; i++)
10488 breakat_flags[i] = FALSE;
10489
10490 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010491 for (p = p_breakat; *p; p++)
10492 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493}
10494
10495# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010496 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497# endif
10498
10499#endif
10500
10501/*
10502 * Check an option that can be a range of string values.
10503 *
10504 * Return OK for correct value, FAIL otherwise.
10505 * Empty is always OK.
10506 */
10507 static int
10508check_opt_strings(val, values, list)
10509 char_u *val;
10510 char **values;
10511 int list; /* when TRUE: accept a list of values */
10512{
10513 return opt_strings_flags(val, values, NULL, list);
10514}
10515
10516/*
10517 * Handle an option that can be a range of string values.
10518 * Set a flag in "*flagp" for each string present.
10519 *
10520 * Return OK for correct value, FAIL otherwise.
10521 * Empty is always OK.
10522 */
10523 static int
10524opt_strings_flags(val, values, flagp, list)
10525 char_u *val; /* new value */
10526 char **values; /* array of valid string values */
10527 unsigned *flagp;
10528 int list; /* when TRUE: accept a list of values */
10529{
10530 int i;
10531 int len;
10532 unsigned new_flags = 0;
10533
10534 while (*val)
10535 {
10536 for (i = 0; ; ++i)
10537 {
10538 if (values[i] == NULL) /* val not found in values[] */
10539 return FAIL;
10540
10541 len = (int)STRLEN(values[i]);
10542 if (STRNCMP(values[i], val, len) == 0
10543 && ((list && val[len] == ',') || val[len] == NUL))
10544 {
10545 val += len + (val[len] == ',');
10546 new_flags |= (1 << i);
10547 break; /* check next item in val list */
10548 }
10549 }
10550 }
10551 if (flagp != NULL)
10552 *flagp = new_flags;
10553
10554 return OK;
10555}
10556
10557/*
10558 * Read the 'wildmode' option, fill wim_flags[].
10559 */
10560 static int
10561check_opt_wim()
10562{
10563 char_u new_wim_flags[4];
10564 char_u *p;
10565 int i;
10566 int idx = 0;
10567
10568 for (i = 0; i < 4; ++i)
10569 new_wim_flags[i] = 0;
10570
10571 for (p = p_wim; *p; ++p)
10572 {
10573 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10574 ;
10575 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10576 return FAIL;
10577 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10578 new_wim_flags[idx] |= WIM_LONGEST;
10579 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10580 new_wim_flags[idx] |= WIM_FULL;
10581 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10582 new_wim_flags[idx] |= WIM_LIST;
10583 else
10584 return FAIL;
10585 p += i;
10586 if (*p == NUL)
10587 break;
10588 if (*p == ',')
10589 {
10590 if (idx == 3)
10591 return FAIL;
10592 ++idx;
10593 }
10594 }
10595
10596 /* fill remaining entries with last flag */
10597 while (idx < 3)
10598 {
10599 new_wim_flags[idx + 1] = new_wim_flags[idx];
10600 ++idx;
10601 }
10602
10603 /* only when there are no errors, wim_flags[] is changed */
10604 for (i = 0; i < 4; ++i)
10605 wim_flags[i] = new_wim_flags[i];
10606 return OK;
10607}
10608
10609/*
10610 * Check if backspacing over something is allowed.
10611 */
10612 int
10613can_bs(what)
10614 int what; /* BS_INDENT, BS_EOL or BS_START */
10615{
10616 switch (*p_bs)
10617 {
10618 case '2': return TRUE;
10619 case '1': return (what != BS_START);
10620 case '0': return FALSE;
10621 }
10622 return vim_strchr(p_bs, what) != NULL;
10623}
10624
10625/*
10626 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10627 * the file must be considered changed when the value is different.
10628 */
10629 void
10630save_file_ff(buf)
10631 buf_T *buf;
10632{
10633 buf->b_start_ffc = *buf->b_p_ff;
10634 buf->b_start_eol = buf->b_p_eol;
10635#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010636 buf->b_start_bomb = buf->b_p_bomb;
10637
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638 /* Only use free/alloc when necessary, they take time. */
10639 if (buf->b_start_fenc == NULL
10640 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10641 {
10642 vim_free(buf->b_start_fenc);
10643 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10644 }
10645#endif
10646}
10647
10648/*
10649 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10650 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010651 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
10652 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653 * Don't consider a new, empty buffer to be changed.
10654 */
10655 int
10656file_ff_differs(buf)
10657 buf_T *buf;
10658{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000010659 /* In a buffer that was never loaded the options are not valid. */
10660 if (buf->b_flags & BF_NEVERLOADED)
10661 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010662 if ((buf->b_flags & BF_NEW)
10663 && buf->b_ml.ml_line_count == 1
10664 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10665 return FALSE;
10666 if (buf->b_start_ffc != *buf->b_p_ff)
10667 return TRUE;
10668 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10669 return TRUE;
10670#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010671 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
10672 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673 if (buf->b_start_fenc == NULL)
10674 return (*buf->b_p_fenc != NUL);
10675 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10676#else
10677 return FALSE;
10678#endif
10679}
10680
10681/*
10682 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10683 */
10684 int
10685check_ff_value(p)
10686 char_u *p;
10687{
10688 return check_opt_strings(p, p_ff_values, FALSE);
10689}