blob: c9cad32087b28c40c4834b79e037a297c13b6aaf [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)
Bram Moolenaar64486672010-05-16 15:46:46 +0200210#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000211#ifdef FEAT_LINEBREAK
212# define PV_NUW OPT_WIN(WV_NUW)
213#endif
214#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
215# define PV_PVW OPT_WIN(WV_PVW)
216#endif
217#ifdef FEAT_RIGHTLEFT
218# define PV_RL OPT_WIN(WV_RL)
219# define PV_RLC OPT_WIN(WV_RLC)
220#endif
221#ifdef FEAT_SCROLLBIND
222# define PV_SCBIND OPT_WIN(WV_SCBIND)
223#endif
224#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000225#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_SPELL OPT_WIN(WV_SPELL)
227#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000228#ifdef FEAT_SYN_HL
229# define PV_CUC OPT_WIN(WV_CUC)
230# define PV_CUL OPT_WIN(WV_CUL)
231#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000232#ifdef FEAT_STL_OPT
233# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
234#endif
235#ifdef FEAT_WINDOWS
236# define PV_WFH OPT_WIN(WV_WFH)
237#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000238#ifdef FEAT_VERTSPLIT
239# define PV_WFW OPT_WIN(WV_WFW)
240#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000241#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000242
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243
244/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245typedef enum
246{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000247 PV_NONE = 0,
248 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249} idopt_T;
250
251/*
252 * Options local to a window have a value local to a buffer and global to all
253 * buffers. Indicate this by setting "var" to VAR_WIN.
254 */
255#define VAR_WIN ((char_u *)-1)
256
257/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000258 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259 * Only to be used in option.c!
260 */
261static int p_ai;
262static int p_bin;
263#ifdef FEAT_MBYTE
264static int p_bomb;
265#endif
266#if defined(FEAT_QUICKFIX)
267static char_u *p_bh;
268static char_u *p_bt;
269#endif
270static int p_bl;
271static int p_ci;
272#ifdef FEAT_CINDENT
273static int p_cin;
274static char_u *p_cink;
275static char_u *p_cino;
276#endif
277#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
278static char_u *p_cinw;
279#endif
280#ifdef FEAT_COMMENTS
281static char_u *p_com;
282#endif
283#ifdef FEAT_FOLDING
284static char_u *p_cms;
285#endif
286#ifdef FEAT_INS_EXPAND
287static char_u *p_cpt;
288#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000289#ifdef FEAT_COMPL_FUNC
290static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000291static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293static int p_eol;
294static int p_et;
295#ifdef FEAT_MBYTE
296static char_u *p_fenc;
297#endif
298static char_u *p_ff;
299static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000300static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301#ifdef FEAT_AUTOCMD
302static char_u *p_ft;
303#endif
304static long p_iminsert;
305static long p_imsearch;
306#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
307static char_u *p_inex;
308#endif
309#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
310static char_u *p_inde;
311static char_u *p_indk;
312#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000313#if defined(FEAT_EVAL)
314static char_u *p_fex;
315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static int p_inf;
317static char_u *p_isk;
318#ifdef FEAT_CRYPT
319static char_u *p_key;
320#endif
321#ifdef FEAT_LISP
322static int p_lisp;
323#endif
324static int p_ml;
325static int p_ma;
326static int p_mod;
327static char_u *p_mps;
328static char_u *p_nf;
329#ifdef FEAT_OSFILETYPE
330static char_u *p_oft;
331#endif
332static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000333#ifdef FEAT_TEXTOBJ
334static char_u *p_qe;
335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336static int p_ro;
337#ifdef FEAT_SMARTINDENT
338static int p_si;
339#endif
340#ifndef SHORT_FNAME
341static int p_sn;
342#endif
343static long p_sts;
344#if defined(FEAT_SEARCHPATH)
345static char_u *p_sua;
346#endif
347static long p_sw;
348static int p_swf;
349#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000350static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000352#endif
353#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000354static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000355static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000356static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357#endif
358static long p_ts;
359static long p_tw;
360static int p_tx;
361static long p_wm;
362#ifdef FEAT_KEYMAP
363static char_u *p_keymap;
364#endif
365
366/* Saved values for when 'bin' is set. */
367static int p_et_nobin;
368static int p_ml_nobin;
369static long p_tw_nobin;
370static long p_wm_nobin;
371
372/* Saved values for when 'paste' is set */
373static long p_tw_nopaste;
374static long p_wm_nopaste;
375static long p_sts_nopaste;
376static int p_ai_nopaste;
377
378struct vimoption
379{
380 char *fullname; /* full option name */
381 char *shortname; /* permissible abbreviation */
382 long_u flags; /* see below */
383 char_u *var; /* global option: pointer to variable;
384 * window-local option: VAR_WIN;
385 * buffer-local option: global value */
386 idopt_T indir; /* global option: PV_NONE;
387 * local option: indirect option index */
388 char_u *def_val[2]; /* default values for variable (vi and vim) */
389#ifdef FEAT_EVAL
390 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000391# define SCRIPTID_INIT , 0
392#else
393# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394#endif
395};
396
397#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
398#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
399
400/*
401 * Flags
402 */
403#define P_BOOL 0x01 /* the option is boolean */
404#define P_NUM 0x02 /* the option is numeric */
405#define P_STRING 0x04 /* the option is a string */
406#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000407 must use free_string_option() when
408 assigning new value. Not set if default is
409 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
411 never be used for local or hidden options! */
412#define P_NODEFAULT 0x40 /* don't set to default value */
413#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
414 use vim_free() when assigning new value */
415#define P_WAS_SET 0x100 /* option has been set/reset */
416#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
417#define P_VI_DEF 0x400 /* Use Vi default for Vim */
418#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
419
420 /* when option changed, what to display: */
421#define P_RSTAT 0x1000 /* redraw status lines */
422#define P_RWIN 0x2000 /* redraw current window */
423#define P_RBUF 0x4000 /* redraw current buffer */
424#define P_RALL 0x6000 /* redraw all windows */
425#define P_RCLR 0x7000 /* clear and redraw all */
426
427#define P_COMMA 0x8000 /* comma separated list */
428#define P_NODUP 0x10000L/* don't allow duplicate strings */
429#define P_FLAGLIST 0x20000L/* list of single-char flags */
430
431#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
432#define P_GETTEXT 0x80000L/* expand default value with _() */
433#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000434#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000435#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000436#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
437 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000439#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
440
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000441/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
442 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000443#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000444# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000445#else
446# define ISP_LATIN1 (char_u *)"@,161-255"
447#endif
448
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000449/* The 16 bit MS-DOS version is low on space, make the string as short as
450 * possible when compiling with few features. */
451#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
452 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
453 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
454# 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"
455#else
456# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
457#endif
458
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459/*
460 * options[] is initialized here.
461 * The order of the options MUST be alphabetic for ":set all" and findoption().
462 * All option names MUST start with a lowercase letter (for findoption()).
463 * Exception: "t_" options are at the end.
464 * The options with a NULL variable are 'hidden': a set command for them is
465 * ignored and they are not printed.
466 */
467static struct vimoption
468#ifdef FEAT_GUI_W16
469 _far
470#endif
471 options[] =
472{
473 {"aleph", "al", P_NUM|P_VI_DEF,
474#ifdef FEAT_RIGHTLEFT
475 (char_u *)&p_aleph, PV_NONE,
476#else
477 (char_u *)NULL, PV_NONE,
478#endif
479 {
480#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
481 (char_u *)128L,
482#else
483 (char_u *)224L,
484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000485 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000486 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
487#if defined(FEAT_GUI) && defined(MACOS_X)
488 (char_u *)&p_antialias, PV_NONE,
489 {(char_u *)FALSE, (char_u *)FALSE}
490#else
491 (char_u *)NULL, PV_NONE,
492 {(char_u *)FALSE, (char_u *)FALSE}
493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
496#ifdef FEAT_ARABIC
497 (char_u *)VAR_WIN, PV_ARAB,
498#else
499 (char_u *)NULL, PV_NONE,
500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000501 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
503#ifdef FEAT_ARABIC
504 (char_u *)&p_arshape, PV_NONE,
505#else
506 (char_u *)NULL, PV_NONE,
507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000508 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
510#ifdef FEAT_RIGHTLEFT
511 (char_u *)&p_ari, PV_NONE,
512#else
513 (char_u *)NULL, PV_NONE,
514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
517#ifdef FEAT_FKMAP
518 (char_u *)&p_altkeymap, PV_NONE,
519#else
520 (char_u *)NULL, PV_NONE,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
524#if defined(FEAT_MBYTE)
525 (char_u *)&p_ambw, PV_NONE,
526 {(char_u *)"single", (char_u *)0L}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)0L, (char_u *)0L}
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000532#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"autochdir", "acd", P_BOOL|P_VI_DEF,
534 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536#endif
537 {"autoindent", "ai", P_BOOL|P_VI_DEF,
538 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"autoprint", "ap", P_BOOL|P_VI_DEF,
541 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000544 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autowrite", "aw", P_BOOL|P_VI_DEF,
547 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autowriteall","awa", P_BOOL|P_VI_DEF,
550 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
553 (char_u *)&p_bg, PV_NONE,
554 {
555#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
556 (char_u *)"dark",
557#else
558 (char_u *)"light",
559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
562 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
565 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
568 (char_u *)&p_bkc, PV_NONE,
569#ifdef UNIX
570 {(char_u *)"yes", (char_u *)"auto"}
571#else
572 {(char_u *)"auto", (char_u *)"auto"}
573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
576 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000578 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 (char_u *)&p_bex, PV_NONE,
580 {
581#ifdef VMS
582 (char_u *)"_",
583#else
584 (char_u *)"~",
585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
588#ifdef FEAT_WILDIGN
589 (char_u *)&p_bsk, PV_NONE,
590 {(char_u *)"", (char_u *)0L}
591#else
592 (char_u *)NULL, PV_NONE,
593 {(char_u *)0L, (char_u *)0L}
594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000595 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596#ifdef FEAT_BEVAL
597 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
598 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000599 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
601 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000603# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000604 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000605 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000606 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000607# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608#endif
609 {"beautify", "bf", P_BOOL|P_VI_DEF,
610 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
613 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000614 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
616#ifdef MSDOS
617 (char_u *)&p_biosk, PV_NONE,
618#else
619 (char_u *)NULL, PV_NONE,
620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000621 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
623#ifdef FEAT_MBYTE
624 (char_u *)&p_bomb, PV_BOMB,
625#else
626 (char_u *)NULL, PV_NONE,
627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
630#ifdef FEAT_LINEBREAK
631 (char_u *)&p_breakat, PV_NONE,
632 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
639#ifdef FEAT_BROWSE
640 (char_u *)&p_bsdir, PV_NONE,
641 {(char_u *)"last", (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
648#if defined(FEAT_QUICKFIX)
649 (char_u *)&p_bh, PV_BH,
650 {(char_u *)"", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
657 (char_u *)&p_bl, PV_BL,
658 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000659 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
661#if defined(FEAT_QUICKFIX)
662 (char_u *)&p_bt, PV_BT,
663 {(char_u *)"", (char_u *)0L}
664#else
665 (char_u *)NULL, PV_NONE,
666 {(char_u *)0L, (char_u *)0L}
667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000670#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)&p_cmp, PV_NONE,
672 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000673#else
674 (char_u *)NULL, PV_NONE,
675 {(char_u *)0L, (char_u *)0L}
676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
679#ifdef FEAT_SEARCHPATH
680 (char_u *)&p_cdpath, PV_NONE,
681 {(char_u *)",,", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 {"cedit", NULL, P_STRING,
688#ifdef FEAT_CMDWIN
689 (char_u *)&p_cedit, PV_NONE,
690 {(char_u *)"", (char_u *)CTRL_F_STR}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
697#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
698 (char_u *)&p_ccv, PV_NONE,
699 {(char_u *)"", (char_u *)0L}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
706#ifdef FEAT_CINDENT
707 (char_u *)&p_cin, PV_CIN,
708#else
709 (char_u *)NULL, PV_NONE,
710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000711 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
713#ifdef FEAT_CINDENT
714 (char_u *)&p_cink, PV_CINK,
715 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
722#ifdef FEAT_CINDENT
723 (char_u *)&p_cino, PV_CINO,
724#else
725 (char_u *)NULL, PV_NONE,
726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
729#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
730 (char_u *)&p_cinw, PV_CINW,
731 {(char_u *)"if,else,while,do,for,switch",
732 (char_u *)0L}
733#else
734 (char_u *)NULL, PV_NONE,
735 {(char_u *)0L, (char_u *)0L}
736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000737 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
739#ifdef FEAT_CLIPBOARD
740 (char_u *)&p_cb, PV_NONE,
741# ifdef FEAT_XCLIPBOARD
742 {(char_u *)"autoselect,exclude:cons\\|linux",
743 (char_u *)0L}
744# else
745 {(char_u *)"", (char_u *)0L}
746# endif
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)"", (char_u *)0L}
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
753 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000754 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
756#ifdef FEAT_CMDWIN
757 (char_u *)&p_cwh, PV_NONE,
758#else
759 (char_u *)NULL, PV_NONE,
760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000761 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
763 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
766#ifdef FEAT_COMMENTS
767 (char_u *)&p_com, PV_COM,
768 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
769 (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
776#ifdef FEAT_FOLDING
777 (char_u *)&p_cms, PV_CMS,
778 {(char_u *)"/*%s*/", (char_u *)0L}
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)0L, (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000784 /* P_PRI_MKRC isn't needed here, optval_default()
785 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786 {"compatible", "cp", P_BOOL|P_RALL,
787 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000788 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000789 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
790#ifdef FEAT_INS_EXPAND
791 (char_u *)&p_cpt, PV_CPT,
792 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
793#else
794 (char_u *)NULL, PV_NONE,
795 {(char_u *)0L, (char_u *)0L}
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000798 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
799#ifdef FEAT_COMPL_FUNC
800 (char_u *)&p_cfu, PV_CFU,
801 {(char_u *)"", (char_u *)0L}
802#else
803 (char_u *)NULL, PV_NONE,
804 {(char_u *)0L, (char_u *)0L}
805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000807 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
808#ifdef FEAT_INS_EXPAND
809 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000810 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)0L, (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"confirm", "cf", P_BOOL|P_VI_DEF,
817#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
818 (char_u *)&p_confirm, PV_NONE,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"conskey", "consk",P_BOOL|P_VI_DEF,
824#ifdef MSDOS
825 (char_u *)&p_consk, PV_NONE,
826#else
827 (char_u *)NULL, PV_NONE,
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
831 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
834 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
836 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
838#ifdef FEAT_CSCOPE
839 (char_u *)&p_cspc, PV_NONE,
840#else
841 (char_u *)NULL, PV_NONE,
842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
845#ifdef FEAT_CSCOPE
846 (char_u *)&p_csprg, PV_NONE,
847 {(char_u *)"cscope", (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
854#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
855 (char_u *)&p_csqf, PV_NONE,
856 {(char_u *)"", (char_u *)0L}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)0L, (char_u *)0L}
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
863#ifdef FEAT_CSCOPE
864 (char_u *)&p_cst, PV_NONE,
865#else
866 (char_u *)NULL, PV_NONE,
867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000869 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
870#ifdef FEAT_CSCOPE
871 (char_u *)&p_csto, PV_NONE,
872#else
873 (char_u *)NULL, PV_NONE,
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
877#ifdef FEAT_CSCOPE
878 (char_u *)&p_csverbose, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000883 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
884#ifdef FEAT_SYN_HL
885 (char_u *)VAR_WIN, PV_CUC,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000890 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
891#ifdef FEAT_SYN_HL
892 (char_u *)VAR_WIN, PV_CUL,
893#else
894 (char_u *)NULL, PV_NONE,
895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"debug", NULL, P_STRING|P_VI_DEF,
898 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
901#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000902 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000903 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904#else
905 (char_u *)NULL, PV_NONE,
906 {(char_u *)NULL, (char_u *)0L}
907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
910#ifdef FEAT_MBYTE
911 (char_u *)&p_deco, PV_NONE,
912#else
913 (char_u *)NULL, PV_NONE,
914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
917#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000918 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919#else
920 (char_u *)NULL, PV_NONE,
921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
924#ifdef FEAT_DIFF
925 (char_u *)VAR_WIN, PV_DIFF,
926#else
927 (char_u *)NULL, PV_NONE,
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
931#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
932 (char_u *)&p_dex, PV_NONE,
933 {(char_u *)"", (char_u *)0L}
934#else
935 (char_u *)NULL, PV_NONE,
936 {(char_u *)0L, (char_u *)0L}
937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000938 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000939 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
940#ifdef FEAT_DIFF
941 (char_u *)&p_dip, PV_NONE,
942 {(char_u *)"filler", (char_u *)NULL}
943#else
944 (char_u *)NULL, PV_NONE,
945 {(char_u *)"", (char_u *)NULL}
946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_DIGRAPHS
950 (char_u *)&p_dg, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
956 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
959 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000960 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"eadirection", "ead", P_STRING|P_VI_DEF,
962#ifdef FEAT_VERTSPLIT
963 (char_u *)&p_ead, PV_NONE,
964 {(char_u *)"both", (char_u *)0L}
965#else
966 (char_u *)NULL, PV_NONE,
967 {(char_u *)NULL, (char_u *)0L}
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"edcompatible","ed", P_BOOL|P_VI_DEF,
971 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
974#ifdef FEAT_MBYTE
975 (char_u *)&p_enc, PV_NONE,
976 {(char_u *)ENC_DFLT, (char_u *)0L}
977#else
978 (char_u *)NULL, PV_NONE,
979 {(char_u *)0L, (char_u *)0L}
980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
983 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
986 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000989 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"errorbells", "eb", P_BOOL|P_VI_DEF,
992 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
995#ifdef FEAT_QUICKFIX
996 (char_u *)&p_ef, PV_NONE,
997 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1004#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001005 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#else
1008 (char_u *)NULL, PV_NONE,
1009 {(char_u *)NULL, (char_u *)0L}
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012 {"esckeys", "ek", P_BOOL|P_VIM,
1013 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1016#ifdef FEAT_AUTOCMD
1017 (char_u *)&p_ei, PV_NONE,
1018#else
1019 (char_u *)NULL, PV_NONE,
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1023 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1026 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1029#ifdef FEAT_MBYTE
1030 (char_u *)&p_fenc, PV_FENC,
1031 {(char_u *)"", (char_u *)0L}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)0L, (char_u *)0L}
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1038#ifdef FEAT_MBYTE
1039 (char_u *)&p_fencs, PV_NONE,
1040 {(char_u *)"ucs-bom", (char_u *)0L}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)0L, (char_u *)0L}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1047 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1050 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1052 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001053 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054#ifdef FEAT_AUTOCMD
1055 (char_u *)&p_ft, PV_FT,
1056 {(char_u *)"", (char_u *)0L}
1057#else
1058 (char_u *)NULL, PV_NONE,
1059 {(char_u *)0L, (char_u *)0L}
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1063#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1064 (char_u *)&p_fcs, PV_NONE,
1065 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1066#else
1067 (char_u *)NULL, PV_NONE,
1068 {(char_u *)"", (char_u *)0L}
1069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1072#ifdef FEAT_FKMAP
1073 (char_u *)&p_fkmap, PV_NONE,
1074#else
1075 (char_u *)NULL, PV_NONE,
1076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"flash", "fl", P_BOOL|P_VI_DEF,
1079 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081#ifdef FEAT_FOLDING
1082 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1083 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1086 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1089 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1092# ifdef FEAT_EVAL
1093 (char_u *)VAR_WIN, PV_FDE,
1094 {(char_u *)"0", (char_u *)NULL}
1095# else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)NULL, (char_u *)0L}
1098# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1101 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1104 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1107 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1110 P_RWIN|P_COMMA|P_NODUP,
1111 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)"{{{,}}}", (char_u *)NULL}
1113 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1115 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1118 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1121 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1124 (char_u *)&p_fdo, PV_NONE,
1125 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1128# ifdef FEAT_EVAL
1129 (char_u *)VAR_WIN, PV_FDT,
1130 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001131# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 (char_u *)NULL, PV_NONE,
1133 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001134# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001135 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001137 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001138#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001139 (char_u *)&p_fex, PV_FEX,
1140 {(char_u *)"", (char_u *)0L}
1141#else
1142 (char_u *)NULL, PV_NONE,
1143 {(char_u *)0L, (char_u *)0L}
1144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1147 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001148 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1149 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001150 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1151 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1153 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1155 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001157 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1158#ifdef HAVE_FSYNC
1159 (char_u *)&p_fs, PV_NONE,
1160 {(char_u *)TRUE, (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)FALSE, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1167 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"graphic", "gr", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1173#ifdef FEAT_QUICKFIX
1174 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176#else
1177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
1179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1182#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001183 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 {
1185# ifdef WIN3264
1186 /* may be changed to "grep -n" in os_win32.c */
1187 (char_u *)"findstr /n",
1188# else
1189# ifdef UNIX
1190 /* Add an extra file name so that grep will always
1191 * insert a file name in the match line. */
1192 (char_u *)"grep -n $* /dev/null",
1193# else
1194# ifdef VMS
1195 (char_u *)"SEARCH/NUMBERS ",
1196# else
1197 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198# endif
1199# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1208#ifdef CURSOR_SHAPE
1209 (char_u *)&p_guicursor, PV_NONE,
1210 {
1211# ifdef FEAT_GUI
1212 (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",
1213# else /* MSDOS or Win32 console */
1214 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1215# endif
1216 (char_u *)0L}
1217#else
1218 (char_u *)NULL, PV_NONE,
1219 {(char_u *)NULL, (char_u *)0L}
1220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1223#ifdef FEAT_GUI
1224 (char_u *)&p_guifont, PV_NONE,
1225 {(char_u *)"", (char_u *)0L}
1226#else
1227 (char_u *)NULL, PV_NONE,
1228 {(char_u *)NULL, (char_u *)0L}
1229#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1232#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1233 (char_u *)&p_guifontset, PV_NONE,
1234 {(char_u *)"", (char_u *)0L}
1235#else
1236 (char_u *)NULL, PV_NONE,
1237 {(char_u *)NULL, (char_u *)0L}
1238#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1241#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1242 (char_u *)&p_guifontwide, PV_NONE,
1243 {(char_u *)"", (char_u *)0L}
1244#else
1245 (char_u *)NULL, PV_NONE,
1246 {(char_u *)NULL, (char_u *)0L}
1247#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001250#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 (char_u *)&p_ghr, PV_NONE,
1252#else
1253 (char_u *)NULL, PV_NONE,
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001257#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)&p_go, PV_NONE,
1259# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001260 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001262 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263# endif
1264#else
1265 (char_u *)NULL, PV_NONE,
1266 {(char_u *)NULL, (char_u *)0L}
1267#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001268 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269 {"guipty", NULL, P_BOOL|P_VI_DEF,
1270#if defined(FEAT_GUI)
1271 (char_u *)&p_guipty, PV_NONE,
1272#else
1273 (char_u *)NULL, PV_NONE,
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001276 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001277#if defined(FEAT_GUI_TABLINE)
1278 (char_u *)&p_gtl, PV_NONE,
1279 {(char_u *)"", (char_u *)0L}
1280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001285 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001286#if defined(FEAT_GUI_TABLINE)
1287 (char_u *)&p_gtt, PV_NONE,
1288 {(char_u *)"", (char_u *)0L}
1289#else
1290 (char_u *)NULL, PV_NONE,
1291 {(char_u *)NULL, (char_u *)0L}
1292#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1295 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001296 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1298 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1300 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"helpheight", "hh", P_NUM|P_VI_DEF,
1302#ifdef FEAT_WINDOWS
1303 (char_u *)&p_hh, PV_NONE,
1304#else
1305 (char_u *)NULL, PV_NONE,
1306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1309#ifdef FEAT_MULTI_LANG
1310 (char_u *)&p_hlg, PV_NONE,
1311 {(char_u *)"", (char_u *)0L}
1312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)0L, (char_u *)0L}
1315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"hidden", "hid", P_BOOL|P_VI_DEF,
1318 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1321 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1323 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324 {"history", "hi", P_NUM|P_VIM,
1325 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001326 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1328#ifdef FEAT_RIGHTLEFT
1329 (char_u *)&p_hkmap, PV_NONE,
1330#else
1331 (char_u *)NULL, PV_NONE,
1332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1335#ifdef FEAT_RIGHTLEFT
1336 (char_u *)&p_hkmapp, PV_NONE,
1337#else
1338 (char_u *)NULL, PV_NONE,
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1342 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"icon", NULL, P_BOOL|P_VI_DEF,
1345#ifdef FEAT_TITLE
1346 (char_u *)&p_icon, PV_NONE,
1347#else
1348 (char_u *)NULL, PV_NONE,
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {"iconstring", NULL, P_STRING|P_VI_DEF,
1352#ifdef FEAT_TITLE
1353 (char_u *)&p_iconstring, PV_NONE,
1354#else
1355 (char_u *)NULL, PV_NONE,
1356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001357 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1359 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001362#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 (char_u *)&p_imak, PV_NONE,
1364#else
1365 (char_u *)NULL, PV_NONE,
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1369#ifdef USE_IM_CONTROL
1370 (char_u *)&p_imcmdline, PV_NONE,
1371#else
1372 (char_u *)NULL, PV_NONE,
1373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1376#ifdef USE_IM_CONTROL
1377 (char_u *)&p_imdisable, PV_NONE,
1378#else
1379 (char_u *)NULL, PV_NONE,
1380#endif
1381#ifdef __sgi
1382 {(char_u *)TRUE, (char_u *)0L}
1383#else
1384 {(char_u *)FALSE, (char_u *)0L}
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {"iminsert", "imi", P_NUM|P_VI_DEF,
1388 (char_u *)&p_iminsert, PV_IMI,
1389#ifdef B_IMODE_IM
1390 {(char_u *)B_IMODE_IM, (char_u *)0L}
1391#else
1392 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"imsearch", "ims", P_NUM|P_VI_DEF,
1396 (char_u *)&p_imsearch, PV_IMS,
1397#ifdef B_IMODE_IM
1398 {(char_u *)B_IMODE_IM, (char_u *)0L}
1399#else
1400 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1404#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001405 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)0L, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1413#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1414 (char_u *)&p_inex, PV_INEX,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)0L, (char_u *)0L}
1419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1422 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1425#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1426 (char_u *)&p_inde, PV_INDE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)0L, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1434#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1435 (char_u *)&p_indk, PV_INDK,
1436 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1437#else
1438 (char_u *)NULL, PV_NONE,
1439 {(char_u *)0L, (char_u *)0L}
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"infercase", "inf", P_BOOL|P_VI_DEF,
1443 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1446 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1449 (char_u *)&p_isf, PV_NONE,
1450 {
1451#ifdef BACKSLASH_IN_FILENAME
1452 /* Excluded are: & and ^ are special in cmd.exe
1453 * ( and ) are used in text separating fnames */
1454 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1455#else
1456# ifdef AMIGA
1457 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1458# else
1459# ifdef VMS
1460 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1461# else /* UNIX et al. */
1462# ifdef EBCDIC
1463 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1464# else
1465 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1466# endif
1467# endif
1468# endif
1469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1472 (char_u *)&p_isi, PV_NONE,
1473 {
1474#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1475 (char_u *)"@,48-57,_,128-167,224-235",
1476#else
1477# ifdef EBCDIC
1478 /* TODO: EBCDIC Check this! @ == isalpha()*/
1479 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1480 "112-120,128,140-142,156,158,172,"
1481 "174,186,191,203-207,219-225,235-239,"
1482 "251-254",
1483# else
1484 (char_u *)"@,48-57,_,192-255",
1485# endif
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1489 (char_u *)&p_isk, PV_ISK,
1490 {
1491#ifdef EBCDIC
1492 (char_u *)"@,240-249,_",
1493 /* TODO: EBCDIC Check this! @ == isalpha()*/
1494 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1495 "112-120,128,140-142,156,158,172,"
1496 "174,186,191,203-207,219-225,235-239,"
1497 "251-254",
1498#else
1499 (char_u *)"@,48-57,_",
1500# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1501 (char_u *)"@,48-57,_,128-167,224-235"
1502# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001503 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504# endif
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1508 (char_u *)&p_isp, PV_NONE,
1509 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001510#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1511 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 || defined(VMS)
1513 (char_u *)"@,~-255",
1514#else
1515# ifdef EBCDIC
1516 /* all chars above 63 are printable */
1517 (char_u *)"63-255",
1518# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001519 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520# endif
1521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001522 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1524 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001525 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1527#ifdef FEAT_CRYPT
1528 (char_u *)&p_key, PV_KEY,
1529 {(char_u *)"", (char_u *)0L}
1530#else
1531 (char_u *)NULL, PV_NONE,
1532 {(char_u *)0L, (char_u *)0L}
1533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001534 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001535 {"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 +00001536#ifdef FEAT_KEYMAP
1537 (char_u *)&p_keymap, PV_KMAP,
1538 {(char_u *)"", (char_u *)0L}
1539#else
1540 (char_u *)NULL, PV_NONE,
1541 {(char_u *)"", (char_u *)0L}
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1545#ifdef FEAT_VISUAL
1546 (char_u *)&p_km, PV_NONE,
1547#else
1548 (char_u *)NULL, PV_NONE,
1549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001552 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {
1554#if defined(MSDOS) || defined(MSWIN)
1555 (char_u *)":help",
1556#else
1557#ifdef VMS
1558 (char_u *)"help",
1559#else
1560# if defined(OS2)
1561 (char_u *)"view /",
1562# else
1563# ifdef USEMAN_S
1564 (char_u *)"man -s",
1565# else
1566 (char_u *)"man",
1567# endif
1568# endif
1569#endif
1570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1573#ifdef FEAT_LANGMAP
1574 (char_u *)&p_langmap, PV_NONE,
1575 {(char_u *)"", /* unmatched } */
1576#else
1577 (char_u *)NULL, PV_NONE,
1578 {(char_u *)NULL,
1579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001581 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1583 (char_u *)&p_lm, PV_NONE,
1584#else
1585 (char_u *)NULL, PV_NONE,
1586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1589#ifdef FEAT_WINDOWS
1590 (char_u *)&p_ls, PV_NONE,
1591#else
1592 (char_u *)NULL, PV_NONE,
1593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001594 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1596 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1599#ifdef FEAT_LINEBREAK
1600 (char_u *)VAR_WIN, PV_LBR,
1601#else
1602 (char_u *)NULL, PV_NONE,
1603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001604 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1606 (char_u *)&Rows, PV_NONE,
1607 {
1608#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1609 (char_u *)25L,
1610#else
1611 (char_u *)24L,
1612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1615#ifdef FEAT_GUI
1616 (char_u *)&p_linespace, PV_NONE,
1617#else
1618 (char_u *)NULL, PV_NONE,
1619#endif
1620#ifdef FEAT_GUI_W32
1621 {(char_u *)1L, (char_u *)0L}
1622#else
1623 {(char_u *)0L, (char_u *)0L}
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"lisp", NULL, P_BOOL|P_VI_DEF,
1627#ifdef FEAT_LISP
1628 (char_u *)&p_lisp, PV_LISP,
1629#else
1630 (char_u *)NULL, PV_NONE,
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1634#ifdef FEAT_LISP
1635 (char_u *)&p_lispwords, PV_NONE,
1636 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1637#else
1638 (char_u *)NULL, PV_NONE,
1639 {(char_u *)"", (char_u *)0L}
1640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001641 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1643 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1646 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001647 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1649 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001651#ifdef FEAT_GUI_MAC
1652 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1653 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"magic", NULL, P_BOOL|P_VI_DEF,
1657 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001659 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660#ifdef FEAT_QUICKFIX
1661 (char_u *)&p_mef, PV_NONE,
1662 {(char_u *)"", (char_u *)0L}
1663#else
1664 (char_u *)NULL, PV_NONE,
1665 {(char_u *)NULL, (char_u *)0L}
1666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1669#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001670 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671# ifdef VMS
1672 {(char_u *)"MMS", (char_u *)0L}
1673# else
1674 {(char_u *)"make", (char_u *)0L}
1675# endif
1676#else
1677 (char_u *)NULL, PV_NONE,
1678 {(char_u *)NULL, (char_u *)0L}
1679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001680 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1682 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001683 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"matchtime", "mat", P_NUM|P_VI_DEF,
1686 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001688 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1689#ifdef FEAT_MBYTE
1690 (char_u *)&p_mco, PV_NONE,
1691#else
1692 (char_u *)NULL, PV_NONE,
1693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001694 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1696#ifdef FEAT_EVAL
1697 (char_u *)&p_mfd, PV_NONE,
1698#else
1699 (char_u *)NULL, PV_NONE,
1700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1703 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"maxmem", "mm", P_NUM|P_VI_DEF,
1706 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1708 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001709 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1710 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1713 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1715 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"menuitems", "mis", P_NUM|P_VI_DEF,
1717#ifdef FEAT_MENU
1718 (char_u *)&p_mis, PV_NONE,
1719#else
1720 (char_u *)NULL, PV_NONE,
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"mesg", NULL, P_BOOL|P_VI_DEF,
1724 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001726 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001727#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001728 (char_u *)&p_msm, PV_NONE,
1729 {(char_u *)"460000,2000,500", (char_u *)0L}
1730#else
1731 (char_u *)NULL, PV_NONE,
1732 {(char_u *)0L, (char_u *)0L}
1733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"modeline", "ml", P_BOOL|P_VIM,
1736 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"modelines", "mls", P_NUM|P_VI_DEF,
1739 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1742 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1745 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"more", NULL, P_BOOL|P_VIM,
1748 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1751 (char_u *)&p_mouse, PV_NONE,
1752 {
1753#if defined(MSDOS) || defined(WIN3264)
1754 (char_u *)"a",
1755#else
1756 (char_u *)"",
1757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1760#ifdef FEAT_GUI
1761 (char_u *)&p_mousef, PV_NONE,
1762#else
1763 (char_u *)NULL, PV_NONE,
1764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1767#ifdef FEAT_GUI
1768 (char_u *)&p_mh, PV_NONE,
1769#else
1770 (char_u *)NULL, PV_NONE,
1771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1774 (char_u *)&p_mousem, PV_NONE,
1775 {
1776#if defined(MSDOS) || defined(MSWIN)
1777 (char_u *)"popup",
1778#else
1779# if defined(MACOS)
1780 (char_u *)"popup_setpos",
1781# else
1782 (char_u *)"extend",
1783# endif
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1787#ifdef FEAT_MOUSESHAPE
1788 (char_u *)&p_mouseshape, PV_NONE,
1789 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1790#else
1791 (char_u *)NULL, PV_NONE,
1792 {(char_u *)NULL, (char_u *)0L}
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1796 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001798 {"mzquantum", "mzq", P_NUM,
1799#ifdef FEAT_MZSCHEME
1800 (char_u *)&p_mzq, PV_NONE,
1801#else
1802 (char_u *)NULL, PV_NONE,
1803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"novice", NULL, P_BOOL|P_VI_DEF,
1806 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1809 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)"octal,hex", (char_u *)0L}
1811 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1813 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001815 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1816#ifdef FEAT_LINEBREAK
1817 (char_u *)VAR_WIN, PV_NUW,
1818#else
1819 (char_u *)NULL, PV_NONE,
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001822 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001823#ifdef FEAT_COMPL_FUNC
1824 (char_u *)&p_ofu, PV_OFU,
1825 {(char_u *)"", (char_u *)0L}
1826#else
1827 (char_u *)NULL, PV_NONE,
1828 {(char_u *)0L, (char_u *)0L}
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"open", NULL, P_BOOL|P_VI_DEF,
1832 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001834 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1835#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1836 (char_u *)&p_odev, PV_NONE,
1837#else
1838 (char_u *)NULL, PV_NONE,
1839#endif
1840 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001842 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1843 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"optimize", "opt", P_BOOL|P_VI_DEF,
1846 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1849#ifdef FEAT_OSFILETYPE
1850 (char_u *)&p_oft, PV_OFT,
1851 {(char_u *)DFLT_OFT, (char_u *)0L}
1852#else
1853 (char_u *)NULL, PV_NONE,
1854 {(char_u *)0L, (char_u *)0L}
1855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"paragraphs", "para", P_STRING|P_VI_DEF,
1858 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001859 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001861 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1865 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1868#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1869 (char_u *)&p_pex, PV_NONE,
1870 {(char_u *)"", (char_u *)0L}
1871#else
1872 (char_u *)NULL, PV_NONE,
1873 {(char_u *)0L, (char_u *)0L}
1874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001876 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001880 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {
1882#if defined AMIGA || defined MSDOS || defined MSWIN
1883 (char_u *)".,,",
1884#else
1885# if defined(__EMX__)
1886 (char_u *)".,/emx/include,,",
1887# else /* Unix, probably */
1888 (char_u *)".,/usr/include,,",
1889# endif
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1893 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001895 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1897 (char_u *)&p_pvh, PV_NONE,
1898#else
1899 (char_u *)NULL, PV_NONE,
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1903#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1904 (char_u *)VAR_WIN, PV_PVW,
1905#else
1906 (char_u *)NULL, PV_NONE,
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001909 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910#ifdef FEAT_PRINTER
1911 (char_u *)&p_pdev, PV_NONE,
1912 {(char_u *)"", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)NULL, (char_u *)0L}
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"printencoding", "penc", P_STRING|P_VI_DEF,
1919#ifdef FEAT_POSTSCRIPT
1920 (char_u *)&p_penc, PV_NONE,
1921 {(char_u *)"", (char_u *)0L}
1922#else
1923 (char_u *)NULL, PV_NONE,
1924 {(char_u *)NULL, (char_u *)0L}
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1928#ifdef FEAT_POSTSCRIPT
1929 (char_u *)&p_pexpr, PV_NONE,
1930 {(char_u *)"", (char_u *)0L}
1931#else
1932 (char_u *)NULL, PV_NONE,
1933 {(char_u *)NULL, (char_u *)0L}
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"printfont", "pfn", P_STRING|P_VI_DEF,
1937#ifdef FEAT_PRINTER
1938 (char_u *)&p_pfn, PV_NONE,
1939 {
1940# ifdef MSWIN
1941 (char_u *)"Courier_New:h10",
1942# else
1943 (char_u *)"courier",
1944# endif
1945 (char_u *)0L}
1946#else
1947 (char_u *)NULL, PV_NONE,
1948 {(char_u *)NULL, (char_u *)0L}
1949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1952#ifdef FEAT_PRINTER
1953 (char_u *)&p_header, PV_NONE,
1954 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1955#else
1956 (char_u *)NULL, PV_NONE,
1957 {(char_u *)NULL, (char_u *)0L}
1958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001960 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1961#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1962 (char_u *)&p_pmcs, PV_NONE,
1963 {(char_u *)"", (char_u *)0L}
1964#else
1965 (char_u *)NULL, PV_NONE,
1966 {(char_u *)NULL, (char_u *)0L}
1967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001969 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1970#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1971 (char_u *)&p_pmfn, PV_NONE,
1972 {(char_u *)"", (char_u *)0L}
1973#else
1974 (char_u *)NULL, PV_NONE,
1975 {(char_u *)NULL, (char_u *)0L}
1976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1979#ifdef FEAT_PRINTER
1980 (char_u *)&p_popt, PV_NONE,
1981 {(char_u *)"", (char_u *)0L}
1982#else
1983 (char_u *)NULL, PV_NONE,
1984 {(char_u *)NULL, (char_u *)0L}
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001988 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00001990 {"pumheight", "ph", P_NUM|P_VI_DEF,
1991#ifdef FEAT_INS_EXPAND
1992 (char_u *)&p_ph, PV_NONE,
1993#else
1994 (char_u *)NULL, PV_NONE,
1995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001997 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1998#ifdef FEAT_TEXTOBJ
1999 (char_u *)&p_qe, PV_QE,
2000 {(char_u *)"\\", (char_u *)0L}
2001#else
2002 (char_u *)NULL, PV_NONE,
2003 {(char_u *)NULL, (char_u *)0L}
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2007 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"redraw", NULL, P_BOOL|P_VI_DEF,
2010 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002012 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2013#ifdef FEAT_RELTIME
2014 (char_u *)&p_rdt, PV_NONE,
2015#else
2016 (char_u *)NULL, PV_NONE,
2017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002019 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2020 (char_u *)VAR_WIN, PV_RNU,
2021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 {"remap", NULL, P_BOOL|P_VI_DEF,
2023 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"report", NULL, P_NUM|P_VI_DEF,
2026 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2029#ifdef WIN3264
2030 (char_u *)&p_rs, PV_NONE,
2031#else
2032 (char_u *)NULL, PV_NONE,
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2036#ifdef FEAT_RIGHTLEFT
2037 (char_u *)&p_ri, PV_NONE,
2038#else
2039 (char_u *)NULL, PV_NONE,
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2043#ifdef FEAT_RIGHTLEFT
2044 (char_u *)VAR_WIN, PV_RL,
2045#else
2046 (char_u *)NULL, PV_NONE,
2047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2050#ifdef FEAT_RIGHTLEFT
2051 (char_u *)VAR_WIN, PV_RLC,
2052 {(char_u *)"search", (char_u *)NULL}
2053#else
2054 (char_u *)NULL, PV_NONE,
2055 {(char_u *)NULL, (char_u *)0L}
2056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2059#ifdef FEAT_CMDL_INFO
2060 (char_u *)&p_ru, PV_NONE,
2061#else
2062 (char_u *)NULL, PV_NONE,
2063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2066#ifdef FEAT_STL_OPT
2067 (char_u *)&p_ruf, PV_NONE,
2068#else
2069 (char_u *)NULL, PV_NONE,
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2073 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2075 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2077 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2080#ifdef FEAT_SCROLLBIND
2081 (char_u *)VAR_WIN, PV_SCBIND,
2082#else
2083 (char_u *)NULL, PV_NONE,
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2087 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2090 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2093#ifdef FEAT_SCROLLBIND
2094 (char_u *)&p_sbo, PV_NONE,
2095 {(char_u *)"ver,jump", (char_u *)0L}
2096#else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)0L, (char_u *)0L}
2099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 {"sections", "sect", P_STRING|P_VI_DEF,
2102 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2106 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"selection", "sel", P_STRING|P_VI_DEF,
2109#ifdef FEAT_VISUAL
2110 (char_u *)&p_sel, PV_NONE,
2111#else
2112 (char_u *)NULL, PV_NONE,
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)"inclusive", (char_u *)0L}
2115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2117#ifdef FEAT_VISUAL
2118 (char_u *)&p_slm, PV_NONE,
2119#else
2120 (char_u *)NULL, PV_NONE,
2121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002122 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2124#ifdef FEAT_SESSION
2125 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002126 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 (char_u *)0L}
2128#else
2129 (char_u *)NULL, PV_NONE,
2130 {(char_u *)0L, (char_u *)0L}
2131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002132 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2134 (char_u *)&p_sh, PV_NONE,
2135 {
2136#ifdef VMS
2137 (char_u *)"-",
2138#else
2139# if defined(MSDOS)
2140 (char_u *)"command",
2141# else
2142# if defined(WIN16)
2143 (char_u *)"command.com",
2144# else
2145# if defined(WIN3264)
2146 (char_u *)"", /* set in set_init_1() */
2147# else
2148# if defined(OS2)
2149 (char_u *)"cmd.exe",
2150# else
2151# if defined(ARCHIE)
2152 (char_u *)"gos",
2153# else
2154 (char_u *)"sh",
2155# endif
2156# endif
2157# endif
2158# endif
2159# endif
2160#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2163 (char_u *)&p_shcf, PV_NONE,
2164 {
2165#if defined(MSDOS) || defined(MSWIN)
2166 (char_u *)"/c",
2167#else
2168# if defined(OS2)
2169 (char_u *)"/c",
2170# else
2171 (char_u *)"-c",
2172# endif
2173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002174 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2176#ifdef FEAT_QUICKFIX
2177 (char_u *)&p_sp, PV_NONE,
2178 {
2179#if defined(UNIX) || defined(OS2)
2180# ifdef ARCHIE
2181 (char_u *)"2>",
2182# else
2183 (char_u *)"| tee",
2184# endif
2185#else
2186 (char_u *)">",
2187#endif
2188 (char_u *)0L}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)0L, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2195 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2198 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2201#ifdef BACKSLASH_IN_FILENAME
2202 (char_u *)&p_ssl, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002207 {"shelltemp", "stmp", P_BOOL,
2208 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 {"shelltype", "st", P_NUM|P_VI_DEF,
2211#ifdef AMIGA
2212 (char_u *)&p_st, PV_NONE,
2213#else
2214 (char_u *)NULL, PV_NONE,
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_sxq, PV_NONE,
2219 {
2220#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2221 (char_u *)"\"",
2222#else
2223 (char_u *)"",
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2227 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2230 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2233 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)"", (char_u *)"filnxtToO"}
2235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"shortname", "sn", P_BOOL|P_VI_DEF,
2237#ifdef SHORT_FNAME
2238 (char_u *)NULL, PV_NONE,
2239#else
2240 (char_u *)&p_sn, PV_SN,
2241#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2244#ifdef FEAT_LINEBREAK
2245 (char_u *)&p_sbr, PV_NONE,
2246#else
2247 (char_u *)NULL, PV_NONE,
2248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {"showcmd", "sc", P_BOOL|P_VIM,
2251#ifdef FEAT_CMDL_INFO
2252 (char_u *)&p_sc, PV_NONE,
2253#else
2254 (char_u *)NULL, PV_NONE,
2255#endif
2256 {(char_u *)FALSE,
2257#ifdef UNIX
2258 (char_u *)FALSE
2259#else
2260 (char_u *)TRUE
2261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2264 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2267 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"showmode", "smd", P_BOOL|P_VIM,
2270 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002272 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2273#ifdef FEAT_WINDOWS
2274 (char_u *)&p_stal, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2280 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2283 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2286 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2289 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2292#ifdef FEAT_SMARTINDENT
2293 (char_u *)&p_si, PV_SI,
2294#else
2295 (char_u *)NULL, PV_NONE,
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2299 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2302 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002303 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2305 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002306 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002307 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002308#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002309 (char_u *)VAR_WIN, PV_SPELL,
2310#else
2311 (char_u *)NULL, PV_NONE,
2312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002313 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002314 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002315#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002316 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002317 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002318#else
2319 (char_u *)NULL, PV_NONE,
2320 {(char_u *)0L, (char_u *)0L}
2321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002323 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002324#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002325 (char_u *)&p_spf, PV_SPF,
2326 {(char_u *)"", (char_u *)0L}
2327#else
2328 (char_u *)NULL, PV_NONE,
2329 {(char_u *)0L, (char_u *)0L}
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002332 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002333#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002334 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002335 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)0L, (char_u *)0L}
2339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002341 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002342#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002343 (char_u *)&p_sps, PV_NONE,
2344 {(char_u *)"best", (char_u *)0L}
2345#else
2346 (char_u *)NULL, PV_NONE,
2347 {(char_u *)0L, (char_u *)0L}
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2351#ifdef FEAT_WINDOWS
2352 (char_u *)&p_sb, PV_NONE,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"splitright", "spr", P_BOOL|P_VI_DEF,
2358#ifdef FEAT_VERTSPLIT
2359 (char_u *)&p_spr, PV_NONE,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2365 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2368#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002369 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370#else
2371 (char_u *)NULL, PV_NONE,
2372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2375 (char_u *)&p_su, PV_NONE,
2376 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002379#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)&p_sua, PV_SUA,
2381 {(char_u *)"", (char_u *)0L}
2382#else
2383 (char_u *)NULL, PV_NONE,
2384 {(char_u *)0L, (char_u *)0L}
2385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002386 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2388 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002389 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"swapsync", "sws", P_STRING|P_VI_DEF,
2391 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2394 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002396 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2397#ifdef FEAT_SYN_HL
2398 (char_u *)&p_smc, PV_SMC,
2399 {(char_u *)3000L, (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002405 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406#ifdef FEAT_SYN_HL
2407 (char_u *)&p_syn, PV_SYN,
2408 {(char_u *)"", (char_u *)0L}
2409#else
2410 (char_u *)NULL, PV_NONE,
2411 {(char_u *)0L, (char_u *)0L}
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002414 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2415#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002416 (char_u *)&p_tal, PV_NONE,
2417#else
2418 (char_u *)NULL, PV_NONE,
2419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002421 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2422#ifdef FEAT_WINDOWS
2423 (char_u *)&p_tpm, PV_NONE,
2424#else
2425 (char_u *)NULL, PV_NONE,
2426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2429 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2432 (char_u *)&p_tbs, PV_NONE,
2433#ifdef VMS /* binary searching doesn't appear to work on VMS */
2434 {(char_u *)0L, (char_u *)0L}
2435#else
2436 {(char_u *)TRUE, (char_u *)0L}
2437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"taglength", "tl", P_NUM|P_VI_DEF,
2440 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"tagrelative", "tr", P_BOOL|P_VIM,
2443 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002446 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {
2448#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2449 (char_u *)"./tags,./TAGS,tags,TAGS",
2450#else
2451 (char_u *)"./tags,tags",
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2455 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2458 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2461#ifdef FEAT_ARABIC
2462 (char_u *)&p_tbidi, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2468#ifdef FEAT_MBYTE
2469 (char_u *)&p_tenc, PV_NONE,
2470 {(char_u *)"", (char_u *)0L}
2471#else
2472 (char_u *)NULL, PV_NONE,
2473 {(char_u *)0L, (char_u *)0L}
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"terse", NULL, P_BOOL|P_VI_DEF,
2477 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"textauto", "ta", P_BOOL|P_VIM,
2480 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2482 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2484 (char_u *)&p_tx, PV_TX,
2485 {
2486#ifdef USE_CRNL
2487 (char_u *)TRUE,
2488#else
2489 (char_u *)FALSE,
2490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2493 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002494 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2496#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002497 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498#else
2499 (char_u *)NULL, PV_NONE,
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2503 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"timeout", "to", P_BOOL|P_VI_DEF,
2506 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2509 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"title", NULL, P_BOOL|P_VI_DEF,
2512#ifdef FEAT_TITLE
2513 (char_u *)&p_title, PV_NONE,
2514#else
2515 (char_u *)NULL, PV_NONE,
2516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"titlelen", NULL, P_NUM|P_VI_DEF,
2519#ifdef FEAT_TITLE
2520 (char_u *)&p_titlelen, PV_NONE,
2521#else
2522 (char_u *)NULL, PV_NONE,
2523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002525 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526#ifdef FEAT_TITLE
2527 (char_u *)&p_titleold, PV_NONE,
2528 {(char_u *)N_("Thanks for flying Vim"),
2529 (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"titlestring", NULL, P_STRING|P_VI_DEF,
2536#ifdef FEAT_TITLE
2537 (char_u *)&p_titlestring, PV_NONE,
2538#else
2539 (char_u *)NULL, PV_NONE,
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2543 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2544 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)"icons,tooltips", (char_u *)0L}
2546 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547#endif
2548#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2549 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2550 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552#endif
2553 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2554 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2557 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2560 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2563 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2566#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2567 (char_u *)&p_ttym, PV_NONE,
2568#else
2569 (char_u *)NULL, PV_NONE,
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2573 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2576 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"undolevels", "ul", P_NUM|P_VI_DEF,
2579 (char_u *)&p_ul, PV_NONE,
2580 {
2581#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2582 (char_u *)1000L,
2583#else
2584 (char_u *)100L,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"updatecount", "uc", P_NUM|P_VI_DEF,
2588 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"updatetime", "ut", P_NUM|P_VI_DEF,
2591 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 {"verbose", "vbs", P_NUM|P_VI_DEF,
2594 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002596 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2597 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2600#ifdef FEAT_SESSION
2601 (char_u *)&p_vdir, PV_NONE,
2602 {(char_u *)DFLT_VDIR, (char_u *)0L}
2603#else
2604 (char_u *)NULL, PV_NONE,
2605 {(char_u *)0L, (char_u *)0L}
2606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2609#ifdef FEAT_SESSION
2610 (char_u *)&p_vop, PV_NONE,
2611 {(char_u *)"folds,options,cursor", (char_u *)0L}
2612#else
2613 (char_u *)NULL, PV_NONE,
2614 {(char_u *)0L, (char_u *)0L}
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2618#ifdef FEAT_VIMINFO
2619 (char_u *)&p_viminfo, PV_NONE,
2620#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002621 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622#else
2623# ifdef AMIGA
2624 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002625 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002627 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628# endif
2629#endif
2630#else
2631 (char_u *)NULL, PV_NONE,
2632 {(char_u *)0L, (char_u *)0L}
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2636#ifdef FEAT_VIRTUALEDIT
2637 (char_u *)&p_ve, PV_NONE,
2638 {(char_u *)"", (char_u *)""}
2639#else
2640 (char_u *)NULL, PV_NONE,
2641 {(char_u *)0L, (char_u *)0L}
2642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2645 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"w300", NULL, P_NUM|P_VI_DEF,
2648 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"w1200", NULL, P_NUM|P_VI_DEF,
2651 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"w9600", NULL, P_NUM|P_VI_DEF,
2654 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"warn", NULL, P_BOOL|P_VI_DEF,
2657 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2660 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2663 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"wildchar", "wc", P_NUM|P_VIM,
2666 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2670 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2673#ifdef FEAT_WILDIGN
2674 (char_u *)&p_wig, PV_NONE,
2675#else
2676 (char_u *)NULL, PV_NONE,
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2680#ifdef FEAT_WILDMENU
2681 (char_u *)&p_wmnu, PV_NONE,
2682#else
2683 (char_u *)NULL, PV_NONE,
2684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2687 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002689 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2690#ifdef FEAT_CMDL_COMPL
2691 (char_u *)&p_wop, PV_NONE,
2692 {(char_u *)"", (char_u *)0L}
2693#else
2694 (char_u *)NULL, PV_NONE,
2695 {(char_u *)NULL, (char_u *)0L}
2696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2699#ifdef FEAT_WAK
2700 (char_u *)&p_wak, PV_NONE,
2701 {(char_u *)"menu", (char_u *)0L}
2702#else
2703 (char_u *)NULL, PV_NONE,
2704 {(char_u *)NULL, (char_u *)0L}
2705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002708 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"winheight", "wh", P_NUM|P_VI_DEF,
2711#ifdef FEAT_WINDOWS
2712 (char_u *)&p_wh, PV_NONE,
2713#else
2714 (char_u *)NULL, PV_NONE,
2715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002718#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 (char_u *)VAR_WIN, PV_WFH,
2720#else
2721 (char_u *)NULL, PV_NONE,
2722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002724 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2725#ifdef FEAT_VERTSPLIT
2726 (char_u *)VAR_WIN, PV_WFW,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2732#ifdef FEAT_WINDOWS
2733 (char_u *)&p_wmh, PV_NONE,
2734#else
2735 (char_u *)NULL, PV_NONE,
2736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2739#ifdef FEAT_VERTSPLIT
2740 (char_u *)&p_wmw, PV_NONE,
2741#else
2742 (char_u *)NULL, PV_NONE,
2743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2746#ifdef FEAT_VERTSPLIT
2747 (char_u *)&p_wiw, PV_NONE,
2748#else
2749 (char_u *)NULL, PV_NONE,
2750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2753 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2756 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2759 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"write", NULL, P_BOOL|P_VI_DEF,
2762 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"writeany", "wa", P_BOOL|P_VI_DEF,
2765 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2768 (char_u *)&p_wb, PV_NONE,
2769 {
2770#ifdef FEAT_WRITEBACKUP
2771 (char_u *)TRUE,
2772#else
2773 (char_u *)FALSE,
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"writedelay", "wd", P_NUM|P_VI_DEF,
2777 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779
2780/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002781#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784
2785 p_term("t_AB", T_CAB)
2786 p_term("t_AF", T_CAF)
2787 p_term("t_AL", T_CAL)
2788 p_term("t_al", T_AL)
2789 p_term("t_bc", T_BC)
2790 p_term("t_cd", T_CD)
2791 p_term("t_ce", T_CE)
2792 p_term("t_cl", T_CL)
2793 p_term("t_cm", T_CM)
2794 p_term("t_Co", T_CCO)
2795 p_term("t_CS", T_CCS)
2796 p_term("t_cs", T_CS)
2797#ifdef FEAT_VERTSPLIT
2798 p_term("t_CV", T_CSV)
2799#endif
2800 p_term("t_ut", T_UT)
2801 p_term("t_da", T_DA)
2802 p_term("t_db", T_DB)
2803 p_term("t_DL", T_CDL)
2804 p_term("t_dl", T_DL)
2805 p_term("t_fs", T_FS)
2806 p_term("t_IE", T_CIE)
2807 p_term("t_IS", T_CIS)
2808 p_term("t_ke", T_KE)
2809 p_term("t_ks", T_KS)
2810 p_term("t_le", T_LE)
2811 p_term("t_mb", T_MB)
2812 p_term("t_md", T_MD)
2813 p_term("t_me", T_ME)
2814 p_term("t_mr", T_MR)
2815 p_term("t_ms", T_MS)
2816 p_term("t_nd", T_ND)
2817 p_term("t_op", T_OP)
2818 p_term("t_RI", T_CRI)
2819 p_term("t_RV", T_CRV)
2820 p_term("t_Sb", T_CSB)
2821 p_term("t_Sf", T_CSF)
2822 p_term("t_se", T_SE)
2823 p_term("t_so", T_SO)
2824 p_term("t_sr", T_SR)
2825 p_term("t_ts", T_TS)
2826 p_term("t_te", T_TE)
2827 p_term("t_ti", T_TI)
2828 p_term("t_ue", T_UE)
2829 p_term("t_us", T_US)
2830 p_term("t_vb", T_VB)
2831 p_term("t_ve", T_VE)
2832 p_term("t_vi", T_VI)
2833 p_term("t_vs", T_VS)
2834 p_term("t_WP", T_CWP)
2835 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002836 p_term("t_SI", T_CSI)
2837 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 p_term("t_xs", T_XS)
2839 p_term("t_ZH", T_CZH)
2840 p_term("t_ZR", T_CZR)
2841
2842/* terminal key codes are not in here */
2843
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 /* end marker */
2845 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846};
2847
2848#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2849
2850#ifdef FEAT_MBYTE
2851static char *(p_ambw_values[]) = {"single", "double", NULL};
2852#endif
2853static char *(p_bg_values[]) = {"light", "dark", NULL};
2854static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2855static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002856#ifdef FEAT_CMDL_COMPL
2857static char *(p_wop_values[]) = {"tagfile", NULL};
2858#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859#ifdef FEAT_WAK
2860static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2861#endif
2862static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2863#ifdef FEAT_VISUAL
2864static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2865static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2866#endif
2867#ifdef FEAT_VISUAL
2868static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2869#endif
2870#ifdef FEAT_BROWSE
2871static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2872#endif
2873#ifdef FEAT_SCROLLBIND
2874static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2875#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002876static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877#ifdef FEAT_VERTSPLIT
2878static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2879#endif
2880#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002881# ifdef FEAT_AUTOCMD
2882static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2883# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002885# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2887#endif
2888static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2889#ifdef FEAT_FOLDING
2890static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002891# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002893# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 NULL};
2895static char *(p_fcl_values[]) = {"all", NULL};
2896#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002897#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002898static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900
2901static void set_option_default __ARGS((int, int opt_flags, int compatible));
2902static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002903static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002904static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905static char_u *illegal_char __ARGS((char_u *, int));
2906static int string_to_key __ARGS((char_u *arg));
2907#ifdef FEAT_CMDWIN
2908static char_u *check_cedit __ARGS((void));
2909#endif
2910#ifdef FEAT_TITLE
2911static void did_set_title __ARGS((int icon));
2912#endif
2913static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2914static void didset_options __ARGS((void));
2915static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002916#if defined(FEAT_EVAL) || defined(PROTO)
2917static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2918#else
2919# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2922static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2923static 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));
2924static char_u *set_chars_option __ARGS((char_u **varp));
2925#ifdef FEAT_CLIPBOARD
2926static char_u *check_clipboard_option __ARGS((void));
2927#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002928#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002929static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002930#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002931#ifdef FEAT_EVAL
2932static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002935static 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 +00002936static void check_redraw __ARGS((long_u flags));
2937static int findoption __ARGS((char_u *));
2938static int find_key_option __ARGS((char_u *));
2939static void showoptions __ARGS((int all, int opt_flags));
2940static int optval_default __ARGS((struct vimoption *, char_u *varp));
2941static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2942static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2943static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2944static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2945static int istermoption __ARGS((struct vimoption *));
2946static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2947static char_u *get_varp __ARGS((struct vimoption *));
2948static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2949static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2950#ifdef FEAT_LANGMAP
2951static void langmap_init __ARGS((void));
2952static void langmap_set __ARGS((void));
2953#endif
2954static void paste_option_changed __ARGS((void));
2955static void compatible_set __ARGS((void));
2956#ifdef FEAT_LINEBREAK
2957static void fill_breakat_flags __ARGS((void));
2958#endif
2959static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2960static int check_opt_strings __ARGS((char_u *val, char **values, int));
2961static int check_opt_wim __ARGS((void));
2962
2963/*
2964 * Initialize the options, first part.
2965 *
2966 * Called only once from main(), just after creating the first buffer.
2967 */
2968 void
2969set_init_1()
2970{
2971 char_u *p;
2972 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00002973 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974
2975#ifdef FEAT_LANGMAP
2976 langmap_init();
2977#endif
2978
2979 /* Be Vi compatible by default */
2980 p_cp = TRUE;
2981
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002982 /* Use POSIX compatibility when $VIM_POSIX is set. */
2983 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002984 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002985 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002986 set_string_default("shm", (char_u *)"A");
2987 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002988
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 /*
2990 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002991 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002993 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2995# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002996 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002998 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003000 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001# endif
3002#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003003 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 set_string_default("sh", p);
3005
3006#ifdef FEAT_WILDIGN
3007 /*
3008 * Set the default for 'backupskip' to include environment variables for
3009 * temp files.
3010 */
3011 {
3012# ifdef UNIX
3013 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3014# else
3015 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3016# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003017 int len;
3018 garray_T ga;
3019 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020
3021 ga_init2(&ga, 1, 100);
3022 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3023 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003024 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025# ifdef UNIX
3026 if (*names[n] == NUL)
3027 p = (char_u *)"/tmp";
3028 else
3029# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003030 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 if (p != NULL && *p != NUL)
3032 {
3033 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003034 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 if (ga_grow(&ga, len) == OK)
3036 {
3037 if (ga.ga_len > 0)
3038 STRCAT(ga.ga_data, ",");
3039 STRCAT(ga.ga_data, p);
3040 add_pathsep(ga.ga_data);
3041 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 ga.ga_len += len;
3043 }
3044 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003045 if (mustfree)
3046 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 }
3048 if (ga.ga_data != NULL)
3049 {
3050 set_string_default("bsk", ga.ga_data);
3051 vim_free(ga.ga_data);
3052 }
3053 }
3054#endif
3055
3056 /*
3057 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3058 */
3059 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003060 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003062#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3063 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3064#endif
3065 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003067 /* Use amount of memory available at this moment. */
3068 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069#else
3070# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003071 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003072 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003074 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075# endif
3076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003078 opt_idx = findoption((char_u *)"maxmem");
3079 if (opt_idx >= 0)
3080 {
3081#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3082 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3083 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3084#endif
3085 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3086 }
3087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 }
3089
3090#ifdef FEAT_GUI_W32
3091 /* force 'shortname' for Win32s */
3092 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003093 {
3094 opt_idx = findoption((char_u *)"shortname");
3095 if (opt_idx >= 0)
3096 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3097 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098#endif
3099
3100#ifdef FEAT_SEARCHPATH
3101 {
3102 char_u *cdpath;
3103 char_u *buf;
3104 int i;
3105 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003106 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107
3108 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003109 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 if (cdpath != NULL)
3111 {
3112 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3113 if (buf != NULL)
3114 {
3115 buf[0] = ','; /* start with ",", current dir first */
3116 j = 1;
3117 for (i = 0; cdpath[i] != NUL; ++i)
3118 {
3119 if (vim_ispathlistsep(cdpath[i]))
3120 buf[j++] = ',';
3121 else
3122 {
3123 if (cdpath[i] == ' ' || cdpath[i] == ',')
3124 buf[j++] = '\\';
3125 buf[j++] = cdpath[i];
3126 }
3127 }
3128 buf[j] = NUL;
3129 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003130 if (opt_idx >= 0)
3131 {
3132 options[opt_idx].def_val[VI_DEFAULT] = buf;
3133 options[opt_idx].flags |= P_DEF_ALLOCED;
3134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003136 if (mustfree)
3137 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 }
3139 }
3140#endif
3141
3142#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3143 /* Set print encoding on platforms that don't default to latin1 */
3144 set_string_default("penc",
3145# if defined(MSWIN) || defined(OS2)
3146 (char_u *)"cp1252"
3147# else
3148# ifdef VMS
3149 (char_u *)"dec-mcs"
3150# else
3151# ifdef EBCDIC
3152 (char_u *)"ebcdic-uk"
3153# else
3154# ifdef MAC
3155 (char_u *)"mac-roman"
3156# else /* HPUX */
3157 (char_u *)"hp-roman8"
3158# endif
3159# endif
3160# endif
3161# endif
3162 );
3163#endif
3164
3165#ifdef FEAT_POSTSCRIPT
3166 /* 'printexpr' must be allocated to be able to evaluate it. */
3167 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003168# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3169 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170# else
3171# ifdef VMS
3172 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3173
3174# else
3175 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3176# endif
3177# endif
3178 );
3179#endif
3180
3181 /*
3182 * Set all the options (except the terminal options) to their default
3183 * value. Also set the global value for local options.
3184 */
3185 set_options_default(0);
3186
3187#ifdef FEAT_GUI
3188 if (found_reverse_arg)
3189 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3190#endif
3191
3192 curbuf->b_p_initialized = TRUE;
3193 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3194 check_buf_options(curbuf);
3195 check_win_options(curwin);
3196 check_options();
3197
3198 /* Must be before option_expand(), because that one needs vim_isIDc() */
3199 didset_options();
3200
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003201#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003202 /* Use the current chartab for the generic chartab. */
3203 init_spell_chartab();
3204#endif
3205
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206#ifdef FEAT_LINEBREAK
3207 /*
3208 * initialize the table for 'breakat'.
3209 */
3210 fill_breakat_flags();
3211#endif
3212
3213 /*
3214 * Expand environment variables and things like "~" for the defaults.
3215 * If option_expand() returns non-NULL the variable is expanded. This can
3216 * only happen for non-indirect options.
3217 * Also set the default to the expanded value, so ":set" does not list
3218 * them.
3219 * Don't set the P_ALLOCED flag, because we don't want to free the
3220 * default.
3221 */
3222 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3223 {
3224 if ((options[opt_idx].flags & P_GETTEXT)
3225 && options[opt_idx].var != NULL)
3226 p = (char_u *)_(*(char **)options[opt_idx].var);
3227 else
3228 p = option_expand(opt_idx, NULL);
3229 if (p != NULL && (p = vim_strsave(p)) != NULL)
3230 {
3231 *(char_u **)options[opt_idx].var = p;
3232 /* VIMEXP
3233 * Defaults for all expanded options are currently the same for Vi
3234 * and Vim. When this changes, add some code here! Also need to
3235 * split P_DEF_ALLOCED in two.
3236 */
3237 if (options[opt_idx].flags & P_DEF_ALLOCED)
3238 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3239 options[opt_idx].def_val[VI_DEFAULT] = p;
3240 options[opt_idx].flags |= P_DEF_ALLOCED;
3241 }
3242 }
3243
3244 /* Initialize the highlight_attr[] table. */
3245 highlight_changed();
3246
3247 save_file_ff(curbuf); /* Buffer is unchanged */
3248
3249 /* Parse default for 'wildmode' */
3250 check_opt_wim();
3251
3252#if defined(FEAT_ARABIC)
3253 /* Detect use of mlterm.
3254 * Mlterm is a terminal emulator akin to xterm that has some special
3255 * abilities (bidi namely).
3256 * NOTE: mlterm's author is being asked to 'set' a variable
3257 * instead of an environment variable due to inheritance.
3258 */
3259 if (mch_getenv((char_u *)"MLTERM") != NULL)
3260 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3261#endif
3262
3263#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3264 /* Parse default for 'fillchars'. */
3265 (void)set_chars_option(&p_fcs);
3266#endif
3267
3268#ifdef FEAT_CLIPBOARD
3269 /* Parse default for 'clipboard' */
3270 (void)check_clipboard_option();
3271#endif
3272
3273#ifdef FEAT_MBYTE
3274# if defined(WIN3264) && defined(FEAT_GETTEXT)
3275 /*
3276 * If $LANG isn't set, try to get a good value for it. This makes the
3277 * right language be used automatically. Don't do this for English.
3278 */
3279 if (mch_getenv((char_u *)"LANG") == NULL)
3280 {
3281 char buf[20];
3282
3283 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3284 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3285 * only the first two. */
3286 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3287 (LPTSTR)buf, 20);
3288 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3289 {
3290 /* There are a few exceptions (probably more) */
3291 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3292 STRCPY(buf, "zh_TW");
3293 else if (STRNICMP(buf, "chs", 3) == 0
3294 || STRNICMP(buf, "zhc", 3) == 0)
3295 STRCPY(buf, "zh_CN");
3296 else if (STRNICMP(buf, "jp", 2) == 0)
3297 STRCPY(buf, "ja");
3298 else
3299 buf[2] = NUL; /* truncate to two-letter code */
3300 vim_setenv("LANG", buf);
3301 }
3302 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003303# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003304# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003305 /* Moved to os_mac_conv.c to avoid dependency problems. */
3306 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003307# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308# endif
3309
3310 /* enc_locale() will try to find the encoding of the current locale. */
3311 p = enc_locale();
3312 if (p != NULL)
3313 {
3314 char_u *save_enc;
3315
3316 /* Try setting 'encoding' and check if the value is valid.
3317 * If not, go back to the default "latin1". */
3318 save_enc = p_enc;
3319 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003320 if (STRCMP(p_enc, "gb18030") == 0)
3321 {
3322 /* We don't support "gb18030", but "cp936" is a good substitute
3323 * for practical purposes, thus use that. It's not an alias to
3324 * still support conversion between gb18030 and utf-8. */
3325 p_enc = vim_strsave((char_u *)"cp936");
3326 vim_free(p);
3327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 if (mb_init() == NULL)
3329 {
3330 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003331 if (opt_idx >= 0)
3332 {
3333 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3334 options[opt_idx].flags |= P_DEF_ALLOCED;
3335 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003337#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3338 || defined(VMS)
3339 if (STRCMP(p_enc, "latin1") == 0
3340# ifdef FEAT_MBYTE
3341 || enc_utf8
3342# endif
3343 )
3344 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003345 /* Adjust the default for 'isprint' and 'iskeyword' to match
3346 * latin1. Also set the defaults for when 'nocompatible' is
3347 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003348 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003349 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003350 set_string_option_direct((char_u *)"isk", -1,
3351 ISK_LATIN1, OPT_FREE, SID_NONE);
3352 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003353 if (opt_idx >= 0)
3354 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003355 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003356 if (opt_idx >= 0)
3357 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003358 (void)init_chartab();
3359 }
3360#endif
3361
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362# if defined(WIN3264) && !defined(FEAT_GUI)
3363 /* Win32 console: When GetACP() returns a different value from
3364 * GetConsoleCP() set 'termencoding'. */
3365 if (GetACP() != GetConsoleCP())
3366 {
3367 char buf[50];
3368
3369 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3370 p_tenc = vim_strsave((char_u *)buf);
3371 if (p_tenc != NULL)
3372 {
3373 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003374 if (opt_idx >= 0)
3375 {
3376 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3377 options[opt_idx].flags |= P_DEF_ALLOCED;
3378 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379 convert_setup(&input_conv, p_tenc, p_enc);
3380 convert_setup(&output_conv, p_enc, p_tenc);
3381 }
3382 else
3383 p_tenc = empty_option;
3384 }
3385# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003386# if defined(WIN3264) && defined(FEAT_MBYTE)
3387 /* $HOME may have characters in active code page. */
3388 init_homedir();
3389# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 }
3391 else
3392 {
3393 vim_free(p_enc);
3394 p_enc = save_enc;
3395 }
3396 }
3397#endif
3398
3399#ifdef FEAT_MULTI_LANG
3400 /* Set the default for 'helplang'. */
3401 set_helplang_default(get_mess_lang());
3402#endif
3403}
3404
3405/*
3406 * Set an option to its default value.
3407 * This does not take care of side effects!
3408 */
3409 static void
3410set_option_default(opt_idx, opt_flags, compatible)
3411 int opt_idx;
3412 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3413 int compatible; /* use Vi default value */
3414{
3415 char_u *varp; /* pointer to variable for current option */
3416 int dvi; /* index in def_val[] */
3417 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003418 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3420
3421 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3422 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003423 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 {
3425 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3426 if (flags & P_STRING)
3427 {
3428 /* Use set_string_option_direct() for local options to handle
3429 * freeing and allocating the value. */
3430 if (options[opt_idx].indir != PV_NONE)
3431 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003432 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 else
3434 {
3435 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3436 free_string_option(*(char_u **)(varp));
3437 *(char_u **)varp = options[opt_idx].def_val[dvi];
3438 options[opt_idx].flags &= ~P_ALLOCED;
3439 }
3440 }
3441 else if (flags & P_NUM)
3442 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003443 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 win_comp_scroll(curwin);
3445 else
3446 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003447 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 /* May also set global value for local option. */
3449 if (both)
3450 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3451 *(long *)varp;
3452 }
3453 }
3454 else /* P_BOOL */
3455 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003456 /* the cast to long is required for Manx C, long_i is needed for
3457 * MSVC */
3458 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003459#ifdef UNIX
3460 /* 'modeline' defaults to off for root */
3461 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3462 *(int *)varp = FALSE;
3463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 /* May also set global value for local option. */
3465 if (both)
3466 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3467 *(int *)varp;
3468 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003469
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003470 /* The default value is not insecure. */
3471 flagsp = insecure_flag(opt_idx, opt_flags);
3472 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473 }
3474
3475#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003476 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477#endif
3478}
3479
3480/*
3481 * Set all options (except terminal options) to their default value.
3482 */
3483 static void
3484set_options_default(opt_flags)
3485 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3486{
3487 int i;
3488#ifdef FEAT_WINDOWS
3489 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003490 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491#endif
3492
3493 for (i = 0; !istermoption(&options[i]); i++)
3494 if (!(options[i].flags & P_NODEFAULT))
3495 set_option_default(i, opt_flags, p_cp);
3496
3497#ifdef FEAT_WINDOWS
3498 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003499 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 win_comp_scroll(wp);
3501#else
3502 win_comp_scroll(curwin);
3503#endif
3504}
3505
3506/*
3507 * Set the Vi-default value of a string option.
3508 * Used for 'sh', 'backupskip' and 'term'.
3509 */
3510 void
3511set_string_default(name, val)
3512 char *name;
3513 char_u *val;
3514{
3515 char_u *p;
3516 int opt_idx;
3517
3518 p = vim_strsave(val);
3519 if (p != NULL) /* we don't want a NULL */
3520 {
3521 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003522 if (opt_idx >= 0)
3523 {
3524 if (options[opt_idx].flags & P_DEF_ALLOCED)
3525 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3526 options[opt_idx].def_val[VI_DEFAULT] = p;
3527 options[opt_idx].flags |= P_DEF_ALLOCED;
3528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 }
3530}
3531
3532/*
3533 * Set the Vi-default value of a number option.
3534 * Used for 'lines' and 'columns'.
3535 */
3536 void
3537set_number_default(name, val)
3538 char *name;
3539 long val;
3540{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003541 int opt_idx;
3542
3543 opt_idx = findoption((char_u *)name);
3544 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003545 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546}
3547
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003548#if defined(EXITFREE) || defined(PROTO)
3549/*
3550 * Free all options.
3551 */
3552 void
3553free_all_options()
3554{
3555 int i;
3556
3557 for (i = 0; !istermoption(&options[i]); i++)
3558 {
3559 if (options[i].indir == PV_NONE)
3560 {
3561 /* global option: free value and default value. */
3562 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3563 free_string_option(*(char_u **)options[i].var);
3564 if (options[i].flags & P_DEF_ALLOCED)
3565 free_string_option(options[i].def_val[VI_DEFAULT]);
3566 }
3567 else if (options[i].var != VAR_WIN
3568 && (options[i].flags & P_STRING))
3569 /* buffer-local option: free global value */
3570 free_string_option(*(char_u **)options[i].var);
3571 }
3572}
3573#endif
3574
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576/*
3577 * Initialize the options, part two: After getting Rows and Columns and
3578 * setting 'term'.
3579 */
3580 void
3581set_init_2()
3582{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003583 int idx;
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 /*
3586 * 'scroll' defaults to half the window height. Note that this default is
3587 * wrong when the window height changes.
3588 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003589 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003590 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003591 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003592 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 comp_col();
3594
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003595 /*
3596 * 'window' is only for backwards compatibility with Vi.
3597 * Default is Rows - 1.
3598 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003599 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003600 p_window = Rows - 1;
3601 set_number_default("window", Rows - 1);
3602
Bram Moolenaarf740b292006-02-16 22:11:02 +00003603 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003605 /*
3606 * If 'background' wasn't set by the user, try guessing the value,
3607 * depending on the terminal name. Only need to check for terminals
3608 * with a dark background, that can handle color.
3609 */
3610 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003611 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3612 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003614 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003615 /* don't mark it as set, when starting the GUI it may be
3616 * changed again */
3617 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 }
3619#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003620
3621#ifdef CURSOR_SHAPE
3622 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3623#endif
3624#ifdef FEAT_MOUSESHAPE
3625 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3626#endif
3627#ifdef FEAT_PRINTER
3628 (void)parse_printoptions(); /* parse 'printoptions' default value */
3629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630}
3631
3632/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003633 * Return "dark" or "light" depending on the kind of terminal.
3634 * This is just guessing! Recognized are:
3635 * "linux" Linux console
3636 * "screen.linux" Linux console with screen
3637 * "cygwin" Cygwin shell
3638 * "putty" Putty program
3639 * We also check the COLORFGBG environment variable, which is set by
3640 * rxvt and derivatives. This variable contains either two or three
3641 * values separated by semicolons; we want the last value in either
3642 * case. If this value is 0-6 or 8, our background is dark.
3643 */
3644 static char_u *
3645term_bg_default()
3646{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003647#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3648 /* DOS console nearly always black */
3649 return (char_u *)"dark";
3650#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003651 char_u *p;
3652
Bram Moolenaarf740b292006-02-16 22:11:02 +00003653 if (STRCMP(T_NAME, "linux") == 0
3654 || STRCMP(T_NAME, "screen.linux") == 0
3655 || STRCMP(T_NAME, "cygwin") == 0
3656 || STRCMP(T_NAME, "putty") == 0
3657 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3658 && (p = vim_strrchr(p, ';')) != NULL
3659 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3660 && p[2] == NUL))
3661 return (char_u *)"dark";
3662 return (char_u *)"light";
3663#endif
3664}
3665
3666/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667 * Initialize the options, part three: After reading the .vimrc
3668 */
3669 void
3670set_init_3()
3671{
3672#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3673/*
3674 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3675 * This is done after other initializations, where 'shell' might have been
3676 * set, but only if they have not been set before.
3677 */
3678 char_u *p;
3679 int idx_srr;
3680 int do_srr;
3681#ifdef FEAT_QUICKFIX
3682 int idx_sp;
3683 int do_sp;
3684#endif
3685
3686 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003687 if (idx_srr < 0)
3688 do_srr = FALSE;
3689 else
3690 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691#ifdef FEAT_QUICKFIX
3692 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003693 if (idx_sp < 0)
3694 do_sp = FALSE;
3695 else
3696 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697#endif
3698
3699 /*
3700 * Isolate the name of the shell:
3701 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3702 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003703 * But don't allow a space in the path, so that this works:
3704 * "/usr/bin/csh --rcfile ~/.cshrc"
3705 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003707#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708 p = gettail(p_sh);
3709 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003710#else
3711 p = skiptowhite(p_sh);
3712 if (*p == NUL)
3713 {
3714 /* No white space, use the tail. */
3715 p = vim_strsave(gettail(p_sh));
3716 }
3717 else
3718 {
3719 char_u *p1, *p2;
3720
3721 /* Find the last path separator before the space. */
3722 p1 = p_sh;
3723 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3724 if (vim_ispathsep(*p2))
3725 p1 = p2 + 1;
3726 p = vim_strnsave(p1, (int)(p - p1));
3727 }
3728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 if (p != NULL)
3730 {
3731 /*
3732 * Default for p_sp is "| tee", for p_srr is ">".
3733 * For known shells it is changed here to include stderr.
3734 */
3735 if ( fnamecmp(p, "csh") == 0
3736 || fnamecmp(p, "tcsh") == 0
3737# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3738 || fnamecmp(p, "csh.exe") == 0
3739 || fnamecmp(p, "tcsh.exe") == 0
3740# endif
3741 )
3742 {
3743#if defined(FEAT_QUICKFIX)
3744 if (do_sp)
3745 {
3746# ifdef WIN3264
3747 p_sp = (char_u *)">&";
3748# else
3749 p_sp = (char_u *)"|& tee";
3750# endif
3751 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3752 }
3753#endif
3754 if (do_srr)
3755 {
3756 p_srr = (char_u *)">&";
3757 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3758 }
3759 }
3760 else
3761# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3762 if ( fnamecmp(p, "sh") == 0
3763 || fnamecmp(p, "ksh") == 0
3764 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003765 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 || fnamecmp(p, "bash") == 0
3767# ifdef WIN3264
3768 || fnamecmp(p, "cmd") == 0
3769 || fnamecmp(p, "sh.exe") == 0
3770 || fnamecmp(p, "ksh.exe") == 0
3771 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003772 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 || fnamecmp(p, "bash.exe") == 0
3774 || fnamecmp(p, "cmd.exe") == 0
3775# endif
3776 )
3777# endif
3778 {
3779#if defined(FEAT_QUICKFIX)
3780 if (do_sp)
3781 {
3782# ifdef WIN3264
3783 p_sp = (char_u *)">%s 2>&1";
3784# else
3785 p_sp = (char_u *)"2>&1| tee";
3786# endif
3787 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3788 }
3789#endif
3790 if (do_srr)
3791 {
3792 p_srr = (char_u *)">%s 2>&1";
3793 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3794 }
3795 }
3796 vim_free(p);
3797 }
3798#endif
3799
3800#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3801 /*
3802 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3803 * This is done after other initializations, where 'shell' might have been
3804 * set, but only if they have not been set before. Default for p_shcf is
3805 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3806 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3807 * command.com. And for Win32 we need to set p_sxq instead.
3808 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003809 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 {
3811 int idx3;
3812
3813 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003814 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 {
3816 p_shcf = (char_u *)"-c";
3817 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3818 }
3819
3820# ifndef DJGPP
3821# ifdef WIN3264
3822 /* Somehow Win32 requires the quotes around the redirection too */
3823 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003824 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 {
3826 p_sxq = (char_u *)"\"";
3827 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3828 }
3829# else
3830 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003831 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832 {
3833 p_shq = (char_u *)"\"";
3834 options[idx3].def_val[VI_DEFAULT] = p_shq;
3835 }
3836# endif
3837# endif
3838 }
3839#endif
3840
3841#ifdef FEAT_TITLE
3842 set_title_defaults();
3843#endif
3844}
3845
3846#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3847/*
3848 * When 'helplang' is still at its default value, set it to "lang".
3849 * Only the first two characters of "lang" are used.
3850 */
3851 void
3852set_helplang_default(lang)
3853 char_u *lang;
3854{
3855 int idx;
3856
3857 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3858 return;
3859 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003860 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 {
3862 if (options[idx].flags & P_ALLOCED)
3863 free_string_option(p_hlg);
3864 p_hlg = vim_strsave(lang);
3865 if (p_hlg == NULL)
3866 p_hlg = empty_option;
3867 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003868 {
3869 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3870 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3871 {
3872 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3873 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003876 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 options[idx].flags |= P_ALLOCED;
3878 }
3879}
3880#endif
3881
3882#ifdef FEAT_GUI
3883static char_u *gui_bg_default __ARGS((void));
3884
3885 static char_u *
3886gui_bg_default()
3887{
3888 if (gui_get_lightness(gui.back_pixel) < 127)
3889 return (char_u *)"dark";
3890 return (char_u *)"light";
3891}
3892
3893/*
3894 * Option initializations that can only be done after opening the GUI window.
3895 */
3896 void
3897init_gui_options()
3898{
3899 /* Set the 'background' option according to the lightness of the
3900 * background color, unless the user has set it already. */
3901 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3902 {
3903 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3904 highlight_changed();
3905 }
3906}
3907#endif
3908
3909#ifdef FEAT_TITLE
3910/*
3911 * 'title' and 'icon' only default to true if they have not been set or reset
3912 * in .vimrc and we can read the old value.
3913 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3914 * they can be reset. This reduces startup time when using X on a remote
3915 * machine.
3916 */
3917 void
3918set_title_defaults()
3919{
3920 int idx1;
3921 long val;
3922
3923 /*
3924 * If GUI is (going to be) used, we can always set the window title and
3925 * icon name. Saves a bit of time, because the X11 display server does
3926 * not need to be contacted.
3927 */
3928 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 {
3931#ifdef FEAT_GUI
3932 if (gui.starting || gui.in_use)
3933 val = TRUE;
3934 else
3935#endif
3936 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003937 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 p_title = val;
3939 }
3940 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003941 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 {
3943#ifdef FEAT_GUI
3944 if (gui.starting || gui.in_use)
3945 val = TRUE;
3946 else
3947#endif
3948 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003949 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 p_icon = val;
3951 }
3952}
3953#endif
3954
3955/*
3956 * Parse 'arg' for option settings.
3957 *
3958 * 'arg' may be IObuff, but only when no errors can be present and option
3959 * does not need to be expanded with option_expand().
3960 * "opt_flags":
3961 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003962 * OPT_GLOBAL for ":setglobal"
3963 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003965 * OPT_WINONLY to only set window-local options
3966 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 *
3968 * returns FAIL if an error is detected, OK otherwise
3969 */
3970 int
3971do_set(arg, opt_flags)
3972 char_u *arg; /* option string (may be written to!) */
3973 int opt_flags;
3974{
3975 int opt_idx;
3976 char_u *errmsg;
3977 char_u errbuf[80];
3978 char_u *startarg;
3979 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3980 int nextchar; /* next non-white char after option name */
3981 int afterchar; /* character just after option name */
3982 int len;
3983 int i;
3984 long value;
3985 int key;
3986 long_u flags; /* flags for current option */
3987 char_u *varp = NULL; /* pointer to variable for current option */
3988 int did_show = FALSE; /* already showed one value */
3989 int adding; /* "opt+=arg" */
3990 int prepending; /* "opt^=arg" */
3991 int removing; /* "opt-=arg" */
3992 int cp_val = 0;
3993 char_u key_name[2];
3994
3995 if (*arg == NUL)
3996 {
3997 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003998 did_show = TRUE;
3999 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 }
4001
4002 while (*arg != NUL) /* loop to process all options */
4003 {
4004 errmsg = NULL;
4005 startarg = arg; /* remember for error message */
4006
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004007 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4008 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 {
4010 /*
4011 * ":set all" show all options.
4012 * ":set all&" set all options to their default value.
4013 */
4014 arg += 3;
4015 if (*arg == '&')
4016 {
4017 ++arg;
4018 /* Only for :set command set global value of local options. */
4019 set_options_default(OPT_FREE | opt_flags);
4020 }
4021 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004022 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004024 did_show = TRUE;
4025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004027 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 {
4029 showoptions(2, opt_flags);
4030 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004031 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032 arg += 7;
4033 }
4034 else
4035 {
4036 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004037 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 {
4039 prefix = 0;
4040 arg += 2;
4041 }
4042 else if (STRNCMP(arg, "inv", 3) == 0)
4043 {
4044 prefix = 2;
4045 arg += 3;
4046 }
4047
4048 /* find end of name */
4049 key = 0;
4050 if (*arg == '<')
4051 {
4052 nextchar = 0;
4053 opt_idx = -1;
4054 /* look out for <t_>;> */
4055 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4056 len = 5;
4057 else
4058 {
4059 len = 1;
4060 while (arg[len] != NUL && arg[len] != '>')
4061 ++len;
4062 }
4063 if (arg[len] != '>')
4064 {
4065 errmsg = e_invarg;
4066 goto skip;
4067 }
4068 arg[len] = NUL; /* put NUL after name */
4069 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4070 opt_idx = findoption(arg + 1);
4071 arg[len++] = '>'; /* restore '>' */
4072 if (opt_idx == -1)
4073 key = find_key_option(arg + 1);
4074 }
4075 else
4076 {
4077 len = 0;
4078 /*
4079 * The two characters after "t_" may not be alphanumeric.
4080 */
4081 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4082 len = 4;
4083 else
4084 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4085 ++len;
4086 nextchar = arg[len];
4087 arg[len] = NUL; /* put NUL after name */
4088 opt_idx = findoption(arg);
4089 arg[len] = nextchar; /* restore nextchar */
4090 if (opt_idx == -1)
4091 key = find_key_option(arg);
4092 }
4093
4094 /* remember character after option name */
4095 afterchar = arg[len];
4096
4097 /* skip white space, allow ":set ai ?" */
4098 while (vim_iswhite(arg[len]))
4099 ++len;
4100
4101 adding = FALSE;
4102 prepending = FALSE;
4103 removing = FALSE;
4104 if (arg[len] != NUL && arg[len + 1] == '=')
4105 {
4106 if (arg[len] == '+')
4107 {
4108 adding = TRUE; /* "+=" */
4109 ++len;
4110 }
4111 else if (arg[len] == '^')
4112 {
4113 prepending = TRUE; /* "^=" */
4114 ++len;
4115 }
4116 else if (arg[len] == '-')
4117 {
4118 removing = TRUE; /* "-=" */
4119 ++len;
4120 }
4121 }
4122 nextchar = arg[len];
4123
4124 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4125 {
4126 errmsg = (char_u *)N_("E518: Unknown option");
4127 goto skip;
4128 }
4129
4130 if (opt_idx >= 0)
4131 {
4132 if (options[opt_idx].var == NULL) /* hidden option: skip */
4133 {
4134 /* Only give an error message when requesting the value of
4135 * a hidden option, ignore setting it. */
4136 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4137 && (!(options[opt_idx].flags & P_BOOL)
4138 || nextchar == '?'))
4139 errmsg = (char_u *)N_("E519: Option not supported");
4140 goto skip;
4141 }
4142
4143 flags = options[opt_idx].flags;
4144 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4145 }
4146 else
4147 {
4148 flags = P_STRING;
4149 if (key < 0)
4150 {
4151 key_name[0] = KEY2TERMCAP0(key);
4152 key_name[1] = KEY2TERMCAP1(key);
4153 }
4154 else
4155 {
4156 key_name[0] = KS_KEY;
4157 key_name[1] = (key & 0xff);
4158 }
4159 }
4160
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004161 /* Skip all options that are not window-local (used when showing
4162 * an already loaded buffer in a window). */
4163 if ((opt_flags & OPT_WINONLY)
4164 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4165 goto skip;
4166
Bram Moolenaara3227e22006-03-08 21:32:40 +00004167 /* Skip all options that are window-local (used for :vimgrep). */
4168 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4169 && options[opt_idx].var == VAR_WIN)
4170 goto skip;
4171
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004172 /* Disallow changing some options from modelines. */
4173 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004175 if (flags & P_SECURE)
4176 {
4177 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4178 goto skip;
4179 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004180#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004181 /* In diff mode some options are overruled. This avoids that
4182 * 'foldmethod' becomes "marker" instead of "diff" and that
4183 * "wrap" gets set. */
4184 if (curwin->w_p_diff
4185 && (options[opt_idx].indir == PV_FDM
4186 || options[opt_idx].indir == PV_WRAP))
4187 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 }
4190
4191#ifdef HAVE_SANDBOX
4192 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004193 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 {
4195 errmsg = (char_u *)_(e_sandbox);
4196 goto skip;
4197 }
4198#endif
4199
4200 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4201 {
4202 arg += len;
4203 cp_val = p_cp;
4204 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4205 {
4206 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4207 {
4208 cp_val = FALSE;
4209 arg += 3;
4210 }
4211 else /* "opt&vi": set to Vi default */
4212 {
4213 cp_val = TRUE;
4214 arg += 2;
4215 }
4216 }
4217 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4218 && arg[1] != NUL && !vim_iswhite(arg[1]))
4219 {
4220 errmsg = e_trailing;
4221 goto skip;
4222 }
4223 }
4224
4225 /*
4226 * allow '=' and ':' as MSDOS command.com allows only one
4227 * '=' character per "set" command line. grrr. (jw)
4228 */
4229 if (nextchar == '?'
4230 || (prefix == 1
4231 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4232 && !(flags & P_BOOL)))
4233 {
4234 /*
4235 * print value
4236 */
4237 if (did_show)
4238 msg_putchar('\n'); /* cursor below last one */
4239 else
4240 {
4241 gotocmdline(TRUE); /* cursor at status line */
4242 did_show = TRUE; /* remember that we did a line */
4243 }
4244 if (opt_idx >= 0)
4245 {
4246 showoneopt(&options[opt_idx], opt_flags);
4247#ifdef FEAT_EVAL
4248 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004249 {
4250 /* Mention where the option was last set. */
4251 if (varp == options[opt_idx].var)
4252 last_set_msg(options[opt_idx].scriptID);
4253 else if ((int)options[opt_idx].indir & PV_WIN)
4254 last_set_msg(curwin->w_p_scriptID[
4255 (int)options[opt_idx].indir & PV_MASK]);
4256 else if ((int)options[opt_idx].indir & PV_BUF)
4257 last_set_msg(curbuf->b_p_scriptID[
4258 (int)options[opt_idx].indir & PV_MASK]);
4259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260#endif
4261 }
4262 else
4263 {
4264 char_u *p;
4265
4266 p = find_termcode(key_name);
4267 if (p == NULL)
4268 {
4269 errmsg = (char_u *)N_("E518: Unknown option");
4270 goto skip;
4271 }
4272 else
4273 (void)show_one_termcode(key_name, p, TRUE);
4274 }
4275 if (nextchar != '?'
4276 && nextchar != NUL && !vim_iswhite(afterchar))
4277 errmsg = e_trailing;
4278 }
4279 else
4280 {
4281 if (flags & P_BOOL) /* boolean */
4282 {
4283 if (nextchar == '=' || nextchar == ':')
4284 {
4285 errmsg = e_invarg;
4286 goto skip;
4287 }
4288
4289 /*
4290 * ":set opt!": invert
4291 * ":set opt&": reset to default value
4292 * ":set opt<": reset to global value
4293 */
4294 if (nextchar == '!')
4295 value = *(int *)(varp) ^ 1;
4296 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004297 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 ((flags & P_VI_DEF) || cp_val)
4299 ? VI_DEFAULT : VIM_DEFAULT];
4300 else if (nextchar == '<')
4301 {
4302 /* For 'autoread' -1 means to use global value. */
4303 if ((int *)varp == &curbuf->b_p_ar
4304 && opt_flags == OPT_LOCAL)
4305 value = -1;
4306 else
4307 value = *(int *)get_varp_scope(&(options[opt_idx]),
4308 OPT_GLOBAL);
4309 }
4310 else
4311 {
4312 /*
4313 * ":set invopt": invert
4314 * ":set opt" or ":set noopt": set or reset
4315 */
4316 if (nextchar != NUL && !vim_iswhite(afterchar))
4317 {
4318 errmsg = e_trailing;
4319 goto skip;
4320 }
4321 if (prefix == 2) /* inv */
4322 value = *(int *)(varp) ^ 1;
4323 else
4324 value = prefix;
4325 }
4326
4327 errmsg = set_bool_option(opt_idx, varp, (int)value,
4328 opt_flags);
4329 }
4330 else /* numeric or string */
4331 {
4332 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4333 || prefix != 1)
4334 {
4335 errmsg = e_invarg;
4336 goto skip;
4337 }
4338
4339 if (flags & P_NUM) /* numeric */
4340 {
4341 /*
4342 * Different ways to set a number option:
4343 * & set to default value
4344 * < set to global value
4345 * <xx> accept special key codes for 'wildchar'
4346 * c accept any non-digit for 'wildchar'
4347 * [-]0-9 set number
4348 * other error
4349 */
4350 ++arg;
4351 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004352 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 ((flags & P_VI_DEF) || cp_val)
4354 ? VI_DEFAULT : VIM_DEFAULT];
4355 else if (nextchar == '<')
4356 value = *(long *)get_varp_scope(&(options[opt_idx]),
4357 OPT_GLOBAL);
4358 else if (((long *)varp == &p_wc
4359 || (long *)varp == &p_wcm)
4360 && (*arg == '<'
4361 || *arg == '^'
4362 || ((!arg[1] || vim_iswhite(arg[1]))
4363 && !VIM_ISDIGIT(*arg))))
4364 {
4365 value = string_to_key(arg);
4366 if (value == 0 && (long *)varp != &p_wcm)
4367 {
4368 errmsg = e_invarg;
4369 goto skip;
4370 }
4371 }
4372 /* allow negative numbers (for 'undolevels') */
4373 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4374 {
4375 i = 0;
4376 if (*arg == '-')
4377 i = 1;
4378#ifdef HAVE_STRTOL
4379 value = strtol((char *)arg, NULL, 0);
4380 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4381 i += 2;
4382#else
4383 value = atol((char *)arg);
4384#endif
4385 while (VIM_ISDIGIT(arg[i]))
4386 ++i;
4387 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4388 {
4389 errmsg = e_invarg;
4390 goto skip;
4391 }
4392 }
4393 else
4394 {
4395 errmsg = (char_u *)N_("E521: Number required after =");
4396 goto skip;
4397 }
4398
4399 if (adding)
4400 value = *(long *)varp + value;
4401 if (prepending)
4402 value = *(long *)varp * value;
4403 if (removing)
4404 value = *(long *)varp - value;
4405 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004406 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407 }
4408 else if (opt_idx >= 0) /* string */
4409 {
4410 char_u *save_arg = NULL;
4411 char_u *s = NULL;
4412 char_u *oldval; /* previous value if *varp */
4413 char_u *newval;
4414 char_u *origval;
4415 unsigned newlen;
4416 int comma;
4417 int bs;
4418 int new_value_alloced; /* new string option
4419 was allocated */
4420
4421 /* When using ":set opt=val" for a global option
4422 * with a local value the local value will be
4423 * reset, use the global value here. */
4424 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004425 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 varp = options[opt_idx].var;
4427
4428 /* The old value is kept until we are sure that the
4429 * new value is valid. */
4430 oldval = *(char_u **)varp;
4431 if (nextchar == '&') /* set to default val */
4432 {
4433 newval = options[opt_idx].def_val[
4434 ((flags & P_VI_DEF) || cp_val)
4435 ? VI_DEFAULT : VIM_DEFAULT];
4436 if ((char_u **)varp == &p_bg)
4437 {
4438 /* guess the value of 'background' */
4439#ifdef FEAT_GUI
4440 if (gui.in_use)
4441 newval = gui_bg_default();
4442 else
4443#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004444 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 }
4446
4447 /* expand environment variables and ~ (since the
4448 * default value was already expanded, only
4449 * required when an environment variable was set
4450 * later */
4451 if (newval == NULL)
4452 newval = empty_option;
4453 else
4454 {
4455 s = option_expand(opt_idx, newval);
4456 if (s == NULL)
4457 s = newval;
4458 newval = vim_strsave(s);
4459 }
4460 new_value_alloced = TRUE;
4461 }
4462 else if (nextchar == '<') /* set to global val */
4463 {
4464 newval = vim_strsave(*(char_u **)get_varp_scope(
4465 &(options[opt_idx]), OPT_GLOBAL));
4466 new_value_alloced = TRUE;
4467 }
4468 else
4469 {
4470 ++arg; /* jump to after the '=' or ':' */
4471
4472 /*
4473 * Set 'keywordprg' to ":help" if an empty
4474 * value was passed to :set by the user.
4475 * Misuse errbuf[] for the resulting string.
4476 */
4477 if (varp == (char_u *)&p_kp
4478 && (*arg == NUL || *arg == ' '))
4479 {
4480 STRCPY(errbuf, ":help");
4481 save_arg = arg;
4482 arg = errbuf;
4483 }
4484 /*
4485 * Convert 'whichwrap' number to string, for
4486 * backwards compatibility with Vim 3.0.
4487 * Misuse errbuf[] for the resulting string.
4488 */
4489 else if (varp == (char_u *)&p_ww
4490 && VIM_ISDIGIT(*arg))
4491 {
4492 *errbuf = NUL;
4493 i = getdigits(&arg);
4494 if (i & 1)
4495 STRCAT(errbuf, "b,");
4496 if (i & 2)
4497 STRCAT(errbuf, "s,");
4498 if (i & 4)
4499 STRCAT(errbuf, "h,l,");
4500 if (i & 8)
4501 STRCAT(errbuf, "<,>,");
4502 if (i & 16)
4503 STRCAT(errbuf, "[,],");
4504 if (*errbuf != NUL) /* remove trailing , */
4505 errbuf[STRLEN(errbuf) - 1] = NUL;
4506 save_arg = arg;
4507 arg = errbuf;
4508 }
4509 /*
4510 * Remove '>' before 'dir' and 'bdir', for
4511 * backwards compatibility with version 3.0
4512 */
4513 else if ( *arg == '>'
4514 && (varp == (char_u *)&p_dir
4515 || varp == (char_u *)&p_bdir))
4516 {
4517 ++arg;
4518 }
4519
4520 /* When setting the local value of a global
4521 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004522 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004523 && (opt_flags & OPT_LOCAL))
4524 origval = *(char_u **)get_varp(
4525 &options[opt_idx]);
4526 else
4527 origval = oldval;
4528
4529 /*
4530 * Copy the new string into allocated memory.
4531 * Can't use set_string_option_direct(), because
4532 * we need to remove the backslashes.
4533 */
4534 /* get a bit too much */
4535 newlen = (unsigned)STRLEN(arg) + 1;
4536 if (adding || prepending || removing)
4537 newlen += (unsigned)STRLEN(origval) + 1;
4538 newval = alloc(newlen);
4539 if (newval == NULL) /* out of mem, don't change */
4540 break;
4541 s = newval;
4542
4543 /*
4544 * Copy the string, skip over escaped chars.
4545 * For MS-DOS and WIN32 backslashes before normal
4546 * file name characters are not removed, and keep
4547 * backslash at start, for "\\machine\path", but
4548 * do remove it for "\\\\machine\\path".
4549 * The reverse is found in ExpandOldSetting().
4550 */
4551 while (*arg && !vim_iswhite(*arg))
4552 {
4553 if (*arg == '\\' && arg[1] != NUL
4554#ifdef BACKSLASH_IN_FILENAME
4555 && !((flags & P_EXPAND)
4556 && vim_isfilec(arg[1])
4557 && (arg[1] != '\\'
4558 || (s == newval
4559 && arg[2] != '\\')))
4560#endif
4561 )
4562 ++arg; /* remove backslash */
4563#ifdef FEAT_MBYTE
4564 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004565 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 {
4567 /* copy multibyte char */
4568 mch_memmove(s, arg, (size_t)i);
4569 arg += i;
4570 s += i;
4571 }
4572 else
4573#endif
4574 *s++ = *arg++;
4575 }
4576 *s = NUL;
4577
4578 /*
4579 * Expand environment variables and ~.
4580 * Don't do it when adding without inserting a
4581 * comma.
4582 */
4583 if (!(adding || prepending || removing)
4584 || (flags & P_COMMA))
4585 {
4586 s = option_expand(opt_idx, newval);
4587 if (s != NULL)
4588 {
4589 vim_free(newval);
4590 newlen = (unsigned)STRLEN(s) + 1;
4591 if (adding || prepending || removing)
4592 newlen += (unsigned)STRLEN(origval) + 1;
4593 newval = alloc(newlen);
4594 if (newval == NULL)
4595 break;
4596 STRCPY(newval, s);
4597 }
4598 }
4599
4600 /* locate newval[] in origval[] when removing it
4601 * and when adding to avoid duplicates */
4602 i = 0; /* init for GCC */
4603 if (removing || (flags & P_NODUP))
4604 {
4605 i = (int)STRLEN(newval);
4606 bs = 0;
4607 for (s = origval; *s; ++s)
4608 {
4609 if ((!(flags & P_COMMA)
4610 || s == origval
4611 || (s[-1] == ',' && !(bs & 1)))
4612 && STRNCMP(s, newval, i) == 0
4613 && (!(flags & P_COMMA)
4614 || s[i] == ','
4615 || s[i] == NUL))
4616 break;
4617 /* Count backspaces. Only a comma with an
4618 * even number of backspaces before it is
4619 * recognized as a separator */
4620 if (s > origval && s[-1] == '\\')
4621 ++bs;
4622 else
4623 bs = 0;
4624 }
4625
4626 /* do not add if already there */
4627 if ((adding || prepending) && *s)
4628 {
4629 prepending = FALSE;
4630 adding = FALSE;
4631 STRCPY(newval, origval);
4632 }
4633 }
4634
4635 /* concatenate the two strings; add a ',' if
4636 * needed */
4637 if (adding || prepending)
4638 {
4639 comma = ((flags & P_COMMA) && *origval != NUL
4640 && *newval != NUL);
4641 if (adding)
4642 {
4643 i = (int)STRLEN(origval);
4644 mch_memmove(newval + i + comma, newval,
4645 STRLEN(newval) + 1);
4646 mch_memmove(newval, origval, (size_t)i);
4647 }
4648 else
4649 {
4650 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004651 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 }
4653 if (comma)
4654 newval[i] = ',';
4655 }
4656
4657 /* Remove newval[] from origval[]. (Note: "i" has
4658 * been set above and is used here). */
4659 if (removing)
4660 {
4661 STRCPY(newval, origval);
4662 if (*s)
4663 {
4664 /* may need to remove a comma */
4665 if (flags & P_COMMA)
4666 {
4667 if (s == origval)
4668 {
4669 /* include comma after string */
4670 if (s[i] == ',')
4671 ++i;
4672 }
4673 else
4674 {
4675 /* include comma before string */
4676 --s;
4677 ++i;
4678 }
4679 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004680 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004681 }
4682 }
4683
4684 if (flags & P_FLAGLIST)
4685 {
4686 /* Remove flags that appear twice. */
4687 for (s = newval; *s; ++s)
4688 if ((!(flags & P_COMMA) || *s != ',')
4689 && vim_strchr(s + 1, *s) != NULL)
4690 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004691 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004692 --s;
4693 }
4694 }
4695
4696 if (save_arg != NULL) /* number for 'whichwrap' */
4697 arg = save_arg;
4698 new_value_alloced = TRUE;
4699 }
4700
4701 /* Set the new value. */
4702 *(char_u **)(varp) = newval;
4703
4704 /* Handle side effects, and set the global value for
4705 * ":set" on local options. */
4706 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4707 new_value_alloced, oldval, errbuf, opt_flags);
4708
4709 /* If error detected, print the error message. */
4710 if (errmsg != NULL)
4711 goto skip;
4712 }
4713 else /* key code option */
4714 {
4715 char_u *p;
4716
4717 if (nextchar == '&')
4718 {
4719 if (add_termcap_entry(key_name, TRUE) == FAIL)
4720 errmsg = (char_u *)N_("E522: Not found in termcap");
4721 }
4722 else
4723 {
4724 ++arg; /* jump to after the '=' or ':' */
4725 for (p = arg; *p && !vim_iswhite(*p); ++p)
4726 if (*p == '\\' && p[1] != NUL)
4727 ++p;
4728 nextchar = *p;
4729 *p = NUL;
4730 add_termcode(key_name, arg, FALSE);
4731 *p = nextchar;
4732 }
4733 if (full_screen)
4734 ttest(FALSE);
4735 redraw_all_later(CLEAR);
4736 }
4737 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004738
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004740 did_set_option(opt_idx, opt_flags,
4741 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 }
4743
4744skip:
4745 /*
4746 * Advance to next argument.
4747 * - skip until a blank found, taking care of backslashes
4748 * - skip blanks
4749 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4750 */
4751 for (i = 0; i < 2 ; ++i)
4752 {
4753 while (*arg != NUL && !vim_iswhite(*arg))
4754 if (*arg++ == '\\' && *arg != NUL)
4755 ++arg;
4756 arg = skipwhite(arg);
4757 if (*arg != '=')
4758 break;
4759 }
4760 }
4761
4762 if (errmsg != NULL)
4763 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004764 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004765 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004766 if (i + (arg - startarg) < IOSIZE)
4767 {
4768 /* append the argument with the error */
4769 STRCAT(IObuff, ": ");
4770 mch_memmove(IObuff + i, startarg, (arg - startarg));
4771 IObuff[i + (arg - startarg)] = NUL;
4772 }
4773 /* make sure all characters are printable */
4774 trans_characters(IObuff, IOSIZE);
4775
4776 ++no_wait_return; /* wait_return done later */
4777 emsg(IObuff); /* show error highlighted */
4778 --no_wait_return;
4779
4780 return FAIL;
4781 }
4782
4783 arg = skipwhite(arg);
4784 }
4785
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004786theend:
4787 if (silent_mode && did_show)
4788 {
4789 /* After displaying option values in silent mode. */
4790 silent_mode = FALSE;
4791 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4792 msg_putchar('\n');
4793 cursor_on(); /* msg_start() switches it off */
4794 out_flush();
4795 silent_mode = TRUE;
4796 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4797 }
4798
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 return OK;
4800}
4801
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004802/*
4803 * Call this when an option has been given a new value through a user command.
4804 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4805 */
4806 static void
4807did_set_option(opt_idx, opt_flags, new_value)
4808 int opt_idx;
4809 int opt_flags; /* possibly with OPT_MODELINE */
4810 int new_value; /* value was replaced completely */
4811{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004812 long_u *p;
4813
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004814 options[opt_idx].flags |= P_WAS_SET;
4815
4816 /* When an option is set in the sandbox, from a modeline or in secure mode
4817 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004818 * flag. */
4819 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004820 if (secure
4821#ifdef HAVE_SANDBOX
4822 || sandbox != 0
4823#endif
4824 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004825 *p = *p | P_INSECURE;
4826 else if (new_value)
4827 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004828}
4829
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 static char_u *
4831illegal_char(errbuf, c)
4832 char_u *errbuf;
4833 int c;
4834{
4835 if (errbuf == NULL)
4836 return (char_u *)"";
4837 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004838 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004839 return errbuf;
4840}
4841
4842/*
4843 * Convert a key name or string into a key value.
4844 * Used for 'wildchar' and 'cedit' options.
4845 */
4846 static int
4847string_to_key(arg)
4848 char_u *arg;
4849{
4850 if (*arg == '<')
4851 return find_key_option(arg + 1);
4852 if (*arg == '^')
4853 return Ctrl_chr(arg[1]);
4854 return *arg;
4855}
4856
4857#ifdef FEAT_CMDWIN
4858/*
4859 * Check value of 'cedit' and set cedit_key.
4860 * Returns NULL if value is OK, error message otherwise.
4861 */
4862 static char_u *
4863check_cedit()
4864{
4865 int n;
4866
4867 if (*p_cedit == NUL)
4868 cedit_key = -1;
4869 else
4870 {
4871 n = string_to_key(p_cedit);
4872 if (vim_isprintc(n))
4873 return e_invarg;
4874 cedit_key = n;
4875 }
4876 return NULL;
4877}
4878#endif
4879
4880#ifdef FEAT_TITLE
4881/*
4882 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4883 * maketitle() to create and display it.
4884 * When switching the title or icon off, call mch_restore_title() to get
4885 * the old value back.
4886 */
4887 static void
4888did_set_title(icon)
4889 int icon; /* Did set icon instead of title */
4890{
4891 if (starting != NO_SCREEN
4892#ifdef FEAT_GUI
4893 && !gui.starting
4894#endif
4895 )
4896 {
4897 maketitle();
4898 if (icon)
4899 {
4900 if (!p_icon)
4901 mch_restore_title(2);
4902 }
4903 else
4904 {
4905 if (!p_title)
4906 mch_restore_title(1);
4907 }
4908 }
4909}
4910#endif
4911
4912/*
4913 * set_options_bin - called when 'bin' changes value.
4914 */
4915 void
4916set_options_bin(oldval, newval, opt_flags)
4917 int oldval;
4918 int newval;
4919 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4920{
4921 /*
4922 * The option values that are changed when 'bin' changes are
4923 * copied when 'bin is set and restored when 'bin' is reset.
4924 */
4925 if (newval)
4926 {
4927 if (!oldval) /* switched on */
4928 {
4929 if (!(opt_flags & OPT_GLOBAL))
4930 {
4931 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4932 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4933 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4934 curbuf->b_p_et_nobin = curbuf->b_p_et;
4935 }
4936 if (!(opt_flags & OPT_LOCAL))
4937 {
4938 p_tw_nobin = p_tw;
4939 p_wm_nobin = p_wm;
4940 p_ml_nobin = p_ml;
4941 p_et_nobin = p_et;
4942 }
4943 }
4944
4945 if (!(opt_flags & OPT_GLOBAL))
4946 {
4947 curbuf->b_p_tw = 0; /* no automatic line wrap */
4948 curbuf->b_p_wm = 0; /* no automatic line wrap */
4949 curbuf->b_p_ml = 0; /* no modelines */
4950 curbuf->b_p_et = 0; /* no expandtab */
4951 }
4952 if (!(opt_flags & OPT_LOCAL))
4953 {
4954 p_tw = 0;
4955 p_wm = 0;
4956 p_ml = FALSE;
4957 p_et = FALSE;
4958 p_bin = TRUE; /* needed when called for the "-b" argument */
4959 }
4960 }
4961 else if (oldval) /* switched off */
4962 {
4963 if (!(opt_flags & OPT_GLOBAL))
4964 {
4965 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4966 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4967 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4968 curbuf->b_p_et = curbuf->b_p_et_nobin;
4969 }
4970 if (!(opt_flags & OPT_LOCAL))
4971 {
4972 p_tw = p_tw_nobin;
4973 p_wm = p_wm_nobin;
4974 p_ml = p_ml_nobin;
4975 p_et = p_et_nobin;
4976 }
4977 }
4978}
4979
4980#ifdef FEAT_VIMINFO
4981/*
4982 * Find the parameter represented by the given character (eg ', :, ", or /),
4983 * and return its associated value in the 'viminfo' string.
4984 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004985 * If the parameter is not specified in the string or there is no following
4986 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 */
4988 int
4989get_viminfo_parameter(type)
4990 int type;
4991{
4992 char_u *p;
4993
4994 p = find_viminfo_parameter(type);
4995 if (p != NULL && VIM_ISDIGIT(*p))
4996 return atoi((char *)p);
4997 return -1;
4998}
4999
5000/*
5001 * Find the parameter represented by the given character (eg ''', ':', '"', or
5002 * '/') in the 'viminfo' option and return a pointer to the string after it.
5003 * Return NULL if the parameter is not specified in the string.
5004 */
5005 char_u *
5006find_viminfo_parameter(type)
5007 int type;
5008{
5009 char_u *p;
5010
5011 for (p = p_viminfo; *p; ++p)
5012 {
5013 if (*p == type)
5014 return p + 1;
5015 if (*p == 'n') /* 'n' is always the last one */
5016 break;
5017 p = vim_strchr(p, ','); /* skip until next ',' */
5018 if (p == NULL) /* hit the end without finding parameter */
5019 break;
5020 }
5021 return NULL;
5022}
5023#endif
5024
5025/*
5026 * Expand environment variables for some string options.
5027 * These string options cannot be indirect!
5028 * If "val" is NULL expand the current value of the option.
5029 * Return pointer to NameBuff, or NULL when not expanded.
5030 */
5031 static char_u *
5032option_expand(opt_idx, val)
5033 int opt_idx;
5034 char_u *val;
5035{
5036 /* if option doesn't need expansion nothing to do */
5037 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5038 return NULL;
5039
5040 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5041 * expand_env() would truncate the string. */
5042 if (val != NULL && STRLEN(val) > MAXPATHL)
5043 return NULL;
5044
5045 if (val == NULL)
5046 val = *(char_u **)options[opt_idx].var;
5047
5048 /*
5049 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5050 * Escape spaces when expanding 'tags', they are used to separate file
5051 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005052 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005053 */
5054 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005055 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005056#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005057 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5058#endif
5059 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005060 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5061 return NULL;
5062
5063 return NameBuff;
5064}
5065
5066/*
5067 * After setting various option values: recompute variables that depend on
5068 * option values.
5069 */
5070 static void
5071didset_options()
5072{
5073 /* initialize the table for 'iskeyword' et.al. */
5074 (void)init_chartab();
5075
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005076#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005079 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5080#ifdef FEAT_SESSION
5081 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5082 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5083#endif
5084#ifdef FEAT_FOLDING
5085 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5086#endif
5087 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5088#ifdef FEAT_VIRTUALEDIT
5089 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5090#endif
5091#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5092 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5093#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005094#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005095 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005096 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005097 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5100 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5101#endif
5102#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5103 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5104#endif
5105#ifdef FEAT_CMDWIN
5106 /* set cedit_key */
5107 (void)check_cedit();
5108#endif
5109}
5110
5111/*
5112 * Check for string options that are NULL (normally only termcap options).
5113 */
5114 void
5115check_options()
5116{
5117 int opt_idx;
5118
5119 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5120 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5121 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5122}
5123
5124/*
5125 * Check string options in a buffer for NULL value.
5126 */
5127 void
5128check_buf_options(buf)
5129 buf_T *buf;
5130{
5131#if defined(FEAT_QUICKFIX)
5132 check_string_option(&buf->b_p_bh);
5133 check_string_option(&buf->b_p_bt);
5134#endif
5135#ifdef FEAT_MBYTE
5136 check_string_option(&buf->b_p_fenc);
5137#endif
5138 check_string_option(&buf->b_p_ff);
5139#ifdef FEAT_FIND_ID
5140 check_string_option(&buf->b_p_def);
5141 check_string_option(&buf->b_p_inc);
5142# ifdef FEAT_EVAL
5143 check_string_option(&buf->b_p_inex);
5144# endif
5145#endif
5146#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5147 check_string_option(&buf->b_p_inde);
5148 check_string_option(&buf->b_p_indk);
5149#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005150#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5151 check_string_option(&buf->b_p_bexpr);
5152#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005153#if defined(FEAT_EVAL)
5154 check_string_option(&buf->b_p_fex);
5155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156#ifdef FEAT_CRYPT
5157 check_string_option(&buf->b_p_key);
5158#endif
5159 check_string_option(&buf->b_p_kp);
5160 check_string_option(&buf->b_p_mps);
5161 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005162 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163 check_string_option(&buf->b_p_isk);
5164#ifdef FEAT_COMMENTS
5165 check_string_option(&buf->b_p_com);
5166#endif
5167#ifdef FEAT_FOLDING
5168 check_string_option(&buf->b_p_cms);
5169#endif
5170 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005171#ifdef FEAT_TEXTOBJ
5172 check_string_option(&buf->b_p_qe);
5173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005174#ifdef FEAT_SYN_HL
5175 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005176#endif
5177#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005178 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005179 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005180 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005181#endif
5182#ifdef FEAT_SEARCHPATH
5183 check_string_option(&buf->b_p_sua);
5184#endif
5185#ifdef FEAT_CINDENT
5186 check_string_option(&buf->b_p_cink);
5187 check_string_option(&buf->b_p_cino);
5188#endif
5189#ifdef FEAT_AUTOCMD
5190 check_string_option(&buf->b_p_ft);
5191#endif
5192#ifdef FEAT_OSFILETYPE
5193 check_string_option(&buf->b_p_oft);
5194#endif
5195#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5196 check_string_option(&buf->b_p_cinw);
5197#endif
5198#ifdef FEAT_INS_EXPAND
5199 check_string_option(&buf->b_p_cpt);
5200#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005201#ifdef FEAT_COMPL_FUNC
5202 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005203 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005205#ifdef FEAT_KEYMAP
5206 check_string_option(&buf->b_p_keymap);
5207#endif
5208#ifdef FEAT_QUICKFIX
5209 check_string_option(&buf->b_p_gp);
5210 check_string_option(&buf->b_p_mp);
5211 check_string_option(&buf->b_p_efm);
5212#endif
5213 check_string_option(&buf->b_p_ep);
5214 check_string_option(&buf->b_p_path);
5215 check_string_option(&buf->b_p_tags);
5216#ifdef FEAT_INS_EXPAND
5217 check_string_option(&buf->b_p_dict);
5218 check_string_option(&buf->b_p_tsr);
5219#endif
5220}
5221
5222/*
5223 * Free the string allocated for an option.
5224 * Checks for the string being empty_option. This may happen if we're out of
5225 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5226 * check_options().
5227 * Does NOT check for P_ALLOCED flag!
5228 */
5229 void
5230free_string_option(p)
5231 char_u *p;
5232{
5233 if (p != empty_option)
5234 vim_free(p);
5235}
5236
5237 void
5238clear_string_option(pp)
5239 char_u **pp;
5240{
5241 if (*pp != empty_option)
5242 vim_free(*pp);
5243 *pp = empty_option;
5244}
5245
5246 static void
5247check_string_option(pp)
5248 char_u **pp;
5249{
5250 if (*pp == NULL)
5251 *pp = empty_option;
5252}
5253
5254/*
5255 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5256 */
5257 void
5258set_term_option_alloced(p)
5259 char_u **p;
5260{
5261 int opt_idx;
5262
5263 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5264 if (options[opt_idx].var == (char_u *)p)
5265 {
5266 options[opt_idx].flags |= P_ALLOCED;
5267 return;
5268 }
5269 return; /* cannot happen: didn't find it! */
5270}
5271
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005272#if defined(FEAT_EVAL) || defined(PROTO)
5273/*
5274 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5275 * Return FALSE when it wasn't.
5276 * Return -1 for an unknown option.
5277 */
5278 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005279was_set_insecurely(opt, opt_flags)
5280 char_u *opt;
5281 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005282{
5283 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005284 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005285
5286 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005287 {
5288 flagp = insecure_flag(idx, opt_flags);
5289 return (*flagp & P_INSECURE) != 0;
5290 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005291 EMSG2(_(e_intern2), "was_set_insecurely()");
5292 return -1;
5293}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005294
5295/*
5296 * Get a pointer to the flags used for the P_INSECURE flag of option
5297 * "opt_idx". For some local options a local flags field is used.
5298 */
5299 static long_u *
5300insecure_flag(opt_idx, opt_flags)
5301 int opt_idx;
5302 int opt_flags;
5303{
5304 if (opt_flags & OPT_LOCAL)
5305 switch ((int)options[opt_idx].indir)
5306 {
5307#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005308 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005309#endif
5310#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005311# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005312 case PV_FDE: return &curwin->w_p_fde_flags;
5313 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005314# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005315# ifdef FEAT_BEVAL
5316 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5317# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005318# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005319 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005320# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005321 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005322# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005323 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005324# endif
5325#endif
5326 }
5327
5328 /* Nothing special, return global flags field. */
5329 return &options[opt_idx].flags;
5330}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005331#endif
5332
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005333#ifdef FEAT_TITLE
5334static void redraw_titles __ARGS((void));
5335
5336/*
5337 * Redraw the window title and/or tab page text later.
5338 */
5339static void redraw_titles()
5340{
5341 need_maketitle = TRUE;
5342# ifdef FEAT_WINDOWS
5343 redraw_tabline = TRUE;
5344# endif
5345}
5346#endif
5347
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348/*
5349 * Set a string option to a new value (without checking the effect).
5350 * The string is copied into allocated memory.
5351 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005352 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005353 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 */
5355 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005356set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 char_u *name;
5358 int opt_idx;
5359 char_u *val;
5360 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005361 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362{
5363 char_u *s;
5364 char_u **varp;
5365 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005366 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367
Bram Moolenaar89d40322006-08-29 15:30:07 +00005368 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005370 idx = findoption(name);
5371 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005372 {
5373 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005375 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 }
5377
Bram Moolenaar89d40322006-08-29 15:30:07 +00005378 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 return;
5380
5381 s = vim_strsave(val);
5382 if (s != NULL)
5383 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005384 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005386 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 free_string_option(*varp);
5388 *varp = s;
5389
5390 /* For buffer/window local option may also set the global value. */
5391 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005392 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393
Bram Moolenaar89d40322006-08-29 15:30:07 +00005394 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395
5396 /* When setting both values of a global option with a local value,
5397 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005398 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399 {
5400 free_string_option(*varp);
5401 *varp = empty_option;
5402 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005403# ifdef FEAT_EVAL
5404 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005405 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005406 set_sid == 0 ? current_SID : set_sid);
5407# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005408 }
5409}
5410
5411/*
5412 * Set global value for string option when it's a local option.
5413 */
5414 static void
5415set_string_option_global(opt_idx, varp)
5416 int opt_idx; /* option index */
5417 char_u **varp; /* pointer to option variable */
5418{
5419 char_u **p, *s;
5420
5421 /* the global value is always allocated */
5422 if (options[opt_idx].var == VAR_WIN)
5423 p = (char_u **)GLOBAL_WO(varp);
5424 else
5425 p = (char_u **)options[opt_idx].var;
5426 if (options[opt_idx].indir != PV_NONE
5427 && p != varp
5428 && (s = vim_strsave(*varp)) != NULL)
5429 {
5430 free_string_option(*p);
5431 *p = s;
5432 }
5433}
5434
5435/*
5436 * Set a string option to a new value, and handle the effects.
5437 */
5438 static void
5439set_string_option(opt_idx, value, opt_flags)
5440 int opt_idx;
5441 char_u *value;
5442 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5443{
5444 char_u *s;
5445 char_u **varp;
5446 char_u *oldval;
5447
5448 if (options[opt_idx].var == NULL) /* don't set hidden option */
5449 return;
5450
5451 s = vim_strsave(value);
5452 if (s != NULL)
5453 {
5454 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5455 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005456 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457 ? OPT_GLOBAL : OPT_LOCAL)
5458 : opt_flags);
5459 oldval = *varp;
5460 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005461 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5462 opt_flags) == NULL)
5463 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005464 }
5465}
5466
5467/*
5468 * Handle string options that need some action to perform when changed.
5469 * Returns NULL for success, or an error message for an error.
5470 */
5471 static char_u *
5472did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5473 opt_flags)
5474 int opt_idx; /* index in options[] table */
5475 char_u **varp; /* pointer to the option variable */
5476 int new_value_alloced; /* new value was allocated */
5477 char_u *oldval; /* previous value of the option */
5478 char_u *errbuf; /* buffer for errors, or NULL */
5479 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5480{
5481 char_u *errmsg = NULL;
5482 char_u *s, *p;
5483 int did_chartab = FALSE;
5484 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005485 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005486#ifdef FEAT_GUI
5487 /* set when changing an option that only requires a redraw in the GUI */
5488 int redraw_gui_only = FALSE;
5489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490
5491 /* Get the global option to compare with, otherwise we would have to check
5492 * two values for all local options. */
5493 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5494
5495 /* Disallow changing some options from secure mode */
5496 if ((secure
5497#ifdef HAVE_SANDBOX
5498 || sandbox != 0
5499#endif
5500 ) && (options[opt_idx].flags & P_SECURE))
5501 {
5502 errmsg = e_secure;
5503 }
5504
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005505 /* Check for a "normal" file name in some options. Disallow a path
5506 * separator (slash and/or backslash), wildcards and characters that are
5507 * often illegal in a file name. */
5508 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005509 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005510 {
5511 errmsg = e_invarg;
5512 }
5513
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514 /* 'term' */
5515 else if (varp == &T_NAME)
5516 {
5517 if (T_NAME[0] == NUL)
5518 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5519#ifdef FEAT_GUI
5520 if (gui.in_use)
5521 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5522 else if (term_is_gui(T_NAME))
5523 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5524#endif
5525 else if (set_termname(T_NAME) == FAIL)
5526 errmsg = (char_u *)N_("E522: Not found in termcap");
5527 else
5528 /* Screen colors may have changed. */
5529 redraw_later_clear();
5530 }
5531
5532 /* 'backupcopy' */
5533 else if (varp == &p_bkc)
5534 {
5535 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5536 errmsg = e_invarg;
5537 if (((bkc_flags & BKC_AUTO) != 0)
5538 + ((bkc_flags & BKC_YES) != 0)
5539 + ((bkc_flags & BKC_NO) != 0) != 1)
5540 {
5541 /* Must have exactly one of "auto", "yes" and "no". */
5542 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5543 errmsg = e_invarg;
5544 }
5545 }
5546
5547 /* 'backupext' and 'patchmode' */
5548 else if (varp == &p_bex || varp == &p_pm)
5549 {
5550 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5551 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5552 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5553 }
5554
5555 /*
5556 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5557 * If the new option is invalid, use old value. 'lisp' option: refill
5558 * chartab[] for '-' char
5559 */
5560 else if ( varp == &p_isi
5561 || varp == &(curbuf->b_p_isk)
5562 || varp == &p_isp
5563 || varp == &p_isf)
5564 {
5565 if (init_chartab() == FAIL)
5566 {
5567 did_chartab = TRUE; /* need to restore it below */
5568 errmsg = e_invarg; /* error in value */
5569 }
5570 }
5571
5572 /* 'helpfile' */
5573 else if (varp == &p_hf)
5574 {
5575 /* May compute new values for $VIM and $VIMRUNTIME */
5576 if (didset_vim)
5577 {
5578 vim_setenv((char_u *)"VIM", (char_u *)"");
5579 didset_vim = FALSE;
5580 }
5581 if (didset_vimruntime)
5582 {
5583 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5584 didset_vimruntime = FALSE;
5585 }
5586 }
5587
5588#ifdef FEAT_MULTI_LANG
5589 /* 'helplang' */
5590 else if (varp == &p_hlg)
5591 {
5592 /* Check for "", "ab", "ab,cd", etc. */
5593 for (s = p_hlg; *s != NUL; s += 3)
5594 {
5595 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5596 {
5597 errmsg = e_invarg;
5598 break;
5599 }
5600 if (s[2] == NUL)
5601 break;
5602 }
5603 }
5604#endif
5605
5606 /* 'highlight' */
5607 else if (varp == &p_hl)
5608 {
5609 if (highlight_changed() == FAIL)
5610 errmsg = e_invarg; /* invalid flags */
5611 }
5612
5613 /* 'nrformats' */
5614 else if (gvarp == &p_nf)
5615 {
5616 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5617 errmsg = e_invarg;
5618 }
5619
5620#ifdef FEAT_SESSION
5621 /* 'sessionoptions' */
5622 else if (varp == &p_ssop)
5623 {
5624 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5625 errmsg = e_invarg;
5626 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5627 {
5628 /* Don't allow both "sesdir" and "curdir". */
5629 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5630 errmsg = e_invarg;
5631 }
5632 }
5633 /* 'viewoptions' */
5634 else if (varp == &p_vop)
5635 {
5636 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5637 errmsg = e_invarg;
5638 }
5639#endif
5640
5641 /* 'scrollopt' */
5642#ifdef FEAT_SCROLLBIND
5643 else if (varp == &p_sbo)
5644 {
5645 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5646 errmsg = e_invarg;
5647 }
5648#endif
5649
5650 /* 'ambiwidth' */
5651#ifdef FEAT_MBYTE
5652 else if (varp == &p_ambw)
5653 {
5654 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5655 errmsg = e_invarg;
5656 }
5657#endif
5658
5659 /* 'background' */
5660 else if (varp == &p_bg)
5661 {
5662 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5663 {
5664#ifdef FEAT_EVAL
5665 int dark = (*p_bg == 'd');
5666#endif
5667
5668 init_highlight(FALSE, FALSE);
5669
5670#ifdef FEAT_EVAL
5671 if (dark != (*p_bg == 'd')
5672 && get_var_value((char_u *)"g:colors_name") != NULL)
5673 {
5674 /* The color scheme must have set 'background' back to another
5675 * value, that's not what we want here. Disable the color
5676 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005677 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678 free_string_option(p_bg);
5679 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5680 check_string_option(&p_bg);
5681 init_highlight(FALSE, FALSE);
5682 }
5683#endif
5684 }
5685 else
5686 errmsg = e_invarg;
5687 }
5688
5689 /* 'wildmode' */
5690 else if (varp == &p_wim)
5691 {
5692 if (check_opt_wim() == FAIL)
5693 errmsg = e_invarg;
5694 }
5695
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005696#ifdef FEAT_CMDL_COMPL
5697 /* 'wildoptions' */
5698 else if (varp == &p_wop)
5699 {
5700 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5701 errmsg = e_invarg;
5702 }
5703#endif
5704
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#ifdef FEAT_WAK
5706 /* 'winaltkeys' */
5707 else if (varp == &p_wak)
5708 {
5709 if (*p_wak == NUL
5710 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5711 errmsg = e_invarg;
5712# ifdef FEAT_MENU
5713# ifdef FEAT_GUI_MOTIF
5714 else if (gui.in_use)
5715 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5716# else
5717# ifdef FEAT_GUI_GTK
5718 else if (gui.in_use)
5719 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5720# endif
5721# endif
5722# endif
5723 }
5724#endif
5725
5726#ifdef FEAT_AUTOCMD
5727 /* 'eventignore' */
5728 else if (varp == &p_ei)
5729 {
5730 if (check_ei() == FAIL)
5731 errmsg = e_invarg;
5732 }
5733#endif
5734
5735#ifdef FEAT_MBYTE
5736 /* 'encoding' and 'fileencoding' */
5737 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5738 {
5739 if (gvarp == &p_fenc)
5740 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005741 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742 errmsg = e_modifiable;
5743 else if (vim_strchr(*varp, ',') != NULL)
5744 /* No comma allowed in 'fileencoding'; catches confusing it
5745 * with 'fileencodings'. */
5746 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005748 {
5749# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005751 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005753 /* Add 'fileencoding' to the swap file. */
5754 ml_setflags(curbuf);
5755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756 }
5757 if (errmsg == NULL)
5758 {
5759 /* canonize the value, so that STRCMP() can be used on it */
5760 p = enc_canonize(*varp);
5761 if (p != NULL)
5762 {
5763 vim_free(*varp);
5764 *varp = p;
5765 }
5766 if (varp == &p_enc)
5767 {
5768 errmsg = mb_init();
5769# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005770 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005771# endif
5772 }
5773 }
5774
5775# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5776 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5777 {
5778 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5779 if (STRCMP(p_tenc, "utf-8") != 0)
5780 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5781 }
5782# endif
5783
5784 if (errmsg == NULL)
5785 {
5786# ifdef FEAT_KEYMAP
5787 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5788 * (with another encoding). */
5789 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5790 (void)keymap_init();
5791# endif
5792
5793 /* When 'termencoding' is not empty and 'encoding' changes or when
5794 * 'termencoding' changes, need to setup for keyboard input and
5795 * display output conversion. */
5796 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5797 {
5798 convert_setup(&input_conv, p_tenc, p_enc);
5799 convert_setup(&output_conv, p_enc, p_tenc);
5800 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005801
5802# if defined(WIN3264) && defined(FEAT_MBYTE)
5803 /* $HOME may have characters in active code page. */
5804 if (varp == &p_enc)
5805 init_homedir();
5806# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807 }
5808 }
5809#endif
5810
5811#if defined(FEAT_POSTSCRIPT)
5812 else if (varp == &p_penc)
5813 {
5814 /* Canonize printencoding if VIM standard one */
5815 p = enc_canonize(p_penc);
5816 if (p != NULL)
5817 {
5818 vim_free(p_penc);
5819 p_penc = p;
5820 }
5821 else
5822 {
5823 /* Ensure lower case and '-' for '_' */
5824 for (s = p_penc; *s != NUL; s++)
5825 {
5826 if (*s == '_')
5827 *s = '-';
5828 else
5829 *s = TOLOWER_ASC(*s);
5830 }
5831 }
5832 }
5833#endif
5834
Bram Moolenaar9372a112005-12-06 19:59:18 +00005835#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836 else if (varp == &p_imak)
5837 {
5838 if (gui.in_use && !im_xim_isvalid_imactivate())
5839 errmsg = e_invarg;
5840 }
5841#endif
5842
5843#ifdef FEAT_KEYMAP
5844 else if (varp == &curbuf->b_p_keymap)
5845 {
5846 /* load or unload key mapping tables */
5847 errmsg = keymap_init();
5848
Bram Moolenaarfab06232009-03-04 03:13:35 +00005849 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005851 if (*curbuf->b_p_keymap != NUL)
5852 {
5853 /* Installed a new keymap, switch on using it. */
5854 curbuf->b_p_iminsert = B_IMODE_LMAP;
5855 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5856 curbuf->b_p_imsearch = B_IMODE_LMAP;
5857 }
5858 else
5859 {
5860 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5861 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5862 curbuf->b_p_iminsert = B_IMODE_NONE;
5863 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5864 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5865 }
5866 if ((opt_flags & OPT_LOCAL) == 0)
5867 {
5868 set_iminsert_global();
5869 set_imsearch_global();
5870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871# ifdef FEAT_WINDOWS
5872 status_redraw_curbuf();
5873# endif
5874 }
5875 }
5876#endif
5877
5878 /* 'fileformat' */
5879 else if (gvarp == &p_ff)
5880 {
5881 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5882 errmsg = e_modifiable;
5883 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5884 errmsg = e_invarg;
5885 else
5886 {
5887 /* may also change 'textmode' */
5888 if (get_fileformat(curbuf) == EOL_DOS)
5889 curbuf->b_p_tx = TRUE;
5890 else
5891 curbuf->b_p_tx = FALSE;
5892#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005893 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005895 /* update flag in swap file */
5896 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005897 /* Redraw needed when switching to/from "mac": a CR in the text
5898 * will be displayed differently. */
5899 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5900 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 }
5902 }
5903
5904 /* 'fileformats' */
5905 else if (varp == &p_ffs)
5906 {
5907 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5908 errmsg = e_invarg;
5909 else
5910 {
5911 /* also change 'textauto' */
5912 if (*p_ffs == NUL)
5913 p_ta = FALSE;
5914 else
5915 p_ta = TRUE;
5916 }
5917 }
5918
5919#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5920 /* 'cryptkey' */
5921 else if (gvarp == &p_key)
5922 {
5923 /* Make sure the ":set" command doesn't show the new value in the
5924 * history. */
5925 remove_key_from_history();
5926 }
5927#endif
5928
5929 /* 'matchpairs' */
5930 else if (gvarp == &p_mps)
5931 {
5932 /* Check for "x:y,x:y" */
5933 for (p = *varp; *p != NUL; p += 4)
5934 {
5935 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5936 {
5937 errmsg = e_invarg;
5938 break;
5939 }
5940 if (p[3] == NUL)
5941 break;
5942 }
5943 }
5944
5945#ifdef FEAT_COMMENTS
5946 /* 'comments' */
5947 else if (gvarp == &p_com)
5948 {
5949 for (s = *varp; *s; )
5950 {
5951 while (*s && *s != ':')
5952 {
5953 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5954 && !VIM_ISDIGIT(*s) && *s != '-')
5955 {
5956 errmsg = illegal_char(errbuf, *s);
5957 break;
5958 }
5959 ++s;
5960 }
5961 if (*s++ == NUL)
5962 errmsg = (char_u *)N_("E524: Missing colon");
5963 else if (*s == ',' || *s == NUL)
5964 errmsg = (char_u *)N_("E525: Zero length string");
5965 if (errmsg != NULL)
5966 break;
5967 while (*s && *s != ',')
5968 {
5969 if (*s == '\\' && s[1] != NUL)
5970 ++s;
5971 ++s;
5972 }
5973 s = skip_to_option_part(s);
5974 }
5975 }
5976#endif
5977
5978 /* 'listchars' */
5979 else if (varp == &p_lcs)
5980 {
5981 errmsg = set_chars_option(varp);
5982 }
5983
5984#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5985 /* 'fillchars' */
5986 else if (varp == &p_fcs)
5987 {
5988 errmsg = set_chars_option(varp);
5989 }
5990#endif
5991
5992#ifdef FEAT_CMDWIN
5993 /* 'cedit' */
5994 else if (varp == &p_cedit)
5995 {
5996 errmsg = check_cedit();
5997 }
5998#endif
5999
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006000 /* 'verbosefile' */
6001 else if (varp == &p_vfile)
6002 {
6003 verbose_stop();
6004 if (*p_vfile != NUL && verbose_open() == FAIL)
6005 errmsg = e_invarg;
6006 }
6007
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008#ifdef FEAT_VIMINFO
6009 /* 'viminfo' */
6010 else if (varp == &p_viminfo)
6011 {
6012 for (s = p_viminfo; *s;)
6013 {
6014 /* Check it's a valid character */
6015 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6016 {
6017 errmsg = illegal_char(errbuf, *s);
6018 break;
6019 }
6020 if (*s == 'n') /* name is always last one */
6021 {
6022 break;
6023 }
6024 else if (*s == 'r') /* skip until next ',' */
6025 {
6026 while (*++s && *s != ',')
6027 ;
6028 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006029 else if (*s == '%')
6030 {
6031 /* optional number */
6032 while (vim_isdigit(*++s))
6033 ;
6034 }
6035 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036 ++s; /* no extra chars */
6037 else /* must have a number */
6038 {
6039 while (vim_isdigit(*++s))
6040 ;
6041
6042 if (!VIM_ISDIGIT(*(s - 1)))
6043 {
6044 if (errbuf != NULL)
6045 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006046 sprintf((char *)errbuf,
6047 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048 transchar_byte(*(s - 1)));
6049 errmsg = errbuf;
6050 }
6051 else
6052 errmsg = (char_u *)"";
6053 break;
6054 }
6055 }
6056 if (*s == ',')
6057 ++s;
6058 else if (*s)
6059 {
6060 if (errbuf != NULL)
6061 errmsg = (char_u *)N_("E527: Missing comma");
6062 else
6063 errmsg = (char_u *)"";
6064 break;
6065 }
6066 }
6067 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6068 errmsg = (char_u *)N_("E528: Must specify a ' value");
6069 }
6070#endif /* FEAT_VIMINFO */
6071
6072 /* terminal options */
6073 else if (istermoption(&options[opt_idx]) && full_screen)
6074 {
6075 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6076 if (varp == &T_CCO)
6077 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006078 int colors = atoi((char *)T_CCO);
6079
6080 /* Only reinitialize colors if t_Co value has really changed to
6081 * avoid expensive reload of colorscheme if t_Co is set to the
6082 * same value multiple times. */
6083 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006084 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006085 t_colors = colors;
6086 if (t_colors <= 1)
6087 {
6088 if (new_value_alloced)
6089 vim_free(T_CCO);
6090 T_CCO = empty_option;
6091 }
6092 /* We now have a different color setup, initialize it again. */
6093 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 }
6096 ttest(FALSE);
6097 if (varp == &T_ME)
6098 {
6099 out_str(T_ME);
6100 redraw_later(CLEAR);
6101#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6102 /* Since t_me has been set, this probably means that the user
6103 * wants to use this as default colors. Need to reset default
6104 * background/foreground colors. */
6105 mch_set_normal_colors();
6106#endif
6107 }
6108 }
6109
6110#ifdef FEAT_LINEBREAK
6111 /* 'showbreak' */
6112 else if (varp == &p_sbr)
6113 {
6114 for (s = p_sbr; *s; )
6115 {
6116 if (ptr2cells(s) != 1)
6117 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006118 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 }
6120 }
6121#endif
6122
6123#ifdef FEAT_GUI
6124 /* 'guifont' */
6125 else if (varp == &p_guifont)
6126 {
6127 if (gui.in_use)
6128 {
6129 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006130# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 /*
6132 * Put up a font dialog and let the user select a new value.
6133 * If this is cancelled go back to the old value but don't
6134 * give an error message.
6135 */
6136 if (STRCMP(p, "*") == 0)
6137 {
6138 p = gui_mch_font_dialog(oldval);
6139
6140 if (new_value_alloced)
6141 free_string_option(p_guifont);
6142
6143 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6144 new_value_alloced = TRUE;
6145 }
6146# endif
6147 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6148 {
6149# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6150 if (STRCMP(p_guifont, "*") == 0)
6151 {
6152 /* Dialog was cancelled: Keep the old value without giving
6153 * an error message. */
6154 if (new_value_alloced)
6155 free_string_option(p_guifont);
6156 p_guifont = vim_strsave(oldval);
6157 new_value_alloced = TRUE;
6158 }
6159 else
6160# endif
6161 errmsg = (char_u *)N_("E596: Invalid font(s)");
6162 }
6163 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006164 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165 }
6166# ifdef FEAT_XFONTSET
6167 else if (varp == &p_guifontset)
6168 {
6169 if (STRCMP(p_guifontset, "*") == 0)
6170 errmsg = (char_u *)N_("E597: can't select fontset");
6171 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6172 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006173 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174 }
6175# endif
6176# ifdef FEAT_MBYTE
6177 else if (varp == &p_guifontwide)
6178 {
6179 if (STRCMP(p_guifontwide, "*") == 0)
6180 errmsg = (char_u *)N_("E533: can't select wide font");
6181 else if (gui_get_wide_font() == FAIL)
6182 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006183 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 }
6185# endif
6186#endif
6187
6188#ifdef CURSOR_SHAPE
6189 /* 'guicursor' */
6190 else if (varp == &p_guicursor)
6191 errmsg = parse_shape_opt(SHAPE_CURSOR);
6192#endif
6193
6194#ifdef FEAT_MOUSESHAPE
6195 /* 'mouseshape' */
6196 else if (varp == &p_mouseshape)
6197 {
6198 errmsg = parse_shape_opt(SHAPE_MOUSE);
6199 update_mouseshape(-1);
6200 }
6201#endif
6202
6203#ifdef FEAT_PRINTER
6204 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006205 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006206# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006207 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006208 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006209# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210#endif
6211
6212#ifdef FEAT_LANGMAP
6213 /* 'langmap' */
6214 else if (varp == &p_langmap)
6215 langmap_set();
6216#endif
6217
6218#ifdef FEAT_LINEBREAK
6219 /* 'breakat' */
6220 else if (varp == &p_breakat)
6221 fill_breakat_flags();
6222#endif
6223
6224#ifdef FEAT_TITLE
6225 /* 'titlestring' and 'iconstring' */
6226 else if (varp == &p_titlestring || varp == &p_iconstring)
6227 {
6228# ifdef FEAT_STL_OPT
6229 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6230
6231 /* NULL => statusline syntax */
6232 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6233 stl_syntax |= flagval;
6234 else
6235 stl_syntax &= ~flagval;
6236# endif
6237 did_set_title(varp == &p_iconstring);
6238
6239 }
6240#endif
6241
6242#ifdef FEAT_GUI
6243 /* 'guioptions' */
6244 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006245 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006247 redraw_gui_only = TRUE;
6248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249#endif
6250
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006251#if defined(FEAT_GUI_TABLINE)
6252 /* 'guitablabel' */
6253 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006254 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006255 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006256 redraw_gui_only = TRUE;
6257 }
6258 /* 'guitabtooltip' */
6259 else if (varp == &p_gtt)
6260 {
6261 redraw_gui_only = TRUE;
6262 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006263#endif
6264
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6266 /* 'ttymouse' */
6267 else if (varp == &p_ttym)
6268 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006269 /* Switch the mouse off before changing the escape sequences used for
6270 * that. */
6271 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006272 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6273 errmsg = e_invarg;
6274 else
6275 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006276 if (termcap_active)
6277 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278 }
6279#endif
6280
6281#ifdef FEAT_VISUAL
6282 /* 'selection' */
6283 else if (varp == &p_sel)
6284 {
6285 if (*p_sel == NUL
6286 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6287 errmsg = e_invarg;
6288 }
6289
6290 /* 'selectmode' */
6291 else if (varp == &p_slm)
6292 {
6293 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6294 errmsg = e_invarg;
6295 }
6296#endif
6297
6298#ifdef FEAT_BROWSE
6299 /* 'browsedir' */
6300 else if (varp == &p_bsdir)
6301 {
6302 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6303 && !mch_isdir(p_bsdir))
6304 errmsg = e_invarg;
6305 }
6306#endif
6307
6308#ifdef FEAT_VISUAL
6309 /* 'keymodel' */
6310 else if (varp == &p_km)
6311 {
6312 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6313 errmsg = e_invarg;
6314 else
6315 {
6316 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6317 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6318 }
6319 }
6320#endif
6321
6322 /* 'mousemodel' */
6323 else if (varp == &p_mousem)
6324 {
6325 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6326 errmsg = e_invarg;
6327#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6328 else if (*p_mousem != *oldval)
6329 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6330 * to create or delete the popup menus. */
6331 gui_motif_update_mousemodel(root_menu);
6332#endif
6333 }
6334
6335 /* 'switchbuf' */
6336 else if (varp == &p_swb)
6337 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006338 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 errmsg = e_invarg;
6340 }
6341
6342 /* 'debug' */
6343 else if (varp == &p_debug)
6344 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006345 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 errmsg = e_invarg;
6347 }
6348
6349 /* 'display' */
6350 else if (varp == &p_dy)
6351 {
6352 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6353 errmsg = e_invarg;
6354 else
6355 (void)init_chartab();
6356
6357 }
6358
6359#ifdef FEAT_VERTSPLIT
6360 /* 'eadirection' */
6361 else if (varp == &p_ead)
6362 {
6363 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6364 errmsg = e_invarg;
6365 }
6366#endif
6367
6368#ifdef FEAT_CLIPBOARD
6369 /* 'clipboard' */
6370 else if (varp == &p_cb)
6371 errmsg = check_clipboard_option();
6372#endif
6373
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006374#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006375 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6376 * buffer in which 'spell' is set load the wordlists. */
6377 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006378 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006379 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006380 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006381
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006382 if (varp == &(curbuf->b_p_spf))
6383 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006384 l = (int)STRLEN(curbuf->b_p_spf);
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006385 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6386 ".add") != 0))
6387 errmsg = e_invarg;
6388 }
6389
6390 if (errmsg == NULL)
6391 {
6392 FOR_ALL_WINDOWS(wp)
6393 if (wp->w_buffer == curbuf && wp->w_p_spell)
6394 {
6395 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006396# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006397 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006398# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006399 }
6400 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006401 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006402 /* When 'spellcapcheck' is set compile the regexp program. */
6403 else if (varp == &(curbuf->b_p_spc))
6404 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006405 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006406 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006407 /* 'spellsuggest' */
6408 else if (varp == &p_sps)
6409 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006410 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006411 errmsg = e_invarg;
6412 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006413 /* 'mkspellmem' */
6414 else if (varp == &p_msm)
6415 {
6416 if (spell_check_msm() != OK)
6417 errmsg = e_invarg;
6418 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006419#endif
6420
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421#ifdef FEAT_QUICKFIX
6422 /* When 'bufhidden' is set, check for valid value. */
6423 else if (gvarp == &p_bh)
6424 {
6425 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6426 errmsg = e_invarg;
6427 }
6428
6429 /* When 'buftype' is set, check for valid value. */
6430 else if (gvarp == &p_bt)
6431 {
6432 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6433 errmsg = e_invarg;
6434 else
6435 {
6436# ifdef FEAT_WINDOWS
6437 if (curwin->w_status_height)
6438 {
6439 curwin->w_redr_status = TRUE;
6440 redraw_later(VALID);
6441 }
6442# endif
6443 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006444# ifdef FEAT_TITLE
6445 redraw_titles();
6446# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 }
6448 }
6449#endif
6450
6451#ifdef FEAT_STL_OPT
6452 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006453 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 {
6455 int wid;
6456
6457 if (varp == &p_ruf) /* reset ru_wid first */
6458 ru_wid = 0;
6459 s = *varp;
6460 if (varp == &p_ruf && *s == '%')
6461 {
6462 /* set ru_wid if 'ruf' starts with "%99(" */
6463 if (*++s == '-') /* ignore a '-' */
6464 s++;
6465 wid = getdigits(&s);
6466 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6467 ru_wid = wid;
6468 else
6469 errmsg = check_stl_option(p_ruf);
6470 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006471 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006472 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006473 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006474 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006475 comp_col();
6476 }
6477#endif
6478
6479#ifdef FEAT_INS_EXPAND
6480 /* check if it is a valid value for 'complete' -- Acevedo */
6481 else if (gvarp == &p_cpt)
6482 {
6483 for (s = *varp; *s;)
6484 {
6485 while(*s == ',' || *s == ' ')
6486 s++;
6487 if (!*s)
6488 break;
6489 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6490 {
6491 errmsg = illegal_char(errbuf, *s);
6492 break;
6493 }
6494 if (*++s != NUL && *s != ',' && *s != ' ')
6495 {
6496 if (s[-1] == 'k' || s[-1] == 's')
6497 {
6498 /* skip optional filename after 'k' and 's' */
6499 while (*s && *s != ',' && *s != ' ')
6500 {
6501 if (*s == '\\')
6502 ++s;
6503 ++s;
6504 }
6505 }
6506 else
6507 {
6508 if (errbuf != NULL)
6509 {
6510 sprintf((char *)errbuf,
6511 _("E535: Illegal character after <%c>"),
6512 *--s);
6513 errmsg = errbuf;
6514 }
6515 else
6516 errmsg = (char_u *)"";
6517 break;
6518 }
6519 }
6520 }
6521 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006522
6523 /* 'completeopt' */
6524 else if (varp == &p_cot)
6525 {
6526 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6527 errmsg = e_invarg;
6528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529#endif /* FEAT_INS_EXPAND */
6530
6531
6532#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6533 else if (varp == &p_toolbar)
6534 {
6535 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6536 &toolbar_flags, TRUE) != OK)
6537 errmsg = e_invarg;
6538 else
6539 {
6540 out_flush();
6541 gui_mch_show_toolbar((toolbar_flags &
6542 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6543 }
6544 }
6545#endif
6546
6547#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6548 /* 'toolbariconsize': GTK+ 2 only */
6549 else if (varp == &p_tbis)
6550 {
6551 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6552 errmsg = e_invarg;
6553 else
6554 {
6555 out_flush();
6556 gui_mch_show_toolbar((toolbar_flags &
6557 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6558 }
6559 }
6560#endif
6561
6562 /* 'pastetoggle': translate key codes like in a mapping */
6563 else if (varp == &p_pt)
6564 {
6565 if (*p_pt)
6566 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006567 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 if (p != NULL)
6569 {
6570 if (new_value_alloced)
6571 free_string_option(p_pt);
6572 p_pt = p;
6573 new_value_alloced = TRUE;
6574 }
6575 }
6576 }
6577
6578 /* 'backspace' */
6579 else if (varp == &p_bs)
6580 {
6581 if (VIM_ISDIGIT(*p_bs))
6582 {
6583 if (*p_bs >'2' || p_bs[1] != NUL)
6584 errmsg = e_invarg;
6585 }
6586 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6587 errmsg = e_invarg;
6588 }
6589
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006590#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 /* 'casemap' */
6592 else if (varp == &p_cmp)
6593 {
6594 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6595 errmsg = e_invarg;
6596 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598
6599#ifdef FEAT_DIFF
6600 /* 'diffopt' */
6601 else if (varp == &p_dip)
6602 {
6603 if (diffopt_changed() == FAIL)
6604 errmsg = e_invarg;
6605 }
6606#endif
6607
6608#ifdef FEAT_FOLDING
6609 /* 'foldmethod' */
6610 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6611 {
6612 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6613 || *curwin->w_p_fdm == NUL)
6614 errmsg = e_invarg;
6615 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006616 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006618 if (foldmethodIsDiff(curwin))
6619 newFoldLevel();
6620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006621 }
6622# ifdef FEAT_EVAL
6623 /* 'foldexpr' */
6624 else if (varp == &curwin->w_p_fde)
6625 {
6626 if (foldmethodIsExpr(curwin))
6627 foldUpdateAll(curwin);
6628 }
6629# endif
6630 /* 'foldmarker' */
6631 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6632 {
6633 p = vim_strchr(*varp, ',');
6634 if (p == NULL)
6635 errmsg = (char_u *)N_("E536: comma required");
6636 else if (p == *varp || p[1] == NUL)
6637 errmsg = e_invarg;
6638 else if (foldmethodIsMarker(curwin))
6639 foldUpdateAll(curwin);
6640 }
6641 /* 'commentstring' */
6642 else if (gvarp == &p_cms)
6643 {
6644 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6645 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6646 }
6647 /* 'foldopen' */
6648 else if (varp == &p_fdo)
6649 {
6650 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6651 errmsg = e_invarg;
6652 }
6653 /* 'foldclose' */
6654 else if (varp == &p_fcl)
6655 {
6656 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6657 errmsg = e_invarg;
6658 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006659 /* 'foldignore' */
6660 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6661 {
6662 if (foldmethodIsIndent(curwin))
6663 foldUpdateAll(curwin);
6664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665#endif
6666
6667#ifdef FEAT_VIRTUALEDIT
6668 /* 'virtualedit' */
6669 else if (varp == &p_ve)
6670 {
6671 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6672 errmsg = e_invarg;
6673 else if (STRCMP(p_ve, oldval) != 0)
6674 {
6675 /* Recompute cursor position in case the new 've' setting
6676 * changes something. */
6677 validate_virtcol();
6678 coladvance(curwin->w_virtcol);
6679 }
6680 }
6681#endif
6682
6683#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6684 else if (varp == &p_csqf)
6685 {
6686 if (p_csqf != NULL)
6687 {
6688 p = p_csqf;
6689 while (*p != NUL)
6690 {
6691 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6692 || p[1] == NUL
6693 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6694 || (p[2] != NUL && p[2] != ','))
6695 {
6696 errmsg = e_invarg;
6697 break;
6698 }
6699 else if (p[2] == NUL)
6700 break;
6701 else
6702 p += 3;
6703 }
6704 }
6705 }
6706#endif
6707
6708 /* Options that are a list of flags. */
6709 else
6710 {
6711 p = NULL;
6712 if (varp == &p_ww)
6713 p = (char_u *)WW_ALL;
6714 if (varp == &p_shm)
6715 p = (char_u *)SHM_ALL;
6716 else if (varp == &(p_cpo))
6717 p = (char_u *)CPO_ALL;
6718 else if (varp == &(curbuf->b_p_fo))
6719 p = (char_u *)FO_ALL;
6720 else if (varp == &p_mouse)
6721 {
6722#ifdef FEAT_MOUSE
6723 p = (char_u *)MOUSE_ALL;
6724#else
6725 if (*p_mouse != NUL)
6726 errmsg = (char_u *)N_("E538: No mouse support");
6727#endif
6728 }
6729#if defined(FEAT_GUI)
6730 else if (varp == &p_go)
6731 p = (char_u *)GO_ALL;
6732#endif
6733 if (p != NULL)
6734 {
6735 for (s = *varp; *s; ++s)
6736 if (vim_strchr(p, *s) == NULL)
6737 {
6738 errmsg = illegal_char(errbuf, *s);
6739 break;
6740 }
6741 }
6742 }
6743
6744 /*
6745 * If error detected, restore the previous value.
6746 */
6747 if (errmsg != NULL)
6748 {
6749 if (new_value_alloced)
6750 free_string_option(*varp);
6751 *varp = oldval;
6752 /*
6753 * When resetting some values, need to act on it.
6754 */
6755 if (did_chartab)
6756 (void)init_chartab();
6757 if (varp == &p_hl)
6758 (void)highlight_changed();
6759 }
6760 else
6761 {
6762#ifdef FEAT_EVAL
6763 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006764 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765#endif
6766 /*
6767 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006768 * Use "free_oldval", because recursiveness may change the flags under
6769 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006771 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 free_string_option(oldval);
6773 if (new_value_alloced)
6774 options[opt_idx].flags |= P_ALLOCED;
6775 else
6776 options[opt_idx].flags &= ~P_ALLOCED;
6777
6778 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006779 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 {
6781 /* global option with local value set to use global value; free
6782 * the local value and make it empty */
6783 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6784 free_string_option(*(char_u **)p);
6785 *(char_u **)p = empty_option;
6786 }
6787
6788 /* May set global value for local option. */
6789 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6790 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006791
6792#ifdef FEAT_AUTOCMD
6793 /*
6794 * Trigger the autocommand only after setting the flags.
6795 */
6796# ifdef FEAT_SYN_HL
6797 /* When 'syntax' is set, load the syntax of that name */
6798 if (varp == &(curbuf->b_p_syn))
6799 {
6800 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6801 curbuf->b_fname, TRUE, curbuf);
6802 }
6803# endif
6804 else if (varp == &(curbuf->b_p_ft))
6805 {
6806 /* 'filetype' is set, trigger the FileType autocommand */
6807 did_filetype = TRUE;
6808 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6809 curbuf->b_fname, TRUE, curbuf);
6810 }
6811#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006812#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006813 if (varp == &(curbuf->b_p_spl))
6814 {
6815 char_u fname[200];
6816
6817 /*
6818 * Source the spell/LANG.vim in 'runtimepath'.
6819 * They could set 'spellcapcheck' depending on the language.
6820 * Use the first name in 'spelllang' up to '_region' or
6821 * '.encoding'.
6822 */
6823 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6824 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6825 break;
6826 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6827 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6828 source_runtime(fname, TRUE);
6829 }
6830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 }
6832
6833#ifdef FEAT_MOUSE
6834 if (varp == &p_mouse)
6835 {
6836# ifdef FEAT_MOUSE_TTY
6837 if (*p_mouse == NUL)
6838 mch_setmouse(FALSE); /* switch mouse off */
6839 else
6840# endif
6841 setmouse(); /* in case 'mouse' changed */
6842 }
6843#endif
6844
6845 if (curwin->w_curswant != MAXCOL)
6846 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006847#ifdef FEAT_GUI
6848 /* check redraw when it's not a GUI option or the GUI is active. */
6849 if (!redraw_gui_only || gui.in_use)
6850#endif
6851 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852
6853 return errmsg;
6854}
6855
6856/*
6857 * Handle setting 'listchars' or 'fillchars'.
6858 * Returns error message, NULL if it's OK.
6859 */
6860 static char_u *
6861set_chars_option(varp)
6862 char_u **varp;
6863{
6864 int round, i, len, entries;
6865 char_u *p, *s;
6866 int c1, c2 = 0;
6867 struct charstab
6868 {
6869 int *cp;
6870 char *name;
6871 };
6872#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6873 static struct charstab filltab[] =
6874 {
6875 {&fill_stl, "stl"},
6876 {&fill_stlnc, "stlnc"},
6877 {&fill_vert, "vert"},
6878 {&fill_fold, "fold"},
6879 {&fill_diff, "diff"},
6880 };
6881#endif
6882 static struct charstab lcstab[] =
6883 {
6884 {&lcs_eol, "eol"},
6885 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006886 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006887 {&lcs_prec, "precedes"},
6888 {&lcs_tab2, "tab"},
6889 {&lcs_trail, "trail"},
6890 };
6891 struct charstab *tab;
6892
6893#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6894 if (varp == &p_lcs)
6895#endif
6896 {
6897 tab = lcstab;
6898 entries = sizeof(lcstab) / sizeof(struct charstab);
6899 }
6900#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6901 else
6902 {
6903 tab = filltab;
6904 entries = sizeof(filltab) / sizeof(struct charstab);
6905 }
6906#endif
6907
6908 /* first round: check for valid value, second round: assign values */
6909 for (round = 0; round <= 1; ++round)
6910 {
6911 if (round)
6912 {
6913 /* After checking that the value is valid: set defaults: space for
6914 * 'fillchars', NUL for 'listchars' */
6915 for (i = 0; i < entries; ++i)
6916 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6917 if (varp == &p_lcs)
6918 lcs_tab1 = NUL;
6919#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6920 else
6921 fill_diff = '-';
6922#endif
6923 }
6924 p = *varp;
6925 while (*p)
6926 {
6927 for (i = 0; i < entries; ++i)
6928 {
6929 len = (int)STRLEN(tab[i].name);
6930 if (STRNCMP(p, tab[i].name, len) == 0
6931 && p[len] == ':'
6932 && p[len + 1] != NUL)
6933 {
6934 s = p + len + 1;
6935#ifdef FEAT_MBYTE
6936 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006937 if (mb_char2cells(c1) > 1)
6938 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006939#else
6940 c1 = *s++;
6941#endif
6942 if (tab[i].cp == &lcs_tab2)
6943 {
6944 if (*s == NUL)
6945 continue;
6946#ifdef FEAT_MBYTE
6947 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006948 if (mb_char2cells(c2) > 1)
6949 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950#else
6951 c2 = *s++;
6952#endif
6953 }
6954 if (*s == ',' || *s == NUL)
6955 {
6956 if (round)
6957 {
6958 if (tab[i].cp == &lcs_tab2)
6959 {
6960 lcs_tab1 = c1;
6961 lcs_tab2 = c2;
6962 }
6963 else
6964 *(tab[i].cp) = c1;
6965
6966 }
6967 p = s;
6968 break;
6969 }
6970 }
6971 }
6972
6973 if (i == entries)
6974 return e_invarg;
6975 if (*p == ',')
6976 ++p;
6977 }
6978 }
6979
6980 return NULL; /* no error */
6981}
6982
6983#ifdef FEAT_STL_OPT
6984/*
6985 * Check validity of options with the 'statusline' format.
6986 * Return error message or NULL.
6987 */
6988 char_u *
6989check_stl_option(s)
6990 char_u *s;
6991{
6992 int itemcnt = 0;
6993 int groupdepth = 0;
6994 static char_u errbuf[80];
6995
6996 while (*s && itemcnt < STL_MAX_ITEM)
6997 {
6998 /* Check for valid keys after % sequences */
6999 while (*s && *s != '%')
7000 s++;
7001 if (!*s)
7002 break;
7003 s++;
7004 if (*s != '%' && *s != ')')
7005 ++itemcnt;
7006 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7007 {
7008 s++;
7009 continue;
7010 }
7011 if (*s == ')')
7012 {
7013 s++;
7014 if (--groupdepth < 0)
7015 break;
7016 continue;
7017 }
7018 if (*s == '-')
7019 s++;
7020 while (VIM_ISDIGIT(*s))
7021 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007022 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 continue;
7024 if (*s == '.')
7025 {
7026 s++;
7027 while (*s && VIM_ISDIGIT(*s))
7028 s++;
7029 }
7030 if (*s == '(')
7031 {
7032 groupdepth++;
7033 continue;
7034 }
7035 if (vim_strchr(STL_ALL, *s) == NULL)
7036 {
7037 return illegal_char(errbuf, *s);
7038 }
7039 if (*s == '{')
7040 {
7041 s++;
7042 while (*s != '}' && *s)
7043 s++;
7044 if (*s != '}')
7045 return (char_u *)N_("E540: Unclosed expression sequence");
7046 }
7047 }
7048 if (itemcnt >= STL_MAX_ITEM)
7049 return (char_u *)N_("E541: too many items");
7050 if (groupdepth != 0)
7051 return (char_u *)N_("E542: unbalanced groups");
7052 return NULL;
7053}
7054#endif
7055
7056#ifdef FEAT_CLIPBOARD
7057/*
7058 * Extract the items in the 'clipboard' option and set global values.
7059 */
7060 static char_u *
7061check_clipboard_option()
7062{
7063 int new_unnamed = FALSE;
7064 int new_autoselect = FALSE;
7065 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007066 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 regprog_T *new_exclude_prog = NULL;
7068 char_u *errmsg = NULL;
7069 char_u *p;
7070
7071 for (p = p_cb; *p != NUL; )
7072 {
7073 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7074 {
7075 new_unnamed = TRUE;
7076 p += 7;
7077 }
7078 else if (STRNCMP(p, "autoselect", 10) == 0
7079 && (p[10] == ',' || p[10] == NUL))
7080 {
7081 new_autoselect = TRUE;
7082 p += 10;
7083 }
7084 else if (STRNCMP(p, "autoselectml", 12) == 0
7085 && (p[12] == ',' || p[12] == NUL))
7086 {
7087 new_autoselectml = TRUE;
7088 p += 12;
7089 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007090 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7091 {
7092 new_html = TRUE;
7093 p += 4;
7094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7096 {
7097 p += 8;
7098 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7099 if (new_exclude_prog == NULL)
7100 errmsg = e_invarg;
7101 break;
7102 }
7103 else
7104 {
7105 errmsg = e_invarg;
7106 break;
7107 }
7108 if (*p == ',')
7109 ++p;
7110 }
7111 if (errmsg == NULL)
7112 {
7113 clip_unnamed = new_unnamed;
7114 clip_autoselect = new_autoselect;
7115 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007116 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 vim_free(clip_exclude_prog);
7118 clip_exclude_prog = new_exclude_prog;
7119 }
7120 else
7121 vim_free(new_exclude_prog);
7122
7123 return errmsg;
7124}
7125#endif
7126
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007127#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007128/*
7129 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7130 * Return error message when failed, NULL when OK.
7131 */
7132 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007133compile_cap_prog(buf)
7134 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007135{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007136 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007137 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007138
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007139 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007140 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007141 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007142 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007143 /* Prepend a ^ so that we only match at one column */
7144 re = concat_str((char_u *)"^", buf->b_p_spc);
7145 if (re != NULL)
7146 {
7147 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7148 if (buf->b_cap_prog == NULL)
7149 {
7150 buf->b_cap_prog = rp; /* restore the previous program */
7151 return e_invarg;
7152 }
7153 vim_free(re);
7154 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007155 }
7156
7157 vim_free(rp);
7158 return NULL;
7159}
7160#endif
7161
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007162#if defined(FEAT_EVAL) || defined(PROTO)
7163/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007164 * Set the scriptID for an option, taking care of setting the buffer- or
7165 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007166 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007167 static void
7168set_option_scriptID_idx(opt_idx, opt_flags, id)
7169 int opt_idx;
7170 int opt_flags;
7171 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007172{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007173 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7174 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007175
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007176 /* Remember where the option was set. For local options need to do that
7177 * in the buffer or window structure. */
7178 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007179 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007180 if (both || (opt_flags & OPT_LOCAL))
7181 {
7182 if (indir & PV_BUF)
7183 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7184 else if (indir & PV_WIN)
7185 curwin->w_p_scriptID[indir & PV_MASK] = id;
7186 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007187}
7188#endif
7189
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190/*
7191 * Set the value of a boolean option, and take care of side effects.
7192 * Returns NULL for success, or an error message for an error.
7193 */
7194 static char_u *
7195set_bool_option(opt_idx, varp, value, opt_flags)
7196 int opt_idx; /* index in options[] table */
7197 char_u *varp; /* pointer to the option variable */
7198 int value; /* new value */
7199 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7200{
7201 int old_value = *(int *)varp;
7202
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 /* Disallow changing some options from secure mode */
7204 if ((secure
7205#ifdef HAVE_SANDBOX
7206 || sandbox != 0
7207#endif
7208 ) && (options[opt_idx].flags & P_SECURE))
7209 return e_secure;
7210
7211 *(int *)varp = value; /* set the new value */
7212#ifdef FEAT_EVAL
7213 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007214 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215#endif
7216
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007217#ifdef FEAT_GUI
7218 need_mouse_correct = TRUE;
7219#endif
7220
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221 /* May set global value for local option. */
7222 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7223 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7224
7225 /*
7226 * Handle side effects of changing a bool option.
7227 */
7228
7229 /* 'compatible' */
7230 if ((int *)varp == &p_cp)
7231 {
7232 compatible_set();
7233 }
7234
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007235 /* 'list', 'number' */
7236 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007237 || (int *)varp == &curwin->w_p_nu
7238 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007239 {
7240 if (curwin->w_curswant != MAXCOL)
7241 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007242
7243 /* If 'number' is set, reset 'relativenumber'. */
7244 /* If 'relativenumber' is set, reset 'number'. */
7245 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7246 curwin->w_p_rnu = FALSE;
7247 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7248 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007249 }
7250
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 else if ((int *)varp == &curbuf->b_p_ro)
7252 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007253 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7255 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007256
7257 /* when 'readonly' is set may give W10 again */
7258 if (curbuf->b_p_ro)
7259 curbuf->b_did_warn = FALSE;
7260
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007262 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263#endif
7264 }
7265
7266#ifdef FEAT_TITLE
7267 /* when 'modifiable' is changed, redraw the window title */
7268 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007269 {
7270 redraw_titles();
7271 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272 /* when 'endofline' is changed, redraw the window title */
7273 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007274 {
7275 redraw_titles();
7276 }
7277# ifdef FEAT_MBYTE
7278 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007279 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007280 {
7281 redraw_titles();
7282 }
7283# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284#endif
7285
7286 /* when 'bin' is set also set some other options */
7287 else if ((int *)varp == &curbuf->b_p_bin)
7288 {
7289 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7290#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007291 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292#endif
7293 }
7294
7295#ifdef FEAT_AUTOCMD
7296 /* when 'buflisted' changes, trigger autocommands */
7297 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7298 {
7299 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7300 NULL, NULL, TRUE, curbuf);
7301 }
7302#endif
7303
7304 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7305 else if ((int *)varp == &curbuf->b_p_swf)
7306 {
7307 if (curbuf->b_p_swf && p_uc)
7308 ml_open_file(curbuf); /* create the swap file */
7309 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007310 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7311 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 mf_close_file(curbuf, TRUE); /* remove the swap file */
7313 }
7314
7315 /* when 'terse' is set change 'shortmess' */
7316 else if ((int *)varp == &p_terse)
7317 {
7318 char_u *p;
7319
7320 p = vim_strchr(p_shm, SHM_SEARCH);
7321
7322 /* insert 's' in p_shm */
7323 if (p_terse && p == NULL)
7324 {
7325 STRCPY(IObuff, p_shm);
7326 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007327 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328 }
7329 /* remove 's' from p_shm */
7330 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007331 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332 }
7333
7334 /* when 'paste' is set or reset also change other options */
7335 else if ((int *)varp == &p_paste)
7336 {
7337 paste_option_changed();
7338 }
7339
7340 /* when 'insertmode' is set from an autocommand need to do work here */
7341 else if ((int *)varp == &p_im)
7342 {
7343 if (p_im)
7344 {
7345 if ((State & INSERT) == 0)
7346 need_start_insertmode = TRUE;
7347 stop_insert_mode = FALSE;
7348 }
7349 else
7350 {
7351 need_start_insertmode = FALSE;
7352 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007353 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007354 clear_cmdline = TRUE; /* remove "(insert)" */
7355 restart_edit = 0;
7356 }
7357 }
7358
7359 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7360 else if ((int *)varp == &p_ic && p_hls)
7361 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007362 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007363 }
7364
7365#ifdef FEAT_SEARCH_EXTRA
7366 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7367 else if ((int *)varp == &p_hls)
7368 {
7369 no_hlsearch = FALSE;
7370 }
7371#endif
7372
7373#ifdef FEAT_SCROLLBIND
7374 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7375 * at the end of normal_cmd() */
7376 else if ((int *)varp == &curwin->w_p_scb)
7377 {
7378 if (curwin->w_p_scb)
7379 do_check_scrollbind(FALSE);
7380 }
7381#endif
7382
7383#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7384 /* There can be only one window with 'previewwindow' set. */
7385 else if ((int *)varp == &curwin->w_p_pvw)
7386 {
7387 if (curwin->w_p_pvw)
7388 {
7389 win_T *win;
7390
7391 for (win = firstwin; win != NULL; win = win->w_next)
7392 if (win->w_p_pvw && win != curwin)
7393 {
7394 curwin->w_p_pvw = FALSE;
7395 return (char_u *)N_("E590: A preview window already exists");
7396 }
7397 }
7398 }
7399#endif
7400
7401 /* when 'textmode' is set or reset also change 'fileformat' */
7402 else if ((int *)varp == &curbuf->b_p_tx)
7403 {
7404 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7405 }
7406
7407 /* when 'textauto' is set or reset also change 'fileformats' */
7408 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007409 set_string_option_direct((char_u *)"ffs", -1,
7410 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007411 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007412
7413 /*
7414 * When 'lisp' option changes include/exclude '-' in
7415 * keyword characters.
7416 */
7417#ifdef FEAT_LISP
7418 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7419 {
7420 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7421 }
7422#endif
7423
7424#ifdef FEAT_TITLE
7425 /* when 'title' changed, may need to change the title; same for 'icon' */
7426 else if ((int *)varp == &p_title)
7427 {
7428 did_set_title(FALSE);
7429 }
7430
7431 else if ((int *)varp == &p_icon)
7432 {
7433 did_set_title(TRUE);
7434 }
7435#endif
7436
7437 else if ((int *)varp == &curbuf->b_changed)
7438 {
7439 if (!value)
7440 save_file_ff(curbuf); /* Buffer is unchanged */
7441#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007442 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443#endif
7444#ifdef FEAT_AUTOCMD
7445 modified_was_set = value;
7446#endif
7447 }
7448
7449#ifdef BACKSLASH_IN_FILENAME
7450 else if ((int *)varp == &p_ssl)
7451 {
7452 if (p_ssl)
7453 {
7454 psepc = '/';
7455 psepcN = '\\';
7456 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 }
7458 else
7459 {
7460 psepc = '\\';
7461 psepcN = '/';
7462 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 }
7464
7465 /* need to adjust the file name arguments and buffer names. */
7466 buflist_slash_adjust();
7467 alist_slash_adjust();
7468# ifdef FEAT_EVAL
7469 scriptnames_slash_adjust();
7470# endif
7471 }
7472#endif
7473
7474 /* If 'wrap' is set, set w_leftcol to zero. */
7475 else if ((int *)varp == &curwin->w_p_wrap)
7476 {
7477 if (curwin->w_p_wrap)
7478 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007479 if (curwin->w_curswant != MAXCOL)
7480 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 }
7482
7483#ifdef FEAT_WINDOWS
7484 else if ((int *)varp == &p_ea)
7485 {
7486 if (p_ea && !old_value)
7487 win_equal(curwin, FALSE, 0);
7488 }
7489#endif
7490
7491 else if ((int *)varp == &p_wiv)
7492 {
7493 /*
7494 * When 'weirdinvert' changed, set/reset 't_xs'.
7495 * Then set 'weirdinvert' according to value of 't_xs'.
7496 */
7497 if (p_wiv && !old_value)
7498 T_XS = (char_u *)"y";
7499 else if (!p_wiv && old_value)
7500 T_XS = empty_option;
7501 p_wiv = (*T_XS != NUL);
7502 }
7503
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007504#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007505 else if ((int *)varp == &p_beval)
7506 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 if (p_beval == TRUE)
7508 gui_mch_enable_beval_area(balloonEval);
7509 else
7510 gui_mch_disable_beval_area(balloonEval);
7511 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007514#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 else if ((int *)varp == &p_acd)
7516 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007517 /* Change directories when the 'acd' option is set now. */
7518 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 }
7520#endif
7521
7522#ifdef FEAT_DIFF
7523 /* 'diff' */
7524 else if ((int *)varp == &curwin->w_p_diff)
7525 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007526 /* May add or remove the buffer from the list of diff buffers. */
7527 diff_buf_adjust(curwin);
7528# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 if (foldmethodIsDiff(curwin))
7530 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007531# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532 }
7533#endif
7534
7535#ifdef USE_IM_CONTROL
7536 /* 'imdisable' */
7537 else if ((int *)varp == &p_imdisable)
7538 {
7539 /* Only de-activate it here, it will be enabled when changing mode. */
7540 if (p_imdisable)
7541 im_set_active(FALSE);
7542 }
7543#endif
7544
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007545#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007546 /* 'spell' */
7547 else if ((int *)varp == &curwin->w_p_spell)
7548 {
7549 if (curwin->w_p_spell)
7550 {
7551 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007552
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007553 if (errmsg != NULL)
7554 EMSG(_(errmsg));
7555 }
7556 }
7557#endif
7558
Bram Moolenaar071d4272004-06-13 20:20:40 +00007559#ifdef FEAT_FKMAP
7560 else if ((int *)varp == &p_altkeymap)
7561 {
7562 if (old_value != p_altkeymap)
7563 {
7564 if (!p_altkeymap)
7565 {
7566 p_hkmap = p_fkmap;
7567 p_fkmap = 0;
7568 }
7569 else
7570 {
7571 p_fkmap = p_hkmap;
7572 p_hkmap = 0;
7573 }
7574 (void)init_chartab();
7575 }
7576 }
7577
7578 /*
7579 * In case some second language keymapping options have changed, check
7580 * and correct the setting in a consistent way.
7581 */
7582
7583 /*
7584 * If hkmap or fkmap are set, reset Arabic keymapping.
7585 */
7586 if ((p_hkmap || p_fkmap) && p_altkeymap)
7587 {
7588 p_altkeymap = p_fkmap;
7589# ifdef FEAT_ARABIC
7590 curwin->w_p_arab = FALSE;
7591# endif
7592 (void)init_chartab();
7593 }
7594
7595 /*
7596 * If hkmap set, reset Farsi keymapping.
7597 */
7598 if (p_hkmap && p_altkeymap)
7599 {
7600 p_altkeymap = 0;
7601 p_fkmap = 0;
7602# ifdef FEAT_ARABIC
7603 curwin->w_p_arab = FALSE;
7604# endif
7605 (void)init_chartab();
7606 }
7607
7608 /*
7609 * If fkmap set, reset Hebrew keymapping.
7610 */
7611 if (p_fkmap && !p_altkeymap)
7612 {
7613 p_altkeymap = 1;
7614 p_hkmap = 0;
7615# ifdef FEAT_ARABIC
7616 curwin->w_p_arab = FALSE;
7617# endif
7618 (void)init_chartab();
7619 }
7620#endif
7621
7622#ifdef FEAT_ARABIC
7623 if ((int *)varp == &curwin->w_p_arab)
7624 {
7625 if (curwin->w_p_arab)
7626 {
7627 /*
7628 * 'arabic' is set, handle various sub-settings.
7629 */
7630 if (!p_tbidi)
7631 {
7632 /* set rightleft mode */
7633 if (!curwin->w_p_rl)
7634 {
7635 curwin->w_p_rl = TRUE;
7636 changed_window_setting();
7637 }
7638
7639 /* Enable Arabic shaping (major part of what Arabic requires) */
7640 if (!p_arshape)
7641 {
7642 p_arshape = TRUE;
7643 redraw_later_clear();
7644 }
7645 }
7646
7647 /* Arabic requires a utf-8 encoding, inform the user if its not
7648 * set. */
7649 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007650 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007651 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7652
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007653 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007654 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7655#ifdef FEAT_EVAL
7656 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7657#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659
7660# ifdef FEAT_MBYTE
7661 /* set 'delcombine' */
7662 p_deco = TRUE;
7663# endif
7664
7665# ifdef FEAT_KEYMAP
7666 /* Force-set the necessary keymap for arabic */
7667 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7668 OPT_LOCAL);
7669# endif
7670# ifdef FEAT_FKMAP
7671 p_altkeymap = 0;
7672 p_hkmap = 0;
7673 p_fkmap = 0;
7674 (void)init_chartab();
7675# endif
7676 }
7677 else
7678 {
7679 /*
7680 * 'arabic' is reset, handle various sub-settings.
7681 */
7682 if (!p_tbidi)
7683 {
7684 /* reset rightleft mode */
7685 if (curwin->w_p_rl)
7686 {
7687 curwin->w_p_rl = FALSE;
7688 changed_window_setting();
7689 }
7690
7691 /* 'arabicshape' isn't reset, it is a global option and
7692 * another window may still need it "on". */
7693 }
7694
7695 /* 'delcombine' isn't reset, it is a global option and another
7696 * window may still want it "on". */
7697
7698# ifdef FEAT_KEYMAP
7699 /* Revert to the default keymap */
7700 curbuf->b_p_iminsert = B_IMODE_NONE;
7701 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7702# endif
7703 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007704 if (curwin->w_curswant != MAXCOL)
7705 curwin->w_set_curswant = TRUE;
7706 }
7707
7708 else if ((int *)varp == &p_arshape)
7709 {
7710 if (curwin->w_curswant != MAXCOL)
7711 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 }
7713#endif
7714
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007715#ifdef FEAT_LINEBREAK
7716 if ((int *)varp == &curwin->w_p_lbr)
7717 {
7718 if (curwin->w_curswant != MAXCOL)
7719 curwin->w_set_curswant = TRUE;
7720 }
7721#endif
7722
7723#ifdef FEAT_RIGHTLEFT
7724 if ((int *)varp == &curwin->w_p_rl)
7725 {
7726 if (curwin->w_curswant != MAXCOL)
7727 curwin->w_set_curswant = TRUE;
7728 }
7729#endif
7730
Bram Moolenaar071d4272004-06-13 20:20:40 +00007731 /*
7732 * End of handling side effects for bool options.
7733 */
7734
7735 options[opt_idx].flags |= P_WAS_SET;
7736
7737 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007738
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 check_redraw(options[opt_idx].flags);
7740
7741 return NULL;
7742}
7743
7744/*
7745 * Set the value of a number option, and take care of side effects.
7746 * Returns NULL for success, or an error message for an error.
7747 */
7748 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007749set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 int opt_idx; /* index in options[] table */
7751 char_u *varp; /* pointer to the option variable */
7752 long value; /* new value */
7753 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007754 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7756 OPT_MODELINE */
7757{
7758 char_u *errmsg = NULL;
7759 long old_value = *(long *)varp;
7760 long old_Rows = Rows; /* remember old Rows */
7761 long old_Columns = Columns; /* remember old Columns */
7762 long *pp = (long *)varp;
7763
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007764 /* Disallow changing some options from secure mode. */
7765 if ((secure
7766#ifdef HAVE_SANDBOX
7767 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007769 ) && (options[opt_idx].flags & P_SECURE))
7770 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771
7772 *pp = value;
7773#ifdef FEAT_EVAL
7774 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007775 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007777#ifdef FEAT_GUI
7778 need_mouse_correct = TRUE;
7779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007780
7781 if (curbuf->b_p_sw <= 0)
7782 {
7783 errmsg = e_positive;
7784 curbuf->b_p_sw = curbuf->b_p_ts;
7785 }
7786
7787 /*
7788 * Number options that need some action when changed
7789 */
7790#ifdef FEAT_WINDOWS
7791 if (pp == &p_wh || pp == &p_hh)
7792 {
7793 if (p_wh < 1)
7794 {
7795 errmsg = e_positive;
7796 p_wh = 1;
7797 }
7798 if (p_wmh > p_wh)
7799 {
7800 errmsg = e_winheight;
7801 p_wh = p_wmh;
7802 }
7803 if (p_hh < 0)
7804 {
7805 errmsg = e_positive;
7806 p_hh = 0;
7807 }
7808
7809 /* Change window height NOW */
7810 if (lastwin != firstwin)
7811 {
7812 if (pp == &p_wh && curwin->w_height < p_wh)
7813 win_setheight((int)p_wh);
7814 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7815 win_setheight((int)p_hh);
7816 }
7817 }
7818
7819 /* 'winminheight' */
7820 else if (pp == &p_wmh)
7821 {
7822 if (p_wmh < 0)
7823 {
7824 errmsg = e_positive;
7825 p_wmh = 0;
7826 }
7827 if (p_wmh > p_wh)
7828 {
7829 errmsg = e_winheight;
7830 p_wmh = p_wh;
7831 }
7832 win_setminheight();
7833 }
7834
7835# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007836 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 {
7838 if (p_wiw < 1)
7839 {
7840 errmsg = e_positive;
7841 p_wiw = 1;
7842 }
7843 if (p_wmw > p_wiw)
7844 {
7845 errmsg = e_winwidth;
7846 p_wiw = p_wmw;
7847 }
7848
7849 /* Change window width NOW */
7850 if (lastwin != firstwin && curwin->w_width < p_wiw)
7851 win_setwidth((int)p_wiw);
7852 }
7853
7854 /* 'winminwidth' */
7855 else if (pp == &p_wmw)
7856 {
7857 if (p_wmw < 0)
7858 {
7859 errmsg = e_positive;
7860 p_wmw = 0;
7861 }
7862 if (p_wmw > p_wiw)
7863 {
7864 errmsg = e_winwidth;
7865 p_wmw = p_wiw;
7866 }
7867 win_setminheight();
7868 }
7869# endif
7870
7871#endif
7872
7873#ifdef FEAT_WINDOWS
7874 /* (re)set last window status line */
7875 else if (pp == &p_ls)
7876 {
7877 last_status(FALSE);
7878 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007879
7880 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007881 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007882 {
7883 shell_new_rows(); /* recompute window positions and heights */
7884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885#endif
7886
7887#ifdef FEAT_GUI
7888 else if (pp == &p_linespace)
7889 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007890 /* Recompute gui.char_height and resize the Vim window to keep the
7891 * same number of lines. */
7892 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007893 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 }
7895#endif
7896
7897#ifdef FEAT_FOLDING
7898 /* 'foldlevel' */
7899 else if (pp == &curwin->w_p_fdl)
7900 {
7901 if (curwin->w_p_fdl < 0)
7902 curwin->w_p_fdl = 0;
7903 newFoldLevel();
7904 }
7905
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007906 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 else if (pp == &curwin->w_p_fml)
7908 {
7909 foldUpdateAll(curwin);
7910 }
7911
7912 /* 'foldnestmax' */
7913 else if (pp == &curwin->w_p_fdn)
7914 {
7915 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7916 foldUpdateAll(curwin);
7917 }
7918
7919 /* 'foldcolumn' */
7920 else if (pp == &curwin->w_p_fdc)
7921 {
7922 if (curwin->w_p_fdc < 0)
7923 {
7924 errmsg = e_positive;
7925 curwin->w_p_fdc = 0;
7926 }
7927 else if (curwin->w_p_fdc > 12)
7928 {
7929 errmsg = e_invarg;
7930 curwin->w_p_fdc = 12;
7931 }
7932 }
7933
7934 /* 'shiftwidth' or 'tabstop' */
7935 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7936 {
7937 if (foldmethodIsIndent(curwin))
7938 foldUpdateAll(curwin);
7939 }
7940#endif /* FEAT_FOLDING */
7941
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007942#ifdef FEAT_MBYTE
7943 /* 'maxcombine' */
7944 else if (pp == &p_mco)
7945 {
7946 if (p_mco > MAX_MCO)
7947 p_mco = MAX_MCO;
7948 else if (p_mco < 0)
7949 p_mco = 0;
7950 screenclear(); /* will re-allocate the screen */
7951 }
7952#endif
7953
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 else if (pp == &curbuf->b_p_iminsert)
7955 {
7956 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7957 {
7958 errmsg = e_invarg;
7959 curbuf->b_p_iminsert = B_IMODE_NONE;
7960 }
7961 p_iminsert = curbuf->b_p_iminsert;
7962 if (termcap_active) /* don't do this in the alternate screen */
7963 showmode();
7964#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7965 /* Show/unshow value of 'keymap' in status lines. */
7966 status_redraw_curbuf();
7967#endif
7968 }
7969
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007970 else if (pp == &p_window)
7971 {
7972 if (p_window < 1)
7973 p_window = 1;
7974 else if (p_window >= Rows)
7975 p_window = Rows - 1;
7976 }
7977
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 else if (pp == &curbuf->b_p_imsearch)
7979 {
7980 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7981 {
7982 errmsg = e_invarg;
7983 curbuf->b_p_imsearch = B_IMODE_NONE;
7984 }
7985 p_imsearch = curbuf->b_p_imsearch;
7986 }
7987
7988#ifdef FEAT_TITLE
7989 /* if 'titlelen' has changed, redraw the title */
7990 else if (pp == &p_titlelen)
7991 {
7992 if (p_titlelen < 0)
7993 {
7994 errmsg = e_positive;
7995 p_titlelen = 85;
7996 }
7997 if (starting != NO_SCREEN && old_value != p_titlelen)
7998 need_maketitle = TRUE;
7999 }
8000#endif
8001
8002 /* if p_ch changed value, change the command line height */
8003 else if (pp == &p_ch)
8004 {
8005 if (p_ch < 1)
8006 {
8007 errmsg = e_positive;
8008 p_ch = 1;
8009 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008010 if (p_ch > Rows - min_rows() + 1)
8011 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012
8013 /* Only compute the new window layout when startup has been
8014 * completed. Otherwise the frame sizes may be wrong. */
8015 if (p_ch != old_value && full_screen
8016#ifdef FEAT_GUI
8017 && !gui.starting
8018#endif
8019 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008020 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022
8023 /* when 'updatecount' changes from zero to non-zero, open swap files */
8024 else if (pp == &p_uc)
8025 {
8026 if (p_uc < 0)
8027 {
8028 errmsg = e_positive;
8029 p_uc = 100;
8030 }
8031 if (p_uc && !old_value)
8032 ml_open_files();
8033 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008034#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008035 else if (pp == &p_mzq)
8036 mzvim_reset_timer();
8037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038
8039 /* sync undo before 'undolevels' changes */
8040 else if (pp == &p_ul)
8041 {
8042 /* use the old value, otherwise u_sync() may not work properly */
8043 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008044 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 p_ul = value;
8046 }
8047
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008048#ifdef FEAT_LINEBREAK
8049 /* 'numberwidth' must be positive */
8050 else if (pp == &curwin->w_p_nuw)
8051 {
8052 if (curwin->w_p_nuw < 1)
8053 {
8054 errmsg = e_positive;
8055 curwin->w_p_nuw = 1;
8056 }
8057 if (curwin->w_p_nuw > 10)
8058 {
8059 errmsg = e_invarg;
8060 curwin->w_p_nuw = 10;
8061 }
8062 curwin->w_nrwidth_line_count = 0;
8063 }
8064#endif
8065
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 /*
8067 * Check the bounds for numeric options here
8068 */
8069 if (Rows < min_rows() && full_screen)
8070 {
8071 if (errbuf != NULL)
8072 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008073 vim_snprintf((char *)errbuf, errbuflen,
8074 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075 errmsg = errbuf;
8076 }
8077 Rows = min_rows();
8078 }
8079 if (Columns < MIN_COLUMNS && full_screen)
8080 {
8081 if (errbuf != NULL)
8082 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008083 vim_snprintf((char *)errbuf, errbuflen,
8084 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 errmsg = errbuf;
8086 }
8087 Columns = MIN_COLUMNS;
8088 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008089 /* Limit the values to avoid an overflow in Rows * Columns. */
8090 if (Columns > 10000)
8091 Columns = 10000;
8092 if (Rows > 1000)
8093 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094
8095#ifdef DJGPP
8096 /* avoid a crash by checking for a too large value of 'columns' */
8097 if (old_Columns != Columns && full_screen && term_console)
8098 mch_check_columns();
8099#endif
8100
8101 /*
8102 * If the screen (shell) height has been changed, assume it is the
8103 * physical screenheight.
8104 */
8105 if (old_Rows != Rows || old_Columns != Columns)
8106 {
8107 /* Changing the screen size is not allowed while updating the screen. */
8108 if (updating_screen)
8109 *pp = old_value;
8110 else if (full_screen
8111#ifdef FEAT_GUI
8112 && !gui.starting
8113#endif
8114 )
8115 set_shellsize((int)Columns, (int)Rows, TRUE);
8116 else
8117 {
8118 /* Postpone the resizing; check the size and cmdline position for
8119 * messages. */
8120 check_shellsize();
8121 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8122 cmdline_row = Rows - p_ch;
8123 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008124 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008125 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127
8128 if (curbuf->b_p_sts < 0)
8129 {
8130 errmsg = e_positive;
8131 curbuf->b_p_sts = 0;
8132 }
8133 if (curbuf->b_p_ts <= 0)
8134 {
8135 errmsg = e_positive;
8136 curbuf->b_p_ts = 8;
8137 }
8138 if (curbuf->b_p_tw < 0)
8139 {
8140 errmsg = e_positive;
8141 curbuf->b_p_tw = 0;
8142 }
8143 if (p_tm < 0)
8144 {
8145 errmsg = e_positive;
8146 p_tm = 0;
8147 }
8148 if ((curwin->w_p_scr <= 0
8149 || (curwin->w_p_scr > curwin->w_height
8150 && curwin->w_height > 0))
8151 && full_screen)
8152 {
8153 if (pp == &(curwin->w_p_scr))
8154 {
8155 if (curwin->w_p_scr != 0)
8156 errmsg = e_scroll;
8157 win_comp_scroll(curwin);
8158 }
8159 /* If 'scroll' became invalid because of a side effect silently adjust
8160 * it. */
8161 else if (curwin->w_p_scr <= 0)
8162 curwin->w_p_scr = 1;
8163 else /* curwin->w_p_scr > curwin->w_height */
8164 curwin->w_p_scr = curwin->w_height;
8165 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008166 if (p_hi < 0)
8167 {
8168 errmsg = e_positive;
8169 p_hi = 0;
8170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 if (p_report < 0)
8172 {
8173 errmsg = e_positive;
8174 p_report = 1;
8175 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008176 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 {
8178 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8179 p_sj = Rows / 2;
8180 else
8181 {
8182 errmsg = e_scroll;
8183 p_sj = 1;
8184 }
8185 }
8186 if (p_so < 0 && full_screen)
8187 {
8188 errmsg = e_scroll;
8189 p_so = 0;
8190 }
8191 if (p_siso < 0 && full_screen)
8192 {
8193 errmsg = e_positive;
8194 p_siso = 0;
8195 }
8196#ifdef FEAT_CMDWIN
8197 if (p_cwh < 1)
8198 {
8199 errmsg = e_positive;
8200 p_cwh = 1;
8201 }
8202#endif
8203 if (p_ut < 0)
8204 {
8205 errmsg = e_positive;
8206 p_ut = 2000;
8207 }
8208 if (p_ss < 0)
8209 {
8210 errmsg = e_positive;
8211 p_ss = 0;
8212 }
8213
8214 /* May set global value for local option. */
8215 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8216 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8217
8218 options[opt_idx].flags |= P_WAS_SET;
8219
8220 comp_col(); /* in case 'columns' or 'ls' changed */
8221 if (curwin->w_curswant != MAXCOL)
8222 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8223 check_redraw(options[opt_idx].flags);
8224
8225 return errmsg;
8226}
8227
8228/*
8229 * Called after an option changed: check if something needs to be redrawn.
8230 */
8231 static void
8232check_redraw(flags)
8233 long_u flags;
8234{
8235 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8236 int clear = (flags & P_RCLR) == P_RCLR;
8237 int all = ((flags & P_RALL) == P_RALL || clear);
8238
8239#ifdef FEAT_WINDOWS
8240 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8241 status_redraw_all();
8242#endif
8243
8244 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8245 changed_window_setting();
8246 if (flags & P_RBUF)
8247 redraw_curbuf_later(NOT_VALID);
8248 if (clear)
8249 redraw_all_later(CLEAR);
8250 else if (all)
8251 redraw_all_later(NOT_VALID);
8252}
8253
8254/*
8255 * Find index for option 'arg'.
8256 * Return -1 if not found.
8257 */
8258 static int
8259findoption(arg)
8260 char_u *arg;
8261{
8262 int opt_idx;
8263 char *s, *p;
8264 static short quick_tab[27] = {0, 0}; /* quick access table */
8265 int is_term_opt;
8266
8267 /*
8268 * For first call: Initialize the quick-access table.
8269 * It contains the index for the first option that starts with a certain
8270 * letter. There are 26 letters, plus the first "t_" option.
8271 */
8272 if (quick_tab[1] == 0)
8273 {
8274 p = options[0].fullname;
8275 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8276 {
8277 if (s[0] != p[0])
8278 {
8279 if (s[0] == 't' && s[1] == '_')
8280 quick_tab[26] = opt_idx;
8281 else
8282 quick_tab[CharOrdLow(s[0])] = opt_idx;
8283 }
8284 p = s;
8285 }
8286 }
8287
8288 /*
8289 * Check for name starting with an illegal character.
8290 */
8291#ifdef EBCDIC
8292 if (!islower(arg[0]))
8293#else
8294 if (arg[0] < 'a' || arg[0] > 'z')
8295#endif
8296 return -1;
8297
8298 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8299 if (is_term_opt)
8300 opt_idx = quick_tab[26];
8301 else
8302 opt_idx = quick_tab[CharOrdLow(arg[0])];
8303 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8304 {
8305 if (STRCMP(arg, s) == 0) /* match full name */
8306 break;
8307 }
8308 if (s == NULL && !is_term_opt)
8309 {
8310 opt_idx = quick_tab[CharOrdLow(arg[0])];
8311 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8312 {
8313 s = options[opt_idx].shortname;
8314 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8315 break;
8316 s = NULL;
8317 }
8318 }
8319 if (s == NULL)
8320 opt_idx = -1;
8321 return opt_idx;
8322}
8323
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008324#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325/*
8326 * Get the value for an option.
8327 *
8328 * Returns:
8329 * Number or Toggle option: 1, *numval gets value.
8330 * String option: 0, *stringval gets allocated string.
8331 * Hidden Number or Toggle option: -1.
8332 * hidden String option: -2.
8333 * unknown option: -3.
8334 */
8335 int
8336get_option_value(name, numval, stringval, opt_flags)
8337 char_u *name;
8338 long *numval;
8339 char_u **stringval; /* NULL when only checking existance */
8340 int opt_flags;
8341{
8342 int opt_idx;
8343 char_u *varp;
8344
8345 opt_idx = findoption(name);
8346 if (opt_idx < 0) /* unknown option */
8347 return -3;
8348
8349 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8350
8351 if (options[opt_idx].flags & P_STRING)
8352 {
8353 if (varp == NULL) /* hidden option */
8354 return -2;
8355 if (stringval != NULL)
8356 {
8357#ifdef FEAT_CRYPT
8358 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008359 if ((char_u **)varp == &curbuf->b_p_key
8360 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 *stringval = vim_strsave((char_u *)"*****");
8362 else
8363#endif
8364 *stringval = vim_strsave(*(char_u **)(varp));
8365 }
8366 return 0;
8367 }
8368
8369 if (varp == NULL) /* hidden option */
8370 return -1;
8371 if (options[opt_idx].flags & P_NUM)
8372 *numval = *(long *)varp;
8373 else
8374 {
8375 /* Special case: 'modified' is b_changed, but we also want to consider
8376 * it set when 'ff' or 'fenc' changed. */
8377 if ((int *)varp == &curbuf->b_changed)
8378 *numval = curbufIsChanged();
8379 else
8380 *numval = *(int *)varp;
8381 }
8382 return 1;
8383}
8384#endif
8385
8386/*
8387 * Set the value of option "name".
8388 * Use "string" for string options, use "number" for other options.
8389 */
8390 void
8391set_option_value(name, number, string, opt_flags)
8392 char_u *name;
8393 long number;
8394 char_u *string;
8395 int opt_flags; /* OPT_LOCAL or 0 (both) */
8396{
8397 int opt_idx;
8398 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008399 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400
8401 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008402 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 EMSG2(_("E355: Unknown option: %s"), name);
8404 else
8405 {
8406 flags = options[opt_idx].flags;
8407#ifdef HAVE_SANDBOX
8408 /* Disallow changing some options in the sandbox */
8409 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008411 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008412 return;
8413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008415 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 set_string_option(opt_idx, string, opt_flags);
8417 else
8418 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008419 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 if (varp != NULL) /* hidden option is not changed */
8421 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008422 if (number == 0 && string != NULL)
8423 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008424 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008425
8426 /* Either we are given a string or we are setting option
8427 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008428 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008429 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008430 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008431 {
8432 /* There's another character after zeros or the string
8433 * is empty. In both cases, we are trying to set a
8434 * num option using a string. */
8435 EMSG3(_("E521: Number required: &%s = '%s'"),
8436 name, string);
8437 return; /* do nothing as we hit an error */
8438
8439 }
8440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008442 (void)set_num_option(opt_idx, varp, number,
8443 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008445 (void)set_bool_option(opt_idx, varp, (int)number,
8446 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 }
8448 }
8449 }
8450}
8451
8452/*
8453 * Get the terminal code for a terminal option.
8454 * Returns NULL when not found.
8455 */
8456 char_u *
8457get_term_code(tname)
8458 char_u *tname;
8459{
8460 int opt_idx;
8461 char_u *varp;
8462
8463 if (tname[0] != 't' || tname[1] != '_' ||
8464 tname[2] == NUL || tname[3] == NUL)
8465 return NULL;
8466 if ((opt_idx = findoption(tname)) >= 0)
8467 {
8468 varp = get_varp(&(options[opt_idx]));
8469 if (varp != NULL)
8470 varp = *(char_u **)(varp);
8471 return varp;
8472 }
8473 return find_termcode(tname + 2);
8474}
8475
8476 char_u *
8477get_highlight_default()
8478{
8479 int i;
8480
8481 i = findoption((char_u *)"hl");
8482 if (i >= 0)
8483 return options[i].def_val[VI_DEFAULT];
8484 return (char_u *)NULL;
8485}
8486
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008487#if defined(FEAT_MBYTE) || defined(PROTO)
8488 char_u *
8489get_encoding_default()
8490{
8491 int i;
8492
8493 i = findoption((char_u *)"enc");
8494 if (i >= 0)
8495 return options[i].def_val[VI_DEFAULT];
8496 return (char_u *)NULL;
8497}
8498#endif
8499
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500/*
8501 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8502 */
8503 static int
8504find_key_option(arg)
8505 char_u *arg;
8506{
8507 int key;
8508 int modifiers;
8509
8510 /*
8511 * Don't use get_special_key_code() for t_xx, we don't want it to call
8512 * add_termcap_entry().
8513 */
8514 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8515 key = TERMCAP2KEY(arg[2], arg[3]);
8516 else
8517 {
8518 --arg; /* put arg at the '<' */
8519 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008520 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 if (modifiers) /* can't handle modifiers here */
8522 key = 0;
8523 }
8524 return key;
8525}
8526
8527/*
8528 * if 'all' == 0: show changed options
8529 * if 'all' == 1: show all normal options
8530 * if 'all' == 2: show all terminal options
8531 */
8532 static void
8533showoptions(all, opt_flags)
8534 int all;
8535 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8536{
8537 struct vimoption *p;
8538 int col;
8539 int isterm;
8540 char_u *varp;
8541 struct vimoption **items;
8542 int item_count;
8543 int run;
8544 int row, rows;
8545 int cols;
8546 int i;
8547 int len;
8548
8549#define INC 20
8550#define GAP 3
8551
8552 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8553 PARAM_COUNT));
8554 if (items == NULL)
8555 return;
8556
8557 /* Highlight title */
8558 if (all == 2)
8559 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8560 else if (opt_flags & OPT_GLOBAL)
8561 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8562 else if (opt_flags & OPT_LOCAL)
8563 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8564 else
8565 MSG_PUTS_TITLE(_("\n--- Options ---"));
8566
8567 /*
8568 * do the loop two times:
8569 * 1. display the short items
8570 * 2. display the long items (only strings and numbers)
8571 */
8572 for (run = 1; run <= 2 && !got_int; ++run)
8573 {
8574 /*
8575 * collect the items in items[]
8576 */
8577 item_count = 0;
8578 for (p = &options[0]; p->fullname != NULL; p++)
8579 {
8580 varp = NULL;
8581 isterm = istermoption(p);
8582 if (opt_flags != 0)
8583 {
8584 if (p->indir != PV_NONE && !isterm)
8585 varp = get_varp_scope(p, opt_flags);
8586 }
8587 else
8588 varp = get_varp(p);
8589 if (varp != NULL
8590 && ((all == 2 && isterm)
8591 || (all == 1 && !isterm)
8592 || (all == 0 && !optval_default(p, varp))))
8593 {
8594 if (p->flags & P_BOOL)
8595 len = 1; /* a toggle option fits always */
8596 else
8597 {
8598 option_value2string(p, opt_flags);
8599 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8600 }
8601 if ((len <= INC - GAP && run == 1) ||
8602 (len > INC - GAP && run == 2))
8603 items[item_count++] = p;
8604 }
8605 }
8606
8607 /*
8608 * display the items
8609 */
8610 if (run == 1)
8611 {
8612 cols = (Columns + GAP - 3) / INC;
8613 if (cols == 0)
8614 cols = 1;
8615 rows = (item_count + cols - 1) / cols;
8616 }
8617 else /* run == 2 */
8618 rows = item_count;
8619 for (row = 0; row < rows && !got_int; ++row)
8620 {
8621 msg_putchar('\n'); /* go to next line */
8622 if (got_int) /* 'q' typed in more */
8623 break;
8624 col = 0;
8625 for (i = row; i < item_count; i += rows)
8626 {
8627 msg_col = col; /* make columns */
8628 showoneopt(items[i], opt_flags);
8629 col += INC;
8630 }
8631 out_flush();
8632 ui_breakcheck();
8633 }
8634 }
8635 vim_free(items);
8636}
8637
8638/*
8639 * Return TRUE if option "p" has its default value.
8640 */
8641 static int
8642optval_default(p, varp)
8643 struct vimoption *p;
8644 char_u *varp;
8645{
8646 int dvi;
8647
8648 if (varp == NULL)
8649 return TRUE; /* hidden option is always at default */
8650 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8651 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008652 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008654 /* the cast to long is required for Manx C, long_i is
8655 * needed for MSVC */
8656 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 /* P_STRING */
8658 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8659}
8660
8661/*
8662 * showoneopt: show the value of one option
8663 * must not be called with a hidden option!
8664 */
8665 static void
8666showoneopt(p, opt_flags)
8667 struct vimoption *p;
8668 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8669{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008670 char_u *varp;
8671 int save_silent = silent_mode;
8672
8673 silent_mode = FALSE;
8674 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675
8676 varp = get_varp_scope(p, opt_flags);
8677
8678 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8679 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8680 ? !curbufIsChanged() : !*(int *)varp))
8681 MSG_PUTS("no");
8682 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8683 MSG_PUTS("--");
8684 else
8685 MSG_PUTS(" ");
8686 MSG_PUTS(p->fullname);
8687 if (!(p->flags & P_BOOL))
8688 {
8689 msg_putchar('=');
8690 /* put value string in NameBuff */
8691 option_value2string(p, opt_flags);
8692 msg_outtrans(NameBuff);
8693 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008694
8695 silent_mode = save_silent;
8696 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697}
8698
8699/*
8700 * Write modified options as ":set" commands to a file.
8701 *
8702 * There are three values for "opt_flags":
8703 * OPT_GLOBAL: Write global option values and fresh values of
8704 * buffer-local options (used for start of a session
8705 * file).
8706 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8707 * curwin (used for a vimrc file).
8708 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8709 * and local values for window-local options of
8710 * curwin. Local values are also written when at the
8711 * default value, because a modeline or autocommand
8712 * may have set them when doing ":edit file" and the
8713 * user has set them back at the default or fresh
8714 * value.
8715 * When "local_only" is TRUE, don't write fresh
8716 * values, only local values (for ":mkview").
8717 * (fresh value = value used for a new buffer or window for a local option).
8718 *
8719 * Return FAIL on error, OK otherwise.
8720 */
8721 int
8722makeset(fd, opt_flags, local_only)
8723 FILE *fd;
8724 int opt_flags;
8725 int local_only;
8726{
8727 struct vimoption *p;
8728 char_u *varp; /* currently used value */
8729 char_u *varp_fresh; /* local value */
8730 char_u *varp_local = NULL; /* fresh value */
8731 char *cmd;
8732 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008733 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734
8735 /*
8736 * The options that don't have a default (terminal name, columns, lines)
8737 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008738 * Do the loop over "options[]" twice: once for options with the
8739 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008741 for (pri = 1; pri >= 0; --pri)
8742 {
8743 for (p = &options[0]; !istermoption(p); p++)
8744 if (!(p->flags & P_NO_MKRC)
8745 && !istermoption(p)
8746 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 {
8748 /* skip global option when only doing locals */
8749 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8750 continue;
8751
8752 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8753 * file, they are always buffer-specific. */
8754 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8755 continue;
8756
8757 /* Global values are only written when not at the default value. */
8758 varp = get_varp_scope(p, opt_flags);
8759 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8760 continue;
8761
8762 round = 2;
8763 if (p->indir != PV_NONE)
8764 {
8765 if (p->var == VAR_WIN)
8766 {
8767 /* skip window-local option when only doing globals */
8768 if (!(opt_flags & OPT_LOCAL))
8769 continue;
8770 /* When fresh value of window-local option is not at the
8771 * default, need to write it too. */
8772 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8773 {
8774 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8775 if (!optval_default(p, varp_fresh))
8776 {
8777 round = 1;
8778 varp_local = varp;
8779 varp = varp_fresh;
8780 }
8781 }
8782 }
8783 }
8784
8785 /* Round 1: fresh value for window-local options.
8786 * Round 2: other values */
8787 for ( ; round <= 2; varp = varp_local, ++round)
8788 {
8789 if (round == 1 || (opt_flags & OPT_GLOBAL))
8790 cmd = "set";
8791 else
8792 cmd = "setlocal";
8793
8794 if (p->flags & P_BOOL)
8795 {
8796 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8797 return FAIL;
8798 }
8799 else if (p->flags & P_NUM)
8800 {
8801 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8802 return FAIL;
8803 }
8804 else /* P_STRING */
8805 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008806#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8807 int do_endif = FALSE;
8808
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 /* Don't set 'syntax' and 'filetype' again if the value is
8810 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008811 if (
8812# if defined(FEAT_SYN_HL)
8813 p->indir == PV_SYN
8814# if defined(FEAT_AUTOCMD)
8815 ||
8816# endif
8817# endif
8818# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008819 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008820# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008821 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 {
8823 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8824 *(char_u **)(varp)) < 0
8825 || put_eol(fd) < 0)
8826 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008827 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8831 (p->flags & P_EXPAND) != 0) == FAIL)
8832 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008833#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8834 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 {
8836 if (put_line(fd, "endif") == FAIL)
8837 return FAIL;
8838 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 }
8841 }
8842 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 return OK;
8845}
8846
8847#if defined(FEAT_FOLDING) || defined(PROTO)
8848/*
8849 * Generate set commands for the local fold options only. Used when
8850 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8851 */
8852 int
8853makefoldset(fd)
8854 FILE *fd;
8855{
8856 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8857# ifdef FEAT_EVAL
8858 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8859 == FAIL
8860# endif
8861 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8862 == FAIL
8863 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8864 == FAIL
8865 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8866 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8867 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8868 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8869 )
8870 return FAIL;
8871
8872 return OK;
8873}
8874#endif
8875
8876 static int
8877put_setstring(fd, cmd, name, valuep, expand)
8878 FILE *fd;
8879 char *cmd;
8880 char *name;
8881 char_u **valuep;
8882 int expand;
8883{
8884 char_u *s;
8885 char_u buf[MAXPATHL];
8886
8887 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8888 return FAIL;
8889 if (*valuep != NULL)
8890 {
8891 /* Output 'pastetoggle' as key names. For other
8892 * options some characters have to be escaped with
8893 * CTRL-V or backslash */
8894 if (valuep == &p_pt)
8895 {
8896 s = *valuep;
8897 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00008898 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 return FAIL;
8900 }
8901 else if (expand)
8902 {
8903 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8904 if (put_escstr(fd, buf, 2) == FAIL)
8905 return FAIL;
8906 }
8907 else if (put_escstr(fd, *valuep, 2) == FAIL)
8908 return FAIL;
8909 }
8910 if (put_eol(fd) < 0)
8911 return FAIL;
8912 return OK;
8913}
8914
8915 static int
8916put_setnum(fd, cmd, name, valuep)
8917 FILE *fd;
8918 char *cmd;
8919 char *name;
8920 long *valuep;
8921{
8922 long wc;
8923
8924 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8925 return FAIL;
8926 if (wc_use_keyname((char_u *)valuep, &wc))
8927 {
8928 /* print 'wildchar' and 'wildcharm' as a key name */
8929 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8930 return FAIL;
8931 }
8932 else if (fprintf(fd, "%ld", *valuep) < 0)
8933 return FAIL;
8934 if (put_eol(fd) < 0)
8935 return FAIL;
8936 return OK;
8937}
8938
8939 static int
8940put_setbool(fd, cmd, name, value)
8941 FILE *fd;
8942 char *cmd;
8943 char *name;
8944 int value;
8945{
Bram Moolenaar893de922007-10-02 18:40:57 +00008946 if (value < 0) /* global/local option using global value */
8947 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8949 || put_eol(fd) < 0)
8950 return FAIL;
8951 return OK;
8952}
8953
8954/*
8955 * Clear all the terminal options.
8956 * If the option has been allocated, free the memory.
8957 * Terminal options are never hidden or indirect.
8958 */
8959 void
8960clear_termoptions()
8961{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962 /*
8963 * Reset a few things before clearing the old options. This may cause
8964 * outputting a few things that the terminal doesn't understand, but the
8965 * screen will be cleared later, so this is OK.
8966 */
8967#ifdef FEAT_MOUSE_TTY
8968 mch_setmouse(FALSE); /* switch mouse off */
8969#endif
8970#ifdef FEAT_TITLE
8971 mch_restore_title(3); /* restore window titles */
8972#endif
8973#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8974 /* When starting the GUI close the display opened for the clipboard.
8975 * After restoring the title, because that will need the display. */
8976 if (gui.starting)
8977 clear_xterm_clip();
8978#endif
8979#ifdef WIN3264
8980 /*
8981 * Check if this is allowed now.
8982 */
8983 if (can_end_termcap_mode(FALSE) == TRUE)
8984#endif
8985 stoptermcap(); /* stop termcap mode */
8986
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008987 free_termoptions();
8988}
8989
8990 void
8991free_termoptions()
8992{
8993 struct vimoption *p;
8994
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 for (p = &options[0]; p->fullname != NULL; p++)
8996 if (istermoption(p))
8997 {
8998 if (p->flags & P_ALLOCED)
8999 free_string_option(*(char_u **)(p->var));
9000 if (p->flags & P_DEF_ALLOCED)
9001 free_string_option(p->def_val[VI_DEFAULT]);
9002 *(char_u **)(p->var) = empty_option;
9003 p->def_val[VI_DEFAULT] = empty_option;
9004 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9005 }
9006 clear_termcodes();
9007}
9008
9009/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009010 * Free the string for one term option, if it was allocated.
9011 * Set the string to empty_option and clear allocated flag.
9012 * "var" points to the option value.
9013 */
9014 void
9015free_one_termoption(var)
9016 char_u *var;
9017{
9018 struct vimoption *p;
9019
9020 for (p = &options[0]; p->fullname != NULL; p++)
9021 if (p->var == var)
9022 {
9023 if (p->flags & P_ALLOCED)
9024 free_string_option(*(char_u **)(p->var));
9025 *(char_u **)(p->var) = empty_option;
9026 p->flags &= ~P_ALLOCED;
9027 break;
9028 }
9029}
9030
9031/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032 * Set the terminal option defaults to the current value.
9033 * Used after setting the terminal name.
9034 */
9035 void
9036set_term_defaults()
9037{
9038 struct vimoption *p;
9039
9040 for (p = &options[0]; p->fullname != NULL; p++)
9041 {
9042 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9043 {
9044 if (p->flags & P_DEF_ALLOCED)
9045 {
9046 free_string_option(p->def_val[VI_DEFAULT]);
9047 p->flags &= ~P_DEF_ALLOCED;
9048 }
9049 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9050 if (p->flags & P_ALLOCED)
9051 {
9052 p->flags |= P_DEF_ALLOCED;
9053 p->flags &= ~P_ALLOCED; /* don't free the value now */
9054 }
9055 }
9056 }
9057}
9058
9059/*
9060 * return TRUE if 'p' starts with 't_'
9061 */
9062 static int
9063istermoption(p)
9064 struct vimoption *p;
9065{
9066 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9067}
9068
9069/*
9070 * Compute columns for ruler and shown command. 'sc_col' is also used to
9071 * decide what the maximum length of a message on the status line can be.
9072 * If there is a status line for the last window, 'sc_col' is independent
9073 * of 'ru_col'.
9074 */
9075
9076#define COL_RULER 17 /* columns needed by standard ruler */
9077
9078 void
9079comp_col()
9080{
9081#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9082 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9083
9084 sc_col = 0;
9085 ru_col = 0;
9086 if (p_ru)
9087 {
9088#ifdef FEAT_STL_OPT
9089 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9090#else
9091 ru_col = COL_RULER + 1;
9092#endif
9093 /* no last status line, adjust sc_col */
9094 if (!last_has_status)
9095 sc_col = ru_col;
9096 }
9097 if (p_sc)
9098 {
9099 sc_col += SHOWCMD_COLS;
9100 if (!p_ru || last_has_status) /* no need for separating space */
9101 ++sc_col;
9102 }
9103 sc_col = Columns - sc_col;
9104 ru_col = Columns - ru_col;
9105 if (sc_col <= 0) /* screen too narrow, will become a mess */
9106 sc_col = 1;
9107 if (ru_col <= 0)
9108 ru_col = 1;
9109#else
9110 sc_col = Columns;
9111 ru_col = Columns;
9112#endif
9113}
9114
9115/*
9116 * Get pointer to option variable, depending on local or global scope.
9117 */
9118 static char_u *
9119get_varp_scope(p, opt_flags)
9120 struct vimoption *p;
9121 int opt_flags;
9122{
9123 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9124 {
9125 if (p->var == VAR_WIN)
9126 return (char_u *)GLOBAL_WO(get_varp(p));
9127 return p->var;
9128 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009129 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 {
9131 switch ((int)p->indir)
9132 {
9133#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009134 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9135 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9136 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009138 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9139 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9140 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009141 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009142 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009144 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9145 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009146#endif
9147#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009148 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9149 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009151#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9152 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9153#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009154#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009155 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 }
9158 return NULL; /* "cannot happen" */
9159 }
9160 return get_varp(p);
9161}
9162
9163/*
9164 * Get pointer to option variable.
9165 */
9166 static char_u *
9167get_varp(p)
9168 struct vimoption *p;
9169{
9170 /* hidden option, always return NULL */
9171 if (p->var == NULL)
9172 return NULL;
9173
9174 switch ((int)p->indir)
9175 {
9176 case PV_NONE: return p->var;
9177
9178 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009179 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009181 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009182 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009183 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009184 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009185 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009187 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9189#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009190 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009191 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009192 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9194#endif
9195#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009196 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009198 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009199 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9200#endif
9201#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009202 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009204 case PV_GP: return *curbuf->b_p_gp != NUL
9205 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9206 case PV_MP: return *curbuf->b_p_mp != NUL
9207 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009209#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9210 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9211 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9212#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009213#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009214 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009215 ? (char_u *)&(curwin->w_p_stl) : p->var;
9216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217
9218#ifdef FEAT_ARABIC
9219 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9220#endif
9221 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009222#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009223 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9224#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009225#ifdef FEAT_SYN_HL
9226 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9227 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229#ifdef FEAT_DIFF
9230 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9231#endif
9232#ifdef FEAT_FOLDING
9233 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9234 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9235 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9236 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9237 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9238 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9239 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9240# ifdef FEAT_EVAL
9241 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9242 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9243# endif
9244 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9245#endif
9246 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009247 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009248#ifdef FEAT_LINEBREAK
9249 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009251#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009252 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9253#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009254#ifdef FEAT_VERTSPLIT
9255 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9256#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009257#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9258 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9259#endif
9260#ifdef FEAT_RIGHTLEFT
9261 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9262 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9263#endif
9264 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9265 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9266#ifdef FEAT_LINEBREAK
9267 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9268#endif
9269#ifdef FEAT_SCROLLBIND
9270 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9271#endif
9272
9273 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9274 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9275#ifdef FEAT_MBYTE
9276 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9277#endif
9278#if defined(FEAT_QUICKFIX)
9279 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9280 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9281#endif
9282 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9283 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9284#ifdef FEAT_CINDENT
9285 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9286 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9287 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9288#endif
9289#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9290 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9291#endif
9292#ifdef FEAT_COMMENTS
9293 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9294#endif
9295#ifdef FEAT_FOLDING
9296 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9297#endif
9298#ifdef FEAT_INS_EXPAND
9299 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9300#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009301#ifdef FEAT_COMPL_FUNC
9302 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009303 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9306 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9307#ifdef FEAT_MBYTE
9308 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9309#endif
9310 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9311#ifdef FEAT_AUTOCMD
9312 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9313#endif
9314 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009315 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9317 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9318 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9319 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9320#ifdef FEAT_FIND_ID
9321# ifdef FEAT_EVAL
9322 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9323# endif
9324#endif
9325#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9326 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9327 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9328#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009329#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009330 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332#ifdef FEAT_CRYPT
9333 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9334#endif
9335#ifdef FEAT_LISP
9336 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9337#endif
9338 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9339 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9340 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9341 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9342 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9343#ifdef FEAT_OSFILETYPE
9344 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9345#endif
9346 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009347#ifdef FEAT_TEXTOBJ
9348 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9351#ifdef FEAT_SMARTINDENT
9352 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9353#endif
9354#ifndef SHORT_FNAME
9355 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9356#endif
9357 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9358#ifdef FEAT_SEARCHPATH
9359 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9360#endif
9361 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009363 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009364 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9365#endif
9366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009367 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009368 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009369 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370#endif
9371 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9372 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9373 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9374 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9375 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9376#ifdef FEAT_KEYMAP
9377 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9378#endif
9379 default: EMSG(_("E356: get_varp ERROR"));
9380 }
9381 /* always return a valid pointer to avoid a crash! */
9382 return (char_u *)&(curbuf->b_p_wm);
9383}
9384
9385/*
9386 * Get the value of 'equalprg', either the buffer-local one or the global one.
9387 */
9388 char_u *
9389get_equalprg()
9390{
9391 if (*curbuf->b_p_ep == NUL)
9392 return p_ep;
9393 return curbuf->b_p_ep;
9394}
9395
9396#if defined(FEAT_WINDOWS) || defined(PROTO)
9397/*
9398 * Copy options from one window to another.
9399 * Used when splitting a window.
9400 */
9401 void
9402win_copy_options(wp_from, wp_to)
9403 win_T *wp_from;
9404 win_T *wp_to;
9405{
9406 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9407 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9408# ifdef FEAT_RIGHTLEFT
9409# ifdef FEAT_FKMAP
9410 /* Is this right? */
9411 wp_to->w_farsi = wp_from->w_farsi;
9412# endif
9413# endif
9414}
9415#endif
9416
9417/*
9418 * Copy the options from one winopt_T to another.
9419 * Doesn't free the old option values in "to", use clear_winopt() for that.
9420 * The 'scroll' option is not copied, because it depends on the window height.
9421 * The 'previewwindow' option is reset, there can be only one preview window.
9422 */
9423 void
9424copy_winopt(from, to)
9425 winopt_T *from;
9426 winopt_T *to;
9427{
9428#ifdef FEAT_ARABIC
9429 to->wo_arab = from->wo_arab;
9430#endif
9431 to->wo_list = from->wo_list;
9432 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009433 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009434#ifdef FEAT_LINEBREAK
9435 to->wo_nuw = from->wo_nuw;
9436#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009437#ifdef FEAT_RIGHTLEFT
9438 to->wo_rl = from->wo_rl;
9439 to->wo_rlc = vim_strsave(from->wo_rlc);
9440#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009441#ifdef FEAT_STL_OPT
9442 to->wo_stl = vim_strsave(from->wo_stl);
9443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444 to->wo_wrap = from->wo_wrap;
9445#ifdef FEAT_LINEBREAK
9446 to->wo_lbr = from->wo_lbr;
9447#endif
9448#ifdef FEAT_SCROLLBIND
9449 to->wo_scb = from->wo_scb;
9450#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009451#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009452 to->wo_spell = from->wo_spell;
9453#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009454#ifdef FEAT_SYN_HL
9455 to->wo_cuc = from->wo_cuc;
9456 to->wo_cul = from->wo_cul;
9457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458#ifdef FEAT_DIFF
9459 to->wo_diff = from->wo_diff;
9460#endif
9461#ifdef FEAT_FOLDING
9462 to->wo_fdc = from->wo_fdc;
9463 to->wo_fen = from->wo_fen;
9464 to->wo_fdi = vim_strsave(from->wo_fdi);
9465 to->wo_fml = from->wo_fml;
9466 to->wo_fdl = from->wo_fdl;
9467 to->wo_fdm = vim_strsave(from->wo_fdm);
9468 to->wo_fdn = from->wo_fdn;
9469# ifdef FEAT_EVAL
9470 to->wo_fde = vim_strsave(from->wo_fde);
9471 to->wo_fdt = vim_strsave(from->wo_fdt);
9472# endif
9473 to->wo_fmr = vim_strsave(from->wo_fmr);
9474#endif
9475 check_winopt(to); /* don't want NULL pointers */
9476}
9477
9478/*
9479 * Check string options in a window for a NULL value.
9480 */
9481 void
9482check_win_options(win)
9483 win_T *win;
9484{
9485 check_winopt(&win->w_onebuf_opt);
9486 check_winopt(&win->w_allbuf_opt);
9487}
9488
9489/*
9490 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9491 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009492 void
9493check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009494 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495{
9496#ifdef FEAT_FOLDING
9497 check_string_option(&wop->wo_fdi);
9498 check_string_option(&wop->wo_fdm);
9499# ifdef FEAT_EVAL
9500 check_string_option(&wop->wo_fde);
9501 check_string_option(&wop->wo_fdt);
9502# endif
9503 check_string_option(&wop->wo_fmr);
9504#endif
9505#ifdef FEAT_RIGHTLEFT
9506 check_string_option(&wop->wo_rlc);
9507#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009508#ifdef FEAT_STL_OPT
9509 check_string_option(&wop->wo_stl);
9510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009511}
9512
9513/*
9514 * Free the allocated memory inside a winopt_T.
9515 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009516 void
9517clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009518 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009519{
9520#ifdef FEAT_FOLDING
9521 clear_string_option(&wop->wo_fdi);
9522 clear_string_option(&wop->wo_fdm);
9523# ifdef FEAT_EVAL
9524 clear_string_option(&wop->wo_fde);
9525 clear_string_option(&wop->wo_fdt);
9526# endif
9527 clear_string_option(&wop->wo_fmr);
9528#endif
9529#ifdef FEAT_RIGHTLEFT
9530 clear_string_option(&wop->wo_rlc);
9531#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009532#ifdef FEAT_STL_OPT
9533 clear_string_option(&wop->wo_stl);
9534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535}
9536
9537/*
9538 * Copy global option values to local options for one buffer.
9539 * Used when creating a new buffer and sometimes when entering a buffer.
9540 * flags:
9541 * BCO_ENTER We will enter the buf buffer.
9542 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9543 * appropriate.
9544 * BCO_NOHELP Don't copy the values to a help buffer.
9545 */
9546 void
9547buf_copy_options(buf, flags)
9548 buf_T *buf;
9549 int flags;
9550{
9551 int should_copy = TRUE;
9552 char_u *save_p_isk = NULL; /* init for GCC */
9553 int dont_do_help;
9554 int did_isk = FALSE;
9555
9556 /*
9557 * Don't do anything of the buffer is invalid.
9558 */
9559 if (buf == NULL || !buf_valid(buf))
9560 return;
9561
9562 /*
9563 * Skip this when the option defaults have not been set yet. Happens when
9564 * main() allocates the first buffer.
9565 */
9566 if (p_cpo != NULL)
9567 {
9568 /*
9569 * Always copy when entering and 'cpo' contains 'S'.
9570 * Don't copy when already initialized.
9571 * Don't copy when 'cpo' contains 's' and not entering.
9572 * 'S' BCO_ENTER initialized 's' should_copy
9573 * yes yes X X TRUE
9574 * yes no yes X FALSE
9575 * no X yes X FALSE
9576 * X no no yes FALSE
9577 * X no no no TRUE
9578 * no yes no X TRUE
9579 */
9580 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9581 && (buf->b_p_initialized
9582 || (!(flags & BCO_ENTER)
9583 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9584 should_copy = FALSE;
9585
9586 if (should_copy || (flags & BCO_ALWAYS))
9587 {
9588 /* Don't copy the options specific to a help buffer when
9589 * BCO_NOHELP is given or the options were initialized already
9590 * (jumping back to a help file with CTRL-T or CTRL-O) */
9591 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9592 || buf->b_p_initialized;
9593 if (dont_do_help) /* don't free b_p_isk */
9594 {
9595 save_p_isk = buf->b_p_isk;
9596 buf->b_p_isk = NULL;
9597 }
9598 /*
9599 * Always free the allocated strings.
9600 * If not already initialized, set 'readonly' and copy 'fileformat'.
9601 */
9602 if (!buf->b_p_initialized)
9603 {
9604 free_buf_options(buf, TRUE);
9605 buf->b_p_ro = FALSE; /* don't copy readonly */
9606 buf->b_p_tx = p_tx;
9607#ifdef FEAT_MBYTE
9608 buf->b_p_fenc = vim_strsave(p_fenc);
9609#endif
9610 buf->b_p_ff = vim_strsave(p_ff);
9611#if defined(FEAT_QUICKFIX)
9612 buf->b_p_bh = empty_option;
9613 buf->b_p_bt = empty_option;
9614#endif
9615 }
9616 else
9617 free_buf_options(buf, FALSE);
9618
9619 buf->b_p_ai = p_ai;
9620 buf->b_p_ai_nopaste = p_ai_nopaste;
9621 buf->b_p_sw = p_sw;
9622 buf->b_p_tw = p_tw;
9623 buf->b_p_tw_nopaste = p_tw_nopaste;
9624 buf->b_p_tw_nobin = p_tw_nobin;
9625 buf->b_p_wm = p_wm;
9626 buf->b_p_wm_nopaste = p_wm_nopaste;
9627 buf->b_p_wm_nobin = p_wm_nobin;
9628 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009629#ifdef FEAT_MBYTE
9630 buf->b_p_bomb = p_bomb;
9631#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 buf->b_p_et = p_et;
9633 buf->b_p_et_nobin = p_et_nobin;
9634 buf->b_p_ml = p_ml;
9635 buf->b_p_ml_nobin = p_ml_nobin;
9636 buf->b_p_inf = p_inf;
9637 buf->b_p_swf = p_swf;
9638#ifdef FEAT_INS_EXPAND
9639 buf->b_p_cpt = vim_strsave(p_cpt);
9640#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009641#ifdef FEAT_COMPL_FUNC
9642 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009643 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 buf->b_p_sts = p_sts;
9646 buf->b_p_sts_nopaste = p_sts_nopaste;
9647#ifndef SHORT_FNAME
9648 buf->b_p_sn = p_sn;
9649#endif
9650#ifdef FEAT_COMMENTS
9651 buf->b_p_com = vim_strsave(p_com);
9652#endif
9653#ifdef FEAT_FOLDING
9654 buf->b_p_cms = vim_strsave(p_cms);
9655#endif
9656 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009657 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658 buf->b_p_nf = vim_strsave(p_nf);
9659 buf->b_p_mps = vim_strsave(p_mps);
9660#ifdef FEAT_SMARTINDENT
9661 buf->b_p_si = p_si;
9662#endif
9663 buf->b_p_ci = p_ci;
9664#ifdef FEAT_CINDENT
9665 buf->b_p_cin = p_cin;
9666 buf->b_p_cink = vim_strsave(p_cink);
9667 buf->b_p_cino = vim_strsave(p_cino);
9668#endif
9669#ifdef FEAT_AUTOCMD
9670 /* Don't copy 'filetype', it must be detected */
9671 buf->b_p_ft = empty_option;
9672#endif
9673#ifdef FEAT_OSFILETYPE
9674 buf->b_p_oft = vim_strsave(p_oft);
9675#endif
9676 buf->b_p_pi = p_pi;
9677#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9678 buf->b_p_cinw = vim_strsave(p_cinw);
9679#endif
9680#ifdef FEAT_LISP
9681 buf->b_p_lisp = p_lisp;
9682#endif
9683#ifdef FEAT_SYN_HL
9684 /* Don't copy 'syntax', it must be set */
9685 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009686 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009687#endif
9688#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009689 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009690 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009691 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009692 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693#endif
9694#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9695 buf->b_p_inde = vim_strsave(p_inde);
9696 buf->b_p_indk = vim_strsave(p_indk);
9697#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009698#if defined(FEAT_EVAL)
9699 buf->b_p_fex = vim_strsave(p_fex);
9700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701#ifdef FEAT_CRYPT
9702 buf->b_p_key = vim_strsave(p_key);
9703#endif
9704#ifdef FEAT_SEARCHPATH
9705 buf->b_p_sua = vim_strsave(p_sua);
9706#endif
9707#ifdef FEAT_KEYMAP
9708 buf->b_p_keymap = vim_strsave(p_keymap);
9709 buf->b_kmap_state |= KEYMAP_INIT;
9710#endif
9711 /* This isn't really an option, but copying the langmap and IME
9712 * state from the current buffer is better than resetting it. */
9713 buf->b_p_iminsert = p_iminsert;
9714 buf->b_p_imsearch = p_imsearch;
9715
9716 /* options that are normally global but also have a local value
9717 * are not copied, start using the global value */
9718 buf->b_p_ar = -1;
9719#ifdef FEAT_QUICKFIX
9720 buf->b_p_gp = empty_option;
9721 buf->b_p_mp = empty_option;
9722 buf->b_p_efm = empty_option;
9723#endif
9724 buf->b_p_ep = empty_option;
9725 buf->b_p_kp = empty_option;
9726 buf->b_p_path = empty_option;
9727 buf->b_p_tags = empty_option;
9728#ifdef FEAT_FIND_ID
9729 buf->b_p_def = empty_option;
9730 buf->b_p_inc = empty_option;
9731# ifdef FEAT_EVAL
9732 buf->b_p_inex = vim_strsave(p_inex);
9733# endif
9734#endif
9735#ifdef FEAT_INS_EXPAND
9736 buf->b_p_dict = empty_option;
9737 buf->b_p_tsr = empty_option;
9738#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009739#ifdef FEAT_TEXTOBJ
9740 buf->b_p_qe = vim_strsave(p_qe);
9741#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009742#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9743 buf->b_p_bexpr = empty_option;
9744#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745
9746 /*
9747 * Don't copy the options set by ex_help(), use the saved values,
9748 * when going from a help buffer to a non-help buffer.
9749 * Don't touch these at all when BCO_NOHELP is used and going from
9750 * or to a help buffer.
9751 */
9752 if (dont_do_help)
9753 buf->b_p_isk = save_p_isk;
9754 else
9755 {
9756 buf->b_p_isk = vim_strsave(p_isk);
9757 did_isk = TRUE;
9758 buf->b_p_ts = p_ts;
9759 buf->b_help = FALSE;
9760#ifdef FEAT_QUICKFIX
9761 if (buf->b_p_bt[0] == 'h')
9762 clear_string_option(&buf->b_p_bt);
9763#endif
9764 buf->b_p_ma = p_ma;
9765 }
9766 }
9767
9768 /*
9769 * When the options should be copied (ignoring BCO_ALWAYS), set the
9770 * flag that indicates that the options have been initialized.
9771 */
9772 if (should_copy)
9773 buf->b_p_initialized = TRUE;
9774 }
9775
9776 check_buf_options(buf); /* make sure we don't have NULLs */
9777 if (did_isk)
9778 (void)buf_init_chartab(buf, FALSE);
9779}
9780
9781/*
9782 * Reset the 'modifiable' option and its default value.
9783 */
9784 void
9785reset_modifiable()
9786{
9787 int opt_idx;
9788
9789 curbuf->b_p_ma = FALSE;
9790 p_ma = FALSE;
9791 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009792 if (opt_idx >= 0)
9793 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009794}
9795
9796/*
9797 * Set the global value for 'iminsert' to the local value.
9798 */
9799 void
9800set_iminsert_global()
9801{
9802 p_iminsert = curbuf->b_p_iminsert;
9803}
9804
9805/*
9806 * Set the global value for 'imsearch' to the local value.
9807 */
9808 void
9809set_imsearch_global()
9810{
9811 p_imsearch = curbuf->b_p_imsearch;
9812}
9813
9814#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9815static int expand_option_idx = -1;
9816static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9817static int expand_option_flags = 0;
9818
9819 void
9820set_context_in_set_cmd(xp, arg, opt_flags)
9821 expand_T *xp;
9822 char_u *arg;
9823 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9824{
9825 int nextchar;
9826 long_u flags = 0; /* init for GCC */
9827 int opt_idx = 0; /* init for GCC */
9828 char_u *p;
9829 char_u *s;
9830 int is_term_option = FALSE;
9831 int key;
9832
9833 expand_option_flags = opt_flags;
9834
9835 xp->xp_context = EXPAND_SETTINGS;
9836 if (*arg == NUL)
9837 {
9838 xp->xp_pattern = arg;
9839 return;
9840 }
9841 p = arg + STRLEN(arg) - 1;
9842 if (*p == ' ' && *(p - 1) != '\\')
9843 {
9844 xp->xp_pattern = p + 1;
9845 return;
9846 }
9847 while (p > arg)
9848 {
9849 s = p;
9850 /* count number of backslashes before ' ' or ',' */
9851 if (*p == ' ' || *p == ',')
9852 {
9853 while (s > arg && *(s - 1) == '\\')
9854 --s;
9855 }
9856 /* break at a space with an even number of backslashes */
9857 if (*p == ' ' && ((p - s) & 1) == 0)
9858 {
9859 ++p;
9860 break;
9861 }
9862 --p;
9863 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00009864 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 {
9866 xp->xp_context = EXPAND_BOOL_SETTINGS;
9867 p += 2;
9868 }
9869 if (STRNCMP(p, "inv", 3) == 0)
9870 {
9871 xp->xp_context = EXPAND_BOOL_SETTINGS;
9872 p += 3;
9873 }
9874 xp->xp_pattern = arg = p;
9875 if (*arg == '<')
9876 {
9877 while (*p != '>')
9878 if (*p++ == NUL) /* expand terminal option name */
9879 return;
9880 key = get_special_key_code(arg + 1);
9881 if (key == 0) /* unknown name */
9882 {
9883 xp->xp_context = EXPAND_NOTHING;
9884 return;
9885 }
9886 nextchar = *++p;
9887 is_term_option = TRUE;
9888 expand_option_name[2] = KEY2TERMCAP0(key);
9889 expand_option_name[3] = KEY2TERMCAP1(key);
9890 }
9891 else
9892 {
9893 if (p[0] == 't' && p[1] == '_')
9894 {
9895 p += 2;
9896 if (*p != NUL)
9897 ++p;
9898 if (*p == NUL)
9899 return; /* expand option name */
9900 nextchar = *++p;
9901 is_term_option = TRUE;
9902 expand_option_name[2] = p[-2];
9903 expand_option_name[3] = p[-1];
9904 }
9905 else
9906 {
9907 /* Allow * wildcard */
9908 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9909 p++;
9910 if (*p == NUL)
9911 return;
9912 nextchar = *p;
9913 *p = NUL;
9914 opt_idx = findoption(arg);
9915 *p = nextchar;
9916 if (opt_idx == -1 || options[opt_idx].var == NULL)
9917 {
9918 xp->xp_context = EXPAND_NOTHING;
9919 return;
9920 }
9921 flags = options[opt_idx].flags;
9922 if (flags & P_BOOL)
9923 {
9924 xp->xp_context = EXPAND_NOTHING;
9925 return;
9926 }
9927 }
9928 }
9929 /* handle "-=" and "+=" */
9930 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9931 {
9932 ++p;
9933 nextchar = '=';
9934 }
9935 if ((nextchar != '=' && nextchar != ':')
9936 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9937 {
9938 xp->xp_context = EXPAND_UNSUCCESSFUL;
9939 return;
9940 }
9941 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9942 {
9943 xp->xp_context = EXPAND_OLD_SETTING;
9944 if (is_term_option)
9945 expand_option_idx = -1;
9946 else
9947 expand_option_idx = opt_idx;
9948 xp->xp_pattern = p + 1;
9949 return;
9950 }
9951 xp->xp_context = EXPAND_NOTHING;
9952 if (is_term_option || (flags & P_NUM))
9953 return;
9954
9955 xp->xp_pattern = p + 1;
9956
9957 if (flags & P_EXPAND)
9958 {
9959 p = options[opt_idx].var;
9960 if (p == (char_u *)&p_bdir
9961 || p == (char_u *)&p_dir
9962 || p == (char_u *)&p_path
9963 || p == (char_u *)&p_rtp
9964#ifdef FEAT_SEARCHPATH
9965 || p == (char_u *)&p_cdpath
9966#endif
9967#ifdef FEAT_SESSION
9968 || p == (char_u *)&p_vdir
9969#endif
9970 )
9971 {
9972 xp->xp_context = EXPAND_DIRECTORIES;
9973 if (p == (char_u *)&p_path
9974#ifdef FEAT_SEARCHPATH
9975 || p == (char_u *)&p_cdpath
9976#endif
9977 )
9978 xp->xp_backslash = XP_BS_THREE;
9979 else
9980 xp->xp_backslash = XP_BS_ONE;
9981 }
9982 else
9983 {
9984 xp->xp_context = EXPAND_FILES;
9985 /* for 'tags' need three backslashes for a space */
9986 if (p == (char_u *)&p_tags)
9987 xp->xp_backslash = XP_BS_THREE;
9988 else
9989 xp->xp_backslash = XP_BS_ONE;
9990 }
9991 }
9992
9993 /* For an option that is a list of file names, find the start of the
9994 * last file name. */
9995 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9996 {
9997 /* count number of backslashes before ' ' or ',' */
9998 if (*p == ' ' || *p == ',')
9999 {
10000 s = p;
10001 while (s > xp->xp_pattern && *(s - 1) == '\\')
10002 --s;
10003 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10004 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10005 {
10006 xp->xp_pattern = p + 1;
10007 break;
10008 }
10009 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010010
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010011#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010012 /* for 'spellsuggest' start at "file:" */
10013 if (options[opt_idx].var == (char_u *)&p_sps
10014 && STRNCMP(p, "file:", 5) == 0)
10015 {
10016 xp->xp_pattern = p + 5;
10017 break;
10018 }
10019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010020 }
10021
10022 return;
10023}
10024
10025 int
10026ExpandSettings(xp, regmatch, num_file, file)
10027 expand_T *xp;
10028 regmatch_T *regmatch;
10029 int *num_file;
10030 char_u ***file;
10031{
10032 int num_normal = 0; /* Nr of matching non-term-code settings */
10033 int num_term = 0; /* Nr of matching terminal code settings */
10034 int opt_idx;
10035 int match;
10036 int count = 0;
10037 char_u *str;
10038 int loop;
10039 int is_term_opt;
10040 char_u name_buf[MAX_KEY_NAME_LEN];
10041 static char *(names[]) = {"all", "termcap"};
10042 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10043
10044 /* do this loop twice:
10045 * loop == 0: count the number of matching options
10046 * loop == 1: copy the matching options into allocated memory
10047 */
10048 for (loop = 0; loop <= 1; ++loop)
10049 {
10050 regmatch->rm_ic = ic;
10051 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10052 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010053 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10054 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10056 {
10057 if (loop == 0)
10058 num_normal++;
10059 else
10060 (*file)[count++] = vim_strsave((char_u *)names[match]);
10061 }
10062 }
10063 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10064 opt_idx++)
10065 {
10066 if (options[opt_idx].var == NULL)
10067 continue;
10068 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10069 && !(options[opt_idx].flags & P_BOOL))
10070 continue;
10071 is_term_opt = istermoption(&options[opt_idx]);
10072 if (is_term_opt && num_normal > 0)
10073 continue;
10074 match = FALSE;
10075 if (vim_regexec(regmatch, str, (colnr_T)0)
10076 || (options[opt_idx].shortname != NULL
10077 && vim_regexec(regmatch,
10078 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10079 match = TRUE;
10080 else if (is_term_opt)
10081 {
10082 name_buf[0] = '<';
10083 name_buf[1] = 't';
10084 name_buf[2] = '_';
10085 name_buf[3] = str[2];
10086 name_buf[4] = str[3];
10087 name_buf[5] = '>';
10088 name_buf[6] = NUL;
10089 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10090 {
10091 match = TRUE;
10092 str = name_buf;
10093 }
10094 }
10095 if (match)
10096 {
10097 if (loop == 0)
10098 {
10099 if (is_term_opt)
10100 num_term++;
10101 else
10102 num_normal++;
10103 }
10104 else
10105 (*file)[count++] = vim_strsave(str);
10106 }
10107 }
10108 /*
10109 * Check terminal key codes, these are not in the option table
10110 */
10111 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10112 {
10113 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10114 {
10115 if (!isprint(str[0]) || !isprint(str[1]))
10116 continue;
10117
10118 name_buf[0] = 't';
10119 name_buf[1] = '_';
10120 name_buf[2] = str[0];
10121 name_buf[3] = str[1];
10122 name_buf[4] = NUL;
10123
10124 match = FALSE;
10125 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10126 match = TRUE;
10127 else
10128 {
10129 name_buf[0] = '<';
10130 name_buf[1] = 't';
10131 name_buf[2] = '_';
10132 name_buf[3] = str[0];
10133 name_buf[4] = str[1];
10134 name_buf[5] = '>';
10135 name_buf[6] = NUL;
10136
10137 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10138 match = TRUE;
10139 }
10140 if (match)
10141 {
10142 if (loop == 0)
10143 num_term++;
10144 else
10145 (*file)[count++] = vim_strsave(name_buf);
10146 }
10147 }
10148
10149 /*
10150 * Check special key names.
10151 */
10152 regmatch->rm_ic = TRUE; /* ignore case here */
10153 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10154 {
10155 name_buf[0] = '<';
10156 STRCPY(name_buf + 1, str);
10157 STRCAT(name_buf, ">");
10158
10159 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10160 {
10161 if (loop == 0)
10162 num_term++;
10163 else
10164 (*file)[count++] = vim_strsave(name_buf);
10165 }
10166 }
10167 }
10168 if (loop == 0)
10169 {
10170 if (num_normal > 0)
10171 *num_file = num_normal;
10172 else if (num_term > 0)
10173 *num_file = num_term;
10174 else
10175 return OK;
10176 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10177 if (*file == NULL)
10178 {
10179 *file = (char_u **)"";
10180 return FAIL;
10181 }
10182 }
10183 }
10184 return OK;
10185}
10186
10187 int
10188ExpandOldSetting(num_file, file)
10189 int *num_file;
10190 char_u ***file;
10191{
10192 char_u *var = NULL; /* init for GCC */
10193 char_u *buf;
10194
10195 *num_file = 0;
10196 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10197 if (*file == NULL)
10198 return FAIL;
10199
10200 /*
10201 * For a terminal key code expand_option_idx is < 0.
10202 */
10203 if (expand_option_idx < 0)
10204 {
10205 var = find_termcode(expand_option_name + 2);
10206 if (var == NULL)
10207 expand_option_idx = findoption(expand_option_name);
10208 }
10209
10210 if (expand_option_idx >= 0)
10211 {
10212 /* put string of option value in NameBuff */
10213 option_value2string(&options[expand_option_idx], expand_option_flags);
10214 var = NameBuff;
10215 }
10216 else if (var == NULL)
10217 var = (char_u *)"";
10218
10219 /* A backslash is required before some characters. This is the reverse of
10220 * what happens in do_set(). */
10221 buf = vim_strsave_escaped(var, escape_chars);
10222
10223 if (buf == NULL)
10224 {
10225 vim_free(*file);
10226 *file = NULL;
10227 return FAIL;
10228 }
10229
10230#ifdef BACKSLASH_IN_FILENAME
10231 /* For MS-Windows et al. we don't double backslashes at the start and
10232 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010233 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 if (var[0] == '\\' && var[1] == '\\'
10235 && expand_option_idx >= 0
10236 && (options[expand_option_idx].flags & P_EXPAND)
10237 && vim_isfilec(var[2])
10238 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010239 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240#endif
10241
10242 *file[0] = buf;
10243 *num_file = 1;
10244 return OK;
10245}
10246#endif
10247
10248/*
10249 * Get the value for the numeric or string option *opp in a nice format into
10250 * NameBuff[]. Must not be called with a hidden option!
10251 */
10252 static void
10253option_value2string(opp, opt_flags)
10254 struct vimoption *opp;
10255 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10256{
10257 char_u *varp;
10258
10259 varp = get_varp_scope(opp, opt_flags);
10260
10261 if (opp->flags & P_NUM)
10262 {
10263 long wc = 0;
10264
10265 if (wc_use_keyname(varp, &wc))
10266 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10267 else if (wc != 0)
10268 STRCPY(NameBuff, transchar((int)wc));
10269 else
10270 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10271 }
10272 else /* P_STRING */
10273 {
10274 varp = *(char_u **)(varp);
10275 if (varp == NULL) /* just in case */
10276 NameBuff[0] = NUL;
10277#ifdef FEAT_CRYPT
10278 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010279 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280 STRCPY(NameBuff, "*****");
10281#endif
10282 else if (opp->flags & P_EXPAND)
10283 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10284 /* Translate 'pastetoggle' into special key names */
10285 else if ((char_u **)opp->var == &p_pt)
10286 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10287 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010288 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289 }
10290}
10291
10292/*
10293 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10294 * printed as a keyname.
10295 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10296 */
10297 static int
10298wc_use_keyname(varp, wcp)
10299 char_u *varp;
10300 long *wcp;
10301{
10302 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10303 {
10304 *wcp = *(long *)varp;
10305 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10306 return TRUE;
10307 }
10308 return FALSE;
10309}
10310
10311#ifdef FEAT_LANGMAP
10312/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010313 * Any character has an equivalent 'langmap' character. This is used for
10314 * keyboards that have a special language mode that sends characters above
10315 * 128 (although other characters can be translated too). The "to" field is a
10316 * Vim command character. This avoids having to switch the keyboard back to
10317 * ASCII mode when leaving Insert mode.
10318 *
10319 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10320 * commands.
10321 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10322 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10323 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010325# ifdef FEAT_MBYTE
10326/*
10327 * With multi-byte support use growarray for 'langmap' chars >= 256
10328 */
10329typedef struct
10330{
10331 int from;
10332 int to;
10333} langmap_entry_T;
10334
10335static garray_T langmap_mapga;
10336static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337
10338/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010339 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10340 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010342 static void
10343langmap_set_entry(from, to)
10344 int from;
10345 int to;
10346{
10347 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10348 int a = 0;
10349 int b = langmap_mapga.ga_len;
10350
10351 /* Do a binary search for an existing entry. */
10352 while (a != b)
10353 {
10354 int i = (a + b) / 2;
10355 int d = entries[i].from - from;
10356
10357 if (d == 0)
10358 {
10359 entries[i].to = to;
10360 return;
10361 }
10362 if (d < 0)
10363 a = i + 1;
10364 else
10365 b = i;
10366 }
10367
10368 if (ga_grow(&langmap_mapga, 1) != OK)
10369 return; /* out of memory */
10370
10371 /* insert new entry at position "a" */
10372 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10373 mch_memmove(entries + 1, entries,
10374 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10375 ++langmap_mapga.ga_len;
10376 entries[0].from = from;
10377 entries[0].to = to;
10378}
10379
10380/*
10381 * Apply 'langmap' to multi-byte character "c" and return the result.
10382 */
10383 int
10384langmap_adjust_mb(c)
10385 int c;
10386{
10387 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10388 int a = 0;
10389 int b = langmap_mapga.ga_len;
10390
10391 while (a != b)
10392 {
10393 int i = (a + b) / 2;
10394 int d = entries[i].from - c;
10395
10396 if (d == 0)
10397 return entries[i].to; /* found matching entry */
10398 if (d < 0)
10399 a = i + 1;
10400 else
10401 b = i;
10402 }
10403 return c; /* no entry found, return "c" unmodified */
10404}
10405# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406
10407 static void
10408langmap_init()
10409{
10410 int i;
10411
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010412 for (i = 0; i < 256; i++)
10413 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10414# ifdef FEAT_MBYTE
10415 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10416# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417}
10418
10419/*
10420 * Called when langmap option is set; the language map can be
10421 * changed at any time!
10422 */
10423 static void
10424langmap_set()
10425{
10426 char_u *p;
10427 char_u *p2;
10428 int from, to;
10429
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010430#ifdef FEAT_MBYTE
10431 ga_clear(&langmap_mapga); /* clear the previous map first */
10432#endif
10433 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434
10435 for (p = p_langmap; p[0] != NUL; )
10436 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010437 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10438 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439 {
10440 if (p2[0] == '\\' && p2[1] != NUL)
10441 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442 }
10443 if (p2[0] == ';')
10444 ++p2; /* abcd;ABCD form, p2 points to A */
10445 else
10446 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10447 while (p[0])
10448 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010449 if (p[0] == ',')
10450 {
10451 ++p;
10452 break;
10453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454 if (p[0] == '\\' && p[1] != NUL)
10455 ++p;
10456#ifdef FEAT_MBYTE
10457 from = (*mb_ptr2char)(p);
10458#else
10459 from = p[0];
10460#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010461 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462 if (p2 == NULL)
10463 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010464 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010465 if (p[0] != ',')
10466 {
10467 if (p[0] == '\\')
10468 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010470 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010472 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475 }
10476 else
10477 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010478 if (p2[0] != ',')
10479 {
10480 if (p2[0] == '\\')
10481 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010483 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010485 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488 }
10489 if (to == NUL)
10490 {
10491 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10492 transchar(from));
10493 return;
10494 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010495
10496#ifdef FEAT_MBYTE
10497 if (from >= 256)
10498 langmap_set_entry(from, to);
10499 else
10500#endif
10501 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502
10503 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010504 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010505 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010507 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508 if (*p == ';')
10509 {
10510 p = p2;
10511 if (p[0] != NUL)
10512 {
10513 if (p[0] != ',')
10514 {
10515 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10516 return;
10517 }
10518 ++p;
10519 }
10520 break;
10521 }
10522 }
10523 }
10524 }
10525}
10526#endif
10527
10528/*
10529 * Return TRUE if format option 'x' is in effect.
10530 * Take care of no formatting when 'paste' is set.
10531 */
10532 int
10533has_format_option(x)
10534 int x;
10535{
10536 if (p_paste)
10537 return FALSE;
10538 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10539}
10540
10541/*
10542 * Return TRUE if "x" is present in 'shortmess' option, or
10543 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10544 */
10545 int
10546shortmess(x)
10547 int x;
10548{
10549 return ( vim_strchr(p_shm, x) != NULL
10550 || (vim_strchr(p_shm, 'a') != NULL
10551 && vim_strchr((char_u *)SHM_A, x) != NULL));
10552}
10553
10554/*
10555 * paste_option_changed() - Called after p_paste was set or reset.
10556 */
10557 static void
10558paste_option_changed()
10559{
10560 static int old_p_paste = FALSE;
10561 static int save_sm = 0;
10562#ifdef FEAT_CMDL_INFO
10563 static int save_ru = 0;
10564#endif
10565#ifdef FEAT_RIGHTLEFT
10566 static int save_ri = 0;
10567 static int save_hkmap = 0;
10568#endif
10569 buf_T *buf;
10570
10571 if (p_paste)
10572 {
10573 /*
10574 * Paste switched from off to on.
10575 * Save the current values, so they can be restored later.
10576 */
10577 if (!old_p_paste)
10578 {
10579 /* save options for each buffer */
10580 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10581 {
10582 buf->b_p_tw_nopaste = buf->b_p_tw;
10583 buf->b_p_wm_nopaste = buf->b_p_wm;
10584 buf->b_p_sts_nopaste = buf->b_p_sts;
10585 buf->b_p_ai_nopaste = buf->b_p_ai;
10586 }
10587
10588 /* save global options */
10589 save_sm = p_sm;
10590#ifdef FEAT_CMDL_INFO
10591 save_ru = p_ru;
10592#endif
10593#ifdef FEAT_RIGHTLEFT
10594 save_ri = p_ri;
10595 save_hkmap = p_hkmap;
10596#endif
10597 /* save global values for local buffer options */
10598 p_tw_nopaste = p_tw;
10599 p_wm_nopaste = p_wm;
10600 p_sts_nopaste = p_sts;
10601 p_ai_nopaste = p_ai;
10602 }
10603
10604 /*
10605 * Always set the option values, also when 'paste' is set when it is
10606 * already on.
10607 */
10608 /* set options for each buffer */
10609 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10610 {
10611 buf->b_p_tw = 0; /* textwidth is 0 */
10612 buf->b_p_wm = 0; /* wrapmargin is 0 */
10613 buf->b_p_sts = 0; /* softtabstop is 0 */
10614 buf->b_p_ai = 0; /* no auto-indent */
10615 }
10616
10617 /* set global options */
10618 p_sm = 0; /* no showmatch */
10619#ifdef FEAT_CMDL_INFO
10620# ifdef FEAT_WINDOWS
10621 if (p_ru)
10622 status_redraw_all(); /* redraw to remove the ruler */
10623# endif
10624 p_ru = 0; /* no ruler */
10625#endif
10626#ifdef FEAT_RIGHTLEFT
10627 p_ri = 0; /* no reverse insert */
10628 p_hkmap = 0; /* no Hebrew keyboard */
10629#endif
10630 /* set global values for local buffer options */
10631 p_tw = 0;
10632 p_wm = 0;
10633 p_sts = 0;
10634 p_ai = 0;
10635 }
10636
10637 /*
10638 * Paste switched from on to off: Restore saved values.
10639 */
10640 else if (old_p_paste)
10641 {
10642 /* restore options for each buffer */
10643 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10644 {
10645 buf->b_p_tw = buf->b_p_tw_nopaste;
10646 buf->b_p_wm = buf->b_p_wm_nopaste;
10647 buf->b_p_sts = buf->b_p_sts_nopaste;
10648 buf->b_p_ai = buf->b_p_ai_nopaste;
10649 }
10650
10651 /* restore global options */
10652 p_sm = save_sm;
10653#ifdef FEAT_CMDL_INFO
10654# ifdef FEAT_WINDOWS
10655 if (p_ru != save_ru)
10656 status_redraw_all(); /* redraw to draw the ruler */
10657# endif
10658 p_ru = save_ru;
10659#endif
10660#ifdef FEAT_RIGHTLEFT
10661 p_ri = save_ri;
10662 p_hkmap = save_hkmap;
10663#endif
10664 /* set global values for local buffer options */
10665 p_tw = p_tw_nopaste;
10666 p_wm = p_wm_nopaste;
10667 p_sts = p_sts_nopaste;
10668 p_ai = p_ai_nopaste;
10669 }
10670
10671 old_p_paste = p_paste;
10672}
10673
10674/*
10675 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10676 *
10677 * Reset 'compatible' and set the values for options that didn't get set yet
10678 * to the Vim defaults.
10679 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010680 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681 */
10682 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010683vimrc_found(fname, envname)
10684 char_u *fname;
10685 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010687 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010688 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010689 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690
10691 if (!option_was_set((char_u *)"cp"))
10692 {
10693 p_cp = FALSE;
10694 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10695 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10696 set_option_default(opt_idx, OPT_FREE, FALSE);
10697 didset_options();
10698 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010699
10700 if (fname != NULL)
10701 {
10702 p = vim_getenv(envname, &dofree);
10703 if (p == NULL)
10704 {
10705 /* Set $MYVIMRC to the first vimrc file found. */
10706 p = FullName_save(fname, FALSE);
10707 if (p != NULL)
10708 {
10709 vim_setenv(envname, p);
10710 vim_free(p);
10711 }
10712 }
10713 else if (dofree)
10714 vim_free(p);
10715 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716}
10717
10718/*
10719 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10720 */
10721 void
10722change_compatible(on)
10723 int on;
10724{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010725 int opt_idx;
10726
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 if (p_cp != on)
10728 {
10729 p_cp = on;
10730 compatible_set();
10731 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010732 opt_idx = findoption((char_u *)"cp");
10733 if (opt_idx >= 0)
10734 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735}
10736
10737/*
10738 * Return TRUE when option "name" has been set.
10739 */
10740 int
10741option_was_set(name)
10742 char_u *name;
10743{
10744 int idx;
10745
10746 idx = findoption(name);
10747 if (idx < 0) /* unknown option */
10748 return FALSE;
10749 if (options[idx].flags & P_WAS_SET)
10750 return TRUE;
10751 return FALSE;
10752}
10753
10754/*
10755 * compatible_set() - Called when 'compatible' has been set or unset.
10756 *
10757 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10758 * flag) to a Vi compatible value.
10759 * When 'compatible' is unset: Set all options that have a different default
10760 * for Vim (without the P_VI_DEF flag) to that default.
10761 */
10762 static void
10763compatible_set()
10764{
10765 int opt_idx;
10766
10767 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10768 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10769 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10770 set_option_default(opt_idx, OPT_FREE, p_cp);
10771 didset_options();
10772}
10773
10774#ifdef FEAT_LINEBREAK
10775
10776# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10777 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010778 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779# endif
10780
10781/*
10782 * fill_breakat_flags() -- called when 'breakat' changes value.
10783 */
10784 static void
10785fill_breakat_flags()
10786{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010787 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 int i;
10789
10790 for (i = 0; i < 256; i++)
10791 breakat_flags[i] = FALSE;
10792
10793 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010794 for (p = p_breakat; *p; p++)
10795 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796}
10797
10798# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010799 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800# endif
10801
10802#endif
10803
10804/*
10805 * Check an option that can be a range of string values.
10806 *
10807 * Return OK for correct value, FAIL otherwise.
10808 * Empty is always OK.
10809 */
10810 static int
10811check_opt_strings(val, values, list)
10812 char_u *val;
10813 char **values;
10814 int list; /* when TRUE: accept a list of values */
10815{
10816 return opt_strings_flags(val, values, NULL, list);
10817}
10818
10819/*
10820 * Handle an option that can be a range of string values.
10821 * Set a flag in "*flagp" for each string present.
10822 *
10823 * Return OK for correct value, FAIL otherwise.
10824 * Empty is always OK.
10825 */
10826 static int
10827opt_strings_flags(val, values, flagp, list)
10828 char_u *val; /* new value */
10829 char **values; /* array of valid string values */
10830 unsigned *flagp;
10831 int list; /* when TRUE: accept a list of values */
10832{
10833 int i;
10834 int len;
10835 unsigned new_flags = 0;
10836
10837 while (*val)
10838 {
10839 for (i = 0; ; ++i)
10840 {
10841 if (values[i] == NULL) /* val not found in values[] */
10842 return FAIL;
10843
10844 len = (int)STRLEN(values[i]);
10845 if (STRNCMP(values[i], val, len) == 0
10846 && ((list && val[len] == ',') || val[len] == NUL))
10847 {
10848 val += len + (val[len] == ',');
10849 new_flags |= (1 << i);
10850 break; /* check next item in val list */
10851 }
10852 }
10853 }
10854 if (flagp != NULL)
10855 *flagp = new_flags;
10856
10857 return OK;
10858}
10859
10860/*
10861 * Read the 'wildmode' option, fill wim_flags[].
10862 */
10863 static int
10864check_opt_wim()
10865{
10866 char_u new_wim_flags[4];
10867 char_u *p;
10868 int i;
10869 int idx = 0;
10870
10871 for (i = 0; i < 4; ++i)
10872 new_wim_flags[i] = 0;
10873
10874 for (p = p_wim; *p; ++p)
10875 {
10876 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10877 ;
10878 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10879 return FAIL;
10880 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10881 new_wim_flags[idx] |= WIM_LONGEST;
10882 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10883 new_wim_flags[idx] |= WIM_FULL;
10884 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10885 new_wim_flags[idx] |= WIM_LIST;
10886 else
10887 return FAIL;
10888 p += i;
10889 if (*p == NUL)
10890 break;
10891 if (*p == ',')
10892 {
10893 if (idx == 3)
10894 return FAIL;
10895 ++idx;
10896 }
10897 }
10898
10899 /* fill remaining entries with last flag */
10900 while (idx < 3)
10901 {
10902 new_wim_flags[idx + 1] = new_wim_flags[idx];
10903 ++idx;
10904 }
10905
10906 /* only when there are no errors, wim_flags[] is changed */
10907 for (i = 0; i < 4; ++i)
10908 wim_flags[i] = new_wim_flags[i];
10909 return OK;
10910}
10911
10912/*
10913 * Check if backspacing over something is allowed.
10914 */
10915 int
10916can_bs(what)
10917 int what; /* BS_INDENT, BS_EOL or BS_START */
10918{
10919 switch (*p_bs)
10920 {
10921 case '2': return TRUE;
10922 case '1': return (what != BS_START);
10923 case '0': return FALSE;
10924 }
10925 return vim_strchr(p_bs, what) != NULL;
10926}
10927
10928/*
10929 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10930 * the file must be considered changed when the value is different.
10931 */
10932 void
10933save_file_ff(buf)
10934 buf_T *buf;
10935{
10936 buf->b_start_ffc = *buf->b_p_ff;
10937 buf->b_start_eol = buf->b_p_eol;
10938#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010939 buf->b_start_bomb = buf->b_p_bomb;
10940
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 /* Only use free/alloc when necessary, they take time. */
10942 if (buf->b_start_fenc == NULL
10943 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10944 {
10945 vim_free(buf->b_start_fenc);
10946 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10947 }
10948#endif
10949}
10950
10951/*
10952 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10953 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010954 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
10955 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956 * Don't consider a new, empty buffer to be changed.
10957 */
10958 int
10959file_ff_differs(buf)
10960 buf_T *buf;
10961{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000010962 /* In a buffer that was never loaded the options are not valid. */
10963 if (buf->b_flags & BF_NEVERLOADED)
10964 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965 if ((buf->b_flags & BF_NEW)
10966 && buf->b_ml.ml_line_count == 1
10967 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10968 return FALSE;
10969 if (buf->b_start_ffc != *buf->b_p_ff)
10970 return TRUE;
10971 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10972 return TRUE;
10973#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010974 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
10975 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 if (buf->b_start_fenc == NULL)
10977 return (*buf->b_p_fenc != NUL);
10978 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10979#else
10980 return FALSE;
10981#endif
10982}
10983
10984/*
10985 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10986 */
10987 int
10988check_ff_value(p)
10989 char_u *p;
10990{
10991 return check_opt_strings(p, p_ff_values, FALSE);
10992}