blob: d06381cb84acd42301ee2de7ecdc2a44a3ed71d0 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +020080#define PV_CM OPT_BUF(BV_CM)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
143#ifdef FEAT_OSFILETYPE
144# define PV_OFT OPT_BUF(BV_OFT)
145#endif
146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000193#ifdef FEAT_DIFF
194# define PV_DIFF OPT_WIN(WV_DIFF)
195#endif
196#ifdef FEAT_FOLDING
197# define PV_FDC OPT_WIN(WV_FDC)
198# define PV_FEN OPT_WIN(WV_FEN)
199# define PV_FDI OPT_WIN(WV_FDI)
200# define PV_FDL OPT_WIN(WV_FDL)
201# define PV_FDM OPT_WIN(WV_FDM)
202# define PV_FML OPT_WIN(WV_FML)
203# define PV_FDN OPT_WIN(WV_FDN)
204# ifdef FEAT_EVAL
205# define PV_FDE OPT_WIN(WV_FDE)
206# define PV_FDT OPT_WIN(WV_FDT)
207# endif
208# define PV_FMR OPT_WIN(WV_FMR)
209#endif
210#ifdef FEAT_LINEBREAK
211# define PV_LBR OPT_WIN(WV_LBR)
212#endif
213#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200214#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000215#ifdef FEAT_LINEBREAK
216# define PV_NUW OPT_WIN(WV_NUW)
217#endif
218#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
219# define PV_PVW OPT_WIN(WV_PVW)
220#endif
221#ifdef FEAT_RIGHTLEFT
222# define PV_RL OPT_WIN(WV_RL)
223# define PV_RLC OPT_WIN(WV_RLC)
224#endif
225#ifdef FEAT_SCROLLBIND
226# define PV_SCBIND OPT_WIN(WV_SCBIND)
227#endif
228#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000230# define PV_SPELL OPT_WIN(WV_SPELL)
231#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SYN_HL
233# define PV_CUC OPT_WIN(WV_CUC)
234# define PV_CUL OPT_WIN(WV_CUL)
235#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000236#ifdef FEAT_STL_OPT
237# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
238#endif
239#ifdef FEAT_WINDOWS
240# define PV_WFH OPT_WIN(WV_WFH)
241#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000242#ifdef FEAT_VERTSPLIT
243# define PV_WFW OPT_WIN(WV_WFW)
244#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200246#ifdef FEAT_CURSORBIND
247# define PV_CRBIND OPT_WIN(WV_CRBIND)
248#endif
249#ifdef FEAT_CONCEAL
250# define PV_CONCEAL OPT_WIN(WV_CONCEAL)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252
253/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254typedef enum
255{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000256 PV_NONE = 0,
257 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258} idopt_T;
259
260/*
261 * Options local to a window have a value local to a buffer and global to all
262 * buffers. Indicate this by setting "var" to VAR_WIN.
263 */
264#define VAR_WIN ((char_u *)-1)
265
266/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000267 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268 * Only to be used in option.c!
269 */
270static int p_ai;
271static int p_bin;
272#ifdef FEAT_MBYTE
273static int p_bomb;
274#endif
275#if defined(FEAT_QUICKFIX)
276static char_u *p_bh;
277static char_u *p_bt;
278#endif
279static int p_bl;
280static int p_ci;
281#ifdef FEAT_CINDENT
282static int p_cin;
283static char_u *p_cink;
284static char_u *p_cino;
285#endif
286#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
287static char_u *p_cinw;
288#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200289#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200290static long p_cm;
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292#ifdef FEAT_COMMENTS
293static char_u *p_com;
294#endif
295#ifdef FEAT_FOLDING
296static char_u *p_cms;
297#endif
298#ifdef FEAT_INS_EXPAND
299static char_u *p_cpt;
300#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000301#ifdef FEAT_COMPL_FUNC
302static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000303static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305static int p_eol;
306static int p_et;
307#ifdef FEAT_MBYTE
308static char_u *p_fenc;
309#endif
310static char_u *p_ff;
311static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000312static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313#ifdef FEAT_AUTOCMD
314static char_u *p_ft;
315#endif
316static long p_iminsert;
317static long p_imsearch;
318#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
319static char_u *p_inex;
320#endif
321#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
322static char_u *p_inde;
323static char_u *p_indk;
324#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000325#if defined(FEAT_EVAL)
326static char_u *p_fex;
327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000328static int p_inf;
329static char_u *p_isk;
330#ifdef FEAT_CRYPT
331static char_u *p_key;
332#endif
333#ifdef FEAT_LISP
334static int p_lisp;
335#endif
336static int p_ml;
337static int p_ma;
338static int p_mod;
339static char_u *p_mps;
340static char_u *p_nf;
341#ifdef FEAT_OSFILETYPE
342static char_u *p_oft;
343#endif
344static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000345#ifdef FEAT_TEXTOBJ
346static char_u *p_qe;
347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static int p_ro;
349#ifdef FEAT_SMARTINDENT
350static int p_si;
351#endif
352#ifndef SHORT_FNAME
353static int p_sn;
354#endif
355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
388static long p_tw_nopaste;
389static long p_wm_nopaste;
390static long p_sts_nopaste;
391static int p_ai_nopaste;
392
393struct vimoption
394{
395 char *fullname; /* full option name */
396 char *shortname; /* permissible abbreviation */
397 long_u flags; /* see below */
398 char_u *var; /* global option: pointer to variable;
399 * window-local option: VAR_WIN;
400 * buffer-local option: global value */
401 idopt_T indir; /* global option: PV_NONE;
402 * local option: indirect option index */
403 char_u *def_val[2]; /* default values for variable (vi and vim) */
404#ifdef FEAT_EVAL
405 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000406# define SCRIPTID_INIT , 0
407#else
408# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409#endif
410};
411
412#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
413#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
414
415/*
416 * Flags
417 */
418#define P_BOOL 0x01 /* the option is boolean */
419#define P_NUM 0x02 /* the option is numeric */
420#define P_STRING 0x04 /* the option is a string */
421#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000422 must use free_string_option() when
423 assigning new value. Not set if default is
424 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
426 never be used for local or hidden options! */
427#define P_NODEFAULT 0x40 /* don't set to default value */
428#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
429 use vim_free() when assigning new value */
430#define P_WAS_SET 0x100 /* option has been set/reset */
431#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
432#define P_VI_DEF 0x400 /* Use Vi default for Vim */
433#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
434
435 /* when option changed, what to display: */
436#define P_RSTAT 0x1000 /* redraw status lines */
437#define P_RWIN 0x2000 /* redraw current window */
438#define P_RBUF 0x4000 /* redraw current buffer */
439#define P_RALL 0x6000 /* redraw all windows */
440#define P_RCLR 0x7000 /* clear and redraw all */
441
442#define P_COMMA 0x8000 /* comma separated list */
443#define P_NODUP 0x10000L/* don't allow duplicate strings */
444#define P_FLAGLIST 0x20000L/* list of single-char flags */
445
446#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x80000L/* expand default value with _() */
448#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000449#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000450#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000451#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
452 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000454#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
455
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000456/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
457 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000458#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000459# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000460#else
461# define ISP_LATIN1 (char_u *)"@,161-255"
462#endif
463
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000464/* The 16 bit MS-DOS version is low on space, make the string as short as
465 * possible when compiling with few features. */
466#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
467 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200468 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
469# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000470#else
471# 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"
472#endif
473
Bram Moolenaar071d4272004-06-13 20:20:40 +0000474/*
475 * options[] is initialized here.
476 * The order of the options MUST be alphabetic for ":set all" and findoption().
477 * All option names MUST start with a lowercase letter (for findoption()).
478 * Exception: "t_" options are at the end.
479 * The options with a NULL variable are 'hidden': a set command for them is
480 * ignored and they are not printed.
481 */
482static struct vimoption
483#ifdef FEAT_GUI_W16
484 _far
485#endif
486 options[] =
487{
488 {"aleph", "al", P_NUM|P_VI_DEF,
489#ifdef FEAT_RIGHTLEFT
490 (char_u *)&p_aleph, PV_NONE,
491#else
492 (char_u *)NULL, PV_NONE,
493#endif
494 {
495#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
496 (char_u *)128L,
497#else
498 (char_u *)224L,
499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000500 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
502#if defined(FEAT_GUI) && defined(MACOS_X)
503 (char_u *)&p_antialias, PV_NONE,
504 {(char_u *)FALSE, (char_u *)FALSE}
505#else
506 (char_u *)NULL, PV_NONE,
507 {(char_u *)FALSE, (char_u *)FALSE}
508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000509 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
511#ifdef FEAT_ARABIC
512 (char_u *)VAR_WIN, PV_ARAB,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000516 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
518#ifdef FEAT_ARABIC
519 (char_u *)&p_arshape, PV_NONE,
520#else
521 (char_u *)NULL, PV_NONE,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
525#ifdef FEAT_RIGHTLEFT
526 (char_u *)&p_ari, PV_NONE,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
532#ifdef FEAT_FKMAP
533 (char_u *)&p_altkeymap, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
539#if defined(FEAT_MBYTE)
540 (char_u *)&p_ambw, PV_NONE,
541 {(char_u *)"single", (char_u *)0L}
542#else
543 (char_u *)NULL, PV_NONE,
544 {(char_u *)0L, (char_u *)0L}
545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000547#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000548 {"autochdir", "acd", P_BOOL|P_VI_DEF,
549 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551#endif
552 {"autoindent", "ai", P_BOOL|P_VI_DEF,
553 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autoprint", "ap", P_BOOL|P_VI_DEF,
556 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000559 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"autowrite", "aw", P_BOOL|P_VI_DEF,
562 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autowriteall","awa", P_BOOL|P_VI_DEF,
565 (char_u *)&p_awa, 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 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
568 (char_u *)&p_bg, PV_NONE,
569 {
570#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
571 (char_u *)"dark",
572#else
573 (char_u *)"light",
574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
577 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
580 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
583 (char_u *)&p_bkc, PV_NONE,
584#ifdef UNIX
585 {(char_u *)"yes", (char_u *)"auto"}
586#else
587 {(char_u *)"auto", (char_u *)"auto"}
588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
591 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000593 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 (char_u *)&p_bex, PV_NONE,
595 {
596#ifdef VMS
597 (char_u *)"_",
598#else
599 (char_u *)"~",
600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
603#ifdef FEAT_WILDIGN
604 (char_u *)&p_bsk, PV_NONE,
605 {(char_u *)"", (char_u *)0L}
606#else
607 (char_u *)NULL, PV_NONE,
608 {(char_u *)0L, (char_u *)0L}
609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_BEVAL
612 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
613 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000614 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
616 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000618# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000619 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000620 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000621 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623#endif
624 {"beautify", "bf", P_BOOL|P_VI_DEF,
625 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
628 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
631#ifdef MSDOS
632 (char_u *)&p_biosk, PV_NONE,
633#else
634 (char_u *)NULL, PV_NONE,
635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000636 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
638#ifdef FEAT_MBYTE
639 (char_u *)&p_bomb, PV_BOMB,
640#else
641 (char_u *)NULL, PV_NONE,
642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
645#ifdef FEAT_LINEBREAK
646 (char_u *)&p_breakat, PV_NONE,
647 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
648#else
649 (char_u *)NULL, PV_NONE,
650 {(char_u *)0L, (char_u *)0L}
651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
654#ifdef FEAT_BROWSE
655 (char_u *)&p_bsdir, PV_NONE,
656 {(char_u *)"last", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
663#if defined(FEAT_QUICKFIX)
664 (char_u *)&p_bh, PV_BH,
665 {(char_u *)"", (char_u *)0L}
666#else
667 (char_u *)NULL, PV_NONE,
668 {(char_u *)0L, (char_u *)0L}
669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
672 (char_u *)&p_bl, PV_BL,
673 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
676#if defined(FEAT_QUICKFIX)
677 (char_u *)&p_bt, PV_BT,
678 {(char_u *)"", (char_u *)0L}
679#else
680 (char_u *)NULL, PV_NONE,
681 {(char_u *)0L, (char_u *)0L}
682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000683 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000685#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000686 (char_u *)&p_cmp, PV_NONE,
687 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
694#ifdef FEAT_SEARCHPATH
695 (char_u *)&p_cdpath, PV_NONE,
696 {(char_u *)",,", (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {"cedit", NULL, P_STRING,
703#ifdef FEAT_CMDWIN
704 (char_u *)&p_cedit, PV_NONE,
705 {(char_u *)"", (char_u *)CTRL_F_STR}
706#else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)0L, (char_u *)0L}
709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000710 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
712#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
713 (char_u *)&p_ccv, PV_NONE,
714 {(char_u *)"", (char_u *)0L}
715#else
716 (char_u *)NULL, PV_NONE,
717 {(char_u *)0L, (char_u *)0L}
718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000719 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
721#ifdef FEAT_CINDENT
722 (char_u *)&p_cin, PV_CIN,
723#else
724 (char_u *)NULL, PV_NONE,
725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
728#ifdef FEAT_CINDENT
729 (char_u *)&p_cink, PV_CINK,
730 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
737#ifdef FEAT_CINDENT
738 (char_u *)&p_cino, PV_CINO,
739#else
740 (char_u *)NULL, PV_NONE,
741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000742 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
744#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
745 (char_u *)&p_cinw, PV_CINW,
746 {(char_u *)"if,else,while,do,for,switch",
747 (char_u *)0L}
748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
754#ifdef FEAT_CLIPBOARD
755 (char_u *)&p_cb, PV_NONE,
756# ifdef FEAT_XCLIPBOARD
757 {(char_u *)"autoselect,exclude:cons\\|linux",
758 (char_u *)0L}
759# else
760 {(char_u *)"", (char_u *)0L}
761# endif
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)"", (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
768 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
771#ifdef FEAT_CMDWIN
772 (char_u *)&p_cwh, PV_NONE,
773#else
774 (char_u *)NULL, PV_NONE,
775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000776 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
778 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000779 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
781#ifdef FEAT_COMMENTS
782 (char_u *)&p_com, PV_COM,
783 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
784 (char_u *)0L}
785#else
786 (char_u *)NULL, PV_NONE,
787 {(char_u *)0L, (char_u *)0L}
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
791#ifdef FEAT_FOLDING
792 (char_u *)&p_cms, PV_CMS,
793 {(char_u *)"/*%s*/", (char_u *)0L}
794#else
795 (char_u *)NULL, PV_NONE,
796 {(char_u *)0L, (char_u *)0L}
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000799 /* P_PRI_MKRC isn't needed here, optval_default()
800 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"compatible", "cp", P_BOOL|P_RALL,
802 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
805#ifdef FEAT_INS_EXPAND
806 (char_u *)&p_cpt, PV_CPT,
807 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
808#else
809 (char_u *)NULL, PV_NONE,
810 {(char_u *)0L, (char_u *)0L}
811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000812 SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200813 {"conceallevel","conc", P_NUM|P_RWIN|P_VI_DEF,
814#ifdef FEAT_CONCEAL
815 (char_u *)VAR_WIN, PV_CONCEAL,
816#else
817 (char_u *)NULL, PV_NONE,
818#endif
819 {(char_u *)0L, (char_u *)0L}
820 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000821 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
822#ifdef FEAT_COMPL_FUNC
823 (char_u *)&p_cfu, PV_CFU,
824 {(char_u *)"", (char_u *)0L}
825#else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000830 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
831#ifdef FEAT_INS_EXPAND
832 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000833 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000834#else
835 (char_u *)NULL, PV_NONE,
836 {(char_u *)0L, (char_u *)0L}
837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"confirm", "cf", P_BOOL|P_VI_DEF,
840#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
841 (char_u *)&p_confirm, PV_NONE,
842#else
843 (char_u *)NULL, PV_NONE,
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846 {"conskey", "consk",P_BOOL|P_VI_DEF,
847#ifdef MSDOS
848 (char_u *)&p_consk, PV_NONE,
849#else
850 (char_u *)NULL, PV_NONE,
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
854 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
857 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
859 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200860 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200861#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200862 (char_u *)&p_cm, PV_CM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200863#else
864 (char_u *)NULL, PV_NONE,
865#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200866 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
868#ifdef FEAT_CSCOPE
869 (char_u *)&p_cspc, PV_NONE,
870#else
871 (char_u *)NULL, PV_NONE,
872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000873 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000874 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
875#ifdef FEAT_CSCOPE
876 (char_u *)&p_csprg, PV_NONE,
877 {(char_u *)"cscope", (char_u *)0L}
878#else
879 (char_u *)NULL, PV_NONE,
880 {(char_u *)0L, (char_u *)0L}
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
884#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
885 (char_u *)&p_csqf, PV_NONE,
886 {(char_u *)"", (char_u *)0L}
887#else
888 (char_u *)NULL, PV_NONE,
889 {(char_u *)0L, (char_u *)0L}
890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
893#ifdef FEAT_CSCOPE
894 (char_u *)&p_cst, PV_NONE,
895#else
896 (char_u *)NULL, PV_NONE,
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
900#ifdef FEAT_CSCOPE
901 (char_u *)&p_csto, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_csverbose, PV_NONE,
909#else
910 (char_u *)NULL, PV_NONE,
911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200913 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
914#ifdef FEAT_CURSORBIND
915 (char_u *)VAR_WIN, PV_CRBIND,
916#else
917 (char_u *)NULL, PV_NONE,
918#endif
919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000920 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
921#ifdef FEAT_SYN_HL
922 (char_u *)VAR_WIN, PV_CUC,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000927 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
928#ifdef FEAT_SYN_HL
929 (char_u *)VAR_WIN, PV_CUL,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"debug", NULL, P_STRING|P_VI_DEF,
935 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000936 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
938#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000939 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000940 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)NULL, (char_u *)0L}
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_MBYTE
948 (char_u *)&p_deco, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
954#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000955 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
961#ifdef FEAT_DIFF
962 (char_u *)VAR_WIN, PV_DIFF,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
968#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
969 (char_u *)&p_dex, PV_NONE,
970 {(char_u *)"", (char_u *)0L}
971#else
972 (char_u *)NULL, PV_NONE,
973 {(char_u *)0L, (char_u *)0L}
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
977#ifdef FEAT_DIFF
978 (char_u *)&p_dip, PV_NONE,
979 {(char_u *)"filler", (char_u *)NULL}
980#else
981 (char_u *)NULL, PV_NONE,
982 {(char_u *)"", (char_u *)NULL}
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
986#ifdef FEAT_DIGRAPHS
987 (char_u *)&p_dg, PV_NONE,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
993 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
996 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998 {"eadirection", "ead", P_STRING|P_VI_DEF,
999#ifdef FEAT_VERTSPLIT
1000 (char_u *)&p_ead, PV_NONE,
1001 {(char_u *)"both", (char_u *)0L}
1002#else
1003 (char_u *)NULL, PV_NONE,
1004 {(char_u *)NULL, (char_u *)0L}
1005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1008 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
1011#ifdef FEAT_MBYTE
1012 (char_u *)&p_enc, PV_NONE,
1013 {(char_u *)ENC_DFLT, (char_u *)0L}
1014#else
1015 (char_u *)NULL, PV_NONE,
1016 {(char_u *)0L, (char_u *)0L}
1017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001018 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1020 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1023 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001026 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1029 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1032#ifdef FEAT_QUICKFIX
1033 (char_u *)&p_ef, PV_NONE,
1034 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)NULL, (char_u *)0L}
1038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1041#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001042 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044#else
1045 (char_u *)NULL, PV_NONE,
1046 {(char_u *)NULL, (char_u *)0L}
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"esckeys", "ek", P_BOOL|P_VIM,
1050 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1053#ifdef FEAT_AUTOCMD
1054 (char_u *)&p_ei, PV_NONE,
1055#else
1056 (char_u *)NULL, PV_NONE,
1057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001058 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1060 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1063 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1066#ifdef FEAT_MBYTE
1067 (char_u *)&p_fenc, PV_FENC,
1068 {(char_u *)"", (char_u *)0L}
1069#else
1070 (char_u *)NULL, PV_NONE,
1071 {(char_u *)0L, (char_u *)0L}
1072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1075#ifdef FEAT_MBYTE
1076 (char_u *)&p_fencs, PV_NONE,
1077 {(char_u *)"ucs-bom", (char_u *)0L}
1078#else
1079 (char_u *)NULL, PV_NONE,
1080 {(char_u *)0L, (char_u *)0L}
1081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1084 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1087 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1089 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001090 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#ifdef FEAT_AUTOCMD
1092 (char_u *)&p_ft, PV_FT,
1093 {(char_u *)"", (char_u *)0L}
1094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)0L, (char_u *)0L}
1097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1100#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1101 (char_u *)&p_fcs, PV_NONE,
1102 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)"", (char_u *)0L}
1106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1109#ifdef FEAT_FKMAP
1110 (char_u *)&p_fkmap, PV_NONE,
1111#else
1112 (char_u *)NULL, PV_NONE,
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"flash", "fl", P_BOOL|P_VI_DEF,
1116 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118#ifdef FEAT_FOLDING
1119 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1120 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1123 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1126 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1129# ifdef FEAT_EVAL
1130 (char_u *)VAR_WIN, PV_FDE,
1131 {(char_u *)"0", (char_u *)NULL}
1132# else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)NULL, (char_u *)0L}
1135# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1138 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1141 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1144 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1147 P_RWIN|P_COMMA|P_NODUP,
1148 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)"{{{,}}}", (char_u *)NULL}
1150 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1152 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1155 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1158 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1161 (char_u *)&p_fdo, PV_NONE,
1162 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1165# ifdef FEAT_EVAL
1166 (char_u *)VAR_WIN, PV_FDT,
1167 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001168# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 (char_u *)NULL, PV_NONE,
1170 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001171# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001174 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001175#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001176 (char_u *)&p_fex, PV_FEX,
1177 {(char_u *)"", (char_u *)0L}
1178#else
1179 (char_u *)NULL, PV_NONE,
1180 {(char_u *)0L, (char_u *)0L}
1181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1184 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1186 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001187 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1188 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1190 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1192 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001194 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1195#ifdef HAVE_FSYNC
1196 (char_u *)&p_fs, PV_NONE,
1197 {(char_u *)TRUE, (char_u *)0L}
1198#else
1199 (char_u *)NULL, PV_NONE,
1200 {(char_u *)FALSE, (char_u *)0L}
1201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1204 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001205 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"graphic", "gr", P_BOOL|P_VI_DEF,
1207 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1210#ifdef FEAT_QUICKFIX
1211 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213#else
1214 (char_u *)NULL, PV_NONE,
1215 {(char_u *)NULL, (char_u *)0L}
1216#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1219#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001220 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {
1222# ifdef WIN3264
1223 /* may be changed to "grep -n" in os_win32.c */
1224 (char_u *)"findstr /n",
1225# else
1226# ifdef UNIX
1227 /* Add an extra file name so that grep will always
1228 * insert a file name in the match line. */
1229 (char_u *)"grep -n $* /dev/null",
1230# else
1231# ifdef VMS
1232 (char_u *)"SEARCH/NUMBERS ",
1233# else
1234 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001235# endif
1236# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001238 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001244 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1245#ifdef CURSOR_SHAPE
1246 (char_u *)&p_guicursor, PV_NONE,
1247 {
1248# ifdef FEAT_GUI
1249 (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",
1250# else /* MSDOS or Win32 console */
1251 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1252# endif
1253 (char_u *)0L}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1260#ifdef FEAT_GUI
1261 (char_u *)&p_guifont, PV_NONE,
1262 {(char_u *)"", (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1269#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1270 (char_u *)&p_guifontset, PV_NONE,
1271 {(char_u *)"", (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1278#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1279 (char_u *)&p_guifontwide, PV_NONE,
1280 {(char_u *)"", (char_u *)0L}
1281#else
1282 (char_u *)NULL, PV_NONE,
1283 {(char_u *)NULL, (char_u *)0L}
1284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001287#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 (char_u *)&p_ghr, PV_NONE,
1289#else
1290 (char_u *)NULL, PV_NONE,
1291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001294#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 (char_u *)&p_go, PV_NONE,
1296# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001297 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001299 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300# endif
1301#else
1302 (char_u *)NULL, PV_NONE,
1303 {(char_u *)NULL, (char_u *)0L}
1304#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306 {"guipty", NULL, P_BOOL|P_VI_DEF,
1307#if defined(FEAT_GUI)
1308 (char_u *)&p_guipty, PV_NONE,
1309#else
1310 (char_u *)NULL, PV_NONE,
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001313 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001314#if defined(FEAT_GUI_TABLINE)
1315 (char_u *)&p_gtl, PV_NONE,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)NULL, (char_u *)0L}
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001322 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001323#if defined(FEAT_GUI_TABLINE)
1324 (char_u *)&p_gtt, PV_NONE,
1325 {(char_u *)"", (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1332 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1335 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1337 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"helpheight", "hh", P_NUM|P_VI_DEF,
1339#ifdef FEAT_WINDOWS
1340 (char_u *)&p_hh, PV_NONE,
1341#else
1342 (char_u *)NULL, PV_NONE,
1343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1346#ifdef FEAT_MULTI_LANG
1347 (char_u *)&p_hlg, PV_NONE,
1348 {(char_u *)"", (char_u *)0L}
1349#else
1350 (char_u *)NULL, PV_NONE,
1351 {(char_u *)0L, (char_u *)0L}
1352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354 {"hidden", "hid", P_BOOL|P_VI_DEF,
1355 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1358 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"history", "hi", P_NUM|P_VIM,
1362 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1365#ifdef FEAT_RIGHTLEFT
1366 (char_u *)&p_hkmap, PV_NONE,
1367#else
1368 (char_u *)NULL, PV_NONE,
1369#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1372#ifdef FEAT_RIGHTLEFT
1373 (char_u *)&p_hkmapp, PV_NONE,
1374#else
1375 (char_u *)NULL, PV_NONE,
1376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1379 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381 {"icon", NULL, P_BOOL|P_VI_DEF,
1382#ifdef FEAT_TITLE
1383 (char_u *)&p_icon, PV_NONE,
1384#else
1385 (char_u *)NULL, PV_NONE,
1386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"iconstring", NULL, P_STRING|P_VI_DEF,
1389#ifdef FEAT_TITLE
1390 (char_u *)&p_iconstring, PV_NONE,
1391#else
1392 (char_u *)NULL, PV_NONE,
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1396 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001399#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 (char_u *)&p_imak, PV_NONE,
1401#else
1402 (char_u *)NULL, PV_NONE,
1403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001404 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1406#ifdef USE_IM_CONTROL
1407 (char_u *)&p_imcmdline, PV_NONE,
1408#else
1409 (char_u *)NULL, PV_NONE,
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1413#ifdef USE_IM_CONTROL
1414 (char_u *)&p_imdisable, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
1418#ifdef __sgi
1419 {(char_u *)TRUE, (char_u *)0L}
1420#else
1421 {(char_u *)FALSE, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"iminsert", "imi", P_NUM|P_VI_DEF,
1425 (char_u *)&p_iminsert, PV_IMI,
1426#ifdef B_IMODE_IM
1427 {(char_u *)B_IMODE_IM, (char_u *)0L}
1428#else
1429 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"imsearch", "ims", P_NUM|P_VI_DEF,
1433 (char_u *)&p_imsearch, PV_IMS,
1434#ifdef B_IMODE_IM
1435 {(char_u *)B_IMODE_IM, (char_u *)0L}
1436#else
1437 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1441#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001442 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1444#else
1445 (char_u *)NULL, PV_NONE,
1446 {(char_u *)0L, (char_u *)0L}
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1450#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1451 (char_u *)&p_inex, PV_INEX,
1452 {(char_u *)"", (char_u *)0L}
1453#else
1454 (char_u *)NULL, PV_NONE,
1455 {(char_u *)0L, (char_u *)0L}
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1459 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001460 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1462#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1463 (char_u *)&p_inde, PV_INDE,
1464 {(char_u *)"", (char_u *)0L}
1465#else
1466 (char_u *)NULL, PV_NONE,
1467 {(char_u *)0L, (char_u *)0L}
1468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001469 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1471#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1472 (char_u *)&p_indk, PV_INDK,
1473 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1474#else
1475 (char_u *)NULL, PV_NONE,
1476 {(char_u *)0L, (char_u *)0L}
1477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"infercase", "inf", P_BOOL|P_VI_DEF,
1480 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001481 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1483 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1486 (char_u *)&p_isf, PV_NONE,
1487 {
1488#ifdef BACKSLASH_IN_FILENAME
1489 /* Excluded are: & and ^ are special in cmd.exe
1490 * ( and ) are used in text separating fnames */
1491 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1492#else
1493# ifdef AMIGA
1494 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1495# else
1496# ifdef VMS
1497 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1498# else /* UNIX et al. */
1499# ifdef EBCDIC
1500 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1501# else
1502 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1503# endif
1504# endif
1505# endif
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1509 (char_u *)&p_isi, PV_NONE,
1510 {
1511#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1512 (char_u *)"@,48-57,_,128-167,224-235",
1513#else
1514# ifdef EBCDIC
1515 /* TODO: EBCDIC Check this! @ == isalpha()*/
1516 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1517 "112-120,128,140-142,156,158,172,"
1518 "174,186,191,203-207,219-225,235-239,"
1519 "251-254",
1520# else
1521 (char_u *)"@,48-57,_,192-255",
1522# endif
1523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1526 (char_u *)&p_isk, PV_ISK,
1527 {
1528#ifdef EBCDIC
1529 (char_u *)"@,240-249,_",
1530 /* TODO: EBCDIC Check this! @ == isalpha()*/
1531 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1532 "112-120,128,140-142,156,158,172,"
1533 "174,186,191,203-207,219-225,235-239,"
1534 "251-254",
1535#else
1536 (char_u *)"@,48-57,_",
1537# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1538 (char_u *)"@,48-57,_,128-167,224-235"
1539# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001540 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541# endif
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1545 (char_u *)&p_isp, PV_NONE,
1546 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001547#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1548 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 || defined(VMS)
1550 (char_u *)"@,~-255",
1551#else
1552# ifdef EBCDIC
1553 /* all chars above 63 are printable */
1554 (char_u *)"63-255",
1555# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001556 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557# endif
1558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1561 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1564#ifdef FEAT_CRYPT
1565 (char_u *)&p_key, PV_KEY,
1566 {(char_u *)"", (char_u *)0L}
1567#else
1568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)0L, (char_u *)0L}
1570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001572 {"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 +00001573#ifdef FEAT_KEYMAP
1574 (char_u *)&p_keymap, PV_KMAP,
1575 {(char_u *)"", (char_u *)0L}
1576#else
1577 (char_u *)NULL, PV_NONE,
1578 {(char_u *)"", (char_u *)0L}
1579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1582#ifdef FEAT_VISUAL
1583 (char_u *)&p_km, 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 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001589 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {
1591#if defined(MSDOS) || defined(MSWIN)
1592 (char_u *)":help",
1593#else
1594#ifdef VMS
1595 (char_u *)"help",
1596#else
1597# if defined(OS2)
1598 (char_u *)"view /",
1599# else
1600# ifdef USEMAN_S
1601 (char_u *)"man -s",
1602# else
1603 (char_u *)"man",
1604# endif
1605# endif
1606#endif
1607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001608 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1610#ifdef FEAT_LANGMAP
1611 (char_u *)&p_langmap, PV_NONE,
1612 {(char_u *)"", /* unmatched } */
1613#else
1614 (char_u *)NULL, PV_NONE,
1615 {(char_u *)NULL,
1616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001618 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001619#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1620 (char_u *)&p_lm, PV_NONE,
1621#else
1622 (char_u *)NULL, PV_NONE,
1623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001624 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1626#ifdef FEAT_WINDOWS
1627 (char_u *)&p_ls, PV_NONE,
1628#else
1629 (char_u *)NULL, PV_NONE,
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1633 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1636#ifdef FEAT_LINEBREAK
1637 (char_u *)VAR_WIN, PV_LBR,
1638#else
1639 (char_u *)NULL, PV_NONE,
1640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1643 (char_u *)&Rows, PV_NONE,
1644 {
1645#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1646 (char_u *)25L,
1647#else
1648 (char_u *)24L,
1649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1652#ifdef FEAT_GUI
1653 (char_u *)&p_linespace, PV_NONE,
1654#else
1655 (char_u *)NULL, PV_NONE,
1656#endif
1657#ifdef FEAT_GUI_W32
1658 {(char_u *)1L, (char_u *)0L}
1659#else
1660 {(char_u *)0L, (char_u *)0L}
1661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"lisp", NULL, P_BOOL|P_VI_DEF,
1664#ifdef FEAT_LISP
1665 (char_u *)&p_lisp, PV_LISP,
1666#else
1667 (char_u *)NULL, PV_NONE,
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1671#ifdef FEAT_LISP
1672 (char_u *)&p_lispwords, PV_NONE,
1673 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1674#else
1675 (char_u *)NULL, PV_NONE,
1676 {(char_u *)"", (char_u *)0L}
1677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1680 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1683 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1686 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001688#ifdef FEAT_GUI_MAC
1689 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1690 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"magic", NULL, P_BOOL|P_VI_DEF,
1694 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001696 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697#ifdef FEAT_QUICKFIX
1698 (char_u *)&p_mef, PV_NONE,
1699 {(char_u *)"", (char_u *)0L}
1700#else
1701 (char_u *)NULL, PV_NONE,
1702 {(char_u *)NULL, (char_u *)0L}
1703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1706#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001707 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708# ifdef VMS
1709 {(char_u *)"MMS", (char_u *)0L}
1710# else
1711 {(char_u *)"make", (char_u *)0L}
1712# endif
1713#else
1714 (char_u *)NULL, PV_NONE,
1715 {(char_u *)NULL, (char_u *)0L}
1716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1719 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001720 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"matchtime", "mat", P_NUM|P_VI_DEF,
1723 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001725 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1726#ifdef FEAT_MBYTE
1727 (char_u *)&p_mco, PV_NONE,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1733#ifdef FEAT_EVAL
1734 (char_u *)&p_mfd, PV_NONE,
1735#else
1736 (char_u *)NULL, PV_NONE,
1737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1740 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"maxmem", "mm", P_NUM|P_VI_DEF,
1743 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1745 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001746 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1747 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1750 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"menuitems", "mis", P_NUM|P_VI_DEF,
1754#ifdef FEAT_MENU
1755 (char_u *)&p_mis, PV_NONE,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {"mesg", NULL, P_BOOL|P_VI_DEF,
1761 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001763 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001764#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001765 (char_u *)&p_msm, PV_NONE,
1766 {(char_u *)"460000,2000,500", (char_u *)0L}
1767#else
1768 (char_u *)NULL, PV_NONE,
1769 {(char_u *)0L, (char_u *)0L}
1770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"modeline", "ml", P_BOOL|P_VIM,
1773 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 {"modelines", "mls", P_NUM|P_VI_DEF,
1776 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1779 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1782 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"more", NULL, P_BOOL|P_VIM,
1785 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1788 (char_u *)&p_mouse, PV_NONE,
1789 {
1790#if defined(MSDOS) || defined(WIN3264)
1791 (char_u *)"a",
1792#else
1793 (char_u *)"",
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1797#ifdef FEAT_GUI
1798 (char_u *)&p_mousef, PV_NONE,
1799#else
1800 (char_u *)NULL, PV_NONE,
1801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1804#ifdef FEAT_GUI
1805 (char_u *)&p_mh, PV_NONE,
1806#else
1807 (char_u *)NULL, PV_NONE,
1808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1811 (char_u *)&p_mousem, PV_NONE,
1812 {
1813#if defined(MSDOS) || defined(MSWIN)
1814 (char_u *)"popup",
1815#else
1816# if defined(MACOS)
1817 (char_u *)"popup_setpos",
1818# else
1819 (char_u *)"extend",
1820# endif
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1824#ifdef FEAT_MOUSESHAPE
1825 (char_u *)&p_mouseshape, PV_NONE,
1826 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1827#else
1828 (char_u *)NULL, PV_NONE,
1829 {(char_u *)NULL, (char_u *)0L}
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001835 {"mzquantum", "mzq", P_NUM,
1836#ifdef FEAT_MZSCHEME
1837 (char_u *)&p_mzq, PV_NONE,
1838#else
1839 (char_u *)NULL, PV_NONE,
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"novice", NULL, P_BOOL|P_VI_DEF,
1843 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1846 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)"octal,hex", (char_u *)0L}
1848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1850 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001852 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1853#ifdef FEAT_LINEBREAK
1854 (char_u *)VAR_WIN, PV_NUW,
1855#else
1856 (char_u *)NULL, PV_NONE,
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001859 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001860#ifdef FEAT_COMPL_FUNC
1861 (char_u *)&p_ofu, PV_OFU,
1862 {(char_u *)"", (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"open", NULL, P_BOOL|P_VI_DEF,
1869 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001871 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1872#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1873 (char_u *)&p_odev, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
1877 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001879 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1880 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"optimize", "opt", P_BOOL|P_VI_DEF,
1883 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1886#ifdef FEAT_OSFILETYPE
1887 (char_u *)&p_oft, PV_OFT,
1888 {(char_u *)DFLT_OFT, (char_u *)0L}
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)0L, (char_u *)0L}
1892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"paragraphs", "para", P_STRING|P_VI_DEF,
1895 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001896 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001898 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1902 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001903 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1905#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1906 (char_u *)&p_pex, PV_NONE,
1907 {(char_u *)"", (char_u *)0L}
1908#else
1909 (char_u *)NULL, PV_NONE,
1910 {(char_u *)0L, (char_u *)0L}
1911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001913 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001917 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {
1919#if defined AMIGA || defined MSDOS || defined MSWIN
1920 (char_u *)".,,",
1921#else
1922# if defined(__EMX__)
1923 (char_u *)".,/emx/include,,",
1924# else /* Unix, probably */
1925 (char_u *)".,/usr/include,,",
1926# endif
1927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1930 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001932 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1934 (char_u *)&p_pvh, PV_NONE,
1935#else
1936 (char_u *)NULL, PV_NONE,
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1940#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1941 (char_u *)VAR_WIN, PV_PVW,
1942#else
1943 (char_u *)NULL, PV_NONE,
1944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001946 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947#ifdef FEAT_PRINTER
1948 (char_u *)&p_pdev, PV_NONE,
1949 {(char_u *)"", (char_u *)0L}
1950#else
1951 (char_u *)NULL, PV_NONE,
1952 {(char_u *)NULL, (char_u *)0L}
1953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 {"printencoding", "penc", P_STRING|P_VI_DEF,
1956#ifdef FEAT_POSTSCRIPT
1957 (char_u *)&p_penc, PV_NONE,
1958 {(char_u *)"", (char_u *)0L}
1959#else
1960 (char_u *)NULL, PV_NONE,
1961 {(char_u *)NULL, (char_u *)0L}
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1965#ifdef FEAT_POSTSCRIPT
1966 (char_u *)&p_pexpr, PV_NONE,
1967 {(char_u *)"", (char_u *)0L}
1968#else
1969 (char_u *)NULL, PV_NONE,
1970 {(char_u *)NULL, (char_u *)0L}
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"printfont", "pfn", P_STRING|P_VI_DEF,
1974#ifdef FEAT_PRINTER
1975 (char_u *)&p_pfn, PV_NONE,
1976 {
1977# ifdef MSWIN
1978 (char_u *)"Courier_New:h10",
1979# else
1980 (char_u *)"courier",
1981# endif
1982 (char_u *)0L}
1983#else
1984 (char_u *)NULL, PV_NONE,
1985 {(char_u *)NULL, (char_u *)0L}
1986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1989#ifdef FEAT_PRINTER
1990 (char_u *)&p_header, PV_NONE,
1991 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1992#else
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)NULL, (char_u *)0L}
1995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001997 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1998#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1999 (char_u *)&p_pmcs, PV_NONE,
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 Moolenaar8299df92004-07-10 09:47:34 +00002006 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2007#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2008 (char_u *)&p_pmfn, PV_NONE,
2009 {(char_u *)"", (char_u *)0L}
2010#else
2011 (char_u *)NULL, PV_NONE,
2012 {(char_u *)NULL, (char_u *)0L}
2013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002015 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2016#ifdef FEAT_PRINTER
2017 (char_u *)&p_popt, PV_NONE,
2018 {(char_u *)"", (char_u *)0L}
2019#else
2020 (char_u *)NULL, PV_NONE,
2021 {(char_u *)NULL, (char_u *)0L}
2022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002023 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002025 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002027 {"pumheight", "ph", P_NUM|P_VI_DEF,
2028#ifdef FEAT_INS_EXPAND
2029 (char_u *)&p_ph, PV_NONE,
2030#else
2031 (char_u *)NULL, PV_NONE,
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002034 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2035#ifdef FEAT_TEXTOBJ
2036 (char_u *)&p_qe, PV_QE,
2037 {(char_u *)"\\", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)NULL, (char_u *)0L}
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2044 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"redraw", NULL, P_BOOL|P_VI_DEF,
2047 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002049 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2050#ifdef FEAT_RELTIME
2051 (char_u *)&p_rdt, PV_NONE,
2052#else
2053 (char_u *)NULL, PV_NONE,
2054#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002056 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2057 (char_u *)VAR_WIN, PV_RNU,
2058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"remap", NULL, P_BOOL|P_VI_DEF,
2060 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"report", NULL, P_NUM|P_VI_DEF,
2063 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2066#ifdef WIN3264
2067 (char_u *)&p_rs, PV_NONE,
2068#else
2069 (char_u *)NULL, PV_NONE,
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2073#ifdef FEAT_RIGHTLEFT
2074 (char_u *)&p_ri, PV_NONE,
2075#else
2076 (char_u *)NULL, PV_NONE,
2077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2080#ifdef FEAT_RIGHTLEFT
2081 (char_u *)VAR_WIN, PV_RL,
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 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2087#ifdef FEAT_RIGHTLEFT
2088 (char_u *)VAR_WIN, PV_RLC,
2089 {(char_u *)"search", (char_u *)NULL}
2090#else
2091 (char_u *)NULL, PV_NONE,
2092 {(char_u *)NULL, (char_u *)0L}
2093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2096#ifdef FEAT_CMDL_INFO
2097 (char_u *)&p_ru, PV_NONE,
2098#else
2099 (char_u *)NULL, PV_NONE,
2100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2103#ifdef FEAT_STL_OPT
2104 (char_u *)&p_ruf, PV_NONE,
2105#else
2106 (char_u *)NULL, PV_NONE,
2107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2110 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2112 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2114 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2117#ifdef FEAT_SCROLLBIND
2118 (char_u *)VAR_WIN, PV_SCBIND,
2119#else
2120 (char_u *)NULL, PV_NONE,
2121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002122 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2124 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2127 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2130#ifdef FEAT_SCROLLBIND
2131 (char_u *)&p_sbo, PV_NONE,
2132 {(char_u *)"ver,jump", (char_u *)0L}
2133#else
2134 (char_u *)NULL, PV_NONE,
2135 {(char_u *)0L, (char_u *)0L}
2136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"sections", "sect", P_STRING|P_VI_DEF,
2139 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002140 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2141 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2143 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"selection", "sel", P_STRING|P_VI_DEF,
2146#ifdef FEAT_VISUAL
2147 (char_u *)&p_sel, PV_NONE,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)"inclusive", (char_u *)0L}
2152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2154#ifdef FEAT_VISUAL
2155 (char_u *)&p_slm, PV_NONE,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2161#ifdef FEAT_SESSION
2162 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002163 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)0L, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2171 (char_u *)&p_sh, PV_NONE,
2172 {
2173#ifdef VMS
2174 (char_u *)"-",
2175#else
2176# if defined(MSDOS)
2177 (char_u *)"command",
2178# else
2179# if defined(WIN16)
2180 (char_u *)"command.com",
2181# else
2182# if defined(WIN3264)
2183 (char_u *)"", /* set in set_init_1() */
2184# else
2185# if defined(OS2)
2186 (char_u *)"cmd.exe",
2187# else
2188# if defined(ARCHIE)
2189 (char_u *)"gos",
2190# else
2191 (char_u *)"sh",
2192# endif
2193# endif
2194# endif
2195# endif
2196# endif
2197#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002198 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2200 (char_u *)&p_shcf, PV_NONE,
2201 {
2202#if defined(MSDOS) || defined(MSWIN)
2203 (char_u *)"/c",
2204#else
2205# if defined(OS2)
2206 (char_u *)"/c",
2207# else
2208 (char_u *)"-c",
2209# endif
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2213#ifdef FEAT_QUICKFIX
2214 (char_u *)&p_sp, PV_NONE,
2215 {
2216#if defined(UNIX) || defined(OS2)
2217# ifdef ARCHIE
2218 (char_u *)"2>",
2219# else
2220 (char_u *)"| tee",
2221# endif
2222#else
2223 (char_u *)">",
2224#endif
2225 (char_u *)0L}
2226#else
2227 (char_u *)NULL, PV_NONE,
2228 {(char_u *)0L, (char_u *)0L}
2229#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2232 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2235 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2238#ifdef BACKSLASH_IN_FILENAME
2239 (char_u *)&p_ssl, PV_NONE,
2240#else
2241 (char_u *)NULL, PV_NONE,
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002244 {"shelltemp", "stmp", P_BOOL,
2245 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"shelltype", "st", P_NUM|P_VI_DEF,
2248#ifdef AMIGA
2249 (char_u *)&p_st, PV_NONE,
2250#else
2251 (char_u *)NULL, PV_NONE,
2252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2255 (char_u *)&p_sxq, PV_NONE,
2256 {
2257#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2258 (char_u *)"\"",
2259#else
2260 (char_u *)"",
2261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2264 (char_u *)&p_sr, 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 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2267 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2270 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)"", (char_u *)"filnxtToO"}
2272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"shortname", "sn", P_BOOL|P_VI_DEF,
2274#ifdef SHORT_FNAME
2275 (char_u *)NULL, PV_NONE,
2276#else
2277 (char_u *)&p_sn, PV_SN,
2278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2281#ifdef FEAT_LINEBREAK
2282 (char_u *)&p_sbr, PV_NONE,
2283#else
2284 (char_u *)NULL, PV_NONE,
2285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"showcmd", "sc", P_BOOL|P_VIM,
2288#ifdef FEAT_CMDL_INFO
2289 (char_u *)&p_sc, PV_NONE,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
2293 {(char_u *)FALSE,
2294#ifdef UNIX
2295 (char_u *)FALSE
2296#else
2297 (char_u *)TRUE
2298#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2301 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2304 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"showmode", "smd", P_BOOL|P_VIM,
2307 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002309 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2310#ifdef FEAT_WINDOWS
2311 (char_u *)&p_stal, PV_NONE,
2312#else
2313 (char_u *)NULL, PV_NONE,
2314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2317 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2320 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2323 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2326 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2329#ifdef FEAT_SMARTINDENT
2330 (char_u *)&p_si, PV_SI,
2331#else
2332 (char_u *)NULL, PV_NONE,
2333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2336 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2339 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2342 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002344 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002345#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002346 (char_u *)VAR_WIN, PV_SPELL,
2347#else
2348 (char_u *)NULL, PV_NONE,
2349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002351 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002352#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002353 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002354 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002355#else
2356 (char_u *)NULL, PV_NONE,
2357 {(char_u *)0L, (char_u *)0L}
2358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002360 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002361#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002362 (char_u *)&p_spf, PV_SPF,
2363 {(char_u *)"", (char_u *)0L}
2364#else
2365 (char_u *)NULL, PV_NONE,
2366 {(char_u *)0L, (char_u *)0L}
2367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002369 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002370#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002371 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002372 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002373#else
2374 (char_u *)NULL, PV_NONE,
2375 {(char_u *)0L, (char_u *)0L}
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002378 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002379#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002380 (char_u *)&p_sps, PV_NONE,
2381 {(char_u *)"best", (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 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2388#ifdef FEAT_WINDOWS
2389 (char_u *)&p_sb, PV_NONE,
2390#else
2391 (char_u *)NULL, PV_NONE,
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"splitright", "spr", P_BOOL|P_VI_DEF,
2395#ifdef FEAT_VERTSPLIT
2396 (char_u *)&p_spr, PV_NONE,
2397#else
2398 (char_u *)NULL, PV_NONE,
2399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2402 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2405#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002406 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407#else
2408 (char_u *)NULL, PV_NONE,
2409#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2412 (char_u *)&p_su, PV_NONE,
2413 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002416#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 (char_u *)&p_sua, PV_SUA,
2418 {(char_u *)"", (char_u *)0L}
2419#else
2420 (char_u *)NULL, PV_NONE,
2421 {(char_u *)0L, (char_u *)0L}
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2425 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"swapsync", "sws", P_STRING|P_VI_DEF,
2428 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2431 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002433 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2434#ifdef FEAT_SYN_HL
2435 (char_u *)&p_smc, PV_SMC,
2436 {(char_u *)3000L, (char_u *)0L}
2437#else
2438 (char_u *)NULL, PV_NONE,
2439 {(char_u *)0L, (char_u *)0L}
2440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002442 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443#ifdef FEAT_SYN_HL
2444 (char_u *)&p_syn, PV_SYN,
2445 {(char_u *)"", (char_u *)0L}
2446#else
2447 (char_u *)NULL, PV_NONE,
2448 {(char_u *)0L, (char_u *)0L}
2449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002451 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2452#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002453 (char_u *)&p_tal, PV_NONE,
2454#else
2455 (char_u *)NULL, PV_NONE,
2456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002458 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2459#ifdef FEAT_WINDOWS
2460 (char_u *)&p_tpm, PV_NONE,
2461#else
2462 (char_u *)NULL, PV_NONE,
2463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2466 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2469 (char_u *)&p_tbs, PV_NONE,
2470#ifdef VMS /* binary searching doesn't appear to work on VMS */
2471 {(char_u *)0L, (char_u *)0L}
2472#else
2473 {(char_u *)TRUE, (char_u *)0L}
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"taglength", "tl", P_NUM|P_VI_DEF,
2477 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"tagrelative", "tr", P_BOOL|P_VIM,
2480 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002483 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {
2485#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2486 (char_u *)"./tags,./TAGS,tags,TAGS",
2487#else
2488 (char_u *)"./tags,tags",
2489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2492 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2495 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2498#ifdef FEAT_ARABIC
2499 (char_u *)&p_tbidi, PV_NONE,
2500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2505#ifdef FEAT_MBYTE
2506 (char_u *)&p_tenc, PV_NONE,
2507 {(char_u *)"", (char_u *)0L}
2508#else
2509 (char_u *)NULL, PV_NONE,
2510 {(char_u *)0L, (char_u *)0L}
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"terse", NULL, P_BOOL|P_VI_DEF,
2514 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"textauto", "ta", P_BOOL|P_VIM,
2517 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2521 (char_u *)&p_tx, PV_TX,
2522 {
2523#ifdef USE_CRNL
2524 (char_u *)TRUE,
2525#else
2526 (char_u *)FALSE,
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2530 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2533#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002534 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535#else
2536 (char_u *)NULL, PV_NONE,
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2540 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"timeout", "to", P_BOOL|P_VI_DEF,
2543 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2546 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"title", NULL, P_BOOL|P_VI_DEF,
2549#ifdef FEAT_TITLE
2550 (char_u *)&p_title, PV_NONE,
2551#else
2552 (char_u *)NULL, PV_NONE,
2553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"titlelen", NULL, P_NUM|P_VI_DEF,
2556#ifdef FEAT_TITLE
2557 (char_u *)&p_titlelen, PV_NONE,
2558#else
2559 (char_u *)NULL, PV_NONE,
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002562 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563#ifdef FEAT_TITLE
2564 (char_u *)&p_titleold, PV_NONE,
2565 {(char_u *)N_("Thanks for flying Vim"),
2566 (char_u *)0L}
2567#else
2568 (char_u *)NULL, PV_NONE,
2569 {(char_u *)0L, (char_u *)0L}
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"titlestring", NULL, P_STRING|P_VI_DEF,
2573#ifdef FEAT_TITLE
2574 (char_u *)&p_titlestring, PV_NONE,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2580 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2581 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)"icons,tooltips", (char_u *)0L}
2583 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584#endif
2585#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2586 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2587 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589#endif
2590 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2591 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2594 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2597 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2600 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2603#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2604 (char_u *)&p_ttym, PV_NONE,
2605#else
2606 (char_u *)NULL, PV_NONE,
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2610 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2613 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002615 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2616#ifdef FEAT_PERSISTENT_UNDO
2617 (char_u *)&p_udir, PV_NONE,
2618 {(char_u *)".", (char_u *)0L}
2619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
2623 SCRIPTID_INIT},
2624 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2625#ifdef FEAT_PERSISTENT_UNDO
2626 (char_u *)&p_udf, PV_UDF,
2627#else
2628 (char_u *)NULL, PV_NONE,
2629#endif
2630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"undolevels", "ul", P_NUM|P_VI_DEF,
2632 (char_u *)&p_ul, PV_NONE,
2633 {
2634#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2635 (char_u *)1000L,
2636#else
2637 (char_u *)100L,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"updatecount", "uc", P_NUM|P_VI_DEF,
2641 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"updatetime", "ut", P_NUM|P_VI_DEF,
2644 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"verbose", "vbs", P_NUM|P_VI_DEF,
2647 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002649 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2650 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2653#ifdef FEAT_SESSION
2654 (char_u *)&p_vdir, PV_NONE,
2655 {(char_u *)DFLT_VDIR, (char_u *)0L}
2656#else
2657 (char_u *)NULL, PV_NONE,
2658 {(char_u *)0L, (char_u *)0L}
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2662#ifdef FEAT_SESSION
2663 (char_u *)&p_vop, PV_NONE,
2664 {(char_u *)"folds,options,cursor", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2671#ifdef FEAT_VIMINFO
2672 (char_u *)&p_viminfo, PV_NONE,
2673#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002674 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675#else
2676# ifdef AMIGA
2677 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002678 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002680 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681# endif
2682#endif
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2689#ifdef FEAT_VIRTUALEDIT
2690 (char_u *)&p_ve, PV_NONE,
2691 {(char_u *)"", (char_u *)""}
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2698 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 {"w300", NULL, P_NUM|P_VI_DEF,
2701 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002702 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {"w1200", NULL, P_NUM|P_VI_DEF,
2704 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"w9600", NULL, P_NUM|P_VI_DEF,
2707 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"warn", NULL, P_BOOL|P_VI_DEF,
2710 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2713 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2716 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"wildchar", "wc", P_NUM|P_VIM,
2719 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2723 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2726#ifdef FEAT_WILDIGN
2727 (char_u *)&p_wig, PV_NONE,
2728#else
2729 (char_u *)NULL, PV_NONE,
2730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2733#ifdef FEAT_WILDMENU
2734 (char_u *)&p_wmnu, PV_NONE,
2735#else
2736 (char_u *)NULL, PV_NONE,
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2740 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002742 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2743#ifdef FEAT_CMDL_COMPL
2744 (char_u *)&p_wop, PV_NONE,
2745 {(char_u *)"", (char_u *)0L}
2746#else
2747 (char_u *)NULL, PV_NONE,
2748 {(char_u *)NULL, (char_u *)0L}
2749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2752#ifdef FEAT_WAK
2753 (char_u *)&p_wak, PV_NONE,
2754 {(char_u *)"menu", (char_u *)0L}
2755#else
2756 (char_u *)NULL, PV_NONE,
2757 {(char_u *)NULL, (char_u *)0L}
2758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002761 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"winheight", "wh", P_NUM|P_VI_DEF,
2764#ifdef FEAT_WINDOWS
2765 (char_u *)&p_wh, PV_NONE,
2766#else
2767 (char_u *)NULL, PV_NONE,
2768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002771#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 (char_u *)VAR_WIN, PV_WFH,
2773#else
2774 (char_u *)NULL, PV_NONE,
2775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002777 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2778#ifdef FEAT_VERTSPLIT
2779 (char_u *)VAR_WIN, PV_WFW,
2780#else
2781 (char_u *)NULL, PV_NONE,
2782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2785#ifdef FEAT_WINDOWS
2786 (char_u *)&p_wmh, PV_NONE,
2787#else
2788 (char_u *)NULL, PV_NONE,
2789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2792#ifdef FEAT_VERTSPLIT
2793 (char_u *)&p_wmw, PV_NONE,
2794#else
2795 (char_u *)NULL, PV_NONE,
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2799#ifdef FEAT_VERTSPLIT
2800 (char_u *)&p_wiw, PV_NONE,
2801#else
2802 (char_u *)NULL, PV_NONE,
2803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2806 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2809 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2812 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"write", NULL, P_BOOL|P_VI_DEF,
2815 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"writeany", "wa", P_BOOL|P_VI_DEF,
2818 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2821 (char_u *)&p_wb, PV_NONE,
2822 {
2823#ifdef FEAT_WRITEBACKUP
2824 (char_u *)TRUE,
2825#else
2826 (char_u *)FALSE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"writedelay", "wd", P_NUM|P_VI_DEF,
2830 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832
2833/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002834#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837
2838 p_term("t_AB", T_CAB)
2839 p_term("t_AF", T_CAF)
2840 p_term("t_AL", T_CAL)
2841 p_term("t_al", T_AL)
2842 p_term("t_bc", T_BC)
2843 p_term("t_cd", T_CD)
2844 p_term("t_ce", T_CE)
2845 p_term("t_cl", T_CL)
2846 p_term("t_cm", T_CM)
2847 p_term("t_Co", T_CCO)
2848 p_term("t_CS", T_CCS)
2849 p_term("t_cs", T_CS)
2850#ifdef FEAT_VERTSPLIT
2851 p_term("t_CV", T_CSV)
2852#endif
2853 p_term("t_ut", T_UT)
2854 p_term("t_da", T_DA)
2855 p_term("t_db", T_DB)
2856 p_term("t_DL", T_CDL)
2857 p_term("t_dl", T_DL)
2858 p_term("t_fs", T_FS)
2859 p_term("t_IE", T_CIE)
2860 p_term("t_IS", T_CIS)
2861 p_term("t_ke", T_KE)
2862 p_term("t_ks", T_KS)
2863 p_term("t_le", T_LE)
2864 p_term("t_mb", T_MB)
2865 p_term("t_md", T_MD)
2866 p_term("t_me", T_ME)
2867 p_term("t_mr", T_MR)
2868 p_term("t_ms", T_MS)
2869 p_term("t_nd", T_ND)
2870 p_term("t_op", T_OP)
2871 p_term("t_RI", T_CRI)
2872 p_term("t_RV", T_CRV)
2873 p_term("t_Sb", T_CSB)
2874 p_term("t_Sf", T_CSF)
2875 p_term("t_se", T_SE)
2876 p_term("t_so", T_SO)
2877 p_term("t_sr", T_SR)
2878 p_term("t_ts", T_TS)
2879 p_term("t_te", T_TE)
2880 p_term("t_ti", T_TI)
2881 p_term("t_ue", T_UE)
2882 p_term("t_us", T_US)
2883 p_term("t_vb", T_VB)
2884 p_term("t_ve", T_VE)
2885 p_term("t_vi", T_VI)
2886 p_term("t_vs", T_VS)
2887 p_term("t_WP", T_CWP)
2888 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002889 p_term("t_SI", T_CSI)
2890 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 p_term("t_xs", T_XS)
2892 p_term("t_ZH", T_CZH)
2893 p_term("t_ZR", T_CZR)
2894
2895/* terminal key codes are not in here */
2896
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 /* end marker */
2898 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899};
2900
2901#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2902
2903#ifdef FEAT_MBYTE
2904static char *(p_ambw_values[]) = {"single", "double", NULL};
2905#endif
2906static char *(p_bg_values[]) = {"light", "dark", NULL};
2907static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2908static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002909#ifdef FEAT_CMDL_COMPL
2910static char *(p_wop_values[]) = {"tagfile", NULL};
2911#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912#ifdef FEAT_WAK
2913static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2914#endif
2915static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2916#ifdef FEAT_VISUAL
2917static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2918static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2919#endif
2920#ifdef FEAT_VISUAL
2921static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2922#endif
2923#ifdef FEAT_BROWSE
2924static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2925#endif
2926#ifdef FEAT_SCROLLBIND
2927static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2928#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002929static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930#ifdef FEAT_VERTSPLIT
2931static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2932#endif
2933#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002934# ifdef FEAT_AUTOCMD
2935static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2936# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002938# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2940#endif
2941static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2942#ifdef FEAT_FOLDING
2943static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002944# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002946# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 NULL};
2948static char *(p_fcl_values[]) = {"all", NULL};
2949#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002950#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002951static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953
2954static void set_option_default __ARGS((int, int opt_flags, int compatible));
2955static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002956static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002957static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958static char_u *illegal_char __ARGS((char_u *, int));
2959static int string_to_key __ARGS((char_u *arg));
2960#ifdef FEAT_CMDWIN
2961static char_u *check_cedit __ARGS((void));
2962#endif
2963#ifdef FEAT_TITLE
2964static void did_set_title __ARGS((int icon));
2965#endif
2966static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2967static void didset_options __ARGS((void));
2968static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002969#if defined(FEAT_EVAL) || defined(PROTO)
2970static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2971#else
2972# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2975static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2976static 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));
2977static char_u *set_chars_option __ARGS((char_u **varp));
2978#ifdef FEAT_CLIPBOARD
2979static char_u *check_clipboard_option __ARGS((void));
2980#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002981#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02002982static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002983#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002984#ifdef FEAT_EVAL
2985static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2986#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002988static 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 +00002989static void check_redraw __ARGS((long_u flags));
2990static int findoption __ARGS((char_u *));
2991static int find_key_option __ARGS((char_u *));
2992static void showoptions __ARGS((int all, int opt_flags));
2993static int optval_default __ARGS((struct vimoption *, char_u *varp));
2994static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2995static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2996static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2997static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2998static int istermoption __ARGS((struct vimoption *));
2999static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3000static char_u *get_varp __ARGS((struct vimoption *));
3001static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3002static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3003#ifdef FEAT_LANGMAP
3004static void langmap_init __ARGS((void));
3005static void langmap_set __ARGS((void));
3006#endif
3007static void paste_option_changed __ARGS((void));
3008static void compatible_set __ARGS((void));
3009#ifdef FEAT_LINEBREAK
3010static void fill_breakat_flags __ARGS((void));
3011#endif
3012static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3013static int check_opt_strings __ARGS((char_u *val, char **values, int));
3014static int check_opt_wim __ARGS((void));
3015
3016/*
3017 * Initialize the options, first part.
3018 *
3019 * Called only once from main(), just after creating the first buffer.
3020 */
3021 void
3022set_init_1()
3023{
3024 char_u *p;
3025 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003026 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027
3028#ifdef FEAT_LANGMAP
3029 langmap_init();
3030#endif
3031
3032 /* Be Vi compatible by default */
3033 p_cp = TRUE;
3034
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003035 /* Use POSIX compatibility when $VIM_POSIX is set. */
3036 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003037 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003038 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003039 set_string_default("shm", (char_u *)"A");
3040 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003041
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 /*
3043 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003044 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003046 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3048# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003049 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003051 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003053 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054# endif
3055#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003056 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 set_string_default("sh", p);
3058
3059#ifdef FEAT_WILDIGN
3060 /*
3061 * Set the default for 'backupskip' to include environment variables for
3062 * temp files.
3063 */
3064 {
3065# ifdef UNIX
3066 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3067# else
3068 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3069# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003070 int len;
3071 garray_T ga;
3072 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073
3074 ga_init2(&ga, 1, 100);
3075 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3076 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003077 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078# ifdef UNIX
3079 if (*names[n] == NUL)
3080 p = (char_u *)"/tmp";
3081 else
3082# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003083 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 if (p != NULL && *p != NUL)
3085 {
3086 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003087 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 if (ga_grow(&ga, len) == OK)
3089 {
3090 if (ga.ga_len > 0)
3091 STRCAT(ga.ga_data, ",");
3092 STRCAT(ga.ga_data, p);
3093 add_pathsep(ga.ga_data);
3094 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 ga.ga_len += len;
3096 }
3097 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003098 if (mustfree)
3099 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 }
3101 if (ga.ga_data != NULL)
3102 {
3103 set_string_default("bsk", ga.ga_data);
3104 vim_free(ga.ga_data);
3105 }
3106 }
3107#endif
3108
3109 /*
3110 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3111 */
3112 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003113 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003115#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3116 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3117#endif
3118 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003120 /* Use amount of memory available at this moment. */
3121 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122#else
3123# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003124 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003125 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003127 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128# endif
3129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003131 opt_idx = findoption((char_u *)"maxmem");
3132 if (opt_idx >= 0)
3133 {
3134#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3135 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3136 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3137#endif
3138 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3139 }
3140 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 }
3142
3143#ifdef FEAT_GUI_W32
3144 /* force 'shortname' for Win32s */
3145 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003146 {
3147 opt_idx = findoption((char_u *)"shortname");
3148 if (opt_idx >= 0)
3149 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151#endif
3152
3153#ifdef FEAT_SEARCHPATH
3154 {
3155 char_u *cdpath;
3156 char_u *buf;
3157 int i;
3158 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003159 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160
3161 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003162 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 if (cdpath != NULL)
3164 {
3165 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3166 if (buf != NULL)
3167 {
3168 buf[0] = ','; /* start with ",", current dir first */
3169 j = 1;
3170 for (i = 0; cdpath[i] != NUL; ++i)
3171 {
3172 if (vim_ispathlistsep(cdpath[i]))
3173 buf[j++] = ',';
3174 else
3175 {
3176 if (cdpath[i] == ' ' || cdpath[i] == ',')
3177 buf[j++] = '\\';
3178 buf[j++] = cdpath[i];
3179 }
3180 }
3181 buf[j] = NUL;
3182 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003183 if (opt_idx >= 0)
3184 {
3185 options[opt_idx].def_val[VI_DEFAULT] = buf;
3186 options[opt_idx].flags |= P_DEF_ALLOCED;
3187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003189 if (mustfree)
3190 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 }
3192 }
3193#endif
3194
3195#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3196 /* Set print encoding on platforms that don't default to latin1 */
3197 set_string_default("penc",
3198# if defined(MSWIN) || defined(OS2)
3199 (char_u *)"cp1252"
3200# else
3201# ifdef VMS
3202 (char_u *)"dec-mcs"
3203# else
3204# ifdef EBCDIC
3205 (char_u *)"ebcdic-uk"
3206# else
3207# ifdef MAC
3208 (char_u *)"mac-roman"
3209# else /* HPUX */
3210 (char_u *)"hp-roman8"
3211# endif
3212# endif
3213# endif
3214# endif
3215 );
3216#endif
3217
3218#ifdef FEAT_POSTSCRIPT
3219 /* 'printexpr' must be allocated to be able to evaluate it. */
3220 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003221# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3222 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223# else
3224# ifdef VMS
3225 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3226
3227# else
3228 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3229# endif
3230# endif
3231 );
3232#endif
3233
3234 /*
3235 * Set all the options (except the terminal options) to their default
3236 * value. Also set the global value for local options.
3237 */
3238 set_options_default(0);
3239
3240#ifdef FEAT_GUI
3241 if (found_reverse_arg)
3242 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3243#endif
3244
3245 curbuf->b_p_initialized = TRUE;
3246 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3247 check_buf_options(curbuf);
3248 check_win_options(curwin);
3249 check_options();
3250
3251 /* Must be before option_expand(), because that one needs vim_isIDc() */
3252 didset_options();
3253
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003254#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003255 /* Use the current chartab for the generic chartab. */
3256 init_spell_chartab();
3257#endif
3258
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#ifdef FEAT_LINEBREAK
3260 /*
3261 * initialize the table for 'breakat'.
3262 */
3263 fill_breakat_flags();
3264#endif
3265
3266 /*
3267 * Expand environment variables and things like "~" for the defaults.
3268 * If option_expand() returns non-NULL the variable is expanded. This can
3269 * only happen for non-indirect options.
3270 * Also set the default to the expanded value, so ":set" does not list
3271 * them.
3272 * Don't set the P_ALLOCED flag, because we don't want to free the
3273 * default.
3274 */
3275 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3276 {
3277 if ((options[opt_idx].flags & P_GETTEXT)
3278 && options[opt_idx].var != NULL)
3279 p = (char_u *)_(*(char **)options[opt_idx].var);
3280 else
3281 p = option_expand(opt_idx, NULL);
3282 if (p != NULL && (p = vim_strsave(p)) != NULL)
3283 {
3284 *(char_u **)options[opt_idx].var = p;
3285 /* VIMEXP
3286 * Defaults for all expanded options are currently the same for Vi
3287 * and Vim. When this changes, add some code here! Also need to
3288 * split P_DEF_ALLOCED in two.
3289 */
3290 if (options[opt_idx].flags & P_DEF_ALLOCED)
3291 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3292 options[opt_idx].def_val[VI_DEFAULT] = p;
3293 options[opt_idx].flags |= P_DEF_ALLOCED;
3294 }
3295 }
3296
3297 /* Initialize the highlight_attr[] table. */
3298 highlight_changed();
3299
3300 save_file_ff(curbuf); /* Buffer is unchanged */
3301
3302 /* Parse default for 'wildmode' */
3303 check_opt_wim();
3304
3305#if defined(FEAT_ARABIC)
3306 /* Detect use of mlterm.
3307 * Mlterm is a terminal emulator akin to xterm that has some special
3308 * abilities (bidi namely).
3309 * NOTE: mlterm's author is being asked to 'set' a variable
3310 * instead of an environment variable due to inheritance.
3311 */
3312 if (mch_getenv((char_u *)"MLTERM") != NULL)
3313 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3314#endif
3315
3316#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3317 /* Parse default for 'fillchars'. */
3318 (void)set_chars_option(&p_fcs);
3319#endif
3320
3321#ifdef FEAT_CLIPBOARD
3322 /* Parse default for 'clipboard' */
3323 (void)check_clipboard_option();
3324#endif
3325
3326#ifdef FEAT_MBYTE
3327# if defined(WIN3264) && defined(FEAT_GETTEXT)
3328 /*
3329 * If $LANG isn't set, try to get a good value for it. This makes the
3330 * right language be used automatically. Don't do this for English.
3331 */
3332 if (mch_getenv((char_u *)"LANG") == NULL)
3333 {
3334 char buf[20];
3335
3336 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3337 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3338 * only the first two. */
3339 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3340 (LPTSTR)buf, 20);
3341 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3342 {
3343 /* There are a few exceptions (probably more) */
3344 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3345 STRCPY(buf, "zh_TW");
3346 else if (STRNICMP(buf, "chs", 3) == 0
3347 || STRNICMP(buf, "zhc", 3) == 0)
3348 STRCPY(buf, "zh_CN");
3349 else if (STRNICMP(buf, "jp", 2) == 0)
3350 STRCPY(buf, "ja");
3351 else
3352 buf[2] = NUL; /* truncate to two-letter code */
3353 vim_setenv("LANG", buf);
3354 }
3355 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003356# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003357# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003358 /* Moved to os_mac_conv.c to avoid dependency problems. */
3359 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003360# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361# endif
3362
3363 /* enc_locale() will try to find the encoding of the current locale. */
3364 p = enc_locale();
3365 if (p != NULL)
3366 {
3367 char_u *save_enc;
3368
3369 /* Try setting 'encoding' and check if the value is valid.
3370 * If not, go back to the default "latin1". */
3371 save_enc = p_enc;
3372 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003373 if (STRCMP(p_enc, "gb18030") == 0)
3374 {
3375 /* We don't support "gb18030", but "cp936" is a good substitute
3376 * for practical purposes, thus use that. It's not an alias to
3377 * still support conversion between gb18030 and utf-8. */
3378 p_enc = vim_strsave((char_u *)"cp936");
3379 vim_free(p);
3380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 if (mb_init() == NULL)
3382 {
3383 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003384 if (opt_idx >= 0)
3385 {
3386 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3387 options[opt_idx].flags |= P_DEF_ALLOCED;
3388 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003390#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3391 || defined(VMS)
3392 if (STRCMP(p_enc, "latin1") == 0
3393# ifdef FEAT_MBYTE
3394 || enc_utf8
3395# endif
3396 )
3397 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003398 /* Adjust the default for 'isprint' and 'iskeyword' to match
3399 * latin1. Also set the defaults for when 'nocompatible' is
3400 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003401 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003402 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003403 set_string_option_direct((char_u *)"isk", -1,
3404 ISK_LATIN1, OPT_FREE, SID_NONE);
3405 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003406 if (opt_idx >= 0)
3407 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003408 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003409 if (opt_idx >= 0)
3410 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003411 (void)init_chartab();
3412 }
3413#endif
3414
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415# if defined(WIN3264) && !defined(FEAT_GUI)
3416 /* Win32 console: When GetACP() returns a different value from
3417 * GetConsoleCP() set 'termencoding'. */
3418 if (GetACP() != GetConsoleCP())
3419 {
3420 char buf[50];
3421
3422 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3423 p_tenc = vim_strsave((char_u *)buf);
3424 if (p_tenc != NULL)
3425 {
3426 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 if (opt_idx >= 0)
3428 {
3429 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3430 options[opt_idx].flags |= P_DEF_ALLOCED;
3431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 convert_setup(&input_conv, p_tenc, p_enc);
3433 convert_setup(&output_conv, p_enc, p_tenc);
3434 }
3435 else
3436 p_tenc = empty_option;
3437 }
3438# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003439# if defined(WIN3264) && defined(FEAT_MBYTE)
3440 /* $HOME may have characters in active code page. */
3441 init_homedir();
3442# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 }
3444 else
3445 {
3446 vim_free(p_enc);
3447 p_enc = save_enc;
3448 }
3449 }
3450#endif
3451
3452#ifdef FEAT_MULTI_LANG
3453 /* Set the default for 'helplang'. */
3454 set_helplang_default(get_mess_lang());
3455#endif
3456}
3457
3458/*
3459 * Set an option to its default value.
3460 * This does not take care of side effects!
3461 */
3462 static void
3463set_option_default(opt_idx, opt_flags, compatible)
3464 int opt_idx;
3465 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3466 int compatible; /* use Vi default value */
3467{
3468 char_u *varp; /* pointer to variable for current option */
3469 int dvi; /* index in def_val[] */
3470 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003471 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3473
3474 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3475 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003476 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 {
3478 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3479 if (flags & P_STRING)
3480 {
3481 /* Use set_string_option_direct() for local options to handle
3482 * freeing and allocating the value. */
3483 if (options[opt_idx].indir != PV_NONE)
3484 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003485 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 else
3487 {
3488 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3489 free_string_option(*(char_u **)(varp));
3490 *(char_u **)varp = options[opt_idx].def_val[dvi];
3491 options[opt_idx].flags &= ~P_ALLOCED;
3492 }
3493 }
3494 else if (flags & P_NUM)
3495 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003496 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 win_comp_scroll(curwin);
3498 else
3499 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003500 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501 /* May also set global value for local option. */
3502 if (both)
3503 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3504 *(long *)varp;
3505 }
3506 }
3507 else /* P_BOOL */
3508 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003509 /* the cast to long is required for Manx C, long_i is needed for
3510 * MSVC */
3511 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003512#ifdef UNIX
3513 /* 'modeline' defaults to off for root */
3514 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3515 *(int *)varp = FALSE;
3516#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 /* May also set global value for local option. */
3518 if (both)
3519 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3520 *(int *)varp;
3521 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003522
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003523 /* The default value is not insecure. */
3524 flagsp = insecure_flag(opt_idx, opt_flags);
3525 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 }
3527
3528#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003529 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530#endif
3531}
3532
3533/*
3534 * Set all options (except terminal options) to their default value.
3535 */
3536 static void
3537set_options_default(opt_flags)
3538 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3539{
3540 int i;
3541#ifdef FEAT_WINDOWS
3542 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003543 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544#endif
3545
3546 for (i = 0; !istermoption(&options[i]); i++)
3547 if (!(options[i].flags & P_NODEFAULT))
3548 set_option_default(i, opt_flags, p_cp);
3549
3550#ifdef FEAT_WINDOWS
3551 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003552 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 win_comp_scroll(wp);
3554#else
3555 win_comp_scroll(curwin);
3556#endif
3557}
3558
3559/*
3560 * Set the Vi-default value of a string option.
3561 * Used for 'sh', 'backupskip' and 'term'.
3562 */
3563 void
3564set_string_default(name, val)
3565 char *name;
3566 char_u *val;
3567{
3568 char_u *p;
3569 int opt_idx;
3570
3571 p = vim_strsave(val);
3572 if (p != NULL) /* we don't want a NULL */
3573 {
3574 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003575 if (opt_idx >= 0)
3576 {
3577 if (options[opt_idx].flags & P_DEF_ALLOCED)
3578 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3579 options[opt_idx].def_val[VI_DEFAULT] = p;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 }
3583}
3584
3585/*
3586 * Set the Vi-default value of a number option.
3587 * Used for 'lines' and 'columns'.
3588 */
3589 void
3590set_number_default(name, val)
3591 char *name;
3592 long val;
3593{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003594 int opt_idx;
3595
3596 opt_idx = findoption((char_u *)name);
3597 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003598 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599}
3600
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003601#if defined(EXITFREE) || defined(PROTO)
3602/*
3603 * Free all options.
3604 */
3605 void
3606free_all_options()
3607{
3608 int i;
3609
3610 for (i = 0; !istermoption(&options[i]); i++)
3611 {
3612 if (options[i].indir == PV_NONE)
3613 {
3614 /* global option: free value and default value. */
3615 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3616 free_string_option(*(char_u **)options[i].var);
3617 if (options[i].flags & P_DEF_ALLOCED)
3618 free_string_option(options[i].def_val[VI_DEFAULT]);
3619 }
3620 else if (options[i].var != VAR_WIN
3621 && (options[i].flags & P_STRING))
3622 /* buffer-local option: free global value */
3623 free_string_option(*(char_u **)options[i].var);
3624 }
3625}
3626#endif
3627
3628
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629/*
3630 * Initialize the options, part two: After getting Rows and Columns and
3631 * setting 'term'.
3632 */
3633 void
3634set_init_2()
3635{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003636 int idx;
3637
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 /*
3639 * 'scroll' defaults to half the window height. Note that this default is
3640 * wrong when the window height changes.
3641 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003642 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003643 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003644 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003645 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 comp_col();
3647
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003648 /*
3649 * 'window' is only for backwards compatibility with Vi.
3650 * Default is Rows - 1.
3651 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003652 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003653 p_window = Rows - 1;
3654 set_number_default("window", Rows - 1);
3655
Bram Moolenaarf740b292006-02-16 22:11:02 +00003656 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658 /*
3659 * If 'background' wasn't set by the user, try guessing the value,
3660 * depending on the terminal name. Only need to check for terminals
3661 * with a dark background, that can handle color.
3662 */
3663 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003664 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3665 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003667 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003668 /* don't mark it as set, when starting the GUI it may be
3669 * changed again */
3670 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 }
3672#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003673
3674#ifdef CURSOR_SHAPE
3675 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3676#endif
3677#ifdef FEAT_MOUSESHAPE
3678 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3679#endif
3680#ifdef FEAT_PRINTER
3681 (void)parse_printoptions(); /* parse 'printoptions' default value */
3682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683}
3684
3685/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003686 * Return "dark" or "light" depending on the kind of terminal.
3687 * This is just guessing! Recognized are:
3688 * "linux" Linux console
3689 * "screen.linux" Linux console with screen
3690 * "cygwin" Cygwin shell
3691 * "putty" Putty program
3692 * We also check the COLORFGBG environment variable, which is set by
3693 * rxvt and derivatives. This variable contains either two or three
3694 * values separated by semicolons; we want the last value in either
3695 * case. If this value is 0-6 or 8, our background is dark.
3696 */
3697 static char_u *
3698term_bg_default()
3699{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003700#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3701 /* DOS console nearly always black */
3702 return (char_u *)"dark";
3703#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003704 char_u *p;
3705
Bram Moolenaarf740b292006-02-16 22:11:02 +00003706 if (STRCMP(T_NAME, "linux") == 0
3707 || STRCMP(T_NAME, "screen.linux") == 0
3708 || STRCMP(T_NAME, "cygwin") == 0
3709 || STRCMP(T_NAME, "putty") == 0
3710 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3711 && (p = vim_strrchr(p, ';')) != NULL
3712 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3713 && p[2] == NUL))
3714 return (char_u *)"dark";
3715 return (char_u *)"light";
3716#endif
3717}
3718
3719/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 * Initialize the options, part three: After reading the .vimrc
3721 */
3722 void
3723set_init_3()
3724{
3725#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3726/*
3727 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3728 * This is done after other initializations, where 'shell' might have been
3729 * set, but only if they have not been set before.
3730 */
3731 char_u *p;
3732 int idx_srr;
3733 int do_srr;
3734#ifdef FEAT_QUICKFIX
3735 int idx_sp;
3736 int do_sp;
3737#endif
3738
3739 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003740 if (idx_srr < 0)
3741 do_srr = FALSE;
3742 else
3743 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744#ifdef FEAT_QUICKFIX
3745 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003746 if (idx_sp < 0)
3747 do_sp = FALSE;
3748 else
3749 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750#endif
3751
3752 /*
3753 * Isolate the name of the shell:
3754 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3755 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003756 * But don't allow a space in the path, so that this works:
3757 * "/usr/bin/csh --rcfile ~/.cshrc"
3758 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003760#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 p = gettail(p_sh);
3762 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003763#else
3764 p = skiptowhite(p_sh);
3765 if (*p == NUL)
3766 {
3767 /* No white space, use the tail. */
3768 p = vim_strsave(gettail(p_sh));
3769 }
3770 else
3771 {
3772 char_u *p1, *p2;
3773
3774 /* Find the last path separator before the space. */
3775 p1 = p_sh;
3776 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3777 if (vim_ispathsep(*p2))
3778 p1 = p2 + 1;
3779 p = vim_strnsave(p1, (int)(p - p1));
3780 }
3781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782 if (p != NULL)
3783 {
3784 /*
3785 * Default for p_sp is "| tee", for p_srr is ">".
3786 * For known shells it is changed here to include stderr.
3787 */
3788 if ( fnamecmp(p, "csh") == 0
3789 || fnamecmp(p, "tcsh") == 0
3790# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3791 || fnamecmp(p, "csh.exe") == 0
3792 || fnamecmp(p, "tcsh.exe") == 0
3793# endif
3794 )
3795 {
3796#if defined(FEAT_QUICKFIX)
3797 if (do_sp)
3798 {
3799# ifdef WIN3264
3800 p_sp = (char_u *)">&";
3801# else
3802 p_sp = (char_u *)"|& tee";
3803# endif
3804 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3805 }
3806#endif
3807 if (do_srr)
3808 {
3809 p_srr = (char_u *)">&";
3810 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3811 }
3812 }
3813 else
3814# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3815 if ( fnamecmp(p, "sh") == 0
3816 || fnamecmp(p, "ksh") == 0
3817 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003818 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819 || fnamecmp(p, "bash") == 0
3820# ifdef WIN3264
3821 || fnamecmp(p, "cmd") == 0
3822 || fnamecmp(p, "sh.exe") == 0
3823 || fnamecmp(p, "ksh.exe") == 0
3824 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003825 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 || fnamecmp(p, "bash.exe") == 0
3827 || fnamecmp(p, "cmd.exe") == 0
3828# endif
3829 )
3830# endif
3831 {
3832#if defined(FEAT_QUICKFIX)
3833 if (do_sp)
3834 {
3835# ifdef WIN3264
3836 p_sp = (char_u *)">%s 2>&1";
3837# else
3838 p_sp = (char_u *)"2>&1| tee";
3839# endif
3840 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3841 }
3842#endif
3843 if (do_srr)
3844 {
3845 p_srr = (char_u *)">%s 2>&1";
3846 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3847 }
3848 }
3849 vim_free(p);
3850 }
3851#endif
3852
3853#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3854 /*
3855 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3856 * This is done after other initializations, where 'shell' might have been
3857 * set, but only if they have not been set before. Default for p_shcf is
3858 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3859 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3860 * command.com. And for Win32 we need to set p_sxq instead.
3861 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003862 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 {
3864 int idx3;
3865
3866 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003867 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 {
3869 p_shcf = (char_u *)"-c";
3870 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3871 }
3872
3873# ifndef DJGPP
3874# ifdef WIN3264
3875 /* Somehow Win32 requires the quotes around the redirection too */
3876 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003877 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 {
3879 p_sxq = (char_u *)"\"";
3880 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3881 }
3882# else
3883 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003884 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 {
3886 p_shq = (char_u *)"\"";
3887 options[idx3].def_val[VI_DEFAULT] = p_shq;
3888 }
3889# endif
3890# endif
3891 }
3892#endif
3893
3894#ifdef FEAT_TITLE
3895 set_title_defaults();
3896#endif
3897}
3898
3899#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3900/*
3901 * When 'helplang' is still at its default value, set it to "lang".
3902 * Only the first two characters of "lang" are used.
3903 */
3904 void
3905set_helplang_default(lang)
3906 char_u *lang;
3907{
3908 int idx;
3909
3910 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3911 return;
3912 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003913 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 {
3915 if (options[idx].flags & P_ALLOCED)
3916 free_string_option(p_hlg);
3917 p_hlg = vim_strsave(lang);
3918 if (p_hlg == NULL)
3919 p_hlg = empty_option;
3920 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003921 {
3922 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3923 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3924 {
3925 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3926 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003929 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 options[idx].flags |= P_ALLOCED;
3931 }
3932}
3933#endif
3934
3935#ifdef FEAT_GUI
3936static char_u *gui_bg_default __ARGS((void));
3937
3938 static char_u *
3939gui_bg_default()
3940{
3941 if (gui_get_lightness(gui.back_pixel) < 127)
3942 return (char_u *)"dark";
3943 return (char_u *)"light";
3944}
3945
3946/*
3947 * Option initializations that can only be done after opening the GUI window.
3948 */
3949 void
3950init_gui_options()
3951{
3952 /* Set the 'background' option according to the lightness of the
3953 * background color, unless the user has set it already. */
3954 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3955 {
3956 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3957 highlight_changed();
3958 }
3959}
3960#endif
3961
3962#ifdef FEAT_TITLE
3963/*
3964 * 'title' and 'icon' only default to true if they have not been set or reset
3965 * in .vimrc and we can read the old value.
3966 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3967 * they can be reset. This reduces startup time when using X on a remote
3968 * machine.
3969 */
3970 void
3971set_title_defaults()
3972{
3973 int idx1;
3974 long val;
3975
3976 /*
3977 * If GUI is (going to be) used, we can always set the window title and
3978 * icon name. Saves a bit of time, because the X11 display server does
3979 * not need to be contacted.
3980 */
3981 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003982 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 {
3984#ifdef FEAT_GUI
3985 if (gui.starting || gui.in_use)
3986 val = TRUE;
3987 else
3988#endif
3989 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003990 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 p_title = val;
3992 }
3993 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003994 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
3996#ifdef FEAT_GUI
3997 if (gui.starting || gui.in_use)
3998 val = TRUE;
3999 else
4000#endif
4001 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004002 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 p_icon = val;
4004 }
4005}
4006#endif
4007
4008/*
4009 * Parse 'arg' for option settings.
4010 *
4011 * 'arg' may be IObuff, but only when no errors can be present and option
4012 * does not need to be expanded with option_expand().
4013 * "opt_flags":
4014 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004015 * OPT_GLOBAL for ":setglobal"
4016 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004018 * OPT_WINONLY to only set window-local options
4019 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 *
4021 * returns FAIL if an error is detected, OK otherwise
4022 */
4023 int
4024do_set(arg, opt_flags)
4025 char_u *arg; /* option string (may be written to!) */
4026 int opt_flags;
4027{
4028 int opt_idx;
4029 char_u *errmsg;
4030 char_u errbuf[80];
4031 char_u *startarg;
4032 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4033 int nextchar; /* next non-white char after option name */
4034 int afterchar; /* character just after option name */
4035 int len;
4036 int i;
4037 long value;
4038 int key;
4039 long_u flags; /* flags for current option */
4040 char_u *varp = NULL; /* pointer to variable for current option */
4041 int did_show = FALSE; /* already showed one value */
4042 int adding; /* "opt+=arg" */
4043 int prepending; /* "opt^=arg" */
4044 int removing; /* "opt-=arg" */
4045 int cp_val = 0;
4046 char_u key_name[2];
4047
4048 if (*arg == NUL)
4049 {
4050 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004051 did_show = TRUE;
4052 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 }
4054
4055 while (*arg != NUL) /* loop to process all options */
4056 {
4057 errmsg = NULL;
4058 startarg = arg; /* remember for error message */
4059
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004060 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4061 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 {
4063 /*
4064 * ":set all" show all options.
4065 * ":set all&" set all options to their default value.
4066 */
4067 arg += 3;
4068 if (*arg == '&')
4069 {
4070 ++arg;
4071 /* Only for :set command set global value of local options. */
4072 set_options_default(OPT_FREE | opt_flags);
4073 }
4074 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004075 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004077 did_show = TRUE;
4078 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004080 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 {
4082 showoptions(2, opt_flags);
4083 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004084 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 arg += 7;
4086 }
4087 else
4088 {
4089 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004090 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 {
4092 prefix = 0;
4093 arg += 2;
4094 }
4095 else if (STRNCMP(arg, "inv", 3) == 0)
4096 {
4097 prefix = 2;
4098 arg += 3;
4099 }
4100
4101 /* find end of name */
4102 key = 0;
4103 if (*arg == '<')
4104 {
4105 nextchar = 0;
4106 opt_idx = -1;
4107 /* look out for <t_>;> */
4108 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4109 len = 5;
4110 else
4111 {
4112 len = 1;
4113 while (arg[len] != NUL && arg[len] != '>')
4114 ++len;
4115 }
4116 if (arg[len] != '>')
4117 {
4118 errmsg = e_invarg;
4119 goto skip;
4120 }
4121 arg[len] = NUL; /* put NUL after name */
4122 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4123 opt_idx = findoption(arg + 1);
4124 arg[len++] = '>'; /* restore '>' */
4125 if (opt_idx == -1)
4126 key = find_key_option(arg + 1);
4127 }
4128 else
4129 {
4130 len = 0;
4131 /*
4132 * The two characters after "t_" may not be alphanumeric.
4133 */
4134 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4135 len = 4;
4136 else
4137 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4138 ++len;
4139 nextchar = arg[len];
4140 arg[len] = NUL; /* put NUL after name */
4141 opt_idx = findoption(arg);
4142 arg[len] = nextchar; /* restore nextchar */
4143 if (opt_idx == -1)
4144 key = find_key_option(arg);
4145 }
4146
4147 /* remember character after option name */
4148 afterchar = arg[len];
4149
4150 /* skip white space, allow ":set ai ?" */
4151 while (vim_iswhite(arg[len]))
4152 ++len;
4153
4154 adding = FALSE;
4155 prepending = FALSE;
4156 removing = FALSE;
4157 if (arg[len] != NUL && arg[len + 1] == '=')
4158 {
4159 if (arg[len] == '+')
4160 {
4161 adding = TRUE; /* "+=" */
4162 ++len;
4163 }
4164 else if (arg[len] == '^')
4165 {
4166 prepending = TRUE; /* "^=" */
4167 ++len;
4168 }
4169 else if (arg[len] == '-')
4170 {
4171 removing = TRUE; /* "-=" */
4172 ++len;
4173 }
4174 }
4175 nextchar = arg[len];
4176
4177 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4178 {
4179 errmsg = (char_u *)N_("E518: Unknown option");
4180 goto skip;
4181 }
4182
4183 if (opt_idx >= 0)
4184 {
4185 if (options[opt_idx].var == NULL) /* hidden option: skip */
4186 {
4187 /* Only give an error message when requesting the value of
4188 * a hidden option, ignore setting it. */
4189 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4190 && (!(options[opt_idx].flags & P_BOOL)
4191 || nextchar == '?'))
4192 errmsg = (char_u *)N_("E519: Option not supported");
4193 goto skip;
4194 }
4195
4196 flags = options[opt_idx].flags;
4197 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4198 }
4199 else
4200 {
4201 flags = P_STRING;
4202 if (key < 0)
4203 {
4204 key_name[0] = KEY2TERMCAP0(key);
4205 key_name[1] = KEY2TERMCAP1(key);
4206 }
4207 else
4208 {
4209 key_name[0] = KS_KEY;
4210 key_name[1] = (key & 0xff);
4211 }
4212 }
4213
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004214 /* Skip all options that are not window-local (used when showing
4215 * an already loaded buffer in a window). */
4216 if ((opt_flags & OPT_WINONLY)
4217 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4218 goto skip;
4219
Bram Moolenaara3227e22006-03-08 21:32:40 +00004220 /* Skip all options that are window-local (used for :vimgrep). */
4221 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4222 && options[opt_idx].var == VAR_WIN)
4223 goto skip;
4224
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004225 /* Disallow changing some options from modelines. */
4226 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004228 if (flags & P_SECURE)
4229 {
4230 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4231 goto skip;
4232 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004233#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004234 /* In diff mode some options are overruled. This avoids that
4235 * 'foldmethod' becomes "marker" instead of "diff" and that
4236 * "wrap" gets set. */
4237 if (curwin->w_p_diff
4238 && (options[opt_idx].indir == PV_FDM
4239 || options[opt_idx].indir == PV_WRAP))
4240 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242 }
4243
4244#ifdef HAVE_SANDBOX
4245 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004246 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 {
4248 errmsg = (char_u *)_(e_sandbox);
4249 goto skip;
4250 }
4251#endif
4252
4253 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4254 {
4255 arg += len;
4256 cp_val = p_cp;
4257 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4258 {
4259 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4260 {
4261 cp_val = FALSE;
4262 arg += 3;
4263 }
4264 else /* "opt&vi": set to Vi default */
4265 {
4266 cp_val = TRUE;
4267 arg += 2;
4268 }
4269 }
4270 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4271 && arg[1] != NUL && !vim_iswhite(arg[1]))
4272 {
4273 errmsg = e_trailing;
4274 goto skip;
4275 }
4276 }
4277
4278 /*
4279 * allow '=' and ':' as MSDOS command.com allows only one
4280 * '=' character per "set" command line. grrr. (jw)
4281 */
4282 if (nextchar == '?'
4283 || (prefix == 1
4284 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4285 && !(flags & P_BOOL)))
4286 {
4287 /*
4288 * print value
4289 */
4290 if (did_show)
4291 msg_putchar('\n'); /* cursor below last one */
4292 else
4293 {
4294 gotocmdline(TRUE); /* cursor at status line */
4295 did_show = TRUE; /* remember that we did a line */
4296 }
4297 if (opt_idx >= 0)
4298 {
4299 showoneopt(&options[opt_idx], opt_flags);
4300#ifdef FEAT_EVAL
4301 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004302 {
4303 /* Mention where the option was last set. */
4304 if (varp == options[opt_idx].var)
4305 last_set_msg(options[opt_idx].scriptID);
4306 else if ((int)options[opt_idx].indir & PV_WIN)
4307 last_set_msg(curwin->w_p_scriptID[
4308 (int)options[opt_idx].indir & PV_MASK]);
4309 else if ((int)options[opt_idx].indir & PV_BUF)
4310 last_set_msg(curbuf->b_p_scriptID[
4311 (int)options[opt_idx].indir & PV_MASK]);
4312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313#endif
4314 }
4315 else
4316 {
4317 char_u *p;
4318
4319 p = find_termcode(key_name);
4320 if (p == NULL)
4321 {
4322 errmsg = (char_u *)N_("E518: Unknown option");
4323 goto skip;
4324 }
4325 else
4326 (void)show_one_termcode(key_name, p, TRUE);
4327 }
4328 if (nextchar != '?'
4329 && nextchar != NUL && !vim_iswhite(afterchar))
4330 errmsg = e_trailing;
4331 }
4332 else
4333 {
4334 if (flags & P_BOOL) /* boolean */
4335 {
4336 if (nextchar == '=' || nextchar == ':')
4337 {
4338 errmsg = e_invarg;
4339 goto skip;
4340 }
4341
4342 /*
4343 * ":set opt!": invert
4344 * ":set opt&": reset to default value
4345 * ":set opt<": reset to global value
4346 */
4347 if (nextchar == '!')
4348 value = *(int *)(varp) ^ 1;
4349 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004350 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004351 ((flags & P_VI_DEF) || cp_val)
4352 ? VI_DEFAULT : VIM_DEFAULT];
4353 else if (nextchar == '<')
4354 {
4355 /* For 'autoread' -1 means to use global value. */
4356 if ((int *)varp == &curbuf->b_p_ar
4357 && opt_flags == OPT_LOCAL)
4358 value = -1;
4359 else
4360 value = *(int *)get_varp_scope(&(options[opt_idx]),
4361 OPT_GLOBAL);
4362 }
4363 else
4364 {
4365 /*
4366 * ":set invopt": invert
4367 * ":set opt" or ":set noopt": set or reset
4368 */
4369 if (nextchar != NUL && !vim_iswhite(afterchar))
4370 {
4371 errmsg = e_trailing;
4372 goto skip;
4373 }
4374 if (prefix == 2) /* inv */
4375 value = *(int *)(varp) ^ 1;
4376 else
4377 value = prefix;
4378 }
4379
4380 errmsg = set_bool_option(opt_idx, varp, (int)value,
4381 opt_flags);
4382 }
4383 else /* numeric or string */
4384 {
4385 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4386 || prefix != 1)
4387 {
4388 errmsg = e_invarg;
4389 goto skip;
4390 }
4391
4392 if (flags & P_NUM) /* numeric */
4393 {
4394 /*
4395 * Different ways to set a number option:
4396 * & set to default value
4397 * < set to global value
4398 * <xx> accept special key codes for 'wildchar'
4399 * c accept any non-digit for 'wildchar'
4400 * [-]0-9 set number
4401 * other error
4402 */
4403 ++arg;
4404 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004405 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406 ((flags & P_VI_DEF) || cp_val)
4407 ? VI_DEFAULT : VIM_DEFAULT];
4408 else if (nextchar == '<')
4409 value = *(long *)get_varp_scope(&(options[opt_idx]),
4410 OPT_GLOBAL);
4411 else if (((long *)varp == &p_wc
4412 || (long *)varp == &p_wcm)
4413 && (*arg == '<'
4414 || *arg == '^'
4415 || ((!arg[1] || vim_iswhite(arg[1]))
4416 && !VIM_ISDIGIT(*arg))))
4417 {
4418 value = string_to_key(arg);
4419 if (value == 0 && (long *)varp != &p_wcm)
4420 {
4421 errmsg = e_invarg;
4422 goto skip;
4423 }
4424 }
4425 /* allow negative numbers (for 'undolevels') */
4426 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4427 {
4428 i = 0;
4429 if (*arg == '-')
4430 i = 1;
4431#ifdef HAVE_STRTOL
4432 value = strtol((char *)arg, NULL, 0);
4433 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4434 i += 2;
4435#else
4436 value = atol((char *)arg);
4437#endif
4438 while (VIM_ISDIGIT(arg[i]))
4439 ++i;
4440 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4441 {
4442 errmsg = e_invarg;
4443 goto skip;
4444 }
4445 }
4446 else
4447 {
4448 errmsg = (char_u *)N_("E521: Number required after =");
4449 goto skip;
4450 }
4451
4452 if (adding)
4453 value = *(long *)varp + value;
4454 if (prepending)
4455 value = *(long *)varp * value;
4456 if (removing)
4457 value = *(long *)varp - value;
4458 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004459 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460 }
4461 else if (opt_idx >= 0) /* string */
4462 {
4463 char_u *save_arg = NULL;
4464 char_u *s = NULL;
4465 char_u *oldval; /* previous value if *varp */
4466 char_u *newval;
4467 char_u *origval;
4468 unsigned newlen;
4469 int comma;
4470 int bs;
4471 int new_value_alloced; /* new string option
4472 was allocated */
4473
4474 /* When using ":set opt=val" for a global option
4475 * with a local value the local value will be
4476 * reset, use the global value here. */
4477 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004478 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479 varp = options[opt_idx].var;
4480
4481 /* The old value is kept until we are sure that the
4482 * new value is valid. */
4483 oldval = *(char_u **)varp;
4484 if (nextchar == '&') /* set to default val */
4485 {
4486 newval = options[opt_idx].def_val[
4487 ((flags & P_VI_DEF) || cp_val)
4488 ? VI_DEFAULT : VIM_DEFAULT];
4489 if ((char_u **)varp == &p_bg)
4490 {
4491 /* guess the value of 'background' */
4492#ifdef FEAT_GUI
4493 if (gui.in_use)
4494 newval = gui_bg_default();
4495 else
4496#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004497 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004498 }
4499
4500 /* expand environment variables and ~ (since the
4501 * default value was already expanded, only
4502 * required when an environment variable was set
4503 * later */
4504 if (newval == NULL)
4505 newval = empty_option;
4506 else
4507 {
4508 s = option_expand(opt_idx, newval);
4509 if (s == NULL)
4510 s = newval;
4511 newval = vim_strsave(s);
4512 }
4513 new_value_alloced = TRUE;
4514 }
4515 else if (nextchar == '<') /* set to global val */
4516 {
4517 newval = vim_strsave(*(char_u **)get_varp_scope(
4518 &(options[opt_idx]), OPT_GLOBAL));
4519 new_value_alloced = TRUE;
4520 }
4521 else
4522 {
4523 ++arg; /* jump to after the '=' or ':' */
4524
4525 /*
4526 * Set 'keywordprg' to ":help" if an empty
4527 * value was passed to :set by the user.
4528 * Misuse errbuf[] for the resulting string.
4529 */
4530 if (varp == (char_u *)&p_kp
4531 && (*arg == NUL || *arg == ' '))
4532 {
4533 STRCPY(errbuf, ":help");
4534 save_arg = arg;
4535 arg = errbuf;
4536 }
4537 /*
4538 * Convert 'whichwrap' number to string, for
4539 * backwards compatibility with Vim 3.0.
4540 * Misuse errbuf[] for the resulting string.
4541 */
4542 else if (varp == (char_u *)&p_ww
4543 && VIM_ISDIGIT(*arg))
4544 {
4545 *errbuf = NUL;
4546 i = getdigits(&arg);
4547 if (i & 1)
4548 STRCAT(errbuf, "b,");
4549 if (i & 2)
4550 STRCAT(errbuf, "s,");
4551 if (i & 4)
4552 STRCAT(errbuf, "h,l,");
4553 if (i & 8)
4554 STRCAT(errbuf, "<,>,");
4555 if (i & 16)
4556 STRCAT(errbuf, "[,],");
4557 if (*errbuf != NUL) /* remove trailing , */
4558 errbuf[STRLEN(errbuf) - 1] = NUL;
4559 save_arg = arg;
4560 arg = errbuf;
4561 }
4562 /*
4563 * Remove '>' before 'dir' and 'bdir', for
4564 * backwards compatibility with version 3.0
4565 */
4566 else if ( *arg == '>'
4567 && (varp == (char_u *)&p_dir
4568 || varp == (char_u *)&p_bdir))
4569 {
4570 ++arg;
4571 }
4572
4573 /* When setting the local value of a global
4574 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004575 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 && (opt_flags & OPT_LOCAL))
4577 origval = *(char_u **)get_varp(
4578 &options[opt_idx]);
4579 else
4580 origval = oldval;
4581
4582 /*
4583 * Copy the new string into allocated memory.
4584 * Can't use set_string_option_direct(), because
4585 * we need to remove the backslashes.
4586 */
4587 /* get a bit too much */
4588 newlen = (unsigned)STRLEN(arg) + 1;
4589 if (adding || prepending || removing)
4590 newlen += (unsigned)STRLEN(origval) + 1;
4591 newval = alloc(newlen);
4592 if (newval == NULL) /* out of mem, don't change */
4593 break;
4594 s = newval;
4595
4596 /*
4597 * Copy the string, skip over escaped chars.
4598 * For MS-DOS and WIN32 backslashes before normal
4599 * file name characters are not removed, and keep
4600 * backslash at start, for "\\machine\path", but
4601 * do remove it for "\\\\machine\\path".
4602 * The reverse is found in ExpandOldSetting().
4603 */
4604 while (*arg && !vim_iswhite(*arg))
4605 {
4606 if (*arg == '\\' && arg[1] != NUL
4607#ifdef BACKSLASH_IN_FILENAME
4608 && !((flags & P_EXPAND)
4609 && vim_isfilec(arg[1])
4610 && (arg[1] != '\\'
4611 || (s == newval
4612 && arg[2] != '\\')))
4613#endif
4614 )
4615 ++arg; /* remove backslash */
4616#ifdef FEAT_MBYTE
4617 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004618 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 {
4620 /* copy multibyte char */
4621 mch_memmove(s, arg, (size_t)i);
4622 arg += i;
4623 s += i;
4624 }
4625 else
4626#endif
4627 *s++ = *arg++;
4628 }
4629 *s = NUL;
4630
4631 /*
4632 * Expand environment variables and ~.
4633 * Don't do it when adding without inserting a
4634 * comma.
4635 */
4636 if (!(adding || prepending || removing)
4637 || (flags & P_COMMA))
4638 {
4639 s = option_expand(opt_idx, newval);
4640 if (s != NULL)
4641 {
4642 vim_free(newval);
4643 newlen = (unsigned)STRLEN(s) + 1;
4644 if (adding || prepending || removing)
4645 newlen += (unsigned)STRLEN(origval) + 1;
4646 newval = alloc(newlen);
4647 if (newval == NULL)
4648 break;
4649 STRCPY(newval, s);
4650 }
4651 }
4652
4653 /* locate newval[] in origval[] when removing it
4654 * and when adding to avoid duplicates */
4655 i = 0; /* init for GCC */
4656 if (removing || (flags & P_NODUP))
4657 {
4658 i = (int)STRLEN(newval);
4659 bs = 0;
4660 for (s = origval; *s; ++s)
4661 {
4662 if ((!(flags & P_COMMA)
4663 || s == origval
4664 || (s[-1] == ',' && !(bs & 1)))
4665 && STRNCMP(s, newval, i) == 0
4666 && (!(flags & P_COMMA)
4667 || s[i] == ','
4668 || s[i] == NUL))
4669 break;
4670 /* Count backspaces. Only a comma with an
4671 * even number of backspaces before it is
4672 * recognized as a separator */
4673 if (s > origval && s[-1] == '\\')
4674 ++bs;
4675 else
4676 bs = 0;
4677 }
4678
4679 /* do not add if already there */
4680 if ((adding || prepending) && *s)
4681 {
4682 prepending = FALSE;
4683 adding = FALSE;
4684 STRCPY(newval, origval);
4685 }
4686 }
4687
4688 /* concatenate the two strings; add a ',' if
4689 * needed */
4690 if (adding || prepending)
4691 {
4692 comma = ((flags & P_COMMA) && *origval != NUL
4693 && *newval != NUL);
4694 if (adding)
4695 {
4696 i = (int)STRLEN(origval);
4697 mch_memmove(newval + i + comma, newval,
4698 STRLEN(newval) + 1);
4699 mch_memmove(newval, origval, (size_t)i);
4700 }
4701 else
4702 {
4703 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004704 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004705 }
4706 if (comma)
4707 newval[i] = ',';
4708 }
4709
4710 /* Remove newval[] from origval[]. (Note: "i" has
4711 * been set above and is used here). */
4712 if (removing)
4713 {
4714 STRCPY(newval, origval);
4715 if (*s)
4716 {
4717 /* may need to remove a comma */
4718 if (flags & P_COMMA)
4719 {
4720 if (s == origval)
4721 {
4722 /* include comma after string */
4723 if (s[i] == ',')
4724 ++i;
4725 }
4726 else
4727 {
4728 /* include comma before string */
4729 --s;
4730 ++i;
4731 }
4732 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004733 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 }
4735 }
4736
4737 if (flags & P_FLAGLIST)
4738 {
4739 /* Remove flags that appear twice. */
4740 for (s = newval; *s; ++s)
4741 if ((!(flags & P_COMMA) || *s != ',')
4742 && vim_strchr(s + 1, *s) != NULL)
4743 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004744 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 --s;
4746 }
4747 }
4748
4749 if (save_arg != NULL) /* number for 'whichwrap' */
4750 arg = save_arg;
4751 new_value_alloced = TRUE;
4752 }
4753
4754 /* Set the new value. */
4755 *(char_u **)(varp) = newval;
4756
4757 /* Handle side effects, and set the global value for
4758 * ":set" on local options. */
4759 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4760 new_value_alloced, oldval, errbuf, opt_flags);
4761
4762 /* If error detected, print the error message. */
4763 if (errmsg != NULL)
4764 goto skip;
4765 }
4766 else /* key code option */
4767 {
4768 char_u *p;
4769
4770 if (nextchar == '&')
4771 {
4772 if (add_termcap_entry(key_name, TRUE) == FAIL)
4773 errmsg = (char_u *)N_("E522: Not found in termcap");
4774 }
4775 else
4776 {
4777 ++arg; /* jump to after the '=' or ':' */
4778 for (p = arg; *p && !vim_iswhite(*p); ++p)
4779 if (*p == '\\' && p[1] != NUL)
4780 ++p;
4781 nextchar = *p;
4782 *p = NUL;
4783 add_termcode(key_name, arg, FALSE);
4784 *p = nextchar;
4785 }
4786 if (full_screen)
4787 ttest(FALSE);
4788 redraw_all_later(CLEAR);
4789 }
4790 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004791
Bram Moolenaar071d4272004-06-13 20:20:40 +00004792 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004793 did_set_option(opt_idx, opt_flags,
4794 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 }
4796
4797skip:
4798 /*
4799 * Advance to next argument.
4800 * - skip until a blank found, taking care of backslashes
4801 * - skip blanks
4802 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4803 */
4804 for (i = 0; i < 2 ; ++i)
4805 {
4806 while (*arg != NUL && !vim_iswhite(*arg))
4807 if (*arg++ == '\\' && *arg != NUL)
4808 ++arg;
4809 arg = skipwhite(arg);
4810 if (*arg != '=')
4811 break;
4812 }
4813 }
4814
4815 if (errmsg != NULL)
4816 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004817 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004818 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004819 if (i + (arg - startarg) < IOSIZE)
4820 {
4821 /* append the argument with the error */
4822 STRCAT(IObuff, ": ");
4823 mch_memmove(IObuff + i, startarg, (arg - startarg));
4824 IObuff[i + (arg - startarg)] = NUL;
4825 }
4826 /* make sure all characters are printable */
4827 trans_characters(IObuff, IOSIZE);
4828
4829 ++no_wait_return; /* wait_return done later */
4830 emsg(IObuff); /* show error highlighted */
4831 --no_wait_return;
4832
4833 return FAIL;
4834 }
4835
4836 arg = skipwhite(arg);
4837 }
4838
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004839theend:
4840 if (silent_mode && did_show)
4841 {
4842 /* After displaying option values in silent mode. */
4843 silent_mode = FALSE;
4844 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4845 msg_putchar('\n');
4846 cursor_on(); /* msg_start() switches it off */
4847 out_flush();
4848 silent_mode = TRUE;
4849 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4850 }
4851
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 return OK;
4853}
4854
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004855/*
4856 * Call this when an option has been given a new value through a user command.
4857 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4858 */
4859 static void
4860did_set_option(opt_idx, opt_flags, new_value)
4861 int opt_idx;
4862 int opt_flags; /* possibly with OPT_MODELINE */
4863 int new_value; /* value was replaced completely */
4864{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004865 long_u *p;
4866
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004867 options[opt_idx].flags |= P_WAS_SET;
4868
4869 /* When an option is set in the sandbox, from a modeline or in secure mode
4870 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004871 * flag. */
4872 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004873 if (secure
4874#ifdef HAVE_SANDBOX
4875 || sandbox != 0
4876#endif
4877 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004878 *p = *p | P_INSECURE;
4879 else if (new_value)
4880 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004881}
4882
Bram Moolenaar071d4272004-06-13 20:20:40 +00004883 static char_u *
4884illegal_char(errbuf, c)
4885 char_u *errbuf;
4886 int c;
4887{
4888 if (errbuf == NULL)
4889 return (char_u *)"";
4890 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004891 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 return errbuf;
4893}
4894
4895/*
4896 * Convert a key name or string into a key value.
4897 * Used for 'wildchar' and 'cedit' options.
4898 */
4899 static int
4900string_to_key(arg)
4901 char_u *arg;
4902{
4903 if (*arg == '<')
4904 return find_key_option(arg + 1);
4905 if (*arg == '^')
4906 return Ctrl_chr(arg[1]);
4907 return *arg;
4908}
4909
4910#ifdef FEAT_CMDWIN
4911/*
4912 * Check value of 'cedit' and set cedit_key.
4913 * Returns NULL if value is OK, error message otherwise.
4914 */
4915 static char_u *
4916check_cedit()
4917{
4918 int n;
4919
4920 if (*p_cedit == NUL)
4921 cedit_key = -1;
4922 else
4923 {
4924 n = string_to_key(p_cedit);
4925 if (vim_isprintc(n))
4926 return e_invarg;
4927 cedit_key = n;
4928 }
4929 return NULL;
4930}
4931#endif
4932
4933#ifdef FEAT_TITLE
4934/*
4935 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4936 * maketitle() to create and display it.
4937 * When switching the title or icon off, call mch_restore_title() to get
4938 * the old value back.
4939 */
4940 static void
4941did_set_title(icon)
4942 int icon; /* Did set icon instead of title */
4943{
4944 if (starting != NO_SCREEN
4945#ifdef FEAT_GUI
4946 && !gui.starting
4947#endif
4948 )
4949 {
4950 maketitle();
4951 if (icon)
4952 {
4953 if (!p_icon)
4954 mch_restore_title(2);
4955 }
4956 else
4957 {
4958 if (!p_title)
4959 mch_restore_title(1);
4960 }
4961 }
4962}
4963#endif
4964
4965/*
4966 * set_options_bin - called when 'bin' changes value.
4967 */
4968 void
4969set_options_bin(oldval, newval, opt_flags)
4970 int oldval;
4971 int newval;
4972 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4973{
4974 /*
4975 * The option values that are changed when 'bin' changes are
4976 * copied when 'bin is set and restored when 'bin' is reset.
4977 */
4978 if (newval)
4979 {
4980 if (!oldval) /* switched on */
4981 {
4982 if (!(opt_flags & OPT_GLOBAL))
4983 {
4984 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4985 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4986 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4987 curbuf->b_p_et_nobin = curbuf->b_p_et;
4988 }
4989 if (!(opt_flags & OPT_LOCAL))
4990 {
4991 p_tw_nobin = p_tw;
4992 p_wm_nobin = p_wm;
4993 p_ml_nobin = p_ml;
4994 p_et_nobin = p_et;
4995 }
4996 }
4997
4998 if (!(opt_flags & OPT_GLOBAL))
4999 {
5000 curbuf->b_p_tw = 0; /* no automatic line wrap */
5001 curbuf->b_p_wm = 0; /* no automatic line wrap */
5002 curbuf->b_p_ml = 0; /* no modelines */
5003 curbuf->b_p_et = 0; /* no expandtab */
5004 }
5005 if (!(opt_flags & OPT_LOCAL))
5006 {
5007 p_tw = 0;
5008 p_wm = 0;
5009 p_ml = FALSE;
5010 p_et = FALSE;
5011 p_bin = TRUE; /* needed when called for the "-b" argument */
5012 }
5013 }
5014 else if (oldval) /* switched off */
5015 {
5016 if (!(opt_flags & OPT_GLOBAL))
5017 {
5018 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5019 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5020 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5021 curbuf->b_p_et = curbuf->b_p_et_nobin;
5022 }
5023 if (!(opt_flags & OPT_LOCAL))
5024 {
5025 p_tw = p_tw_nobin;
5026 p_wm = p_wm_nobin;
5027 p_ml = p_ml_nobin;
5028 p_et = p_et_nobin;
5029 }
5030 }
5031}
5032
5033#ifdef FEAT_VIMINFO
5034/*
5035 * Find the parameter represented by the given character (eg ', :, ", or /),
5036 * and return its associated value in the 'viminfo' string.
5037 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005038 * If the parameter is not specified in the string or there is no following
5039 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 */
5041 int
5042get_viminfo_parameter(type)
5043 int type;
5044{
5045 char_u *p;
5046
5047 p = find_viminfo_parameter(type);
5048 if (p != NULL && VIM_ISDIGIT(*p))
5049 return atoi((char *)p);
5050 return -1;
5051}
5052
5053/*
5054 * Find the parameter represented by the given character (eg ''', ':', '"', or
5055 * '/') in the 'viminfo' option and return a pointer to the string after it.
5056 * Return NULL if the parameter is not specified in the string.
5057 */
5058 char_u *
5059find_viminfo_parameter(type)
5060 int type;
5061{
5062 char_u *p;
5063
5064 for (p = p_viminfo; *p; ++p)
5065 {
5066 if (*p == type)
5067 return p + 1;
5068 if (*p == 'n') /* 'n' is always the last one */
5069 break;
5070 p = vim_strchr(p, ','); /* skip until next ',' */
5071 if (p == NULL) /* hit the end without finding parameter */
5072 break;
5073 }
5074 return NULL;
5075}
5076#endif
5077
5078/*
5079 * Expand environment variables for some string options.
5080 * These string options cannot be indirect!
5081 * If "val" is NULL expand the current value of the option.
5082 * Return pointer to NameBuff, or NULL when not expanded.
5083 */
5084 static char_u *
5085option_expand(opt_idx, val)
5086 int opt_idx;
5087 char_u *val;
5088{
5089 /* if option doesn't need expansion nothing to do */
5090 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5091 return NULL;
5092
5093 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5094 * expand_env() would truncate the string. */
5095 if (val != NULL && STRLEN(val) > MAXPATHL)
5096 return NULL;
5097
5098 if (val == NULL)
5099 val = *(char_u **)options[opt_idx].var;
5100
5101 /*
5102 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5103 * Escape spaces when expanding 'tags', they are used to separate file
5104 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005105 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 */
5107 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005108 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005109#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005110 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5111#endif
5112 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5114 return NULL;
5115
5116 return NameBuff;
5117}
5118
5119/*
5120 * After setting various option values: recompute variables that depend on
5121 * option values.
5122 */
5123 static void
5124didset_options()
5125{
5126 /* initialize the table for 'iskeyword' et.al. */
5127 (void)init_chartab();
5128
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005129#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005130 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5133#ifdef FEAT_SESSION
5134 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5135 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5136#endif
5137#ifdef FEAT_FOLDING
5138 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5139#endif
5140 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5141#ifdef FEAT_VIRTUALEDIT
5142 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5143#endif
5144#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5145 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5146#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005147#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005148 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005149 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005150 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005151#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5153 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5154#endif
5155#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5156 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5157#endif
5158#ifdef FEAT_CMDWIN
5159 /* set cedit_key */
5160 (void)check_cedit();
5161#endif
5162}
5163
5164/*
5165 * Check for string options that are NULL (normally only termcap options).
5166 */
5167 void
5168check_options()
5169{
5170 int opt_idx;
5171
5172 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5173 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5174 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5175}
5176
5177/*
5178 * Check string options in a buffer for NULL value.
5179 */
5180 void
5181check_buf_options(buf)
5182 buf_T *buf;
5183{
5184#if defined(FEAT_QUICKFIX)
5185 check_string_option(&buf->b_p_bh);
5186 check_string_option(&buf->b_p_bt);
5187#endif
5188#ifdef FEAT_MBYTE
5189 check_string_option(&buf->b_p_fenc);
5190#endif
5191 check_string_option(&buf->b_p_ff);
5192#ifdef FEAT_FIND_ID
5193 check_string_option(&buf->b_p_def);
5194 check_string_option(&buf->b_p_inc);
5195# ifdef FEAT_EVAL
5196 check_string_option(&buf->b_p_inex);
5197# endif
5198#endif
5199#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5200 check_string_option(&buf->b_p_inde);
5201 check_string_option(&buf->b_p_indk);
5202#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005203#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5204 check_string_option(&buf->b_p_bexpr);
5205#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005206#if defined(FEAT_EVAL)
5207 check_string_option(&buf->b_p_fex);
5208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005209#ifdef FEAT_CRYPT
5210 check_string_option(&buf->b_p_key);
5211#endif
5212 check_string_option(&buf->b_p_kp);
5213 check_string_option(&buf->b_p_mps);
5214 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005215 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005216 check_string_option(&buf->b_p_isk);
5217#ifdef FEAT_COMMENTS
5218 check_string_option(&buf->b_p_com);
5219#endif
5220#ifdef FEAT_FOLDING
5221 check_string_option(&buf->b_p_cms);
5222#endif
5223 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005224#ifdef FEAT_TEXTOBJ
5225 check_string_option(&buf->b_p_qe);
5226#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005227#ifdef FEAT_SYN_HL
5228 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005229#endif
5230#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005231 check_string_option(&buf->b_s.b_p_spc);
5232 check_string_option(&buf->b_s.b_p_spf);
5233 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234#endif
5235#ifdef FEAT_SEARCHPATH
5236 check_string_option(&buf->b_p_sua);
5237#endif
5238#ifdef FEAT_CINDENT
5239 check_string_option(&buf->b_p_cink);
5240 check_string_option(&buf->b_p_cino);
5241#endif
5242#ifdef FEAT_AUTOCMD
5243 check_string_option(&buf->b_p_ft);
5244#endif
5245#ifdef FEAT_OSFILETYPE
5246 check_string_option(&buf->b_p_oft);
5247#endif
5248#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5249 check_string_option(&buf->b_p_cinw);
5250#endif
5251#ifdef FEAT_INS_EXPAND
5252 check_string_option(&buf->b_p_cpt);
5253#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005254#ifdef FEAT_COMPL_FUNC
5255 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005256 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258#ifdef FEAT_KEYMAP
5259 check_string_option(&buf->b_p_keymap);
5260#endif
5261#ifdef FEAT_QUICKFIX
5262 check_string_option(&buf->b_p_gp);
5263 check_string_option(&buf->b_p_mp);
5264 check_string_option(&buf->b_p_efm);
5265#endif
5266 check_string_option(&buf->b_p_ep);
5267 check_string_option(&buf->b_p_path);
5268 check_string_option(&buf->b_p_tags);
5269#ifdef FEAT_INS_EXPAND
5270 check_string_option(&buf->b_p_dict);
5271 check_string_option(&buf->b_p_tsr);
5272#endif
5273}
5274
5275/*
5276 * Free the string allocated for an option.
5277 * Checks for the string being empty_option. This may happen if we're out of
5278 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5279 * check_options().
5280 * Does NOT check for P_ALLOCED flag!
5281 */
5282 void
5283free_string_option(p)
5284 char_u *p;
5285{
5286 if (p != empty_option)
5287 vim_free(p);
5288}
5289
5290 void
5291clear_string_option(pp)
5292 char_u **pp;
5293{
5294 if (*pp != empty_option)
5295 vim_free(*pp);
5296 *pp = empty_option;
5297}
5298
5299 static void
5300check_string_option(pp)
5301 char_u **pp;
5302{
5303 if (*pp == NULL)
5304 *pp = empty_option;
5305}
5306
5307/*
5308 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5309 */
5310 void
5311set_term_option_alloced(p)
5312 char_u **p;
5313{
5314 int opt_idx;
5315
5316 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5317 if (options[opt_idx].var == (char_u *)p)
5318 {
5319 options[opt_idx].flags |= P_ALLOCED;
5320 return;
5321 }
5322 return; /* cannot happen: didn't find it! */
5323}
5324
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005325#if defined(FEAT_EVAL) || defined(PROTO)
5326/*
5327 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5328 * Return FALSE when it wasn't.
5329 * Return -1 for an unknown option.
5330 */
5331 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005332was_set_insecurely(opt, opt_flags)
5333 char_u *opt;
5334 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005335{
5336 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005337 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005338
5339 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005340 {
5341 flagp = insecure_flag(idx, opt_flags);
5342 return (*flagp & P_INSECURE) != 0;
5343 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005344 EMSG2(_(e_intern2), "was_set_insecurely()");
5345 return -1;
5346}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005347
5348/*
5349 * Get a pointer to the flags used for the P_INSECURE flag of option
5350 * "opt_idx". For some local options a local flags field is used.
5351 */
5352 static long_u *
5353insecure_flag(opt_idx, opt_flags)
5354 int opt_idx;
5355 int opt_flags;
5356{
5357 if (opt_flags & OPT_LOCAL)
5358 switch ((int)options[opt_idx].indir)
5359 {
5360#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005361 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005362#endif
5363#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005364# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005365 case PV_FDE: return &curwin->w_p_fde_flags;
5366 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005367# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005368# ifdef FEAT_BEVAL
5369 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5370# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005371# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005372 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005373# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005374 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005375# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005376 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005377# endif
5378#endif
5379 }
5380
5381 /* Nothing special, return global flags field. */
5382 return &options[opt_idx].flags;
5383}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005384#endif
5385
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005386#ifdef FEAT_TITLE
5387static void redraw_titles __ARGS((void));
5388
5389/*
5390 * Redraw the window title and/or tab page text later.
5391 */
5392static void redraw_titles()
5393{
5394 need_maketitle = TRUE;
5395# ifdef FEAT_WINDOWS
5396 redraw_tabline = TRUE;
5397# endif
5398}
5399#endif
5400
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401/*
5402 * Set a string option to a new value (without checking the effect).
5403 * The string is copied into allocated memory.
5404 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005405 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005406 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407 */
5408 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005409set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005410 char_u *name;
5411 int opt_idx;
5412 char_u *val;
5413 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005414 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005415{
5416 char_u *s;
5417 char_u **varp;
5418 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005419 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005420
Bram Moolenaar89d40322006-08-29 15:30:07 +00005421 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005423 idx = findoption(name);
5424 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005425 {
5426 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005429 }
5430
Bram Moolenaar89d40322006-08-29 15:30:07 +00005431 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432 return;
5433
5434 s = vim_strsave(val);
5435 if (s != NULL)
5436 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005437 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005438 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005439 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 free_string_option(*varp);
5441 *varp = s;
5442
5443 /* For buffer/window local option may also set the global value. */
5444 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005445 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446
Bram Moolenaar89d40322006-08-29 15:30:07 +00005447 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005448
5449 /* When setting both values of a global option with a local value,
5450 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005451 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452 {
5453 free_string_option(*varp);
5454 *varp = empty_option;
5455 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005456# ifdef FEAT_EVAL
5457 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005458 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005459 set_sid == 0 ? current_SID : set_sid);
5460# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461 }
5462}
5463
5464/*
5465 * Set global value for string option when it's a local option.
5466 */
5467 static void
5468set_string_option_global(opt_idx, varp)
5469 int opt_idx; /* option index */
5470 char_u **varp; /* pointer to option variable */
5471{
5472 char_u **p, *s;
5473
5474 /* the global value is always allocated */
5475 if (options[opt_idx].var == VAR_WIN)
5476 p = (char_u **)GLOBAL_WO(varp);
5477 else
5478 p = (char_u **)options[opt_idx].var;
5479 if (options[opt_idx].indir != PV_NONE
5480 && p != varp
5481 && (s = vim_strsave(*varp)) != NULL)
5482 {
5483 free_string_option(*p);
5484 *p = s;
5485 }
5486}
5487
5488/*
5489 * Set a string option to a new value, and handle the effects.
5490 */
5491 static void
5492set_string_option(opt_idx, value, opt_flags)
5493 int opt_idx;
5494 char_u *value;
5495 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5496{
5497 char_u *s;
5498 char_u **varp;
5499 char_u *oldval;
5500
5501 if (options[opt_idx].var == NULL) /* don't set hidden option */
5502 return;
5503
5504 s = vim_strsave(value);
5505 if (s != NULL)
5506 {
5507 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5508 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005509 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510 ? OPT_GLOBAL : OPT_LOCAL)
5511 : opt_flags);
5512 oldval = *varp;
5513 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005514 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5515 opt_flags) == NULL)
5516 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517 }
5518}
5519
5520/*
5521 * Handle string options that need some action to perform when changed.
5522 * Returns NULL for success, or an error message for an error.
5523 */
5524 static char_u *
5525did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5526 opt_flags)
5527 int opt_idx; /* index in options[] table */
5528 char_u **varp; /* pointer to the option variable */
5529 int new_value_alloced; /* new value was allocated */
5530 char_u *oldval; /* previous value of the option */
5531 char_u *errbuf; /* buffer for errors, or NULL */
5532 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5533{
5534 char_u *errmsg = NULL;
5535 char_u *s, *p;
5536 int did_chartab = FALSE;
5537 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005538 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005539#ifdef FEAT_GUI
5540 /* set when changing an option that only requires a redraw in the GUI */
5541 int redraw_gui_only = FALSE;
5542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543
5544 /* Get the global option to compare with, otherwise we would have to check
5545 * two values for all local options. */
5546 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5547
5548 /* Disallow changing some options from secure mode */
5549 if ((secure
5550#ifdef HAVE_SANDBOX
5551 || sandbox != 0
5552#endif
5553 ) && (options[opt_idx].flags & P_SECURE))
5554 {
5555 errmsg = e_secure;
5556 }
5557
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005558 /* Check for a "normal" file name in some options. Disallow a path
5559 * separator (slash and/or backslash), wildcards and characters that are
5560 * often illegal in a file name. */
5561 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005562 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005563 {
5564 errmsg = e_invarg;
5565 }
5566
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567 /* 'term' */
5568 else if (varp == &T_NAME)
5569 {
5570 if (T_NAME[0] == NUL)
5571 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5572#ifdef FEAT_GUI
5573 if (gui.in_use)
5574 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5575 else if (term_is_gui(T_NAME))
5576 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5577#endif
5578 else if (set_termname(T_NAME) == FAIL)
5579 errmsg = (char_u *)N_("E522: Not found in termcap");
5580 else
5581 /* Screen colors may have changed. */
5582 redraw_later_clear();
5583 }
5584
5585 /* 'backupcopy' */
5586 else if (varp == &p_bkc)
5587 {
5588 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5589 errmsg = e_invarg;
5590 if (((bkc_flags & BKC_AUTO) != 0)
5591 + ((bkc_flags & BKC_YES) != 0)
5592 + ((bkc_flags & BKC_NO) != 0) != 1)
5593 {
5594 /* Must have exactly one of "auto", "yes" and "no". */
5595 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5596 errmsg = e_invarg;
5597 }
5598 }
5599
5600 /* 'backupext' and 'patchmode' */
5601 else if (varp == &p_bex || varp == &p_pm)
5602 {
5603 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5604 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5605 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5606 }
5607
5608 /*
5609 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5610 * If the new option is invalid, use old value. 'lisp' option: refill
5611 * chartab[] for '-' char
5612 */
5613 else if ( varp == &p_isi
5614 || varp == &(curbuf->b_p_isk)
5615 || varp == &p_isp
5616 || varp == &p_isf)
5617 {
5618 if (init_chartab() == FAIL)
5619 {
5620 did_chartab = TRUE; /* need to restore it below */
5621 errmsg = e_invarg; /* error in value */
5622 }
5623 }
5624
5625 /* 'helpfile' */
5626 else if (varp == &p_hf)
5627 {
5628 /* May compute new values for $VIM and $VIMRUNTIME */
5629 if (didset_vim)
5630 {
5631 vim_setenv((char_u *)"VIM", (char_u *)"");
5632 didset_vim = FALSE;
5633 }
5634 if (didset_vimruntime)
5635 {
5636 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5637 didset_vimruntime = FALSE;
5638 }
5639 }
5640
5641#ifdef FEAT_MULTI_LANG
5642 /* 'helplang' */
5643 else if (varp == &p_hlg)
5644 {
5645 /* Check for "", "ab", "ab,cd", etc. */
5646 for (s = p_hlg; *s != NUL; s += 3)
5647 {
5648 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5649 {
5650 errmsg = e_invarg;
5651 break;
5652 }
5653 if (s[2] == NUL)
5654 break;
5655 }
5656 }
5657#endif
5658
5659 /* 'highlight' */
5660 else if (varp == &p_hl)
5661 {
5662 if (highlight_changed() == FAIL)
5663 errmsg = e_invarg; /* invalid flags */
5664 }
5665
5666 /* 'nrformats' */
5667 else if (gvarp == &p_nf)
5668 {
5669 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5670 errmsg = e_invarg;
5671 }
5672
5673#ifdef FEAT_SESSION
5674 /* 'sessionoptions' */
5675 else if (varp == &p_ssop)
5676 {
5677 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5678 errmsg = e_invarg;
5679 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5680 {
5681 /* Don't allow both "sesdir" and "curdir". */
5682 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5683 errmsg = e_invarg;
5684 }
5685 }
5686 /* 'viewoptions' */
5687 else if (varp == &p_vop)
5688 {
5689 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5690 errmsg = e_invarg;
5691 }
5692#endif
5693
5694 /* 'scrollopt' */
5695#ifdef FEAT_SCROLLBIND
5696 else if (varp == &p_sbo)
5697 {
5698 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5699 errmsg = e_invarg;
5700 }
5701#endif
5702
5703 /* 'ambiwidth' */
5704#ifdef FEAT_MBYTE
5705 else if (varp == &p_ambw)
5706 {
5707 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5708 errmsg = e_invarg;
5709 }
5710#endif
5711
5712 /* 'background' */
5713 else if (varp == &p_bg)
5714 {
5715 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5716 {
5717#ifdef FEAT_EVAL
5718 int dark = (*p_bg == 'd');
5719#endif
5720
5721 init_highlight(FALSE, FALSE);
5722
5723#ifdef FEAT_EVAL
5724 if (dark != (*p_bg == 'd')
5725 && get_var_value((char_u *)"g:colors_name") != NULL)
5726 {
5727 /* The color scheme must have set 'background' back to another
5728 * value, that's not what we want here. Disable the color
5729 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005730 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 free_string_option(p_bg);
5732 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5733 check_string_option(&p_bg);
5734 init_highlight(FALSE, FALSE);
5735 }
5736#endif
5737 }
5738 else
5739 errmsg = e_invarg;
5740 }
5741
5742 /* 'wildmode' */
5743 else if (varp == &p_wim)
5744 {
5745 if (check_opt_wim() == FAIL)
5746 errmsg = e_invarg;
5747 }
5748
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005749#ifdef FEAT_CMDL_COMPL
5750 /* 'wildoptions' */
5751 else if (varp == &p_wop)
5752 {
5753 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5754 errmsg = e_invarg;
5755 }
5756#endif
5757
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758#ifdef FEAT_WAK
5759 /* 'winaltkeys' */
5760 else if (varp == &p_wak)
5761 {
5762 if (*p_wak == NUL
5763 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5764 errmsg = e_invarg;
5765# ifdef FEAT_MENU
5766# ifdef FEAT_GUI_MOTIF
5767 else if (gui.in_use)
5768 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5769# else
5770# ifdef FEAT_GUI_GTK
5771 else if (gui.in_use)
5772 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5773# endif
5774# endif
5775# endif
5776 }
5777#endif
5778
5779#ifdef FEAT_AUTOCMD
5780 /* 'eventignore' */
5781 else if (varp == &p_ei)
5782 {
5783 if (check_ei() == FAIL)
5784 errmsg = e_invarg;
5785 }
5786#endif
5787
5788#ifdef FEAT_MBYTE
5789 /* 'encoding' and 'fileencoding' */
5790 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5791 {
5792 if (gvarp == &p_fenc)
5793 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005794 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005795 errmsg = e_modifiable;
5796 else if (vim_strchr(*varp, ',') != NULL)
5797 /* No comma allowed in 'fileencoding'; catches confusing it
5798 * with 'fileencodings'. */
5799 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005801 {
5802# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005803 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005804 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005805# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005806 /* Add 'fileencoding' to the swap file. */
5807 ml_setflags(curbuf);
5808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809 }
5810 if (errmsg == NULL)
5811 {
5812 /* canonize the value, so that STRCMP() can be used on it */
5813 p = enc_canonize(*varp);
5814 if (p != NULL)
5815 {
5816 vim_free(*varp);
5817 *varp = p;
5818 }
5819 if (varp == &p_enc)
5820 {
5821 errmsg = mb_init();
5822# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005823 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824# endif
5825 }
5826 }
5827
5828# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5829 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5830 {
5831 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5832 if (STRCMP(p_tenc, "utf-8") != 0)
5833 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5834 }
5835# endif
5836
5837 if (errmsg == NULL)
5838 {
5839# ifdef FEAT_KEYMAP
5840 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5841 * (with another encoding). */
5842 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5843 (void)keymap_init();
5844# endif
5845
5846 /* When 'termencoding' is not empty and 'encoding' changes or when
5847 * 'termencoding' changes, need to setup for keyboard input and
5848 * display output conversion. */
5849 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5850 {
5851 convert_setup(&input_conv, p_tenc, p_enc);
5852 convert_setup(&output_conv, p_enc, p_tenc);
5853 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005854
5855# if defined(WIN3264) && defined(FEAT_MBYTE)
5856 /* $HOME may have characters in active code page. */
5857 if (varp == &p_enc)
5858 init_homedir();
5859# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 }
5861 }
5862#endif
5863
5864#if defined(FEAT_POSTSCRIPT)
5865 else if (varp == &p_penc)
5866 {
5867 /* Canonize printencoding if VIM standard one */
5868 p = enc_canonize(p_penc);
5869 if (p != NULL)
5870 {
5871 vim_free(p_penc);
5872 p_penc = p;
5873 }
5874 else
5875 {
5876 /* Ensure lower case and '-' for '_' */
5877 for (s = p_penc; *s != NUL; s++)
5878 {
5879 if (*s == '_')
5880 *s = '-';
5881 else
5882 *s = TOLOWER_ASC(*s);
5883 }
5884 }
5885 }
5886#endif
5887
Bram Moolenaar9372a112005-12-06 19:59:18 +00005888#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 else if (varp == &p_imak)
5890 {
5891 if (gui.in_use && !im_xim_isvalid_imactivate())
5892 errmsg = e_invarg;
5893 }
5894#endif
5895
5896#ifdef FEAT_KEYMAP
5897 else if (varp == &curbuf->b_p_keymap)
5898 {
5899 /* load or unload key mapping tables */
5900 errmsg = keymap_init();
5901
Bram Moolenaarfab06232009-03-04 03:13:35 +00005902 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005904 if (*curbuf->b_p_keymap != NUL)
5905 {
5906 /* Installed a new keymap, switch on using it. */
5907 curbuf->b_p_iminsert = B_IMODE_LMAP;
5908 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5909 curbuf->b_p_imsearch = B_IMODE_LMAP;
5910 }
5911 else
5912 {
5913 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5914 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5915 curbuf->b_p_iminsert = B_IMODE_NONE;
5916 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5917 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5918 }
5919 if ((opt_flags & OPT_LOCAL) == 0)
5920 {
5921 set_iminsert_global();
5922 set_imsearch_global();
5923 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924# ifdef FEAT_WINDOWS
5925 status_redraw_curbuf();
5926# endif
5927 }
5928 }
5929#endif
5930
5931 /* 'fileformat' */
5932 else if (gvarp == &p_ff)
5933 {
5934 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5935 errmsg = e_modifiable;
5936 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5937 errmsg = e_invarg;
5938 else
5939 {
5940 /* may also change 'textmode' */
5941 if (get_fileformat(curbuf) == EOL_DOS)
5942 curbuf->b_p_tx = TRUE;
5943 else
5944 curbuf->b_p_tx = FALSE;
5945#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005946 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005948 /* update flag in swap file */
5949 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005950 /* Redraw needed when switching to/from "mac": a CR in the text
5951 * will be displayed differently. */
5952 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5953 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954 }
5955 }
5956
5957 /* 'fileformats' */
5958 else if (varp == &p_ffs)
5959 {
5960 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5961 errmsg = e_invarg;
5962 else
5963 {
5964 /* also change 'textauto' */
5965 if (*p_ffs == NUL)
5966 p_ta = FALSE;
5967 else
5968 p_ta = TRUE;
5969 }
5970 }
5971
5972#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5973 /* 'cryptkey' */
5974 else if (gvarp == &p_key)
5975 {
5976 /* Make sure the ":set" command doesn't show the new value in the
5977 * history. */
5978 remove_key_from_history();
5979 }
5980#endif
5981
5982 /* 'matchpairs' */
5983 else if (gvarp == &p_mps)
5984 {
5985 /* Check for "x:y,x:y" */
5986 for (p = *varp; *p != NUL; p += 4)
5987 {
5988 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5989 {
5990 errmsg = e_invarg;
5991 break;
5992 }
5993 if (p[3] == NUL)
5994 break;
5995 }
5996 }
5997
5998#ifdef FEAT_COMMENTS
5999 /* 'comments' */
6000 else if (gvarp == &p_com)
6001 {
6002 for (s = *varp; *s; )
6003 {
6004 while (*s && *s != ':')
6005 {
6006 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6007 && !VIM_ISDIGIT(*s) && *s != '-')
6008 {
6009 errmsg = illegal_char(errbuf, *s);
6010 break;
6011 }
6012 ++s;
6013 }
6014 if (*s++ == NUL)
6015 errmsg = (char_u *)N_("E524: Missing colon");
6016 else if (*s == ',' || *s == NUL)
6017 errmsg = (char_u *)N_("E525: Zero length string");
6018 if (errmsg != NULL)
6019 break;
6020 while (*s && *s != ',')
6021 {
6022 if (*s == '\\' && s[1] != NUL)
6023 ++s;
6024 ++s;
6025 }
6026 s = skip_to_option_part(s);
6027 }
6028 }
6029#endif
6030
6031 /* 'listchars' */
6032 else if (varp == &p_lcs)
6033 {
6034 errmsg = set_chars_option(varp);
6035 }
6036
6037#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6038 /* 'fillchars' */
6039 else if (varp == &p_fcs)
6040 {
6041 errmsg = set_chars_option(varp);
6042 }
6043#endif
6044
6045#ifdef FEAT_CMDWIN
6046 /* 'cedit' */
6047 else if (varp == &p_cedit)
6048 {
6049 errmsg = check_cedit();
6050 }
6051#endif
6052
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006053 /* 'verbosefile' */
6054 else if (varp == &p_vfile)
6055 {
6056 verbose_stop();
6057 if (*p_vfile != NUL && verbose_open() == FAIL)
6058 errmsg = e_invarg;
6059 }
6060
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061#ifdef FEAT_VIMINFO
6062 /* 'viminfo' */
6063 else if (varp == &p_viminfo)
6064 {
6065 for (s = p_viminfo; *s;)
6066 {
6067 /* Check it's a valid character */
6068 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6069 {
6070 errmsg = illegal_char(errbuf, *s);
6071 break;
6072 }
6073 if (*s == 'n') /* name is always last one */
6074 {
6075 break;
6076 }
6077 else if (*s == 'r') /* skip until next ',' */
6078 {
6079 while (*++s && *s != ',')
6080 ;
6081 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006082 else if (*s == '%')
6083 {
6084 /* optional number */
6085 while (vim_isdigit(*++s))
6086 ;
6087 }
6088 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 ++s; /* no extra chars */
6090 else /* must have a number */
6091 {
6092 while (vim_isdigit(*++s))
6093 ;
6094
6095 if (!VIM_ISDIGIT(*(s - 1)))
6096 {
6097 if (errbuf != NULL)
6098 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006099 sprintf((char *)errbuf,
6100 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 transchar_byte(*(s - 1)));
6102 errmsg = errbuf;
6103 }
6104 else
6105 errmsg = (char_u *)"";
6106 break;
6107 }
6108 }
6109 if (*s == ',')
6110 ++s;
6111 else if (*s)
6112 {
6113 if (errbuf != NULL)
6114 errmsg = (char_u *)N_("E527: Missing comma");
6115 else
6116 errmsg = (char_u *)"";
6117 break;
6118 }
6119 }
6120 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6121 errmsg = (char_u *)N_("E528: Must specify a ' value");
6122 }
6123#endif /* FEAT_VIMINFO */
6124
6125 /* terminal options */
6126 else if (istermoption(&options[opt_idx]) && full_screen)
6127 {
6128 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6129 if (varp == &T_CCO)
6130 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006131 int colors = atoi((char *)T_CCO);
6132
6133 /* Only reinitialize colors if t_Co value has really changed to
6134 * avoid expensive reload of colorscheme if t_Co is set to the
6135 * same value multiple times. */
6136 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006138 t_colors = colors;
6139 if (t_colors <= 1)
6140 {
6141 if (new_value_alloced)
6142 vim_free(T_CCO);
6143 T_CCO = empty_option;
6144 }
6145 /* We now have a different color setup, initialize it again. */
6146 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 }
6149 ttest(FALSE);
6150 if (varp == &T_ME)
6151 {
6152 out_str(T_ME);
6153 redraw_later(CLEAR);
6154#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6155 /* Since t_me has been set, this probably means that the user
6156 * wants to use this as default colors. Need to reset default
6157 * background/foreground colors. */
6158 mch_set_normal_colors();
6159#endif
6160 }
6161 }
6162
6163#ifdef FEAT_LINEBREAK
6164 /* 'showbreak' */
6165 else if (varp == &p_sbr)
6166 {
6167 for (s = p_sbr; *s; )
6168 {
6169 if (ptr2cells(s) != 1)
6170 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006171 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172 }
6173 }
6174#endif
6175
6176#ifdef FEAT_GUI
6177 /* 'guifont' */
6178 else if (varp == &p_guifont)
6179 {
6180 if (gui.in_use)
6181 {
6182 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006183# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 /*
6185 * Put up a font dialog and let the user select a new value.
6186 * If this is cancelled go back to the old value but don't
6187 * give an error message.
6188 */
6189 if (STRCMP(p, "*") == 0)
6190 {
6191 p = gui_mch_font_dialog(oldval);
6192
6193 if (new_value_alloced)
6194 free_string_option(p_guifont);
6195
6196 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6197 new_value_alloced = TRUE;
6198 }
6199# endif
6200 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6201 {
6202# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6203 if (STRCMP(p_guifont, "*") == 0)
6204 {
6205 /* Dialog was cancelled: Keep the old value without giving
6206 * an error message. */
6207 if (new_value_alloced)
6208 free_string_option(p_guifont);
6209 p_guifont = vim_strsave(oldval);
6210 new_value_alloced = TRUE;
6211 }
6212 else
6213# endif
6214 errmsg = (char_u *)N_("E596: Invalid font(s)");
6215 }
6216 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006217 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 }
6219# ifdef FEAT_XFONTSET
6220 else if (varp == &p_guifontset)
6221 {
6222 if (STRCMP(p_guifontset, "*") == 0)
6223 errmsg = (char_u *)N_("E597: can't select fontset");
6224 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6225 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006226 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227 }
6228# endif
6229# ifdef FEAT_MBYTE
6230 else if (varp == &p_guifontwide)
6231 {
6232 if (STRCMP(p_guifontwide, "*") == 0)
6233 errmsg = (char_u *)N_("E533: can't select wide font");
6234 else if (gui_get_wide_font() == FAIL)
6235 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006236 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 }
6238# endif
6239#endif
6240
6241#ifdef CURSOR_SHAPE
6242 /* 'guicursor' */
6243 else if (varp == &p_guicursor)
6244 errmsg = parse_shape_opt(SHAPE_CURSOR);
6245#endif
6246
6247#ifdef FEAT_MOUSESHAPE
6248 /* 'mouseshape' */
6249 else if (varp == &p_mouseshape)
6250 {
6251 errmsg = parse_shape_opt(SHAPE_MOUSE);
6252 update_mouseshape(-1);
6253 }
6254#endif
6255
6256#ifdef FEAT_PRINTER
6257 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006258 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006259# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006260 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006261 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006262# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263#endif
6264
6265#ifdef FEAT_LANGMAP
6266 /* 'langmap' */
6267 else if (varp == &p_langmap)
6268 langmap_set();
6269#endif
6270
6271#ifdef FEAT_LINEBREAK
6272 /* 'breakat' */
6273 else if (varp == &p_breakat)
6274 fill_breakat_flags();
6275#endif
6276
6277#ifdef FEAT_TITLE
6278 /* 'titlestring' and 'iconstring' */
6279 else if (varp == &p_titlestring || varp == &p_iconstring)
6280 {
6281# ifdef FEAT_STL_OPT
6282 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6283
6284 /* NULL => statusline syntax */
6285 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6286 stl_syntax |= flagval;
6287 else
6288 stl_syntax &= ~flagval;
6289# endif
6290 did_set_title(varp == &p_iconstring);
6291
6292 }
6293#endif
6294
6295#ifdef FEAT_GUI
6296 /* 'guioptions' */
6297 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006298 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006300 redraw_gui_only = TRUE;
6301 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302#endif
6303
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006304#if defined(FEAT_GUI_TABLINE)
6305 /* 'guitablabel' */
6306 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006307 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006308 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006309 redraw_gui_only = TRUE;
6310 }
6311 /* 'guitabtooltip' */
6312 else if (varp == &p_gtt)
6313 {
6314 redraw_gui_only = TRUE;
6315 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006316#endif
6317
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6319 /* 'ttymouse' */
6320 else if (varp == &p_ttym)
6321 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006322 /* Switch the mouse off before changing the escape sequences used for
6323 * that. */
6324 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6326 errmsg = e_invarg;
6327 else
6328 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006329 if (termcap_active)
6330 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 }
6332#endif
6333
6334#ifdef FEAT_VISUAL
6335 /* 'selection' */
6336 else if (varp == &p_sel)
6337 {
6338 if (*p_sel == NUL
6339 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6340 errmsg = e_invarg;
6341 }
6342
6343 /* 'selectmode' */
6344 else if (varp == &p_slm)
6345 {
6346 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6347 errmsg = e_invarg;
6348 }
6349#endif
6350
6351#ifdef FEAT_BROWSE
6352 /* 'browsedir' */
6353 else if (varp == &p_bsdir)
6354 {
6355 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6356 && !mch_isdir(p_bsdir))
6357 errmsg = e_invarg;
6358 }
6359#endif
6360
6361#ifdef FEAT_VISUAL
6362 /* 'keymodel' */
6363 else if (varp == &p_km)
6364 {
6365 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6366 errmsg = e_invarg;
6367 else
6368 {
6369 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6370 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6371 }
6372 }
6373#endif
6374
6375 /* 'mousemodel' */
6376 else if (varp == &p_mousem)
6377 {
6378 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6379 errmsg = e_invarg;
6380#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6381 else if (*p_mousem != *oldval)
6382 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6383 * to create or delete the popup menus. */
6384 gui_motif_update_mousemodel(root_menu);
6385#endif
6386 }
6387
6388 /* 'switchbuf' */
6389 else if (varp == &p_swb)
6390 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006391 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 errmsg = e_invarg;
6393 }
6394
6395 /* 'debug' */
6396 else if (varp == &p_debug)
6397 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006398 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 errmsg = e_invarg;
6400 }
6401
6402 /* 'display' */
6403 else if (varp == &p_dy)
6404 {
6405 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6406 errmsg = e_invarg;
6407 else
6408 (void)init_chartab();
6409
6410 }
6411
6412#ifdef FEAT_VERTSPLIT
6413 /* 'eadirection' */
6414 else if (varp == &p_ead)
6415 {
6416 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6417 errmsg = e_invarg;
6418 }
6419#endif
6420
6421#ifdef FEAT_CLIPBOARD
6422 /* 'clipboard' */
6423 else if (varp == &p_cb)
6424 errmsg = check_clipboard_option();
6425#endif
6426
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006427#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006428 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6429 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006430 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006431 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006432 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006433 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006434
Bram Moolenaar860cae12010-06-05 23:22:07 +02006435 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006436 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006437 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6438 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006439 ".add") != 0))
6440 errmsg = e_invarg;
6441 }
6442
6443 if (errmsg == NULL)
6444 {
6445 FOR_ALL_WINDOWS(wp)
6446 if (wp->w_buffer == curbuf && wp->w_p_spell)
6447 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006448 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006449# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006450 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006451# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006452 }
6453 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006454 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006455 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006456 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006457 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006458 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006459 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006460 /* 'spellsuggest' */
6461 else if (varp == &p_sps)
6462 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006463 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006464 errmsg = e_invarg;
6465 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006466 /* 'mkspellmem' */
6467 else if (varp == &p_msm)
6468 {
6469 if (spell_check_msm() != OK)
6470 errmsg = e_invarg;
6471 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006472#endif
6473
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474#ifdef FEAT_QUICKFIX
6475 /* When 'bufhidden' is set, check for valid value. */
6476 else if (gvarp == &p_bh)
6477 {
6478 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6479 errmsg = e_invarg;
6480 }
6481
6482 /* When 'buftype' is set, check for valid value. */
6483 else if (gvarp == &p_bt)
6484 {
6485 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6486 errmsg = e_invarg;
6487 else
6488 {
6489# ifdef FEAT_WINDOWS
6490 if (curwin->w_status_height)
6491 {
6492 curwin->w_redr_status = TRUE;
6493 redraw_later(VALID);
6494 }
6495# endif
6496 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006497# ifdef FEAT_TITLE
6498 redraw_titles();
6499# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500 }
6501 }
6502#endif
6503
6504#ifdef FEAT_STL_OPT
6505 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006506 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006507 {
6508 int wid;
6509
6510 if (varp == &p_ruf) /* reset ru_wid first */
6511 ru_wid = 0;
6512 s = *varp;
6513 if (varp == &p_ruf && *s == '%')
6514 {
6515 /* set ru_wid if 'ruf' starts with "%99(" */
6516 if (*++s == '-') /* ignore a '-' */
6517 s++;
6518 wid = getdigits(&s);
6519 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6520 ru_wid = wid;
6521 else
6522 errmsg = check_stl_option(p_ruf);
6523 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006524 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006525 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006526 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006527 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006528 comp_col();
6529 }
6530#endif
6531
6532#ifdef FEAT_INS_EXPAND
6533 /* check if it is a valid value for 'complete' -- Acevedo */
6534 else if (gvarp == &p_cpt)
6535 {
6536 for (s = *varp; *s;)
6537 {
6538 while(*s == ',' || *s == ' ')
6539 s++;
6540 if (!*s)
6541 break;
6542 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6543 {
6544 errmsg = illegal_char(errbuf, *s);
6545 break;
6546 }
6547 if (*++s != NUL && *s != ',' && *s != ' ')
6548 {
6549 if (s[-1] == 'k' || s[-1] == 's')
6550 {
6551 /* skip optional filename after 'k' and 's' */
6552 while (*s && *s != ',' && *s != ' ')
6553 {
6554 if (*s == '\\')
6555 ++s;
6556 ++s;
6557 }
6558 }
6559 else
6560 {
6561 if (errbuf != NULL)
6562 {
6563 sprintf((char *)errbuf,
6564 _("E535: Illegal character after <%c>"),
6565 *--s);
6566 errmsg = errbuf;
6567 }
6568 else
6569 errmsg = (char_u *)"";
6570 break;
6571 }
6572 }
6573 }
6574 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006575
6576 /* 'completeopt' */
6577 else if (varp == &p_cot)
6578 {
6579 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6580 errmsg = e_invarg;
6581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582#endif /* FEAT_INS_EXPAND */
6583
6584
6585#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6586 else if (varp == &p_toolbar)
6587 {
6588 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6589 &toolbar_flags, TRUE) != OK)
6590 errmsg = e_invarg;
6591 else
6592 {
6593 out_flush();
6594 gui_mch_show_toolbar((toolbar_flags &
6595 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6596 }
6597 }
6598#endif
6599
6600#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6601 /* 'toolbariconsize': GTK+ 2 only */
6602 else if (varp == &p_tbis)
6603 {
6604 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6605 errmsg = e_invarg;
6606 else
6607 {
6608 out_flush();
6609 gui_mch_show_toolbar((toolbar_flags &
6610 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6611 }
6612 }
6613#endif
6614
6615 /* 'pastetoggle': translate key codes like in a mapping */
6616 else if (varp == &p_pt)
6617 {
6618 if (*p_pt)
6619 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006620 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006621 if (p != NULL)
6622 {
6623 if (new_value_alloced)
6624 free_string_option(p_pt);
6625 p_pt = p;
6626 new_value_alloced = TRUE;
6627 }
6628 }
6629 }
6630
6631 /* 'backspace' */
6632 else if (varp == &p_bs)
6633 {
6634 if (VIM_ISDIGIT(*p_bs))
6635 {
6636 if (*p_bs >'2' || p_bs[1] != NUL)
6637 errmsg = e_invarg;
6638 }
6639 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6640 errmsg = e_invarg;
6641 }
6642
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006643#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 /* 'casemap' */
6645 else if (varp == &p_cmp)
6646 {
6647 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6648 errmsg = e_invarg;
6649 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651
6652#ifdef FEAT_DIFF
6653 /* 'diffopt' */
6654 else if (varp == &p_dip)
6655 {
6656 if (diffopt_changed() == FAIL)
6657 errmsg = e_invarg;
6658 }
6659#endif
6660
6661#ifdef FEAT_FOLDING
6662 /* 'foldmethod' */
6663 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6664 {
6665 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6666 || *curwin->w_p_fdm == NUL)
6667 errmsg = e_invarg;
6668 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006669 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006671 if (foldmethodIsDiff(curwin))
6672 newFoldLevel();
6673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674 }
6675# ifdef FEAT_EVAL
6676 /* 'foldexpr' */
6677 else if (varp == &curwin->w_p_fde)
6678 {
6679 if (foldmethodIsExpr(curwin))
6680 foldUpdateAll(curwin);
6681 }
6682# endif
6683 /* 'foldmarker' */
6684 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6685 {
6686 p = vim_strchr(*varp, ',');
6687 if (p == NULL)
6688 errmsg = (char_u *)N_("E536: comma required");
6689 else if (p == *varp || p[1] == NUL)
6690 errmsg = e_invarg;
6691 else if (foldmethodIsMarker(curwin))
6692 foldUpdateAll(curwin);
6693 }
6694 /* 'commentstring' */
6695 else if (gvarp == &p_cms)
6696 {
6697 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6698 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6699 }
6700 /* 'foldopen' */
6701 else if (varp == &p_fdo)
6702 {
6703 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6704 errmsg = e_invarg;
6705 }
6706 /* 'foldclose' */
6707 else if (varp == &p_fcl)
6708 {
6709 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6710 errmsg = e_invarg;
6711 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006712 /* 'foldignore' */
6713 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6714 {
6715 if (foldmethodIsIndent(curwin))
6716 foldUpdateAll(curwin);
6717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718#endif
6719
6720#ifdef FEAT_VIRTUALEDIT
6721 /* 'virtualedit' */
6722 else if (varp == &p_ve)
6723 {
6724 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6725 errmsg = e_invarg;
6726 else if (STRCMP(p_ve, oldval) != 0)
6727 {
6728 /* Recompute cursor position in case the new 've' setting
6729 * changes something. */
6730 validate_virtcol();
6731 coladvance(curwin->w_virtcol);
6732 }
6733 }
6734#endif
6735
6736#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6737 else if (varp == &p_csqf)
6738 {
6739 if (p_csqf != NULL)
6740 {
6741 p = p_csqf;
6742 while (*p != NUL)
6743 {
6744 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6745 || p[1] == NUL
6746 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6747 || (p[2] != NUL && p[2] != ','))
6748 {
6749 errmsg = e_invarg;
6750 break;
6751 }
6752 else if (p[2] == NUL)
6753 break;
6754 else
6755 p += 3;
6756 }
6757 }
6758 }
6759#endif
6760
6761 /* Options that are a list of flags. */
6762 else
6763 {
6764 p = NULL;
6765 if (varp == &p_ww)
6766 p = (char_u *)WW_ALL;
6767 if (varp == &p_shm)
6768 p = (char_u *)SHM_ALL;
6769 else if (varp == &(p_cpo))
6770 p = (char_u *)CPO_ALL;
6771 else if (varp == &(curbuf->b_p_fo))
6772 p = (char_u *)FO_ALL;
6773 else if (varp == &p_mouse)
6774 {
6775#ifdef FEAT_MOUSE
6776 p = (char_u *)MOUSE_ALL;
6777#else
6778 if (*p_mouse != NUL)
6779 errmsg = (char_u *)N_("E538: No mouse support");
6780#endif
6781 }
6782#if defined(FEAT_GUI)
6783 else if (varp == &p_go)
6784 p = (char_u *)GO_ALL;
6785#endif
6786 if (p != NULL)
6787 {
6788 for (s = *varp; *s; ++s)
6789 if (vim_strchr(p, *s) == NULL)
6790 {
6791 errmsg = illegal_char(errbuf, *s);
6792 break;
6793 }
6794 }
6795 }
6796
6797 /*
6798 * If error detected, restore the previous value.
6799 */
6800 if (errmsg != NULL)
6801 {
6802 if (new_value_alloced)
6803 free_string_option(*varp);
6804 *varp = oldval;
6805 /*
6806 * When resetting some values, need to act on it.
6807 */
6808 if (did_chartab)
6809 (void)init_chartab();
6810 if (varp == &p_hl)
6811 (void)highlight_changed();
6812 }
6813 else
6814 {
6815#ifdef FEAT_EVAL
6816 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006817 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818#endif
6819 /*
6820 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006821 * Use "free_oldval", because recursiveness may change the flags under
6822 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006824 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006825 free_string_option(oldval);
6826 if (new_value_alloced)
6827 options[opt_idx].flags |= P_ALLOCED;
6828 else
6829 options[opt_idx].flags &= ~P_ALLOCED;
6830
6831 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006832 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006833 {
6834 /* global option with local value set to use global value; free
6835 * the local value and make it empty */
6836 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6837 free_string_option(*(char_u **)p);
6838 *(char_u **)p = empty_option;
6839 }
6840
6841 /* May set global value for local option. */
6842 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6843 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006844
6845#ifdef FEAT_AUTOCMD
6846 /*
6847 * Trigger the autocommand only after setting the flags.
6848 */
6849# ifdef FEAT_SYN_HL
6850 /* When 'syntax' is set, load the syntax of that name */
6851 if (varp == &(curbuf->b_p_syn))
6852 {
6853 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6854 curbuf->b_fname, TRUE, curbuf);
6855 }
6856# endif
6857 else if (varp == &(curbuf->b_p_ft))
6858 {
6859 /* 'filetype' is set, trigger the FileType autocommand */
6860 did_filetype = TRUE;
6861 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6862 curbuf->b_fname, TRUE, curbuf);
6863 }
6864#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006865#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006866 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006867 {
6868 char_u fname[200];
6869
6870 /*
6871 * Source the spell/LANG.vim in 'runtimepath'.
6872 * They could set 'spellcapcheck' depending on the language.
6873 * Use the first name in 'spelllang' up to '_region' or
6874 * '.encoding'.
6875 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006876 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006877 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6878 break;
6879 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006880 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006881 source_runtime(fname, TRUE);
6882 }
6883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 }
6885
6886#ifdef FEAT_MOUSE
6887 if (varp == &p_mouse)
6888 {
6889# ifdef FEAT_MOUSE_TTY
6890 if (*p_mouse == NUL)
6891 mch_setmouse(FALSE); /* switch mouse off */
6892 else
6893# endif
6894 setmouse(); /* in case 'mouse' changed */
6895 }
6896#endif
6897
6898 if (curwin->w_curswant != MAXCOL)
6899 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006900#ifdef FEAT_GUI
6901 /* check redraw when it's not a GUI option or the GUI is active. */
6902 if (!redraw_gui_only || gui.in_use)
6903#endif
6904 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905
6906 return errmsg;
6907}
6908
6909/*
6910 * Handle setting 'listchars' or 'fillchars'.
6911 * Returns error message, NULL if it's OK.
6912 */
6913 static char_u *
6914set_chars_option(varp)
6915 char_u **varp;
6916{
6917 int round, i, len, entries;
6918 char_u *p, *s;
6919 int c1, c2 = 0;
6920 struct charstab
6921 {
6922 int *cp;
6923 char *name;
6924 };
6925#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6926 static struct charstab filltab[] =
6927 {
6928 {&fill_stl, "stl"},
6929 {&fill_stlnc, "stlnc"},
6930 {&fill_vert, "vert"},
6931 {&fill_fold, "fold"},
6932 {&fill_diff, "diff"},
6933 };
6934#endif
6935 static struct charstab lcstab[] =
6936 {
6937 {&lcs_eol, "eol"},
6938 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006939 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 {&lcs_prec, "precedes"},
6941 {&lcs_tab2, "tab"},
6942 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02006943#ifdef FEAT_CONCEAL
6944 {&lcs_conceal, "conceal"},
6945#else
6946 {NULL, "conceal"},
6947#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 };
6949 struct charstab *tab;
6950
6951#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6952 if (varp == &p_lcs)
6953#endif
6954 {
6955 tab = lcstab;
6956 entries = sizeof(lcstab) / sizeof(struct charstab);
6957 }
6958#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6959 else
6960 {
6961 tab = filltab;
6962 entries = sizeof(filltab) / sizeof(struct charstab);
6963 }
6964#endif
6965
6966 /* first round: check for valid value, second round: assign values */
6967 for (round = 0; round <= 1; ++round)
6968 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006969 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 {
6971 /* After checking that the value is valid: set defaults: space for
6972 * 'fillchars', NUL for 'listchars' */
6973 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02006974 if (tab[i].cp != NULL)
6975 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976 if (varp == &p_lcs)
6977 lcs_tab1 = NUL;
6978#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6979 else
6980 fill_diff = '-';
6981#endif
6982 }
6983 p = *varp;
6984 while (*p)
6985 {
6986 for (i = 0; i < entries; ++i)
6987 {
6988 len = (int)STRLEN(tab[i].name);
6989 if (STRNCMP(p, tab[i].name, len) == 0
6990 && p[len] == ':'
6991 && p[len + 1] != NUL)
6992 {
6993 s = p + len + 1;
6994#ifdef FEAT_MBYTE
6995 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006996 if (mb_char2cells(c1) > 1)
6997 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998#else
6999 c1 = *s++;
7000#endif
7001 if (tab[i].cp == &lcs_tab2)
7002 {
7003 if (*s == NUL)
7004 continue;
7005#ifdef FEAT_MBYTE
7006 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007007 if (mb_char2cells(c2) > 1)
7008 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009#else
7010 c2 = *s++;
7011#endif
7012 }
7013 if (*s == ',' || *s == NUL)
7014 {
7015 if (round)
7016 {
7017 if (tab[i].cp == &lcs_tab2)
7018 {
7019 lcs_tab1 = c1;
7020 lcs_tab2 = c2;
7021 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007022 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 *(tab[i].cp) = c1;
7024
7025 }
7026 p = s;
7027 break;
7028 }
7029 }
7030 }
7031
7032 if (i == entries)
7033 return e_invarg;
7034 if (*p == ',')
7035 ++p;
7036 }
7037 }
7038
7039 return NULL; /* no error */
7040}
7041
7042#ifdef FEAT_STL_OPT
7043/*
7044 * Check validity of options with the 'statusline' format.
7045 * Return error message or NULL.
7046 */
7047 char_u *
7048check_stl_option(s)
7049 char_u *s;
7050{
7051 int itemcnt = 0;
7052 int groupdepth = 0;
7053 static char_u errbuf[80];
7054
7055 while (*s && itemcnt < STL_MAX_ITEM)
7056 {
7057 /* Check for valid keys after % sequences */
7058 while (*s && *s != '%')
7059 s++;
7060 if (!*s)
7061 break;
7062 s++;
7063 if (*s != '%' && *s != ')')
7064 ++itemcnt;
7065 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7066 {
7067 s++;
7068 continue;
7069 }
7070 if (*s == ')')
7071 {
7072 s++;
7073 if (--groupdepth < 0)
7074 break;
7075 continue;
7076 }
7077 if (*s == '-')
7078 s++;
7079 while (VIM_ISDIGIT(*s))
7080 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007081 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082 continue;
7083 if (*s == '.')
7084 {
7085 s++;
7086 while (*s && VIM_ISDIGIT(*s))
7087 s++;
7088 }
7089 if (*s == '(')
7090 {
7091 groupdepth++;
7092 continue;
7093 }
7094 if (vim_strchr(STL_ALL, *s) == NULL)
7095 {
7096 return illegal_char(errbuf, *s);
7097 }
7098 if (*s == '{')
7099 {
7100 s++;
7101 while (*s != '}' && *s)
7102 s++;
7103 if (*s != '}')
7104 return (char_u *)N_("E540: Unclosed expression sequence");
7105 }
7106 }
7107 if (itemcnt >= STL_MAX_ITEM)
7108 return (char_u *)N_("E541: too many items");
7109 if (groupdepth != 0)
7110 return (char_u *)N_("E542: unbalanced groups");
7111 return NULL;
7112}
7113#endif
7114
7115#ifdef FEAT_CLIPBOARD
7116/*
7117 * Extract the items in the 'clipboard' option and set global values.
7118 */
7119 static char_u *
7120check_clipboard_option()
7121{
7122 int new_unnamed = FALSE;
7123 int new_autoselect = FALSE;
7124 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007125 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126 regprog_T *new_exclude_prog = NULL;
7127 char_u *errmsg = NULL;
7128 char_u *p;
7129
7130 for (p = p_cb; *p != NUL; )
7131 {
7132 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7133 {
7134 new_unnamed = TRUE;
7135 p += 7;
7136 }
7137 else if (STRNCMP(p, "autoselect", 10) == 0
7138 && (p[10] == ',' || p[10] == NUL))
7139 {
7140 new_autoselect = TRUE;
7141 p += 10;
7142 }
7143 else if (STRNCMP(p, "autoselectml", 12) == 0
7144 && (p[12] == ',' || p[12] == NUL))
7145 {
7146 new_autoselectml = TRUE;
7147 p += 12;
7148 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007149 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7150 {
7151 new_html = TRUE;
7152 p += 4;
7153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7155 {
7156 p += 8;
7157 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7158 if (new_exclude_prog == NULL)
7159 errmsg = e_invarg;
7160 break;
7161 }
7162 else
7163 {
7164 errmsg = e_invarg;
7165 break;
7166 }
7167 if (*p == ',')
7168 ++p;
7169 }
7170 if (errmsg == NULL)
7171 {
7172 clip_unnamed = new_unnamed;
7173 clip_autoselect = new_autoselect;
7174 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007175 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176 vim_free(clip_exclude_prog);
7177 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007178#ifdef FEAT_GUI_GTK
7179 if (gui.in_use)
7180 {
7181 gui_gtk_set_selection_targets();
7182 gui_gtk_set_dnd_targets();
7183 }
7184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007185 }
7186 else
7187 vim_free(new_exclude_prog);
7188
7189 return errmsg;
7190}
7191#endif
7192
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007193#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007194/*
7195 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7196 * Return error message when failed, NULL when OK.
7197 */
7198 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007199compile_cap_prog(synblock)
7200 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007201{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007202 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007203 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007204
Bram Moolenaar860cae12010-06-05 23:22:07 +02007205 if (*synblock->b_p_spc == NUL)
7206 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007207 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007208 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007209 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007210 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007211 if (re != NULL)
7212 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007213 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7214 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007215 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007216 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007217 return e_invarg;
7218 }
7219 vim_free(re);
7220 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007221 }
7222
7223 vim_free(rp);
7224 return NULL;
7225}
7226#endif
7227
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007228#if defined(FEAT_EVAL) || defined(PROTO)
7229/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007230 * Set the scriptID for an option, taking care of setting the buffer- or
7231 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007232 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007233 static void
7234set_option_scriptID_idx(opt_idx, opt_flags, id)
7235 int opt_idx;
7236 int opt_flags;
7237 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007238{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007239 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7240 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007241
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007242 /* Remember where the option was set. For local options need to do that
7243 * in the buffer or window structure. */
7244 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007245 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007246 if (both || (opt_flags & OPT_LOCAL))
7247 {
7248 if (indir & PV_BUF)
7249 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7250 else if (indir & PV_WIN)
7251 curwin->w_p_scriptID[indir & PV_MASK] = id;
7252 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007253}
7254#endif
7255
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256/*
7257 * Set the value of a boolean option, and take care of side effects.
7258 * Returns NULL for success, or an error message for an error.
7259 */
7260 static char_u *
7261set_bool_option(opt_idx, varp, value, opt_flags)
7262 int opt_idx; /* index in options[] table */
7263 char_u *varp; /* pointer to the option variable */
7264 int value; /* new value */
7265 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7266{
7267 int old_value = *(int *)varp;
7268
Bram Moolenaar071d4272004-06-13 20:20:40 +00007269 /* Disallow changing some options from secure mode */
7270 if ((secure
7271#ifdef HAVE_SANDBOX
7272 || sandbox != 0
7273#endif
7274 ) && (options[opt_idx].flags & P_SECURE))
7275 return e_secure;
7276
7277 *(int *)varp = value; /* set the new value */
7278#ifdef FEAT_EVAL
7279 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007280 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281#endif
7282
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007283#ifdef FEAT_GUI
7284 need_mouse_correct = TRUE;
7285#endif
7286
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287 /* May set global value for local option. */
7288 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7289 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7290
7291 /*
7292 * Handle side effects of changing a bool option.
7293 */
7294
7295 /* 'compatible' */
7296 if ((int *)varp == &p_cp)
7297 {
7298 compatible_set();
7299 }
7300
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007301 /* 'list', 'number' */
7302 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007303 || (int *)varp == &curwin->w_p_nu
7304 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007305 {
7306 if (curwin->w_curswant != MAXCOL)
7307 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007308
7309 /* If 'number' is set, reset 'relativenumber'. */
7310 /* If 'relativenumber' is set, reset 'number'. */
7311 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7312 curwin->w_p_rnu = FALSE;
7313 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7314 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007315 }
7316
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 else if ((int *)varp == &curbuf->b_p_ro)
7318 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007319 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7321 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007322
7323 /* when 'readonly' is set may give W10 again */
7324 if (curbuf->b_p_ro)
7325 curbuf->b_did_warn = FALSE;
7326
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007328 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329#endif
7330 }
7331
7332#ifdef FEAT_TITLE
7333 /* when 'modifiable' is changed, redraw the window title */
7334 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007335 {
7336 redraw_titles();
7337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 /* when 'endofline' is changed, redraw the window title */
7339 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007340 {
7341 redraw_titles();
7342 }
7343# ifdef FEAT_MBYTE
7344 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007345 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007346 {
7347 redraw_titles();
7348 }
7349# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350#endif
7351
7352 /* when 'bin' is set also set some other options */
7353 else if ((int *)varp == &curbuf->b_p_bin)
7354 {
7355 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7356#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007357 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358#endif
7359 }
7360
7361#ifdef FEAT_AUTOCMD
7362 /* when 'buflisted' changes, trigger autocommands */
7363 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7364 {
7365 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7366 NULL, NULL, TRUE, curbuf);
7367 }
7368#endif
7369
7370 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7371 else if ((int *)varp == &curbuf->b_p_swf)
7372 {
7373 if (curbuf->b_p_swf && p_uc)
7374 ml_open_file(curbuf); /* create the swap file */
7375 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007376 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7377 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007378 mf_close_file(curbuf, TRUE); /* remove the swap file */
7379 }
7380
7381 /* when 'terse' is set change 'shortmess' */
7382 else if ((int *)varp == &p_terse)
7383 {
7384 char_u *p;
7385
7386 p = vim_strchr(p_shm, SHM_SEARCH);
7387
7388 /* insert 's' in p_shm */
7389 if (p_terse && p == NULL)
7390 {
7391 STRCPY(IObuff, p_shm);
7392 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007393 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007394 }
7395 /* remove 's' from p_shm */
7396 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007397 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007398 }
7399
7400 /* when 'paste' is set or reset also change other options */
7401 else if ((int *)varp == &p_paste)
7402 {
7403 paste_option_changed();
7404 }
7405
7406 /* when 'insertmode' is set from an autocommand need to do work here */
7407 else if ((int *)varp == &p_im)
7408 {
7409 if (p_im)
7410 {
7411 if ((State & INSERT) == 0)
7412 need_start_insertmode = TRUE;
7413 stop_insert_mode = FALSE;
7414 }
7415 else
7416 {
7417 need_start_insertmode = FALSE;
7418 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007419 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007420 clear_cmdline = TRUE; /* remove "(insert)" */
7421 restart_edit = 0;
7422 }
7423 }
7424
7425 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7426 else if ((int *)varp == &p_ic && p_hls)
7427 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007428 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 }
7430
7431#ifdef FEAT_SEARCH_EXTRA
7432 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7433 else if ((int *)varp == &p_hls)
7434 {
7435 no_hlsearch = FALSE;
7436 }
7437#endif
7438
7439#ifdef FEAT_SCROLLBIND
7440 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7441 * at the end of normal_cmd() */
7442 else if ((int *)varp == &curwin->w_p_scb)
7443 {
7444 if (curwin->w_p_scb)
7445 do_check_scrollbind(FALSE);
7446 }
7447#endif
7448
7449#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7450 /* There can be only one window with 'previewwindow' set. */
7451 else if ((int *)varp == &curwin->w_p_pvw)
7452 {
7453 if (curwin->w_p_pvw)
7454 {
7455 win_T *win;
7456
7457 for (win = firstwin; win != NULL; win = win->w_next)
7458 if (win->w_p_pvw && win != curwin)
7459 {
7460 curwin->w_p_pvw = FALSE;
7461 return (char_u *)N_("E590: A preview window already exists");
7462 }
7463 }
7464 }
7465#endif
7466
7467 /* when 'textmode' is set or reset also change 'fileformat' */
7468 else if ((int *)varp == &curbuf->b_p_tx)
7469 {
7470 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7471 }
7472
7473 /* when 'textauto' is set or reset also change 'fileformats' */
7474 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 set_string_option_direct((char_u *)"ffs", -1,
7476 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007477 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478
7479 /*
7480 * When 'lisp' option changes include/exclude '-' in
7481 * keyword characters.
7482 */
7483#ifdef FEAT_LISP
7484 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7485 {
7486 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7487 }
7488#endif
7489
7490#ifdef FEAT_TITLE
7491 /* when 'title' changed, may need to change the title; same for 'icon' */
7492 else if ((int *)varp == &p_title)
7493 {
7494 did_set_title(FALSE);
7495 }
7496
7497 else if ((int *)varp == &p_icon)
7498 {
7499 did_set_title(TRUE);
7500 }
7501#endif
7502
7503 else if ((int *)varp == &curbuf->b_changed)
7504 {
7505 if (!value)
7506 save_file_ff(curbuf); /* Buffer is unchanged */
7507#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007508 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509#endif
7510#ifdef FEAT_AUTOCMD
7511 modified_was_set = value;
7512#endif
7513 }
7514
7515#ifdef BACKSLASH_IN_FILENAME
7516 else if ((int *)varp == &p_ssl)
7517 {
7518 if (p_ssl)
7519 {
7520 psepc = '/';
7521 psepcN = '\\';
7522 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 }
7524 else
7525 {
7526 psepc = '\\';
7527 psepcN = '/';
7528 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 }
7530
7531 /* need to adjust the file name arguments and buffer names. */
7532 buflist_slash_adjust();
7533 alist_slash_adjust();
7534# ifdef FEAT_EVAL
7535 scriptnames_slash_adjust();
7536# endif
7537 }
7538#endif
7539
7540 /* If 'wrap' is set, set w_leftcol to zero. */
7541 else if ((int *)varp == &curwin->w_p_wrap)
7542 {
7543 if (curwin->w_p_wrap)
7544 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007545 if (curwin->w_curswant != MAXCOL)
7546 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 }
7548
7549#ifdef FEAT_WINDOWS
7550 else if ((int *)varp == &p_ea)
7551 {
7552 if (p_ea && !old_value)
7553 win_equal(curwin, FALSE, 0);
7554 }
7555#endif
7556
7557 else if ((int *)varp == &p_wiv)
7558 {
7559 /*
7560 * When 'weirdinvert' changed, set/reset 't_xs'.
7561 * Then set 'weirdinvert' according to value of 't_xs'.
7562 */
7563 if (p_wiv && !old_value)
7564 T_XS = (char_u *)"y";
7565 else if (!p_wiv && old_value)
7566 T_XS = empty_option;
7567 p_wiv = (*T_XS != NUL);
7568 }
7569
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007570#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 else if ((int *)varp == &p_beval)
7572 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 if (p_beval == TRUE)
7574 gui_mch_enable_beval_area(balloonEval);
7575 else
7576 gui_mch_disable_beval_area(balloonEval);
7577 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007580#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 else if ((int *)varp == &p_acd)
7582 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007583 /* Change directories when the 'acd' option is set now. */
7584 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 }
7586#endif
7587
7588#ifdef FEAT_DIFF
7589 /* 'diff' */
7590 else if ((int *)varp == &curwin->w_p_diff)
7591 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007592 /* May add or remove the buffer from the list of diff buffers. */
7593 diff_buf_adjust(curwin);
7594# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007595 if (foldmethodIsDiff(curwin))
7596 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007597# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 }
7599#endif
7600
7601#ifdef USE_IM_CONTROL
7602 /* 'imdisable' */
7603 else if ((int *)varp == &p_imdisable)
7604 {
7605 /* Only de-activate it here, it will be enabled when changing mode. */
7606 if (p_imdisable)
7607 im_set_active(FALSE);
7608 }
7609#endif
7610
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007611#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007612 /* 'spell' */
7613 else if ((int *)varp == &curwin->w_p_spell)
7614 {
7615 if (curwin->w_p_spell)
7616 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007617 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007618 if (errmsg != NULL)
7619 EMSG(_(errmsg));
7620 }
7621 }
7622#endif
7623
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624#ifdef FEAT_FKMAP
7625 else if ((int *)varp == &p_altkeymap)
7626 {
7627 if (old_value != p_altkeymap)
7628 {
7629 if (!p_altkeymap)
7630 {
7631 p_hkmap = p_fkmap;
7632 p_fkmap = 0;
7633 }
7634 else
7635 {
7636 p_fkmap = p_hkmap;
7637 p_hkmap = 0;
7638 }
7639 (void)init_chartab();
7640 }
7641 }
7642
7643 /*
7644 * In case some second language keymapping options have changed, check
7645 * and correct the setting in a consistent way.
7646 */
7647
7648 /*
7649 * If hkmap or fkmap are set, reset Arabic keymapping.
7650 */
7651 if ((p_hkmap || p_fkmap) && p_altkeymap)
7652 {
7653 p_altkeymap = p_fkmap;
7654# ifdef FEAT_ARABIC
7655 curwin->w_p_arab = FALSE;
7656# endif
7657 (void)init_chartab();
7658 }
7659
7660 /*
7661 * If hkmap set, reset Farsi keymapping.
7662 */
7663 if (p_hkmap && p_altkeymap)
7664 {
7665 p_altkeymap = 0;
7666 p_fkmap = 0;
7667# ifdef FEAT_ARABIC
7668 curwin->w_p_arab = FALSE;
7669# endif
7670 (void)init_chartab();
7671 }
7672
7673 /*
7674 * If fkmap set, reset Hebrew keymapping.
7675 */
7676 if (p_fkmap && !p_altkeymap)
7677 {
7678 p_altkeymap = 1;
7679 p_hkmap = 0;
7680# ifdef FEAT_ARABIC
7681 curwin->w_p_arab = FALSE;
7682# endif
7683 (void)init_chartab();
7684 }
7685#endif
7686
7687#ifdef FEAT_ARABIC
7688 if ((int *)varp == &curwin->w_p_arab)
7689 {
7690 if (curwin->w_p_arab)
7691 {
7692 /*
7693 * 'arabic' is set, handle various sub-settings.
7694 */
7695 if (!p_tbidi)
7696 {
7697 /* set rightleft mode */
7698 if (!curwin->w_p_rl)
7699 {
7700 curwin->w_p_rl = TRUE;
7701 changed_window_setting();
7702 }
7703
7704 /* Enable Arabic shaping (major part of what Arabic requires) */
7705 if (!p_arshape)
7706 {
7707 p_arshape = TRUE;
7708 redraw_later_clear();
7709 }
7710 }
7711
7712 /* Arabic requires a utf-8 encoding, inform the user if its not
7713 * set. */
7714 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007715 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007716 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7717
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007718 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007719 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7720#ifdef FEAT_EVAL
7721 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7722#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007723 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724
7725# ifdef FEAT_MBYTE
7726 /* set 'delcombine' */
7727 p_deco = TRUE;
7728# endif
7729
7730# ifdef FEAT_KEYMAP
7731 /* Force-set the necessary keymap for arabic */
7732 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7733 OPT_LOCAL);
7734# endif
7735# ifdef FEAT_FKMAP
7736 p_altkeymap = 0;
7737 p_hkmap = 0;
7738 p_fkmap = 0;
7739 (void)init_chartab();
7740# endif
7741 }
7742 else
7743 {
7744 /*
7745 * 'arabic' is reset, handle various sub-settings.
7746 */
7747 if (!p_tbidi)
7748 {
7749 /* reset rightleft mode */
7750 if (curwin->w_p_rl)
7751 {
7752 curwin->w_p_rl = FALSE;
7753 changed_window_setting();
7754 }
7755
7756 /* 'arabicshape' isn't reset, it is a global option and
7757 * another window may still need it "on". */
7758 }
7759
7760 /* 'delcombine' isn't reset, it is a global option and another
7761 * window may still want it "on". */
7762
7763# ifdef FEAT_KEYMAP
7764 /* Revert to the default keymap */
7765 curbuf->b_p_iminsert = B_IMODE_NONE;
7766 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7767# endif
7768 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007769 if (curwin->w_curswant != MAXCOL)
7770 curwin->w_set_curswant = TRUE;
7771 }
7772
7773 else if ((int *)varp == &p_arshape)
7774 {
7775 if (curwin->w_curswant != MAXCOL)
7776 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 }
7778#endif
7779
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007780#ifdef FEAT_LINEBREAK
7781 if ((int *)varp == &curwin->w_p_lbr)
7782 {
7783 if (curwin->w_curswant != MAXCOL)
7784 curwin->w_set_curswant = TRUE;
7785 }
7786#endif
7787
7788#ifdef FEAT_RIGHTLEFT
7789 if ((int *)varp == &curwin->w_p_rl)
7790 {
7791 if (curwin->w_curswant != MAXCOL)
7792 curwin->w_set_curswant = TRUE;
7793 }
7794#endif
7795
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 /*
7797 * End of handling side effects for bool options.
7798 */
7799
7800 options[opt_idx].flags |= P_WAS_SET;
7801
7802 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007803
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804 check_redraw(options[opt_idx].flags);
7805
7806 return NULL;
7807}
7808
7809/*
7810 * Set the value of a number option, and take care of side effects.
7811 * Returns NULL for success, or an error message for an error.
7812 */
7813 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007814set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815 int opt_idx; /* index in options[] table */
7816 char_u *varp; /* pointer to the option variable */
7817 long value; /* new value */
7818 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007819 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7821 OPT_MODELINE */
7822{
7823 char_u *errmsg = NULL;
7824 long old_value = *(long *)varp;
7825 long old_Rows = Rows; /* remember old Rows */
7826 long old_Columns = Columns; /* remember old Columns */
7827 long *pp = (long *)varp;
7828
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007829 /* Disallow changing some options from secure mode. */
7830 if ((secure
7831#ifdef HAVE_SANDBOX
7832 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007834 ) && (options[opt_idx].flags & P_SECURE))
7835 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836
7837 *pp = value;
7838#ifdef FEAT_EVAL
7839 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007840 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007842#ifdef FEAT_GUI
7843 need_mouse_correct = TRUE;
7844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845
7846 if (curbuf->b_p_sw <= 0)
7847 {
7848 errmsg = e_positive;
7849 curbuf->b_p_sw = curbuf->b_p_ts;
7850 }
7851
7852 /*
7853 * Number options that need some action when changed
7854 */
7855#ifdef FEAT_WINDOWS
7856 if (pp == &p_wh || pp == &p_hh)
7857 {
7858 if (p_wh < 1)
7859 {
7860 errmsg = e_positive;
7861 p_wh = 1;
7862 }
7863 if (p_wmh > p_wh)
7864 {
7865 errmsg = e_winheight;
7866 p_wh = p_wmh;
7867 }
7868 if (p_hh < 0)
7869 {
7870 errmsg = e_positive;
7871 p_hh = 0;
7872 }
7873
7874 /* Change window height NOW */
7875 if (lastwin != firstwin)
7876 {
7877 if (pp == &p_wh && curwin->w_height < p_wh)
7878 win_setheight((int)p_wh);
7879 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7880 win_setheight((int)p_hh);
7881 }
7882 }
7883
7884 /* 'winminheight' */
7885 else if (pp == &p_wmh)
7886 {
7887 if (p_wmh < 0)
7888 {
7889 errmsg = e_positive;
7890 p_wmh = 0;
7891 }
7892 if (p_wmh > p_wh)
7893 {
7894 errmsg = e_winheight;
7895 p_wmh = p_wh;
7896 }
7897 win_setminheight();
7898 }
7899
7900# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007901 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 {
7903 if (p_wiw < 1)
7904 {
7905 errmsg = e_positive;
7906 p_wiw = 1;
7907 }
7908 if (p_wmw > p_wiw)
7909 {
7910 errmsg = e_winwidth;
7911 p_wiw = p_wmw;
7912 }
7913
7914 /* Change window width NOW */
7915 if (lastwin != firstwin && curwin->w_width < p_wiw)
7916 win_setwidth((int)p_wiw);
7917 }
7918
7919 /* 'winminwidth' */
7920 else if (pp == &p_wmw)
7921 {
7922 if (p_wmw < 0)
7923 {
7924 errmsg = e_positive;
7925 p_wmw = 0;
7926 }
7927 if (p_wmw > p_wiw)
7928 {
7929 errmsg = e_winwidth;
7930 p_wmw = p_wiw;
7931 }
7932 win_setminheight();
7933 }
7934# endif
7935
7936#endif
7937
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007938#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007939 else if (pp == &curbuf->b_p_cm)
7940 {
7941 if (curbuf->b_p_cm < 0)
7942 {
7943 errmsg = e_positive;
7944 curbuf->b_p_cm = 0;
7945 }
7946 if (curbuf->b_p_cm > 1)
7947 {
7948 errmsg = e_invarg;
7949 curbuf->b_p_cm = 1;
7950 }
7951 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
7952 curbuf->b_p_cm = 0;
7953 }
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007954#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007955
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956#ifdef FEAT_WINDOWS
7957 /* (re)set last window status line */
7958 else if (pp == &p_ls)
7959 {
7960 last_status(FALSE);
7961 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007962
7963 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007964 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007965 {
7966 shell_new_rows(); /* recompute window positions and heights */
7967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968#endif
7969
7970#ifdef FEAT_GUI
7971 else if (pp == &p_linespace)
7972 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007973 /* Recompute gui.char_height and resize the Vim window to keep the
7974 * same number of lines. */
7975 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007976 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977 }
7978#endif
7979
7980#ifdef FEAT_FOLDING
7981 /* 'foldlevel' */
7982 else if (pp == &curwin->w_p_fdl)
7983 {
7984 if (curwin->w_p_fdl < 0)
7985 curwin->w_p_fdl = 0;
7986 newFoldLevel();
7987 }
7988
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007989 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 else if (pp == &curwin->w_p_fml)
7991 {
7992 foldUpdateAll(curwin);
7993 }
7994
7995 /* 'foldnestmax' */
7996 else if (pp == &curwin->w_p_fdn)
7997 {
7998 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7999 foldUpdateAll(curwin);
8000 }
8001
8002 /* 'foldcolumn' */
8003 else if (pp == &curwin->w_p_fdc)
8004 {
8005 if (curwin->w_p_fdc < 0)
8006 {
8007 errmsg = e_positive;
8008 curwin->w_p_fdc = 0;
8009 }
8010 else if (curwin->w_p_fdc > 12)
8011 {
8012 errmsg = e_invarg;
8013 curwin->w_p_fdc = 12;
8014 }
8015 }
8016
8017 /* 'shiftwidth' or 'tabstop' */
8018 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8019 {
8020 if (foldmethodIsIndent(curwin))
8021 foldUpdateAll(curwin);
8022 }
8023#endif /* FEAT_FOLDING */
8024
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008025#ifdef FEAT_MBYTE
8026 /* 'maxcombine' */
8027 else if (pp == &p_mco)
8028 {
8029 if (p_mco > MAX_MCO)
8030 p_mco = MAX_MCO;
8031 else if (p_mco < 0)
8032 p_mco = 0;
8033 screenclear(); /* will re-allocate the screen */
8034 }
8035#endif
8036
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 else if (pp == &curbuf->b_p_iminsert)
8038 {
8039 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8040 {
8041 errmsg = e_invarg;
8042 curbuf->b_p_iminsert = B_IMODE_NONE;
8043 }
8044 p_iminsert = curbuf->b_p_iminsert;
8045 if (termcap_active) /* don't do this in the alternate screen */
8046 showmode();
8047#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8048 /* Show/unshow value of 'keymap' in status lines. */
8049 status_redraw_curbuf();
8050#endif
8051 }
8052
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008053 else if (pp == &p_window)
8054 {
8055 if (p_window < 1)
8056 p_window = 1;
8057 else if (p_window >= Rows)
8058 p_window = Rows - 1;
8059 }
8060
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061 else if (pp == &curbuf->b_p_imsearch)
8062 {
8063 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8064 {
8065 errmsg = e_invarg;
8066 curbuf->b_p_imsearch = B_IMODE_NONE;
8067 }
8068 p_imsearch = curbuf->b_p_imsearch;
8069 }
8070
8071#ifdef FEAT_TITLE
8072 /* if 'titlelen' has changed, redraw the title */
8073 else if (pp == &p_titlelen)
8074 {
8075 if (p_titlelen < 0)
8076 {
8077 errmsg = e_positive;
8078 p_titlelen = 85;
8079 }
8080 if (starting != NO_SCREEN && old_value != p_titlelen)
8081 need_maketitle = TRUE;
8082 }
8083#endif
8084
8085 /* if p_ch changed value, change the command line height */
8086 else if (pp == &p_ch)
8087 {
8088 if (p_ch < 1)
8089 {
8090 errmsg = e_positive;
8091 p_ch = 1;
8092 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008093 if (p_ch > Rows - min_rows() + 1)
8094 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095
8096 /* Only compute the new window layout when startup has been
8097 * completed. Otherwise the frame sizes may be wrong. */
8098 if (p_ch != old_value && full_screen
8099#ifdef FEAT_GUI
8100 && !gui.starting
8101#endif
8102 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008103 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 }
8105
8106 /* when 'updatecount' changes from zero to non-zero, open swap files */
8107 else if (pp == &p_uc)
8108 {
8109 if (p_uc < 0)
8110 {
8111 errmsg = e_positive;
8112 p_uc = 100;
8113 }
8114 if (p_uc && !old_value)
8115 ml_open_files();
8116 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008117#ifdef FEAT_CONCEAL
8118 else if (pp == (long *)&curwin->w_p_conceal)
8119 {
8120 if (curwin->w_p_conceal < 0)
8121 {
8122 errmsg = e_positive;
8123 curwin->w_p_conceal = 0;
8124 }
8125 else if (curwin->w_p_conceal > 3)
8126 {
8127 errmsg = e_invarg;
8128 curwin->w_p_conceal = 3;
8129 }
8130 }
8131#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008132#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008133 else if (pp == &p_mzq)
8134 mzvim_reset_timer();
8135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136
8137 /* sync undo before 'undolevels' changes */
8138 else if (pp == &p_ul)
8139 {
8140 /* use the old value, otherwise u_sync() may not work properly */
8141 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008142 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 p_ul = value;
8144 }
8145
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008146#ifdef FEAT_LINEBREAK
8147 /* 'numberwidth' must be positive */
8148 else if (pp == &curwin->w_p_nuw)
8149 {
8150 if (curwin->w_p_nuw < 1)
8151 {
8152 errmsg = e_positive;
8153 curwin->w_p_nuw = 1;
8154 }
8155 if (curwin->w_p_nuw > 10)
8156 {
8157 errmsg = e_invarg;
8158 curwin->w_p_nuw = 10;
8159 }
8160 curwin->w_nrwidth_line_count = 0;
8161 }
8162#endif
8163
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 /*
8165 * Check the bounds for numeric options here
8166 */
8167 if (Rows < min_rows() && full_screen)
8168 {
8169 if (errbuf != NULL)
8170 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008171 vim_snprintf((char *)errbuf, errbuflen,
8172 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 errmsg = errbuf;
8174 }
8175 Rows = min_rows();
8176 }
8177 if (Columns < MIN_COLUMNS && full_screen)
8178 {
8179 if (errbuf != NULL)
8180 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008181 vim_snprintf((char *)errbuf, errbuflen,
8182 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 errmsg = errbuf;
8184 }
8185 Columns = MIN_COLUMNS;
8186 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008187 /* Limit the values to avoid an overflow in Rows * Columns. */
8188 if (Columns > 10000)
8189 Columns = 10000;
8190 if (Rows > 1000)
8191 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192
8193#ifdef DJGPP
8194 /* avoid a crash by checking for a too large value of 'columns' */
8195 if (old_Columns != Columns && full_screen && term_console)
8196 mch_check_columns();
8197#endif
8198
8199 /*
8200 * If the screen (shell) height has been changed, assume it is the
8201 * physical screenheight.
8202 */
8203 if (old_Rows != Rows || old_Columns != Columns)
8204 {
8205 /* Changing the screen size is not allowed while updating the screen. */
8206 if (updating_screen)
8207 *pp = old_value;
8208 else if (full_screen
8209#ifdef FEAT_GUI
8210 && !gui.starting
8211#endif
8212 )
8213 set_shellsize((int)Columns, (int)Rows, TRUE);
8214 else
8215 {
8216 /* Postpone the resizing; check the size and cmdline position for
8217 * messages. */
8218 check_shellsize();
8219 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8220 cmdline_row = Rows - p_ch;
8221 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008222 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008223 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 }
8225
8226 if (curbuf->b_p_sts < 0)
8227 {
8228 errmsg = e_positive;
8229 curbuf->b_p_sts = 0;
8230 }
8231 if (curbuf->b_p_ts <= 0)
8232 {
8233 errmsg = e_positive;
8234 curbuf->b_p_ts = 8;
8235 }
8236 if (curbuf->b_p_tw < 0)
8237 {
8238 errmsg = e_positive;
8239 curbuf->b_p_tw = 0;
8240 }
8241 if (p_tm < 0)
8242 {
8243 errmsg = e_positive;
8244 p_tm = 0;
8245 }
8246 if ((curwin->w_p_scr <= 0
8247 || (curwin->w_p_scr > curwin->w_height
8248 && curwin->w_height > 0))
8249 && full_screen)
8250 {
8251 if (pp == &(curwin->w_p_scr))
8252 {
8253 if (curwin->w_p_scr != 0)
8254 errmsg = e_scroll;
8255 win_comp_scroll(curwin);
8256 }
8257 /* If 'scroll' became invalid because of a side effect silently adjust
8258 * it. */
8259 else if (curwin->w_p_scr <= 0)
8260 curwin->w_p_scr = 1;
8261 else /* curwin->w_p_scr > curwin->w_height */
8262 curwin->w_p_scr = curwin->w_height;
8263 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008264 if (p_hi < 0)
8265 {
8266 errmsg = e_positive;
8267 p_hi = 0;
8268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269 if (p_report < 0)
8270 {
8271 errmsg = e_positive;
8272 p_report = 1;
8273 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008274 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 {
8276 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8277 p_sj = Rows / 2;
8278 else
8279 {
8280 errmsg = e_scroll;
8281 p_sj = 1;
8282 }
8283 }
8284 if (p_so < 0 && full_screen)
8285 {
8286 errmsg = e_scroll;
8287 p_so = 0;
8288 }
8289 if (p_siso < 0 && full_screen)
8290 {
8291 errmsg = e_positive;
8292 p_siso = 0;
8293 }
8294#ifdef FEAT_CMDWIN
8295 if (p_cwh < 1)
8296 {
8297 errmsg = e_positive;
8298 p_cwh = 1;
8299 }
8300#endif
8301 if (p_ut < 0)
8302 {
8303 errmsg = e_positive;
8304 p_ut = 2000;
8305 }
8306 if (p_ss < 0)
8307 {
8308 errmsg = e_positive;
8309 p_ss = 0;
8310 }
8311
8312 /* May set global value for local option. */
8313 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8314 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8315
8316 options[opt_idx].flags |= P_WAS_SET;
8317
8318 comp_col(); /* in case 'columns' or 'ls' changed */
8319 if (curwin->w_curswant != MAXCOL)
8320 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8321 check_redraw(options[opt_idx].flags);
8322
8323 return errmsg;
8324}
8325
8326/*
8327 * Called after an option changed: check if something needs to be redrawn.
8328 */
8329 static void
8330check_redraw(flags)
8331 long_u flags;
8332{
8333 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8334 int clear = (flags & P_RCLR) == P_RCLR;
8335 int all = ((flags & P_RALL) == P_RALL || clear);
8336
8337#ifdef FEAT_WINDOWS
8338 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8339 status_redraw_all();
8340#endif
8341
8342 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8343 changed_window_setting();
8344 if (flags & P_RBUF)
8345 redraw_curbuf_later(NOT_VALID);
8346 if (clear)
8347 redraw_all_later(CLEAR);
8348 else if (all)
8349 redraw_all_later(NOT_VALID);
8350}
8351
8352/*
8353 * Find index for option 'arg'.
8354 * Return -1 if not found.
8355 */
8356 static int
8357findoption(arg)
8358 char_u *arg;
8359{
8360 int opt_idx;
8361 char *s, *p;
8362 static short quick_tab[27] = {0, 0}; /* quick access table */
8363 int is_term_opt;
8364
8365 /*
8366 * For first call: Initialize the quick-access table.
8367 * It contains the index for the first option that starts with a certain
8368 * letter. There are 26 letters, plus the first "t_" option.
8369 */
8370 if (quick_tab[1] == 0)
8371 {
8372 p = options[0].fullname;
8373 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8374 {
8375 if (s[0] != p[0])
8376 {
8377 if (s[0] == 't' && s[1] == '_')
8378 quick_tab[26] = opt_idx;
8379 else
8380 quick_tab[CharOrdLow(s[0])] = opt_idx;
8381 }
8382 p = s;
8383 }
8384 }
8385
8386 /*
8387 * Check for name starting with an illegal character.
8388 */
8389#ifdef EBCDIC
8390 if (!islower(arg[0]))
8391#else
8392 if (arg[0] < 'a' || arg[0] > 'z')
8393#endif
8394 return -1;
8395
8396 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8397 if (is_term_opt)
8398 opt_idx = quick_tab[26];
8399 else
8400 opt_idx = quick_tab[CharOrdLow(arg[0])];
8401 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8402 {
8403 if (STRCMP(arg, s) == 0) /* match full name */
8404 break;
8405 }
8406 if (s == NULL && !is_term_opt)
8407 {
8408 opt_idx = quick_tab[CharOrdLow(arg[0])];
8409 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8410 {
8411 s = options[opt_idx].shortname;
8412 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8413 break;
8414 s = NULL;
8415 }
8416 }
8417 if (s == NULL)
8418 opt_idx = -1;
8419 return opt_idx;
8420}
8421
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008422#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423/*
8424 * Get the value for an option.
8425 *
8426 * Returns:
8427 * Number or Toggle option: 1, *numval gets value.
8428 * String option: 0, *stringval gets allocated string.
8429 * Hidden Number or Toggle option: -1.
8430 * hidden String option: -2.
8431 * unknown option: -3.
8432 */
8433 int
8434get_option_value(name, numval, stringval, opt_flags)
8435 char_u *name;
8436 long *numval;
8437 char_u **stringval; /* NULL when only checking existance */
8438 int opt_flags;
8439{
8440 int opt_idx;
8441 char_u *varp;
8442
8443 opt_idx = findoption(name);
8444 if (opt_idx < 0) /* unknown option */
8445 return -3;
8446
8447 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8448
8449 if (options[opt_idx].flags & P_STRING)
8450 {
8451 if (varp == NULL) /* hidden option */
8452 return -2;
8453 if (stringval != NULL)
8454 {
8455#ifdef FEAT_CRYPT
8456 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008457 if ((char_u **)varp == &curbuf->b_p_key
8458 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459 *stringval = vim_strsave((char_u *)"*****");
8460 else
8461#endif
8462 *stringval = vim_strsave(*(char_u **)(varp));
8463 }
8464 return 0;
8465 }
8466
8467 if (varp == NULL) /* hidden option */
8468 return -1;
8469 if (options[opt_idx].flags & P_NUM)
8470 *numval = *(long *)varp;
8471 else
8472 {
8473 /* Special case: 'modified' is b_changed, but we also want to consider
8474 * it set when 'ff' or 'fenc' changed. */
8475 if ((int *)varp == &curbuf->b_changed)
8476 *numval = curbufIsChanged();
8477 else
8478 *numval = *(int *)varp;
8479 }
8480 return 1;
8481}
8482#endif
8483
8484/*
8485 * Set the value of option "name".
8486 * Use "string" for string options, use "number" for other options.
8487 */
8488 void
8489set_option_value(name, number, string, opt_flags)
8490 char_u *name;
8491 long number;
8492 char_u *string;
8493 int opt_flags; /* OPT_LOCAL or 0 (both) */
8494{
8495 int opt_idx;
8496 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008497 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498
8499 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008500 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 EMSG2(_("E355: Unknown option: %s"), name);
8502 else
8503 {
8504 flags = options[opt_idx].flags;
8505#ifdef HAVE_SANDBOX
8506 /* Disallow changing some options in the sandbox */
8507 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008508 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008510 return;
8511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008513 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 set_string_option(opt_idx, string, opt_flags);
8515 else
8516 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008517 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008518 if (varp != NULL) /* hidden option is not changed */
8519 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008520 if (number == 0 && string != NULL)
8521 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008522 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008523
8524 /* Either we are given a string or we are setting option
8525 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008526 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008527 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008528 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008529 {
8530 /* There's another character after zeros or the string
8531 * is empty. In both cases, we are trying to set a
8532 * num option using a string. */
8533 EMSG3(_("E521: Number required: &%s = '%s'"),
8534 name, string);
8535 return; /* do nothing as we hit an error */
8536
8537 }
8538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008540 (void)set_num_option(opt_idx, varp, number,
8541 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008543 (void)set_bool_option(opt_idx, varp, (int)number,
8544 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546 }
8547 }
8548}
8549
8550/*
8551 * Get the terminal code for a terminal option.
8552 * Returns NULL when not found.
8553 */
8554 char_u *
8555get_term_code(tname)
8556 char_u *tname;
8557{
8558 int opt_idx;
8559 char_u *varp;
8560
8561 if (tname[0] != 't' || tname[1] != '_' ||
8562 tname[2] == NUL || tname[3] == NUL)
8563 return NULL;
8564 if ((opt_idx = findoption(tname)) >= 0)
8565 {
8566 varp = get_varp(&(options[opt_idx]));
8567 if (varp != NULL)
8568 varp = *(char_u **)(varp);
8569 return varp;
8570 }
8571 return find_termcode(tname + 2);
8572}
8573
8574 char_u *
8575get_highlight_default()
8576{
8577 int i;
8578
8579 i = findoption((char_u *)"hl");
8580 if (i >= 0)
8581 return options[i].def_val[VI_DEFAULT];
8582 return (char_u *)NULL;
8583}
8584
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008585#if defined(FEAT_MBYTE) || defined(PROTO)
8586 char_u *
8587get_encoding_default()
8588{
8589 int i;
8590
8591 i = findoption((char_u *)"enc");
8592 if (i >= 0)
8593 return options[i].def_val[VI_DEFAULT];
8594 return (char_u *)NULL;
8595}
8596#endif
8597
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598/*
8599 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8600 */
8601 static int
8602find_key_option(arg)
8603 char_u *arg;
8604{
8605 int key;
8606 int modifiers;
8607
8608 /*
8609 * Don't use get_special_key_code() for t_xx, we don't want it to call
8610 * add_termcap_entry().
8611 */
8612 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8613 key = TERMCAP2KEY(arg[2], arg[3]);
8614 else
8615 {
8616 --arg; /* put arg at the '<' */
8617 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008618 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008619 if (modifiers) /* can't handle modifiers here */
8620 key = 0;
8621 }
8622 return key;
8623}
8624
8625/*
8626 * if 'all' == 0: show changed options
8627 * if 'all' == 1: show all normal options
8628 * if 'all' == 2: show all terminal options
8629 */
8630 static void
8631showoptions(all, opt_flags)
8632 int all;
8633 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8634{
8635 struct vimoption *p;
8636 int col;
8637 int isterm;
8638 char_u *varp;
8639 struct vimoption **items;
8640 int item_count;
8641 int run;
8642 int row, rows;
8643 int cols;
8644 int i;
8645 int len;
8646
8647#define INC 20
8648#define GAP 3
8649
8650 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8651 PARAM_COUNT));
8652 if (items == NULL)
8653 return;
8654
8655 /* Highlight title */
8656 if (all == 2)
8657 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8658 else if (opt_flags & OPT_GLOBAL)
8659 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8660 else if (opt_flags & OPT_LOCAL)
8661 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8662 else
8663 MSG_PUTS_TITLE(_("\n--- Options ---"));
8664
8665 /*
8666 * do the loop two times:
8667 * 1. display the short items
8668 * 2. display the long items (only strings and numbers)
8669 */
8670 for (run = 1; run <= 2 && !got_int; ++run)
8671 {
8672 /*
8673 * collect the items in items[]
8674 */
8675 item_count = 0;
8676 for (p = &options[0]; p->fullname != NULL; p++)
8677 {
8678 varp = NULL;
8679 isterm = istermoption(p);
8680 if (opt_flags != 0)
8681 {
8682 if (p->indir != PV_NONE && !isterm)
8683 varp = get_varp_scope(p, opt_flags);
8684 }
8685 else
8686 varp = get_varp(p);
8687 if (varp != NULL
8688 && ((all == 2 && isterm)
8689 || (all == 1 && !isterm)
8690 || (all == 0 && !optval_default(p, varp))))
8691 {
8692 if (p->flags & P_BOOL)
8693 len = 1; /* a toggle option fits always */
8694 else
8695 {
8696 option_value2string(p, opt_flags);
8697 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8698 }
8699 if ((len <= INC - GAP && run == 1) ||
8700 (len > INC - GAP && run == 2))
8701 items[item_count++] = p;
8702 }
8703 }
8704
8705 /*
8706 * display the items
8707 */
8708 if (run == 1)
8709 {
8710 cols = (Columns + GAP - 3) / INC;
8711 if (cols == 0)
8712 cols = 1;
8713 rows = (item_count + cols - 1) / cols;
8714 }
8715 else /* run == 2 */
8716 rows = item_count;
8717 for (row = 0; row < rows && !got_int; ++row)
8718 {
8719 msg_putchar('\n'); /* go to next line */
8720 if (got_int) /* 'q' typed in more */
8721 break;
8722 col = 0;
8723 for (i = row; i < item_count; i += rows)
8724 {
8725 msg_col = col; /* make columns */
8726 showoneopt(items[i], opt_flags);
8727 col += INC;
8728 }
8729 out_flush();
8730 ui_breakcheck();
8731 }
8732 }
8733 vim_free(items);
8734}
8735
8736/*
8737 * Return TRUE if option "p" has its default value.
8738 */
8739 static int
8740optval_default(p, varp)
8741 struct vimoption *p;
8742 char_u *varp;
8743{
8744 int dvi;
8745
8746 if (varp == NULL)
8747 return TRUE; /* hidden option is always at default */
8748 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8749 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008750 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008752 /* the cast to long is required for Manx C, long_i is
8753 * needed for MSVC */
8754 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 /* P_STRING */
8756 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8757}
8758
8759/*
8760 * showoneopt: show the value of one option
8761 * must not be called with a hidden option!
8762 */
8763 static void
8764showoneopt(p, opt_flags)
8765 struct vimoption *p;
8766 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8767{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008768 char_u *varp;
8769 int save_silent = silent_mode;
8770
8771 silent_mode = FALSE;
8772 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773
8774 varp = get_varp_scope(p, opt_flags);
8775
8776 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8777 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8778 ? !curbufIsChanged() : !*(int *)varp))
8779 MSG_PUTS("no");
8780 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8781 MSG_PUTS("--");
8782 else
8783 MSG_PUTS(" ");
8784 MSG_PUTS(p->fullname);
8785 if (!(p->flags & P_BOOL))
8786 {
8787 msg_putchar('=');
8788 /* put value string in NameBuff */
8789 option_value2string(p, opt_flags);
8790 msg_outtrans(NameBuff);
8791 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008792
8793 silent_mode = save_silent;
8794 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795}
8796
8797/*
8798 * Write modified options as ":set" commands to a file.
8799 *
8800 * There are three values for "opt_flags":
8801 * OPT_GLOBAL: Write global option values and fresh values of
8802 * buffer-local options (used for start of a session
8803 * file).
8804 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8805 * curwin (used for a vimrc file).
8806 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8807 * and local values for window-local options of
8808 * curwin. Local values are also written when at the
8809 * default value, because a modeline or autocommand
8810 * may have set them when doing ":edit file" and the
8811 * user has set them back at the default or fresh
8812 * value.
8813 * When "local_only" is TRUE, don't write fresh
8814 * values, only local values (for ":mkview").
8815 * (fresh value = value used for a new buffer or window for a local option).
8816 *
8817 * Return FAIL on error, OK otherwise.
8818 */
8819 int
8820makeset(fd, opt_flags, local_only)
8821 FILE *fd;
8822 int opt_flags;
8823 int local_only;
8824{
8825 struct vimoption *p;
8826 char_u *varp; /* currently used value */
8827 char_u *varp_fresh; /* local value */
8828 char_u *varp_local = NULL; /* fresh value */
8829 char *cmd;
8830 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008831 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832
8833 /*
8834 * The options that don't have a default (terminal name, columns, lines)
8835 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008836 * Do the loop over "options[]" twice: once for options with the
8837 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008839 for (pri = 1; pri >= 0; --pri)
8840 {
8841 for (p = &options[0]; !istermoption(p); p++)
8842 if (!(p->flags & P_NO_MKRC)
8843 && !istermoption(p)
8844 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 {
8846 /* skip global option when only doing locals */
8847 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8848 continue;
8849
8850 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8851 * file, they are always buffer-specific. */
8852 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8853 continue;
8854
8855 /* Global values are only written when not at the default value. */
8856 varp = get_varp_scope(p, opt_flags);
8857 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8858 continue;
8859
8860 round = 2;
8861 if (p->indir != PV_NONE)
8862 {
8863 if (p->var == VAR_WIN)
8864 {
8865 /* skip window-local option when only doing globals */
8866 if (!(opt_flags & OPT_LOCAL))
8867 continue;
8868 /* When fresh value of window-local option is not at the
8869 * default, need to write it too. */
8870 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8871 {
8872 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8873 if (!optval_default(p, varp_fresh))
8874 {
8875 round = 1;
8876 varp_local = varp;
8877 varp = varp_fresh;
8878 }
8879 }
8880 }
8881 }
8882
8883 /* Round 1: fresh value for window-local options.
8884 * Round 2: other values */
8885 for ( ; round <= 2; varp = varp_local, ++round)
8886 {
8887 if (round == 1 || (opt_flags & OPT_GLOBAL))
8888 cmd = "set";
8889 else
8890 cmd = "setlocal";
8891
8892 if (p->flags & P_BOOL)
8893 {
8894 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8895 return FAIL;
8896 }
8897 else if (p->flags & P_NUM)
8898 {
8899 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8900 return FAIL;
8901 }
8902 else /* P_STRING */
8903 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008904#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8905 int do_endif = FALSE;
8906
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 /* Don't set 'syntax' and 'filetype' again if the value is
8908 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008909 if (
8910# if defined(FEAT_SYN_HL)
8911 p->indir == PV_SYN
8912# if defined(FEAT_AUTOCMD)
8913 ||
8914# endif
8915# endif
8916# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008917 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008918# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008919 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 {
8921 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8922 *(char_u **)(varp)) < 0
8923 || put_eol(fd) < 0)
8924 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008925 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8929 (p->flags & P_EXPAND) != 0) == FAIL)
8930 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008931#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8932 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 {
8934 if (put_line(fd, "endif") == FAIL)
8935 return FAIL;
8936 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008937#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 }
8939 }
8940 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 return OK;
8943}
8944
8945#if defined(FEAT_FOLDING) || defined(PROTO)
8946/*
8947 * Generate set commands for the local fold options only. Used when
8948 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8949 */
8950 int
8951makefoldset(fd)
8952 FILE *fd;
8953{
8954 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8955# ifdef FEAT_EVAL
8956 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8957 == FAIL
8958# endif
8959 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8960 == FAIL
8961 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8962 == FAIL
8963 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8964 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8965 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8966 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8967 )
8968 return FAIL;
8969
8970 return OK;
8971}
8972#endif
8973
8974 static int
8975put_setstring(fd, cmd, name, valuep, expand)
8976 FILE *fd;
8977 char *cmd;
8978 char *name;
8979 char_u **valuep;
8980 int expand;
8981{
8982 char_u *s;
8983 char_u buf[MAXPATHL];
8984
8985 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8986 return FAIL;
8987 if (*valuep != NULL)
8988 {
8989 /* Output 'pastetoggle' as key names. For other
8990 * options some characters have to be escaped with
8991 * CTRL-V or backslash */
8992 if (valuep == &p_pt)
8993 {
8994 s = *valuep;
8995 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00008996 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997 return FAIL;
8998 }
8999 else if (expand)
9000 {
9001 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9002 if (put_escstr(fd, buf, 2) == FAIL)
9003 return FAIL;
9004 }
9005 else if (put_escstr(fd, *valuep, 2) == FAIL)
9006 return FAIL;
9007 }
9008 if (put_eol(fd) < 0)
9009 return FAIL;
9010 return OK;
9011}
9012
9013 static int
9014put_setnum(fd, cmd, name, valuep)
9015 FILE *fd;
9016 char *cmd;
9017 char *name;
9018 long *valuep;
9019{
9020 long wc;
9021
9022 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9023 return FAIL;
9024 if (wc_use_keyname((char_u *)valuep, &wc))
9025 {
9026 /* print 'wildchar' and 'wildcharm' as a key name */
9027 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9028 return FAIL;
9029 }
9030 else if (fprintf(fd, "%ld", *valuep) < 0)
9031 return FAIL;
9032 if (put_eol(fd) < 0)
9033 return FAIL;
9034 return OK;
9035}
9036
9037 static int
9038put_setbool(fd, cmd, name, value)
9039 FILE *fd;
9040 char *cmd;
9041 char *name;
9042 int value;
9043{
Bram Moolenaar893de922007-10-02 18:40:57 +00009044 if (value < 0) /* global/local option using global value */
9045 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9047 || put_eol(fd) < 0)
9048 return FAIL;
9049 return OK;
9050}
9051
9052/*
9053 * Clear all the terminal options.
9054 * If the option has been allocated, free the memory.
9055 * Terminal options are never hidden or indirect.
9056 */
9057 void
9058clear_termoptions()
9059{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 /*
9061 * Reset a few things before clearing the old options. This may cause
9062 * outputting a few things that the terminal doesn't understand, but the
9063 * screen will be cleared later, so this is OK.
9064 */
9065#ifdef FEAT_MOUSE_TTY
9066 mch_setmouse(FALSE); /* switch mouse off */
9067#endif
9068#ifdef FEAT_TITLE
9069 mch_restore_title(3); /* restore window titles */
9070#endif
9071#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9072 /* When starting the GUI close the display opened for the clipboard.
9073 * After restoring the title, because that will need the display. */
9074 if (gui.starting)
9075 clear_xterm_clip();
9076#endif
9077#ifdef WIN3264
9078 /*
9079 * Check if this is allowed now.
9080 */
9081 if (can_end_termcap_mode(FALSE) == TRUE)
9082#endif
9083 stoptermcap(); /* stop termcap mode */
9084
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009085 free_termoptions();
9086}
9087
9088 void
9089free_termoptions()
9090{
9091 struct vimoption *p;
9092
Bram Moolenaar071d4272004-06-13 20:20:40 +00009093 for (p = &options[0]; p->fullname != NULL; p++)
9094 if (istermoption(p))
9095 {
9096 if (p->flags & P_ALLOCED)
9097 free_string_option(*(char_u **)(p->var));
9098 if (p->flags & P_DEF_ALLOCED)
9099 free_string_option(p->def_val[VI_DEFAULT]);
9100 *(char_u **)(p->var) = empty_option;
9101 p->def_val[VI_DEFAULT] = empty_option;
9102 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9103 }
9104 clear_termcodes();
9105}
9106
9107/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009108 * Free the string for one term option, if it was allocated.
9109 * Set the string to empty_option and clear allocated flag.
9110 * "var" points to the option value.
9111 */
9112 void
9113free_one_termoption(var)
9114 char_u *var;
9115{
9116 struct vimoption *p;
9117
9118 for (p = &options[0]; p->fullname != NULL; p++)
9119 if (p->var == var)
9120 {
9121 if (p->flags & P_ALLOCED)
9122 free_string_option(*(char_u **)(p->var));
9123 *(char_u **)(p->var) = empty_option;
9124 p->flags &= ~P_ALLOCED;
9125 break;
9126 }
9127}
9128
9129/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 * Set the terminal option defaults to the current value.
9131 * Used after setting the terminal name.
9132 */
9133 void
9134set_term_defaults()
9135{
9136 struct vimoption *p;
9137
9138 for (p = &options[0]; p->fullname != NULL; p++)
9139 {
9140 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9141 {
9142 if (p->flags & P_DEF_ALLOCED)
9143 {
9144 free_string_option(p->def_val[VI_DEFAULT]);
9145 p->flags &= ~P_DEF_ALLOCED;
9146 }
9147 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9148 if (p->flags & P_ALLOCED)
9149 {
9150 p->flags |= P_DEF_ALLOCED;
9151 p->flags &= ~P_ALLOCED; /* don't free the value now */
9152 }
9153 }
9154 }
9155}
9156
9157/*
9158 * return TRUE if 'p' starts with 't_'
9159 */
9160 static int
9161istermoption(p)
9162 struct vimoption *p;
9163{
9164 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9165}
9166
9167/*
9168 * Compute columns for ruler and shown command. 'sc_col' is also used to
9169 * decide what the maximum length of a message on the status line can be.
9170 * If there is a status line for the last window, 'sc_col' is independent
9171 * of 'ru_col'.
9172 */
9173
9174#define COL_RULER 17 /* columns needed by standard ruler */
9175
9176 void
9177comp_col()
9178{
9179#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9180 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9181
9182 sc_col = 0;
9183 ru_col = 0;
9184 if (p_ru)
9185 {
9186#ifdef FEAT_STL_OPT
9187 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9188#else
9189 ru_col = COL_RULER + 1;
9190#endif
9191 /* no last status line, adjust sc_col */
9192 if (!last_has_status)
9193 sc_col = ru_col;
9194 }
9195 if (p_sc)
9196 {
9197 sc_col += SHOWCMD_COLS;
9198 if (!p_ru || last_has_status) /* no need for separating space */
9199 ++sc_col;
9200 }
9201 sc_col = Columns - sc_col;
9202 ru_col = Columns - ru_col;
9203 if (sc_col <= 0) /* screen too narrow, will become a mess */
9204 sc_col = 1;
9205 if (ru_col <= 0)
9206 ru_col = 1;
9207#else
9208 sc_col = Columns;
9209 ru_col = Columns;
9210#endif
9211}
9212
9213/*
9214 * Get pointer to option variable, depending on local or global scope.
9215 */
9216 static char_u *
9217get_varp_scope(p, opt_flags)
9218 struct vimoption *p;
9219 int opt_flags;
9220{
9221 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9222 {
9223 if (p->var == VAR_WIN)
9224 return (char_u *)GLOBAL_WO(get_varp(p));
9225 return p->var;
9226 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009227 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 {
9229 switch ((int)p->indir)
9230 {
9231#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009232 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9233 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9234 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009236 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9237 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9238 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009239 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009240 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009241#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009242 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9243 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244#endif
9245#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009246 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9247 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009248#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009249#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9250 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9251#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009252#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009253 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 }
9256 return NULL; /* "cannot happen" */
9257 }
9258 return get_varp(p);
9259}
9260
9261/*
9262 * Get pointer to option variable.
9263 */
9264 static char_u *
9265get_varp(p)
9266 struct vimoption *p;
9267{
9268 /* hidden option, always return NULL */
9269 if (p->var == NULL)
9270 return NULL;
9271
9272 switch ((int)p->indir)
9273 {
9274 case PV_NONE: return p->var;
9275
9276 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009277 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009279 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009281 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009283 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009285 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009286 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9287#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009288 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009290 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009291 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9292#endif
9293#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009294 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009296 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9298#endif
9299#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009300 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009302 case PV_GP: return *curbuf->b_p_gp != NUL
9303 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9304 case PV_MP: return *curbuf->b_p_mp != NUL
9305 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009307#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9308 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9309 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9310#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009311#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009312 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009313 ? (char_u *)&(curwin->w_p_stl) : p->var;
9314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315
9316#ifdef FEAT_ARABIC
9317 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9318#endif
9319 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009320#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009321 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9322#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009323#ifdef FEAT_SYN_HL
9324 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9325 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327#ifdef FEAT_DIFF
9328 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9329#endif
9330#ifdef FEAT_FOLDING
9331 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9332 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9333 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9334 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9335 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9336 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9337 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9338# ifdef FEAT_EVAL
9339 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9340 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9341# endif
9342 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9343#endif
9344 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009345 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009346#ifdef FEAT_LINEBREAK
9347 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9348#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009349#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9351#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009352#ifdef FEAT_VERTSPLIT
9353 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9356 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9357#endif
9358#ifdef FEAT_RIGHTLEFT
9359 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9360 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9361#endif
9362 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9363 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9364#ifdef FEAT_LINEBREAK
9365 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9366#endif
9367#ifdef FEAT_SCROLLBIND
9368 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9369#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009370#ifdef FEAT_CURSORBIND
9371 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9372#endif
9373#ifdef FEAT_CONCEAL
9374 case PV_CONCEAL: return (char_u *)&(curwin->w_p_conceal);
9375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376
9377 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9378 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9379#ifdef FEAT_MBYTE
9380 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9381#endif
9382#if defined(FEAT_QUICKFIX)
9383 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9384 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9385#endif
9386 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9387 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9388#ifdef FEAT_CINDENT
9389 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9390 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9391 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9392#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009393#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009394 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9397 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9398#endif
9399#ifdef FEAT_COMMENTS
9400 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9401#endif
9402#ifdef FEAT_FOLDING
9403 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9404#endif
9405#ifdef FEAT_INS_EXPAND
9406 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9407#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009408#ifdef FEAT_COMPL_FUNC
9409 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009410 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009411#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9413 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9414#ifdef FEAT_MBYTE
9415 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9416#endif
9417 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9418#ifdef FEAT_AUTOCMD
9419 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9420#endif
9421 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009422 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9424 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9425 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9426 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9427#ifdef FEAT_FIND_ID
9428# ifdef FEAT_EVAL
9429 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9430# endif
9431#endif
9432#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9433 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9434 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9435#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009436#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009437 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439#ifdef FEAT_CRYPT
9440 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9441#endif
9442#ifdef FEAT_LISP
9443 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9444#endif
9445 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9446 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9447 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9448 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9449 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9450#ifdef FEAT_OSFILETYPE
9451 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9452#endif
9453 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009454#ifdef FEAT_TEXTOBJ
9455 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9456#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9458#ifdef FEAT_SMARTINDENT
9459 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9460#endif
9461#ifndef SHORT_FNAME
9462 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9463#endif
9464 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9465#ifdef FEAT_SEARCHPATH
9466 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9467#endif
9468 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9469#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009470 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009471 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9472#endif
9473#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009474 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9475 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9476 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009477#endif
9478 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9479 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9480 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9481 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009482#ifdef FEAT_PERSISTENT_UNDO
9483 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9486#ifdef FEAT_KEYMAP
9487 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9488#endif
9489 default: EMSG(_("E356: get_varp ERROR"));
9490 }
9491 /* always return a valid pointer to avoid a crash! */
9492 return (char_u *)&(curbuf->b_p_wm);
9493}
9494
9495/*
9496 * Get the value of 'equalprg', either the buffer-local one or the global one.
9497 */
9498 char_u *
9499get_equalprg()
9500{
9501 if (*curbuf->b_p_ep == NUL)
9502 return p_ep;
9503 return curbuf->b_p_ep;
9504}
9505
9506#if defined(FEAT_WINDOWS) || defined(PROTO)
9507/*
9508 * Copy options from one window to another.
9509 * Used when splitting a window.
9510 */
9511 void
9512win_copy_options(wp_from, wp_to)
9513 win_T *wp_from;
9514 win_T *wp_to;
9515{
9516 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9517 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9518# ifdef FEAT_RIGHTLEFT
9519# ifdef FEAT_FKMAP
9520 /* Is this right? */
9521 wp_to->w_farsi = wp_from->w_farsi;
9522# endif
9523# endif
9524}
9525#endif
9526
9527/*
9528 * Copy the options from one winopt_T to another.
9529 * Doesn't free the old option values in "to", use clear_winopt() for that.
9530 * The 'scroll' option is not copied, because it depends on the window height.
9531 * The 'previewwindow' option is reset, there can be only one preview window.
9532 */
9533 void
9534copy_winopt(from, to)
9535 winopt_T *from;
9536 winopt_T *to;
9537{
9538#ifdef FEAT_ARABIC
9539 to->wo_arab = from->wo_arab;
9540#endif
9541 to->wo_list = from->wo_list;
9542 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009543 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009544#ifdef FEAT_LINEBREAK
9545 to->wo_nuw = from->wo_nuw;
9546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547#ifdef FEAT_RIGHTLEFT
9548 to->wo_rl = from->wo_rl;
9549 to->wo_rlc = vim_strsave(from->wo_rlc);
9550#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009551#ifdef FEAT_STL_OPT
9552 to->wo_stl = vim_strsave(from->wo_stl);
9553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 to->wo_wrap = from->wo_wrap;
9555#ifdef FEAT_LINEBREAK
9556 to->wo_lbr = from->wo_lbr;
9557#endif
9558#ifdef FEAT_SCROLLBIND
9559 to->wo_scb = from->wo_scb;
9560#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009561#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009562 to->wo_spell = from->wo_spell;
9563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009564#ifdef FEAT_SYN_HL
9565 to->wo_cuc = from->wo_cuc;
9566 to->wo_cul = from->wo_cul;
9567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568#ifdef FEAT_DIFF
9569 to->wo_diff = from->wo_diff;
9570#endif
9571#ifdef FEAT_FOLDING
9572 to->wo_fdc = from->wo_fdc;
9573 to->wo_fen = from->wo_fen;
9574 to->wo_fdi = vim_strsave(from->wo_fdi);
9575 to->wo_fml = from->wo_fml;
9576 to->wo_fdl = from->wo_fdl;
9577 to->wo_fdm = vim_strsave(from->wo_fdm);
9578 to->wo_fdn = from->wo_fdn;
9579# ifdef FEAT_EVAL
9580 to->wo_fde = vim_strsave(from->wo_fde);
9581 to->wo_fdt = vim_strsave(from->wo_fdt);
9582# endif
9583 to->wo_fmr = vim_strsave(from->wo_fmr);
9584#endif
9585 check_winopt(to); /* don't want NULL pointers */
9586}
9587
9588/*
9589 * Check string options in a window for a NULL value.
9590 */
9591 void
9592check_win_options(win)
9593 win_T *win;
9594{
9595 check_winopt(&win->w_onebuf_opt);
9596 check_winopt(&win->w_allbuf_opt);
9597}
9598
9599/*
9600 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9601 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602 void
9603check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009604 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009605{
9606#ifdef FEAT_FOLDING
9607 check_string_option(&wop->wo_fdi);
9608 check_string_option(&wop->wo_fdm);
9609# ifdef FEAT_EVAL
9610 check_string_option(&wop->wo_fde);
9611 check_string_option(&wop->wo_fdt);
9612# endif
9613 check_string_option(&wop->wo_fmr);
9614#endif
9615#ifdef FEAT_RIGHTLEFT
9616 check_string_option(&wop->wo_rlc);
9617#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009618#ifdef FEAT_STL_OPT
9619 check_string_option(&wop->wo_stl);
9620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621}
9622
9623/*
9624 * Free the allocated memory inside a winopt_T.
9625 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009626 void
9627clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009628 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629{
9630#ifdef FEAT_FOLDING
9631 clear_string_option(&wop->wo_fdi);
9632 clear_string_option(&wop->wo_fdm);
9633# ifdef FEAT_EVAL
9634 clear_string_option(&wop->wo_fde);
9635 clear_string_option(&wop->wo_fdt);
9636# endif
9637 clear_string_option(&wop->wo_fmr);
9638#endif
9639#ifdef FEAT_RIGHTLEFT
9640 clear_string_option(&wop->wo_rlc);
9641#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009642#ifdef FEAT_STL_OPT
9643 clear_string_option(&wop->wo_stl);
9644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645}
9646
9647/*
9648 * Copy global option values to local options for one buffer.
9649 * Used when creating a new buffer and sometimes when entering a buffer.
9650 * flags:
9651 * BCO_ENTER We will enter the buf buffer.
9652 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9653 * appropriate.
9654 * BCO_NOHELP Don't copy the values to a help buffer.
9655 */
9656 void
9657buf_copy_options(buf, flags)
9658 buf_T *buf;
9659 int flags;
9660{
9661 int should_copy = TRUE;
9662 char_u *save_p_isk = NULL; /* init for GCC */
9663 int dont_do_help;
9664 int did_isk = FALSE;
9665
9666 /*
9667 * Don't do anything of the buffer is invalid.
9668 */
9669 if (buf == NULL || !buf_valid(buf))
9670 return;
9671
9672 /*
9673 * Skip this when the option defaults have not been set yet. Happens when
9674 * main() allocates the first buffer.
9675 */
9676 if (p_cpo != NULL)
9677 {
9678 /*
9679 * Always copy when entering and 'cpo' contains 'S'.
9680 * Don't copy when already initialized.
9681 * Don't copy when 'cpo' contains 's' and not entering.
9682 * 'S' BCO_ENTER initialized 's' should_copy
9683 * yes yes X X TRUE
9684 * yes no yes X FALSE
9685 * no X yes X FALSE
9686 * X no no yes FALSE
9687 * X no no no TRUE
9688 * no yes no X TRUE
9689 */
9690 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9691 && (buf->b_p_initialized
9692 || (!(flags & BCO_ENTER)
9693 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9694 should_copy = FALSE;
9695
9696 if (should_copy || (flags & BCO_ALWAYS))
9697 {
9698 /* Don't copy the options specific to a help buffer when
9699 * BCO_NOHELP is given or the options were initialized already
9700 * (jumping back to a help file with CTRL-T or CTRL-O) */
9701 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9702 || buf->b_p_initialized;
9703 if (dont_do_help) /* don't free b_p_isk */
9704 {
9705 save_p_isk = buf->b_p_isk;
9706 buf->b_p_isk = NULL;
9707 }
9708 /*
9709 * Always free the allocated strings.
9710 * If not already initialized, set 'readonly' and copy 'fileformat'.
9711 */
9712 if (!buf->b_p_initialized)
9713 {
9714 free_buf_options(buf, TRUE);
9715 buf->b_p_ro = FALSE; /* don't copy readonly */
9716 buf->b_p_tx = p_tx;
9717#ifdef FEAT_MBYTE
9718 buf->b_p_fenc = vim_strsave(p_fenc);
9719#endif
9720 buf->b_p_ff = vim_strsave(p_ff);
9721#if defined(FEAT_QUICKFIX)
9722 buf->b_p_bh = empty_option;
9723 buf->b_p_bt = empty_option;
9724#endif
9725 }
9726 else
9727 free_buf_options(buf, FALSE);
9728
9729 buf->b_p_ai = p_ai;
9730 buf->b_p_ai_nopaste = p_ai_nopaste;
9731 buf->b_p_sw = p_sw;
9732 buf->b_p_tw = p_tw;
9733 buf->b_p_tw_nopaste = p_tw_nopaste;
9734 buf->b_p_tw_nobin = p_tw_nobin;
9735 buf->b_p_wm = p_wm;
9736 buf->b_p_wm_nopaste = p_wm_nopaste;
9737 buf->b_p_wm_nobin = p_wm_nobin;
9738 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009739#ifdef FEAT_MBYTE
9740 buf->b_p_bomb = p_bomb;
9741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 buf->b_p_et = p_et;
9743 buf->b_p_et_nobin = p_et_nobin;
9744 buf->b_p_ml = p_ml;
9745 buf->b_p_ml_nobin = p_ml_nobin;
9746 buf->b_p_inf = p_inf;
9747 buf->b_p_swf = p_swf;
9748#ifdef FEAT_INS_EXPAND
9749 buf->b_p_cpt = vim_strsave(p_cpt);
9750#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009751#ifdef FEAT_COMPL_FUNC
9752 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009753 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 buf->b_p_sts = p_sts;
9756 buf->b_p_sts_nopaste = p_sts_nopaste;
9757#ifndef SHORT_FNAME
9758 buf->b_p_sn = p_sn;
9759#endif
9760#ifdef FEAT_COMMENTS
9761 buf->b_p_com = vim_strsave(p_com);
9762#endif
9763#ifdef FEAT_FOLDING
9764 buf->b_p_cms = vim_strsave(p_cms);
9765#endif
9766 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009767 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768 buf->b_p_nf = vim_strsave(p_nf);
9769 buf->b_p_mps = vim_strsave(p_mps);
9770#ifdef FEAT_SMARTINDENT
9771 buf->b_p_si = p_si;
9772#endif
9773 buf->b_p_ci = p_ci;
9774#ifdef FEAT_CINDENT
9775 buf->b_p_cin = p_cin;
9776 buf->b_p_cink = vim_strsave(p_cink);
9777 buf->b_p_cino = vim_strsave(p_cino);
9778#endif
9779#ifdef FEAT_AUTOCMD
9780 /* Don't copy 'filetype', it must be detected */
9781 buf->b_p_ft = empty_option;
9782#endif
9783#ifdef FEAT_OSFILETYPE
9784 buf->b_p_oft = vim_strsave(p_oft);
9785#endif
9786 buf->b_p_pi = p_pi;
9787#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9788 buf->b_p_cinw = vim_strsave(p_cinw);
9789#endif
9790#ifdef FEAT_LISP
9791 buf->b_p_lisp = p_lisp;
9792#endif
9793#ifdef FEAT_SYN_HL
9794 /* Don't copy 'syntax', it must be set */
9795 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009796 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009797#endif
9798#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009799 buf->b_s.b_p_spc = vim_strsave(p_spf);
9800 (void)compile_cap_prog(&buf->b_s);
9801 buf->b_s.b_p_spf = vim_strsave(p_spf);
9802 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803#endif
9804#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9805 buf->b_p_inde = vim_strsave(p_inde);
9806 buf->b_p_indk = vim_strsave(p_indk);
9807#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009808#if defined(FEAT_EVAL)
9809 buf->b_p_fex = vim_strsave(p_fex);
9810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811#ifdef FEAT_CRYPT
9812 buf->b_p_key = vim_strsave(p_key);
9813#endif
9814#ifdef FEAT_SEARCHPATH
9815 buf->b_p_sua = vim_strsave(p_sua);
9816#endif
9817#ifdef FEAT_KEYMAP
9818 buf->b_p_keymap = vim_strsave(p_keymap);
9819 buf->b_kmap_state |= KEYMAP_INIT;
9820#endif
9821 /* This isn't really an option, but copying the langmap and IME
9822 * state from the current buffer is better than resetting it. */
9823 buf->b_p_iminsert = p_iminsert;
9824 buf->b_p_imsearch = p_imsearch;
9825
9826 /* options that are normally global but also have a local value
9827 * are not copied, start using the global value */
9828 buf->b_p_ar = -1;
9829#ifdef FEAT_QUICKFIX
9830 buf->b_p_gp = empty_option;
9831 buf->b_p_mp = empty_option;
9832 buf->b_p_efm = empty_option;
9833#endif
9834 buf->b_p_ep = empty_option;
9835 buf->b_p_kp = empty_option;
9836 buf->b_p_path = empty_option;
9837 buf->b_p_tags = empty_option;
9838#ifdef FEAT_FIND_ID
9839 buf->b_p_def = empty_option;
9840 buf->b_p_inc = empty_option;
9841# ifdef FEAT_EVAL
9842 buf->b_p_inex = vim_strsave(p_inex);
9843# endif
9844#endif
9845#ifdef FEAT_INS_EXPAND
9846 buf->b_p_dict = empty_option;
9847 buf->b_p_tsr = empty_option;
9848#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009849#ifdef FEAT_TEXTOBJ
9850 buf->b_p_qe = vim_strsave(p_qe);
9851#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009852#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9853 buf->b_p_bexpr = empty_option;
9854#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009855#ifdef FEAT_PERSISTENT_UNDO
9856 buf->b_p_udf = p_udf;
9857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858
9859 /*
9860 * Don't copy the options set by ex_help(), use the saved values,
9861 * when going from a help buffer to a non-help buffer.
9862 * Don't touch these at all when BCO_NOHELP is used and going from
9863 * or to a help buffer.
9864 */
9865 if (dont_do_help)
9866 buf->b_p_isk = save_p_isk;
9867 else
9868 {
9869 buf->b_p_isk = vim_strsave(p_isk);
9870 did_isk = TRUE;
9871 buf->b_p_ts = p_ts;
9872 buf->b_help = FALSE;
9873#ifdef FEAT_QUICKFIX
9874 if (buf->b_p_bt[0] == 'h')
9875 clear_string_option(&buf->b_p_bt);
9876#endif
9877 buf->b_p_ma = p_ma;
9878 }
9879 }
9880
9881 /*
9882 * When the options should be copied (ignoring BCO_ALWAYS), set the
9883 * flag that indicates that the options have been initialized.
9884 */
9885 if (should_copy)
9886 buf->b_p_initialized = TRUE;
9887 }
9888
9889 check_buf_options(buf); /* make sure we don't have NULLs */
9890 if (did_isk)
9891 (void)buf_init_chartab(buf, FALSE);
9892}
9893
9894/*
9895 * Reset the 'modifiable' option and its default value.
9896 */
9897 void
9898reset_modifiable()
9899{
9900 int opt_idx;
9901
9902 curbuf->b_p_ma = FALSE;
9903 p_ma = FALSE;
9904 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009905 if (opt_idx >= 0)
9906 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009907}
9908
9909/*
9910 * Set the global value for 'iminsert' to the local value.
9911 */
9912 void
9913set_iminsert_global()
9914{
9915 p_iminsert = curbuf->b_p_iminsert;
9916}
9917
9918/*
9919 * Set the global value for 'imsearch' to the local value.
9920 */
9921 void
9922set_imsearch_global()
9923{
9924 p_imsearch = curbuf->b_p_imsearch;
9925}
9926
9927#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9928static int expand_option_idx = -1;
9929static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9930static int expand_option_flags = 0;
9931
9932 void
9933set_context_in_set_cmd(xp, arg, opt_flags)
9934 expand_T *xp;
9935 char_u *arg;
9936 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9937{
9938 int nextchar;
9939 long_u flags = 0; /* init for GCC */
9940 int opt_idx = 0; /* init for GCC */
9941 char_u *p;
9942 char_u *s;
9943 int is_term_option = FALSE;
9944 int key;
9945
9946 expand_option_flags = opt_flags;
9947
9948 xp->xp_context = EXPAND_SETTINGS;
9949 if (*arg == NUL)
9950 {
9951 xp->xp_pattern = arg;
9952 return;
9953 }
9954 p = arg + STRLEN(arg) - 1;
9955 if (*p == ' ' && *(p - 1) != '\\')
9956 {
9957 xp->xp_pattern = p + 1;
9958 return;
9959 }
9960 while (p > arg)
9961 {
9962 s = p;
9963 /* count number of backslashes before ' ' or ',' */
9964 if (*p == ' ' || *p == ',')
9965 {
9966 while (s > arg && *(s - 1) == '\\')
9967 --s;
9968 }
9969 /* break at a space with an even number of backslashes */
9970 if (*p == ' ' && ((p - s) & 1) == 0)
9971 {
9972 ++p;
9973 break;
9974 }
9975 --p;
9976 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00009977 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 {
9979 xp->xp_context = EXPAND_BOOL_SETTINGS;
9980 p += 2;
9981 }
9982 if (STRNCMP(p, "inv", 3) == 0)
9983 {
9984 xp->xp_context = EXPAND_BOOL_SETTINGS;
9985 p += 3;
9986 }
9987 xp->xp_pattern = arg = p;
9988 if (*arg == '<')
9989 {
9990 while (*p != '>')
9991 if (*p++ == NUL) /* expand terminal option name */
9992 return;
9993 key = get_special_key_code(arg + 1);
9994 if (key == 0) /* unknown name */
9995 {
9996 xp->xp_context = EXPAND_NOTHING;
9997 return;
9998 }
9999 nextchar = *++p;
10000 is_term_option = TRUE;
10001 expand_option_name[2] = KEY2TERMCAP0(key);
10002 expand_option_name[3] = KEY2TERMCAP1(key);
10003 }
10004 else
10005 {
10006 if (p[0] == 't' && p[1] == '_')
10007 {
10008 p += 2;
10009 if (*p != NUL)
10010 ++p;
10011 if (*p == NUL)
10012 return; /* expand option name */
10013 nextchar = *++p;
10014 is_term_option = TRUE;
10015 expand_option_name[2] = p[-2];
10016 expand_option_name[3] = p[-1];
10017 }
10018 else
10019 {
10020 /* Allow * wildcard */
10021 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10022 p++;
10023 if (*p == NUL)
10024 return;
10025 nextchar = *p;
10026 *p = NUL;
10027 opt_idx = findoption(arg);
10028 *p = nextchar;
10029 if (opt_idx == -1 || options[opt_idx].var == NULL)
10030 {
10031 xp->xp_context = EXPAND_NOTHING;
10032 return;
10033 }
10034 flags = options[opt_idx].flags;
10035 if (flags & P_BOOL)
10036 {
10037 xp->xp_context = EXPAND_NOTHING;
10038 return;
10039 }
10040 }
10041 }
10042 /* handle "-=" and "+=" */
10043 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10044 {
10045 ++p;
10046 nextchar = '=';
10047 }
10048 if ((nextchar != '=' && nextchar != ':')
10049 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10050 {
10051 xp->xp_context = EXPAND_UNSUCCESSFUL;
10052 return;
10053 }
10054 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10055 {
10056 xp->xp_context = EXPAND_OLD_SETTING;
10057 if (is_term_option)
10058 expand_option_idx = -1;
10059 else
10060 expand_option_idx = opt_idx;
10061 xp->xp_pattern = p + 1;
10062 return;
10063 }
10064 xp->xp_context = EXPAND_NOTHING;
10065 if (is_term_option || (flags & P_NUM))
10066 return;
10067
10068 xp->xp_pattern = p + 1;
10069
10070 if (flags & P_EXPAND)
10071 {
10072 p = options[opt_idx].var;
10073 if (p == (char_u *)&p_bdir
10074 || p == (char_u *)&p_dir
10075 || p == (char_u *)&p_path
10076 || p == (char_u *)&p_rtp
10077#ifdef FEAT_SEARCHPATH
10078 || p == (char_u *)&p_cdpath
10079#endif
10080#ifdef FEAT_SESSION
10081 || p == (char_u *)&p_vdir
10082#endif
10083 )
10084 {
10085 xp->xp_context = EXPAND_DIRECTORIES;
10086 if (p == (char_u *)&p_path
10087#ifdef FEAT_SEARCHPATH
10088 || p == (char_u *)&p_cdpath
10089#endif
10090 )
10091 xp->xp_backslash = XP_BS_THREE;
10092 else
10093 xp->xp_backslash = XP_BS_ONE;
10094 }
10095 else
10096 {
10097 xp->xp_context = EXPAND_FILES;
10098 /* for 'tags' need three backslashes for a space */
10099 if (p == (char_u *)&p_tags)
10100 xp->xp_backslash = XP_BS_THREE;
10101 else
10102 xp->xp_backslash = XP_BS_ONE;
10103 }
10104 }
10105
10106 /* For an option that is a list of file names, find the start of the
10107 * last file name. */
10108 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10109 {
10110 /* count number of backslashes before ' ' or ',' */
10111 if (*p == ' ' || *p == ',')
10112 {
10113 s = p;
10114 while (s > xp->xp_pattern && *(s - 1) == '\\')
10115 --s;
10116 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10117 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10118 {
10119 xp->xp_pattern = p + 1;
10120 break;
10121 }
10122 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010123
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010124#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010125 /* for 'spellsuggest' start at "file:" */
10126 if (options[opt_idx].var == (char_u *)&p_sps
10127 && STRNCMP(p, "file:", 5) == 0)
10128 {
10129 xp->xp_pattern = p + 5;
10130 break;
10131 }
10132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133 }
10134
10135 return;
10136}
10137
10138 int
10139ExpandSettings(xp, regmatch, num_file, file)
10140 expand_T *xp;
10141 regmatch_T *regmatch;
10142 int *num_file;
10143 char_u ***file;
10144{
10145 int num_normal = 0; /* Nr of matching non-term-code settings */
10146 int num_term = 0; /* Nr of matching terminal code settings */
10147 int opt_idx;
10148 int match;
10149 int count = 0;
10150 char_u *str;
10151 int loop;
10152 int is_term_opt;
10153 char_u name_buf[MAX_KEY_NAME_LEN];
10154 static char *(names[]) = {"all", "termcap"};
10155 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10156
10157 /* do this loop twice:
10158 * loop == 0: count the number of matching options
10159 * loop == 1: copy the matching options into allocated memory
10160 */
10161 for (loop = 0; loop <= 1; ++loop)
10162 {
10163 regmatch->rm_ic = ic;
10164 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10165 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010166 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10167 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10169 {
10170 if (loop == 0)
10171 num_normal++;
10172 else
10173 (*file)[count++] = vim_strsave((char_u *)names[match]);
10174 }
10175 }
10176 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10177 opt_idx++)
10178 {
10179 if (options[opt_idx].var == NULL)
10180 continue;
10181 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10182 && !(options[opt_idx].flags & P_BOOL))
10183 continue;
10184 is_term_opt = istermoption(&options[opt_idx]);
10185 if (is_term_opt && num_normal > 0)
10186 continue;
10187 match = FALSE;
10188 if (vim_regexec(regmatch, str, (colnr_T)0)
10189 || (options[opt_idx].shortname != NULL
10190 && vim_regexec(regmatch,
10191 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10192 match = TRUE;
10193 else if (is_term_opt)
10194 {
10195 name_buf[0] = '<';
10196 name_buf[1] = 't';
10197 name_buf[2] = '_';
10198 name_buf[3] = str[2];
10199 name_buf[4] = str[3];
10200 name_buf[5] = '>';
10201 name_buf[6] = NUL;
10202 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10203 {
10204 match = TRUE;
10205 str = name_buf;
10206 }
10207 }
10208 if (match)
10209 {
10210 if (loop == 0)
10211 {
10212 if (is_term_opt)
10213 num_term++;
10214 else
10215 num_normal++;
10216 }
10217 else
10218 (*file)[count++] = vim_strsave(str);
10219 }
10220 }
10221 /*
10222 * Check terminal key codes, these are not in the option table
10223 */
10224 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10225 {
10226 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10227 {
10228 if (!isprint(str[0]) || !isprint(str[1]))
10229 continue;
10230
10231 name_buf[0] = 't';
10232 name_buf[1] = '_';
10233 name_buf[2] = str[0];
10234 name_buf[3] = str[1];
10235 name_buf[4] = NUL;
10236
10237 match = FALSE;
10238 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10239 match = TRUE;
10240 else
10241 {
10242 name_buf[0] = '<';
10243 name_buf[1] = 't';
10244 name_buf[2] = '_';
10245 name_buf[3] = str[0];
10246 name_buf[4] = str[1];
10247 name_buf[5] = '>';
10248 name_buf[6] = NUL;
10249
10250 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10251 match = TRUE;
10252 }
10253 if (match)
10254 {
10255 if (loop == 0)
10256 num_term++;
10257 else
10258 (*file)[count++] = vim_strsave(name_buf);
10259 }
10260 }
10261
10262 /*
10263 * Check special key names.
10264 */
10265 regmatch->rm_ic = TRUE; /* ignore case here */
10266 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10267 {
10268 name_buf[0] = '<';
10269 STRCPY(name_buf + 1, str);
10270 STRCAT(name_buf, ">");
10271
10272 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10273 {
10274 if (loop == 0)
10275 num_term++;
10276 else
10277 (*file)[count++] = vim_strsave(name_buf);
10278 }
10279 }
10280 }
10281 if (loop == 0)
10282 {
10283 if (num_normal > 0)
10284 *num_file = num_normal;
10285 else if (num_term > 0)
10286 *num_file = num_term;
10287 else
10288 return OK;
10289 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10290 if (*file == NULL)
10291 {
10292 *file = (char_u **)"";
10293 return FAIL;
10294 }
10295 }
10296 }
10297 return OK;
10298}
10299
10300 int
10301ExpandOldSetting(num_file, file)
10302 int *num_file;
10303 char_u ***file;
10304{
10305 char_u *var = NULL; /* init for GCC */
10306 char_u *buf;
10307
10308 *num_file = 0;
10309 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10310 if (*file == NULL)
10311 return FAIL;
10312
10313 /*
10314 * For a terminal key code expand_option_idx is < 0.
10315 */
10316 if (expand_option_idx < 0)
10317 {
10318 var = find_termcode(expand_option_name + 2);
10319 if (var == NULL)
10320 expand_option_idx = findoption(expand_option_name);
10321 }
10322
10323 if (expand_option_idx >= 0)
10324 {
10325 /* put string of option value in NameBuff */
10326 option_value2string(&options[expand_option_idx], expand_option_flags);
10327 var = NameBuff;
10328 }
10329 else if (var == NULL)
10330 var = (char_u *)"";
10331
10332 /* A backslash is required before some characters. This is the reverse of
10333 * what happens in do_set(). */
10334 buf = vim_strsave_escaped(var, escape_chars);
10335
10336 if (buf == NULL)
10337 {
10338 vim_free(*file);
10339 *file = NULL;
10340 return FAIL;
10341 }
10342
10343#ifdef BACKSLASH_IN_FILENAME
10344 /* For MS-Windows et al. we don't double backslashes at the start and
10345 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010346 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347 if (var[0] == '\\' && var[1] == '\\'
10348 && expand_option_idx >= 0
10349 && (options[expand_option_idx].flags & P_EXPAND)
10350 && vim_isfilec(var[2])
10351 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010352 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353#endif
10354
10355 *file[0] = buf;
10356 *num_file = 1;
10357 return OK;
10358}
10359#endif
10360
10361/*
10362 * Get the value for the numeric or string option *opp in a nice format into
10363 * NameBuff[]. Must not be called with a hidden option!
10364 */
10365 static void
10366option_value2string(opp, opt_flags)
10367 struct vimoption *opp;
10368 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10369{
10370 char_u *varp;
10371
10372 varp = get_varp_scope(opp, opt_flags);
10373
10374 if (opp->flags & P_NUM)
10375 {
10376 long wc = 0;
10377
10378 if (wc_use_keyname(varp, &wc))
10379 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10380 else if (wc != 0)
10381 STRCPY(NameBuff, transchar((int)wc));
10382 else
10383 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10384 }
10385 else /* P_STRING */
10386 {
10387 varp = *(char_u **)(varp);
10388 if (varp == NULL) /* just in case */
10389 NameBuff[0] = NUL;
10390#ifdef FEAT_CRYPT
10391 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010392 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 STRCPY(NameBuff, "*****");
10394#endif
10395 else if (opp->flags & P_EXPAND)
10396 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10397 /* Translate 'pastetoggle' into special key names */
10398 else if ((char_u **)opp->var == &p_pt)
10399 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10400 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010401 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 }
10403}
10404
10405/*
10406 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10407 * printed as a keyname.
10408 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10409 */
10410 static int
10411wc_use_keyname(varp, wcp)
10412 char_u *varp;
10413 long *wcp;
10414{
10415 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10416 {
10417 *wcp = *(long *)varp;
10418 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10419 return TRUE;
10420 }
10421 return FALSE;
10422}
10423
10424#ifdef FEAT_LANGMAP
10425/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010426 * Any character has an equivalent 'langmap' character. This is used for
10427 * keyboards that have a special language mode that sends characters above
10428 * 128 (although other characters can be translated too). The "to" field is a
10429 * Vim command character. This avoids having to switch the keyboard back to
10430 * ASCII mode when leaving Insert mode.
10431 *
10432 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10433 * commands.
10434 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10435 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10436 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010438# ifdef FEAT_MBYTE
10439/*
10440 * With multi-byte support use growarray for 'langmap' chars >= 256
10441 */
10442typedef struct
10443{
10444 int from;
10445 int to;
10446} langmap_entry_T;
10447
10448static garray_T langmap_mapga;
10449static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010450
10451/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010452 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10453 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010455 static void
10456langmap_set_entry(from, to)
10457 int from;
10458 int to;
10459{
10460 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10461 int a = 0;
10462 int b = langmap_mapga.ga_len;
10463
10464 /* Do a binary search for an existing entry. */
10465 while (a != b)
10466 {
10467 int i = (a + b) / 2;
10468 int d = entries[i].from - from;
10469
10470 if (d == 0)
10471 {
10472 entries[i].to = to;
10473 return;
10474 }
10475 if (d < 0)
10476 a = i + 1;
10477 else
10478 b = i;
10479 }
10480
10481 if (ga_grow(&langmap_mapga, 1) != OK)
10482 return; /* out of memory */
10483
10484 /* insert new entry at position "a" */
10485 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10486 mch_memmove(entries + 1, entries,
10487 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10488 ++langmap_mapga.ga_len;
10489 entries[0].from = from;
10490 entries[0].to = to;
10491}
10492
10493/*
10494 * Apply 'langmap' to multi-byte character "c" and return the result.
10495 */
10496 int
10497langmap_adjust_mb(c)
10498 int c;
10499{
10500 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10501 int a = 0;
10502 int b = langmap_mapga.ga_len;
10503
10504 while (a != b)
10505 {
10506 int i = (a + b) / 2;
10507 int d = entries[i].from - c;
10508
10509 if (d == 0)
10510 return entries[i].to; /* found matching entry */
10511 if (d < 0)
10512 a = i + 1;
10513 else
10514 b = i;
10515 }
10516 return c; /* no entry found, return "c" unmodified */
10517}
10518# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519
10520 static void
10521langmap_init()
10522{
10523 int i;
10524
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010525 for (i = 0; i < 256; i++)
10526 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10527# ifdef FEAT_MBYTE
10528 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10529# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530}
10531
10532/*
10533 * Called when langmap option is set; the language map can be
10534 * changed at any time!
10535 */
10536 static void
10537langmap_set()
10538{
10539 char_u *p;
10540 char_u *p2;
10541 int from, to;
10542
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010543#ifdef FEAT_MBYTE
10544 ga_clear(&langmap_mapga); /* clear the previous map first */
10545#endif
10546 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547
10548 for (p = p_langmap; p[0] != NUL; )
10549 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010550 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10551 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552 {
10553 if (p2[0] == '\\' && p2[1] != NUL)
10554 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 }
10556 if (p2[0] == ';')
10557 ++p2; /* abcd;ABCD form, p2 points to A */
10558 else
10559 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10560 while (p[0])
10561 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010562 if (p[0] == ',')
10563 {
10564 ++p;
10565 break;
10566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 if (p[0] == '\\' && p[1] != NUL)
10568 ++p;
10569#ifdef FEAT_MBYTE
10570 from = (*mb_ptr2char)(p);
10571#else
10572 from = p[0];
10573#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010574 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 if (p2 == NULL)
10576 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010577 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010578 if (p[0] != ',')
10579 {
10580 if (p[0] == '\\')
10581 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010583 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010585 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010587 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 }
10589 else
10590 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010591 if (p2[0] != ',')
10592 {
10593 if (p2[0] == '\\')
10594 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010596 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010598 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 }
10602 if (to == NUL)
10603 {
10604 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10605 transchar(from));
10606 return;
10607 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010608
10609#ifdef FEAT_MBYTE
10610 if (from >= 256)
10611 langmap_set_entry(from, to);
10612 else
10613#endif
10614 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615
10616 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010617 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010618 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010620 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621 if (*p == ';')
10622 {
10623 p = p2;
10624 if (p[0] != NUL)
10625 {
10626 if (p[0] != ',')
10627 {
10628 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10629 return;
10630 }
10631 ++p;
10632 }
10633 break;
10634 }
10635 }
10636 }
10637 }
10638}
10639#endif
10640
10641/*
10642 * Return TRUE if format option 'x' is in effect.
10643 * Take care of no formatting when 'paste' is set.
10644 */
10645 int
10646has_format_option(x)
10647 int x;
10648{
10649 if (p_paste)
10650 return FALSE;
10651 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10652}
10653
10654/*
10655 * Return TRUE if "x" is present in 'shortmess' option, or
10656 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10657 */
10658 int
10659shortmess(x)
10660 int x;
10661{
10662 return ( vim_strchr(p_shm, x) != NULL
10663 || (vim_strchr(p_shm, 'a') != NULL
10664 && vim_strchr((char_u *)SHM_A, x) != NULL));
10665}
10666
10667/*
10668 * paste_option_changed() - Called after p_paste was set or reset.
10669 */
10670 static void
10671paste_option_changed()
10672{
10673 static int old_p_paste = FALSE;
10674 static int save_sm = 0;
10675#ifdef FEAT_CMDL_INFO
10676 static int save_ru = 0;
10677#endif
10678#ifdef FEAT_RIGHTLEFT
10679 static int save_ri = 0;
10680 static int save_hkmap = 0;
10681#endif
10682 buf_T *buf;
10683
10684 if (p_paste)
10685 {
10686 /*
10687 * Paste switched from off to on.
10688 * Save the current values, so they can be restored later.
10689 */
10690 if (!old_p_paste)
10691 {
10692 /* save options for each buffer */
10693 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10694 {
10695 buf->b_p_tw_nopaste = buf->b_p_tw;
10696 buf->b_p_wm_nopaste = buf->b_p_wm;
10697 buf->b_p_sts_nopaste = buf->b_p_sts;
10698 buf->b_p_ai_nopaste = buf->b_p_ai;
10699 }
10700
10701 /* save global options */
10702 save_sm = p_sm;
10703#ifdef FEAT_CMDL_INFO
10704 save_ru = p_ru;
10705#endif
10706#ifdef FEAT_RIGHTLEFT
10707 save_ri = p_ri;
10708 save_hkmap = p_hkmap;
10709#endif
10710 /* save global values for local buffer options */
10711 p_tw_nopaste = p_tw;
10712 p_wm_nopaste = p_wm;
10713 p_sts_nopaste = p_sts;
10714 p_ai_nopaste = p_ai;
10715 }
10716
10717 /*
10718 * Always set the option values, also when 'paste' is set when it is
10719 * already on.
10720 */
10721 /* set options for each buffer */
10722 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10723 {
10724 buf->b_p_tw = 0; /* textwidth is 0 */
10725 buf->b_p_wm = 0; /* wrapmargin is 0 */
10726 buf->b_p_sts = 0; /* softtabstop is 0 */
10727 buf->b_p_ai = 0; /* no auto-indent */
10728 }
10729
10730 /* set global options */
10731 p_sm = 0; /* no showmatch */
10732#ifdef FEAT_CMDL_INFO
10733# ifdef FEAT_WINDOWS
10734 if (p_ru)
10735 status_redraw_all(); /* redraw to remove the ruler */
10736# endif
10737 p_ru = 0; /* no ruler */
10738#endif
10739#ifdef FEAT_RIGHTLEFT
10740 p_ri = 0; /* no reverse insert */
10741 p_hkmap = 0; /* no Hebrew keyboard */
10742#endif
10743 /* set global values for local buffer options */
10744 p_tw = 0;
10745 p_wm = 0;
10746 p_sts = 0;
10747 p_ai = 0;
10748 }
10749
10750 /*
10751 * Paste switched from on to off: Restore saved values.
10752 */
10753 else if (old_p_paste)
10754 {
10755 /* restore options for each buffer */
10756 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10757 {
10758 buf->b_p_tw = buf->b_p_tw_nopaste;
10759 buf->b_p_wm = buf->b_p_wm_nopaste;
10760 buf->b_p_sts = buf->b_p_sts_nopaste;
10761 buf->b_p_ai = buf->b_p_ai_nopaste;
10762 }
10763
10764 /* restore global options */
10765 p_sm = save_sm;
10766#ifdef FEAT_CMDL_INFO
10767# ifdef FEAT_WINDOWS
10768 if (p_ru != save_ru)
10769 status_redraw_all(); /* redraw to draw the ruler */
10770# endif
10771 p_ru = save_ru;
10772#endif
10773#ifdef FEAT_RIGHTLEFT
10774 p_ri = save_ri;
10775 p_hkmap = save_hkmap;
10776#endif
10777 /* set global values for local buffer options */
10778 p_tw = p_tw_nopaste;
10779 p_wm = p_wm_nopaste;
10780 p_sts = p_sts_nopaste;
10781 p_ai = p_ai_nopaste;
10782 }
10783
10784 old_p_paste = p_paste;
10785}
10786
10787/*
10788 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10789 *
10790 * Reset 'compatible' and set the values for options that didn't get set yet
10791 * to the Vim defaults.
10792 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010793 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794 */
10795 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010796vimrc_found(fname, envname)
10797 char_u *fname;
10798 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010800 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010801 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010802 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803
10804 if (!option_was_set((char_u *)"cp"))
10805 {
10806 p_cp = FALSE;
10807 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10808 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10809 set_option_default(opt_idx, OPT_FREE, FALSE);
10810 didset_options();
10811 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010812
10813 if (fname != NULL)
10814 {
10815 p = vim_getenv(envname, &dofree);
10816 if (p == NULL)
10817 {
10818 /* Set $MYVIMRC to the first vimrc file found. */
10819 p = FullName_save(fname, FALSE);
10820 if (p != NULL)
10821 {
10822 vim_setenv(envname, p);
10823 vim_free(p);
10824 }
10825 }
10826 else if (dofree)
10827 vim_free(p);
10828 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829}
10830
10831/*
10832 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10833 */
10834 void
10835change_compatible(on)
10836 int on;
10837{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010838 int opt_idx;
10839
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 if (p_cp != on)
10841 {
10842 p_cp = on;
10843 compatible_set();
10844 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010845 opt_idx = findoption((char_u *)"cp");
10846 if (opt_idx >= 0)
10847 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848}
10849
10850/*
10851 * Return TRUE when option "name" has been set.
10852 */
10853 int
10854option_was_set(name)
10855 char_u *name;
10856{
10857 int idx;
10858
10859 idx = findoption(name);
10860 if (idx < 0) /* unknown option */
10861 return FALSE;
10862 if (options[idx].flags & P_WAS_SET)
10863 return TRUE;
10864 return FALSE;
10865}
10866
10867/*
10868 * compatible_set() - Called when 'compatible' has been set or unset.
10869 *
10870 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10871 * flag) to a Vi compatible value.
10872 * When 'compatible' is unset: Set all options that have a different default
10873 * for Vim (without the P_VI_DEF flag) to that default.
10874 */
10875 static void
10876compatible_set()
10877{
10878 int opt_idx;
10879
10880 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10881 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10882 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10883 set_option_default(opt_idx, OPT_FREE, p_cp);
10884 didset_options();
10885}
10886
10887#ifdef FEAT_LINEBREAK
10888
10889# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10890 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010891 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892# endif
10893
10894/*
10895 * fill_breakat_flags() -- called when 'breakat' changes value.
10896 */
10897 static void
10898fill_breakat_flags()
10899{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010900 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901 int i;
10902
10903 for (i = 0; i < 256; i++)
10904 breakat_flags[i] = FALSE;
10905
10906 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010907 for (p = p_breakat; *p; p++)
10908 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909}
10910
10911# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010912 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913# endif
10914
10915#endif
10916
10917/*
10918 * Check an option that can be a range of string values.
10919 *
10920 * Return OK for correct value, FAIL otherwise.
10921 * Empty is always OK.
10922 */
10923 static int
10924check_opt_strings(val, values, list)
10925 char_u *val;
10926 char **values;
10927 int list; /* when TRUE: accept a list of values */
10928{
10929 return opt_strings_flags(val, values, NULL, list);
10930}
10931
10932/*
10933 * Handle an option that can be a range of string values.
10934 * Set a flag in "*flagp" for each string present.
10935 *
10936 * Return OK for correct value, FAIL otherwise.
10937 * Empty is always OK.
10938 */
10939 static int
10940opt_strings_flags(val, values, flagp, list)
10941 char_u *val; /* new value */
10942 char **values; /* array of valid string values */
10943 unsigned *flagp;
10944 int list; /* when TRUE: accept a list of values */
10945{
10946 int i;
10947 int len;
10948 unsigned new_flags = 0;
10949
10950 while (*val)
10951 {
10952 for (i = 0; ; ++i)
10953 {
10954 if (values[i] == NULL) /* val not found in values[] */
10955 return FAIL;
10956
10957 len = (int)STRLEN(values[i]);
10958 if (STRNCMP(values[i], val, len) == 0
10959 && ((list && val[len] == ',') || val[len] == NUL))
10960 {
10961 val += len + (val[len] == ',');
10962 new_flags |= (1 << i);
10963 break; /* check next item in val list */
10964 }
10965 }
10966 }
10967 if (flagp != NULL)
10968 *flagp = new_flags;
10969
10970 return OK;
10971}
10972
10973/*
10974 * Read the 'wildmode' option, fill wim_flags[].
10975 */
10976 static int
10977check_opt_wim()
10978{
10979 char_u new_wim_flags[4];
10980 char_u *p;
10981 int i;
10982 int idx = 0;
10983
10984 for (i = 0; i < 4; ++i)
10985 new_wim_flags[i] = 0;
10986
10987 for (p = p_wim; *p; ++p)
10988 {
10989 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10990 ;
10991 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10992 return FAIL;
10993 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10994 new_wim_flags[idx] |= WIM_LONGEST;
10995 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10996 new_wim_flags[idx] |= WIM_FULL;
10997 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10998 new_wim_flags[idx] |= WIM_LIST;
10999 else
11000 return FAIL;
11001 p += i;
11002 if (*p == NUL)
11003 break;
11004 if (*p == ',')
11005 {
11006 if (idx == 3)
11007 return FAIL;
11008 ++idx;
11009 }
11010 }
11011
11012 /* fill remaining entries with last flag */
11013 while (idx < 3)
11014 {
11015 new_wim_flags[idx + 1] = new_wim_flags[idx];
11016 ++idx;
11017 }
11018
11019 /* only when there are no errors, wim_flags[] is changed */
11020 for (i = 0; i < 4; ++i)
11021 wim_flags[i] = new_wim_flags[i];
11022 return OK;
11023}
11024
11025/*
11026 * Check if backspacing over something is allowed.
11027 */
11028 int
11029can_bs(what)
11030 int what; /* BS_INDENT, BS_EOL or BS_START */
11031{
11032 switch (*p_bs)
11033 {
11034 case '2': return TRUE;
11035 case '1': return (what != BS_START);
11036 case '0': return FALSE;
11037 }
11038 return vim_strchr(p_bs, what) != NULL;
11039}
11040
11041/*
11042 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11043 * the file must be considered changed when the value is different.
11044 */
11045 void
11046save_file_ff(buf)
11047 buf_T *buf;
11048{
11049 buf->b_start_ffc = *buf->b_p_ff;
11050 buf->b_start_eol = buf->b_p_eol;
11051#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011052 buf->b_start_bomb = buf->b_p_bomb;
11053
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 /* Only use free/alloc when necessary, they take time. */
11055 if (buf->b_start_fenc == NULL
11056 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11057 {
11058 vim_free(buf->b_start_fenc);
11059 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11060 }
11061#endif
11062}
11063
11064/*
11065 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11066 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011067 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11068 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069 * Don't consider a new, empty buffer to be changed.
11070 */
11071 int
11072file_ff_differs(buf)
11073 buf_T *buf;
11074{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011075 /* In a buffer that was never loaded the options are not valid. */
11076 if (buf->b_flags & BF_NEVERLOADED)
11077 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 if ((buf->b_flags & BF_NEW)
11079 && buf->b_ml.ml_line_count == 1
11080 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11081 return FALSE;
11082 if (buf->b_start_ffc != *buf->b_p_ff)
11083 return TRUE;
11084 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11085 return TRUE;
11086#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011087 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11088 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 if (buf->b_start_fenc == NULL)
11090 return (*buf->b_p_fenc != NUL);
11091 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11092#else
11093 return FALSE;
11094#endif
11095}
11096
11097/*
11098 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11099 */
11100 int
11101check_ff_value(p)
11102 char_u *p;
11103{
11104 return check_opt_strings(p, p_ff_values, FALSE);
11105}